@things-factory/operato-mms 3.8.19 → 3.8.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.js +66 -29
- package/dist-server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.js.map +1 -1
- package/package.json +4 -4
- package/server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.ts +89 -53
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.warehouseMarketplaceProduct = exports.warehouseMarketplaceProductsResolver = void 0;
|
|
4
4
|
const biz_base_1 = require("@things-factory/biz-base");
|
|
5
|
-
const product_base_1 = require("@things-factory/product-base");
|
|
6
5
|
exports.warehouseMarketplaceProductsResolver = {
|
|
7
6
|
async warehouseMarketplaceProducts(_, params, context) {
|
|
8
7
|
try {
|
|
@@ -33,7 +32,7 @@ async function warehouseMarketplaceProduct(params, domain, user, tx) {
|
|
|
33
32
|
OR Lower("Product"."description") LIKE '${productInfo.value.toLowerCase()}')`;
|
|
34
33
|
}
|
|
35
34
|
await tx.query(`
|
|
36
|
-
CREATE TEMP TABLE "temp_products" AS (
|
|
35
|
+
CREATE TEMP TABLE "temp_products" ON COMMIT DROP AS (
|
|
37
36
|
SELECT * FROM (
|
|
38
37
|
SELECT "Product"."id" AS "product_id", "Product"."sku" AS "product_sku", "Product"."name" AS "product_name",
|
|
39
38
|
"Product"."description" AS "product_description", "Product"."creator_id", "Product"."updater_id",
|
|
@@ -59,7 +58,47 @@ async function warehouseMarketplaceProduct(params, domain, user, tx) {
|
|
|
59
58
|
)
|
|
60
59
|
`);
|
|
61
60
|
await tx.query(`
|
|
62
|
-
CREATE TEMP TABLE "
|
|
61
|
+
CREATE TEMP TABLE "temp_inventory" ON COMMIT DROP AS (
|
|
62
|
+
select "fc"."id" as "fulfillment_id", "fc"."name" as "fulfillment_name",
|
|
63
|
+
"i2"."product_id", SUM(greatest(coalesce("locked_qty",0),0) + greatest(coalesce(oi.release_qty,0),0)) as "inventory_locked_qty", sum(coalesce("qty",0)) as "inventory_qty",
|
|
64
|
+
"i2"."domain_id"
|
|
65
|
+
from inventories "i2"
|
|
66
|
+
inner join warehouses "w" on "w"."id" = "i2"."warehouse_id"
|
|
67
|
+
inner join domains "d2" on "d2"."id" = "w"."domain_id" and "d2"."ext_type" ='warehouse'
|
|
68
|
+
inner join fulfillment_centers "fc" ON "fc"."center_id" = "d2"."subdomain"
|
|
69
|
+
inner join (
|
|
70
|
+
select case when "Product"."type" = 'PRODUCT' then "Product"."product_id" else "pbs"."product_id" end as "product_id"
|
|
71
|
+
from temp_products "Product"
|
|
72
|
+
left join product_bundles "pb" on "pb"."id" = "Product"."product_id"
|
|
73
|
+
left join product_bundle_settings "pbs" on "pbs"."product_bundle_id" = "pb"."id"
|
|
74
|
+
) "Product" on "Product"."product_id" = "i2"."product_id"
|
|
75
|
+
left join (
|
|
76
|
+
SELECT
|
|
77
|
+
SUM(oi.release_qty) AS release_qty, SUM(oi.release_uom_value) AS release_uom_value, oi.batch_id, oi.batch_id_ref,
|
|
78
|
+
oi.product_id, p.product_name, oi.packing_type, oi.packing_size, oi.uom
|
|
79
|
+
FROM
|
|
80
|
+
order_inventories oi
|
|
81
|
+
LEFT JOIN
|
|
82
|
+
temp_products p ON oi.product_id = p.product_id
|
|
83
|
+
INNER JOIN
|
|
84
|
+
domains d2 on d2.id = oi.domain_id and d2.ext_type ='warehouse'
|
|
85
|
+
INNER JOIN
|
|
86
|
+
fulfillment_centers fc ON fc.center_id = d2.subdomain
|
|
87
|
+
WHERE
|
|
88
|
+
fc.domain_id = $1
|
|
89
|
+
AND (oi.status = 'PENDING' or oi.status = 'PENDING_RECEIVE' or oi.status = 'PENDING_WORKSHEET' or oi.status = 'PENDING_SPLIT')
|
|
90
|
+
AND oi.batch_id NOTNULL AND oi.product_id NOTNULL AND oi.packing_type NOTNULL AND oi.packing_size NOTNULL AND oi.inventory_id IS NULL
|
|
91
|
+
GROUP BY
|
|
92
|
+
oi.batch_id, oi.batch_id_ref, oi.product_id, oi.packing_type,
|
|
93
|
+
oi.packing_size, oi.uom, p.product_name
|
|
94
|
+
)"oi" ON "i2".batch_id = "oi".batch_id AND "Product"."product_id" = "oi".product_id AND "i2".packing_type = "oi".packing_type AND "i2".packing_size = oi.packing_size AND "i2".uom = oi.uom
|
|
95
|
+
where "fc"."domain_id" = $1
|
|
96
|
+
and "i2"."status" = 'STORED'
|
|
97
|
+
group by "i2"."domain_id", "fc"."id", "fc"."name", "i2"."product_id"
|
|
98
|
+
)
|
|
99
|
+
`, [domain.id]);
|
|
100
|
+
await tx.query(`
|
|
101
|
+
CREATE TEMP TABLE "temp_json_warehouse_marketplace_products" ON COMMIT DROP AS (
|
|
63
102
|
select "product_id", array_to_json(array_agg(row_to_json(dt))) AS "Json_marketplaceProducts" FROM (
|
|
64
103
|
select "dt"."marketplace_store_id", "dt"."product_id", "dt"."sku", array_agg(row_to_json(dt)) as product_variation
|
|
65
104
|
from (
|
|
@@ -75,32 +114,33 @@ async function warehouseMarketplaceProduct(params, domain, user, tx) {
|
|
|
75
114
|
)
|
|
76
115
|
`);
|
|
77
116
|
await tx.query(`
|
|
78
|
-
CREATE TEMP TABLE temp_json_warehouse_inventory AS (
|
|
117
|
+
CREATE TEMP TABLE temp_json_warehouse_inventory ON COMMIT DROP AS (
|
|
79
118
|
select "product_id", array_to_json(array_agg((row_to_json("dt")))) AS "Json_warehouseInventory" from(
|
|
80
|
-
select "
|
|
81
|
-
"
|
|
82
|
-
from
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
119
|
+
select "domain_id", "fulfillment_id", "fulfillment_name",
|
|
120
|
+
"product_id", "inventory_locked_qty", "inventory_qty"
|
|
121
|
+
from temp_inventory
|
|
122
|
+
union
|
|
123
|
+
select "bundledInv"."domain_id", "bundledInv"."fulfillment_id", "bundledInv"."fulfillment_name", "bundledInv"."product_id",
|
|
124
|
+
max("bundledInv"."inventory_locked_qty") as "inventory_locked_qty", min("bundledInv"."inventory_qty") as "inventory_qty" from (
|
|
125
|
+
select "Product"."product_id", fc.domain_id, "fc"."id" as "fulfillment_id", "fc"."name" as "fulfillment_name",
|
|
126
|
+
"pbs"."bundle_qty",
|
|
127
|
+
case when "pbs"."bundle_qty" <= 0 then 0 else ceil(greatest("i2"."inventory_locked_qty",0)/ "pbs"."bundle_qty") end AS "inventory_locked_qty",
|
|
128
|
+
case when "pbs"."bundle_qty" <= 0 then 0 else floor(greatest("i2"."inventory_qty", 0)/ "pbs"."bundle_qty") end AS "inventory_qty"
|
|
129
|
+
from temp_products "Product"
|
|
130
|
+
inner join product_bundle_settings pbs ON pbs.product_bundle_id = "Product"."product_id"
|
|
131
|
+
inner join products p on p.id = pbs.product_id
|
|
132
|
+
cross join fulfillment_centers fc
|
|
133
|
+
inner join domains "d2" on "d2"."ext_type" ='warehouse' and "fc"."center_id" = "d2"."subdomain"
|
|
134
|
+
left join temp_inventory i2 ON i2.product_id = pbs.product_id and "d2"."id" = "i2"."domain_id"
|
|
135
|
+
where "fc"."domain_id" = $1
|
|
136
|
+
order by fc.id, "Product"."product_sku", p.sku
|
|
137
|
+
) "bundledInv"
|
|
138
|
+
group by "domain_id","fulfillment_id","fulfillment_name","product_id"
|
|
99
139
|
) "dt" group by "dt"."product_id"
|
|
100
140
|
)
|
|
101
|
-
|
|
102
|
-
await tx.
|
|
103
|
-
|
|
141
|
+
`, [domain.id]);
|
|
142
|
+
await tx.query(`
|
|
143
|
+
CREATE TEMP TABLE temp_warehouse_marketplace_products ON COMMIT DROP as (
|
|
104
144
|
SELECT "Product"."product_id" AS "Product_id", "Product"."product_sku" AS "Product_sku",
|
|
105
145
|
"Product"."product_name" AS "Product_name", "Product"."product_description" AS "Product_description",
|
|
106
146
|
"Product"."product_bizplace_id" AS "Product_bizplace_id",
|
|
@@ -126,9 +166,6 @@ async function warehouseMarketplaceProduct(params, domain, user, tx) {
|
|
|
126
166
|
const total = await tx.query(`select count(*) from temp_warehouse_marketplace_products`);
|
|
127
167
|
const items = await tx.query(`
|
|
128
168
|
select * from temp_warehouse_marketplace_products ${offsetQuery}
|
|
129
|
-
`);
|
|
130
|
-
tx.query(`
|
|
131
|
-
drop table temp_products, temp_json_warehouse_marketplace_products, temp_json_warehouse_inventory, temp_warehouse_marketplace_products
|
|
132
169
|
`);
|
|
133
170
|
return {
|
|
134
171
|
items: items.map((itm, index) => {
|
package/dist-server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"warehouse-marketplace-products.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.ts"],"names":[],"mappings":";;;AAGA,uDAAsF;
|
|
1
|
+
{"version":3,"file":"warehouse-marketplace-products.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.ts"],"names":[],"mappings":";;;AAGA,uDAAsF;AAIzE,QAAA,oCAAoC,GAAG;IAClD,KAAK,CAAC,4BAA4B,CAAC,CAAM,EAAE,MAAiB,EAAE,OAAY;QACxE,IAAI;YACF,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAsD,OAAO,CAAC,KAAK,CAAA;YAC7F,OAAO,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;SAC7D;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;CACF,CAAA;AAEM,KAAK,UAAU,2BAA2B,CAAC,MAAiB,EAAE,MAAc,EAAE,IAAU,EAAE,EAAkB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AAC,CAAC,CAAC;yBAClG,CAAA;oBACH,CAAC,CAAC;oBACF,CAAC,CAAC,IAAI;aACT,CAAA;QACH,CAAC,CAAC;QACF,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK;KACtB,CAAA;AACH,CAAC;AAhND,kEAgNC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/operato-mms",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.21",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@things-factory/integration-fulfillment": "^3.8.19",
|
|
62
62
|
"@things-factory/integration-lmd": "^3.8.19",
|
|
63
63
|
"@things-factory/lite-menu": "^3.8.0",
|
|
64
|
-
"@things-factory/marketplace-base": "^3.8.
|
|
64
|
+
"@things-factory/marketplace-base": "^3.8.21",
|
|
65
65
|
"@things-factory/more-ui": "^3.8.0",
|
|
66
66
|
"@things-factory/notification": "^3.8.0",
|
|
67
67
|
"@things-factory/oauth2-client": "^3.8.0",
|
|
@@ -99,11 +99,11 @@
|
|
|
99
99
|
"@things-factory/scene-wheel-sorter": "^3.7.5",
|
|
100
100
|
"@things-factory/setting-ui": "^3.8.19",
|
|
101
101
|
"@things-factory/system-ui": "^3.8.0",
|
|
102
|
-
"@things-factory/warehouse-base": "^3.8.
|
|
102
|
+
"@things-factory/warehouse-base": "^3.8.21"
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": {
|
|
105
105
|
"@things-factory/builder": "^3.7.5",
|
|
106
106
|
"@types/node-fetch": "^2.5.7"
|
|
107
107
|
},
|
|
108
|
-
"gitHead": "
|
|
108
|
+
"gitHead": "38e4bc33b7191c172a8516aac6ab3019fa12dac1"
|
|
109
109
|
}
|
|
@@ -40,7 +40,7 @@ export async function warehouseMarketplaceProduct(params: ListParam, domain: Dom
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
await tx.query(`
|
|
43
|
-
CREATE TEMP TABLE "temp_products" AS (
|
|
43
|
+
CREATE TEMP TABLE "temp_products" ON COMMIT DROP AS (
|
|
44
44
|
SELECT * FROM (
|
|
45
45
|
SELECT "Product"."id" AS "product_id", "Product"."sku" AS "product_sku", "Product"."name" AS "product_name",
|
|
46
46
|
"Product"."description" AS "product_description", "Product"."creator_id", "Product"."updater_id",
|
|
@@ -67,7 +67,48 @@ export async function warehouseMarketplaceProduct(params: ListParam, domain: Dom
|
|
|
67
67
|
`)
|
|
68
68
|
|
|
69
69
|
await tx.query(`
|
|
70
|
-
CREATE TEMP TABLE "
|
|
70
|
+
CREATE TEMP TABLE "temp_inventory" ON COMMIT DROP AS (
|
|
71
|
+
select "fc"."id" as "fulfillment_id", "fc"."name" as "fulfillment_name",
|
|
72
|
+
"i2"."product_id", SUM(greatest(coalesce("locked_qty",0),0) + greatest(coalesce(oi.release_qty,0),0)) as "inventory_locked_qty", sum(coalesce("qty",0)) as "inventory_qty",
|
|
73
|
+
"i2"."domain_id"
|
|
74
|
+
from inventories "i2"
|
|
75
|
+
inner join warehouses "w" on "w"."id" = "i2"."warehouse_id"
|
|
76
|
+
inner join domains "d2" on "d2"."id" = "w"."domain_id" and "d2"."ext_type" ='warehouse'
|
|
77
|
+
inner join fulfillment_centers "fc" ON "fc"."center_id" = "d2"."subdomain"
|
|
78
|
+
inner join (
|
|
79
|
+
select case when "Product"."type" = 'PRODUCT' then "Product"."product_id" else "pbs"."product_id" end as "product_id"
|
|
80
|
+
from temp_products "Product"
|
|
81
|
+
left join product_bundles "pb" on "pb"."id" = "Product"."product_id"
|
|
82
|
+
left join product_bundle_settings "pbs" on "pbs"."product_bundle_id" = "pb"."id"
|
|
83
|
+
) "Product" on "Product"."product_id" = "i2"."product_id"
|
|
84
|
+
left join (
|
|
85
|
+
SELECT
|
|
86
|
+
SUM(oi.release_qty) AS release_qty, SUM(oi.release_uom_value) AS release_uom_value, oi.batch_id, oi.batch_id_ref,
|
|
87
|
+
oi.product_id, p.product_name, oi.packing_type, oi.packing_size, oi.uom
|
|
88
|
+
FROM
|
|
89
|
+
order_inventories oi
|
|
90
|
+
LEFT JOIN
|
|
91
|
+
temp_products p ON oi.product_id = p.product_id
|
|
92
|
+
INNER JOIN
|
|
93
|
+
domains d2 on d2.id = oi.domain_id and d2.ext_type ='warehouse'
|
|
94
|
+
INNER JOIN
|
|
95
|
+
fulfillment_centers fc ON fc.center_id = d2.subdomain
|
|
96
|
+
WHERE
|
|
97
|
+
fc.domain_id = $1
|
|
98
|
+
AND (oi.status = 'PENDING' or oi.status = 'PENDING_RECEIVE' or oi.status = 'PENDING_WORKSHEET' or oi.status = 'PENDING_SPLIT')
|
|
99
|
+
AND oi.batch_id NOTNULL AND oi.product_id NOTNULL AND oi.packing_type NOTNULL AND oi.packing_size NOTNULL AND oi.inventory_id IS NULL
|
|
100
|
+
GROUP BY
|
|
101
|
+
oi.batch_id, oi.batch_id_ref, oi.product_id, oi.packing_type,
|
|
102
|
+
oi.packing_size, oi.uom, p.product_name
|
|
103
|
+
)"oi" ON "i2".batch_id = "oi".batch_id AND "Product"."product_id" = "oi".product_id AND "i2".packing_type = "oi".packing_type AND "i2".packing_size = oi.packing_size AND "i2".uom = oi.uom
|
|
104
|
+
where "fc"."domain_id" = $1
|
|
105
|
+
and "i2"."status" = 'STORED'
|
|
106
|
+
group by "i2"."domain_id", "fc"."id", "fc"."name", "i2"."product_id"
|
|
107
|
+
)
|
|
108
|
+
`, [domain.id])
|
|
109
|
+
|
|
110
|
+
await tx.query(`
|
|
111
|
+
CREATE TEMP TABLE "temp_json_warehouse_marketplace_products" ON COMMIT DROP AS (
|
|
71
112
|
select "product_id", array_to_json(array_agg(row_to_json(dt))) AS "Json_marketplaceProducts" FROM (
|
|
72
113
|
select "dt"."marketplace_store_id", "dt"."product_id", "dt"."sku", array_agg(row_to_json(dt)) as product_variation
|
|
73
114
|
from (
|
|
@@ -84,34 +125,34 @@ export async function warehouseMarketplaceProduct(params: ListParam, domain: Dom
|
|
|
84
125
|
`)
|
|
85
126
|
|
|
86
127
|
await tx.query(`
|
|
87
|
-
CREATE TEMP TABLE temp_json_warehouse_inventory AS (
|
|
128
|
+
CREATE TEMP TABLE temp_json_warehouse_inventory ON COMMIT DROP AS (
|
|
88
129
|
select "product_id", array_to_json(array_agg((row_to_json("dt")))) AS "Json_warehouseInventory" from(
|
|
89
|
-
select "
|
|
90
|
-
"
|
|
91
|
-
from
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
130
|
+
select "domain_id", "fulfillment_id", "fulfillment_name",
|
|
131
|
+
"product_id", "inventory_locked_qty", "inventory_qty"
|
|
132
|
+
from temp_inventory
|
|
133
|
+
union
|
|
134
|
+
select "bundledInv"."domain_id", "bundledInv"."fulfillment_id", "bundledInv"."fulfillment_name", "bundledInv"."product_id",
|
|
135
|
+
max("bundledInv"."inventory_locked_qty") as "inventory_locked_qty", min("bundledInv"."inventory_qty") as "inventory_qty" from (
|
|
136
|
+
select "Product"."product_id", fc.domain_id, "fc"."id" as "fulfillment_id", "fc"."name" as "fulfillment_name",
|
|
137
|
+
"pbs"."bundle_qty",
|
|
138
|
+
case when "pbs"."bundle_qty" <= 0 then 0 else ceil(greatest("i2"."inventory_locked_qty",0)/ "pbs"."bundle_qty") end AS "inventory_locked_qty",
|
|
139
|
+
case when "pbs"."bundle_qty" <= 0 then 0 else floor(greatest("i2"."inventory_qty", 0)/ "pbs"."bundle_qty") end AS "inventory_qty"
|
|
140
|
+
from temp_products "Product"
|
|
141
|
+
inner join product_bundle_settings pbs ON pbs.product_bundle_id = "Product"."product_id"
|
|
142
|
+
inner join products p on p.id = pbs.product_id
|
|
143
|
+
cross join fulfillment_centers fc
|
|
144
|
+
inner join domains "d2" on "d2"."ext_type" ='warehouse' and "fc"."center_id" = "d2"."subdomain"
|
|
145
|
+
left join temp_inventory i2 ON i2.product_id = pbs.product_id and "d2"."id" = "i2"."domain_id"
|
|
146
|
+
where "fc"."domain_id" = $1
|
|
147
|
+
order by fc.id, "Product"."product_sku", p.sku
|
|
148
|
+
) "bundledInv"
|
|
149
|
+
group by "domain_id","fulfillment_id","fulfillment_name","product_id"
|
|
108
150
|
) "dt" group by "dt"."product_id"
|
|
109
151
|
)
|
|
110
|
-
|
|
152
|
+
`, [domain.id])
|
|
111
153
|
|
|
112
|
-
await tx.
|
|
113
|
-
|
|
114
|
-
create temp table temp_warehouse_marketplace_products as (
|
|
154
|
+
await tx.query(`
|
|
155
|
+
CREATE TEMP TABLE temp_warehouse_marketplace_products ON COMMIT DROP as (
|
|
115
156
|
SELECT "Product"."product_id" AS "Product_id", "Product"."product_sku" AS "Product_sku",
|
|
116
157
|
"Product"."product_name" AS "Product_name", "Product"."product_description" AS "Product_description",
|
|
117
158
|
"Product"."product_bizplace_id" AS "Product_bizplace_id",
|
|
@@ -130,8 +171,7 @@ export async function warehouseMarketplaceProduct(params: ListParam, domain: Dom
|
|
|
130
171
|
LEFT JOIN "temp_json_warehouse_inventory" "whInv" ON "whInv"."product_id" = "Product"."product_id"
|
|
131
172
|
LEFT JOIN "temp_json_warehouse_marketplace_products" "mktPrd" ON "mktPrd"."product_id" = "Product"."product_id"
|
|
132
173
|
)
|
|
133
|
-
`
|
|
134
|
-
)
|
|
174
|
+
`)
|
|
135
175
|
|
|
136
176
|
const offsetQuery: string = params?.pagination
|
|
137
177
|
? `OFFSET ${(params.pagination.page - 1) * params.pagination.limit} LIMIT ${params.pagination.limit}`
|
|
@@ -145,10 +185,6 @@ export async function warehouseMarketplaceProduct(params: ListParam, domain: Dom
|
|
|
145
185
|
`
|
|
146
186
|
)
|
|
147
187
|
|
|
148
|
-
tx.query(`
|
|
149
|
-
drop table temp_products, temp_json_warehouse_marketplace_products, temp_json_warehouse_inventory, temp_warehouse_marketplace_products
|
|
150
|
-
`)
|
|
151
|
-
|
|
152
188
|
return {
|
|
153
189
|
items: items.map((itm, index) => {
|
|
154
190
|
return {
|
|
@@ -159,30 +195,30 @@ export async function warehouseMarketplaceProduct(params: ListParam, domain: Dom
|
|
|
159
195
|
description: itm.Product_description,
|
|
160
196
|
marketplaceProduct: itm.Json_marketplaceProducts
|
|
161
197
|
? itm.Json_marketplaceProducts.map(product => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
198
|
+
return {
|
|
199
|
+
marketplaceStore: { id: product.marketplace_store_id },
|
|
200
|
+
marketplaceProductVariations: product.product_variation.map(variation => {
|
|
201
|
+
return {
|
|
202
|
+
id: variation.marketplace_product_variation_id,
|
|
203
|
+
name: variation.name,
|
|
204
|
+
qty: variation.qty,
|
|
205
|
+
reserveQty: variation.reserve_qty
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
})
|
|
174
210
|
: null,
|
|
175
211
|
warehouseInventory: itm.Json_warehouseInventory
|
|
176
212
|
? itm.Json_warehouseInventory.map(inventory => {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
213
|
+
return {
|
|
214
|
+
bizplace: { id: inventory.fulfillment_id, name: inventory.fulfillment_name },
|
|
215
|
+
product: { id: inventory.product_id },
|
|
216
|
+
qty: inventory.inventory_qty,
|
|
217
|
+
lockedQty: inventory.inventory_locked_qty ? inventory.inventory_locked_qty : 0,
|
|
218
|
+
remainQty:
|
|
219
|
+
inventory.inventory_qty - (inventory.inventory_locked_qty ? inventory.inventory_locked_qty : 0)
|
|
220
|
+
}
|
|
221
|
+
})
|
|
186
222
|
: null
|
|
187
223
|
}
|
|
188
224
|
}),
|