repzo-sap-absjo 1.0.18 → 1.0.20
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/lib/actions/create_invoice.d.ts +13 -19
- package/lib/actions/create_invoice.js +207 -365
- package/lib/actions/create_payment.d.ts +1 -4
- package/lib/actions/create_payment.js +107 -195
- package/lib/actions/create_proforma.d.ts +1 -4
- package/lib/actions/create_proforma.js +146 -285
- package/lib/actions/create_return_invoice.d.ts +1 -4
- package/lib/actions/create_return_invoice.js +158 -312
- package/lib/actions/create_transfer.d.ts +1 -4
- package/lib/actions/create_transfer.js +126 -223
- package/lib/actions/index.js +15 -23
- package/lib/commands/adjust_inventory.d.ts +2 -4
- package/lib/commands/adjust_inventory.js +160 -290
- package/lib/commands/bank.d.ts +2 -4
- package/lib/commands/bank.js +157 -279
- package/lib/commands/basic.js +48 -67
- package/lib/commands/brand.d.ts +1 -3
- package/lib/commands/brand.js +100 -174
- package/lib/commands/category.d.ts +1 -3
- package/lib/commands/category.js +104 -178
- package/lib/commands/channel.d.ts +1 -3
- package/lib/commands/channel.js +117 -198
- package/lib/commands/client.d.ts +32 -34
- package/lib/commands/client.js +244 -404
- package/lib/commands/client_disabled.d.ts +1 -3
- package/lib/commands/client_disabled.js +94 -163
- package/lib/commands/index.d.ts +11 -15
- package/lib/commands/index.js +62 -62
- package/lib/commands/join.js +66 -192
- package/lib/commands/measureunit.d.ts +14 -19
- package/lib/commands/measureunit.js +191 -289
- package/lib/commands/measureunit_family.d.ts +8 -10
- package/lib/commands/measureunit_family.js +138 -250
- package/lib/commands/payment_term.d.ts +1 -3
- package/lib/commands/payment_term.js +123 -202
- package/lib/commands/price_list.d.ts +15 -15
- package/lib/commands/price_list.js +326 -612
- package/lib/commands/product.d.ts +30 -32
- package/lib/commands/product.js +263 -485
- package/lib/commands/product_disabled.d.ts +1 -3
- package/lib/commands/product_disabled.js +94 -160
- package/lib/commands/rep.js +141 -221
- package/lib/commands/tag.js +109 -174
- package/lib/commands/tax.js +112 -177
- package/lib/commands/warehouse.d.ts +1 -3
- package/lib/commands/warehouse.js +119 -207
- package/lib/index.d.ts +12 -21
- package/lib/test/actions/create_invoice.js +188 -193
- package/lib/test/actions/create_payment.js +107 -112
- package/lib/test/actions/create_proforma.js +216 -220
- package/lib/test/actions/create_return_invoice.js +200 -205
- package/lib/test/actions/create_transfer.js +115 -120
- package/lib/test/commands/adjust_inventory.js +90 -90
- package/lib/test/commands/bank.js +90 -90
- package/lib/test/commands/basic.js +327 -328
- package/lib/test/commands/brand.js +90 -90
- package/lib/test/commands/category.js +90 -90
- package/lib/test/commands/channel.js +90 -90
- package/lib/test/commands/client.js +353 -355
- package/lib/test/commands/client_disabled.js +90 -90
- package/lib/test/commands/join.js +327 -328
- package/lib/test/commands/measureunit.js +90 -90
- package/lib/test/commands/measureunit_family.js +90 -90
- package/lib/test/commands/payment_term.js +90 -90
- package/lib/test/commands/price_list.js +334 -337
- package/lib/test/commands/product.js +90 -90
- package/lib/test/commands/product_disabled.js +90 -90
- package/lib/test/commands/rep.js +344 -346
- package/lib/test/commands/tag.js +90 -90
- package/lib/test/commands/tax.js +90 -90
- package/lib/test/commands/warehouse.js +90 -90
- package/lib/types.d.ts +53 -77
- package/lib/util.d.ts +19 -70
- package/lib/util.js +144 -170
- package/package.json +1 -1
package/lib/commands/product.js
CHANGED
|
@@ -1,504 +1,282 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import {
|
|
3
|
-
_create,
|
|
4
|
-
update_bench_time,
|
|
5
|
-
date_formatting,
|
|
6
|
-
set_error,
|
|
7
|
-
} from "../util.js";
|
|
2
|
+
import { _create, update_bench_time, date_formatting, set_error, } from "../util.js";
|
|
8
3
|
export const sync_product = async (commandEvent) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
_d,
|
|
13
|
-
_e,
|
|
14
|
-
_f,
|
|
15
|
-
_g,
|
|
16
|
-
_h,
|
|
17
|
-
_j,
|
|
18
|
-
_k,
|
|
19
|
-
_l,
|
|
20
|
-
_m,
|
|
21
|
-
_o,
|
|
22
|
-
_p,
|
|
23
|
-
_q,
|
|
24
|
-
_r,
|
|
25
|
-
_s,
|
|
26
|
-
_t,
|
|
27
|
-
_u;
|
|
28
|
-
const repzo = new Repzo(
|
|
29
|
-
(_a = commandEvent.app.formData) === null || _a === void 0
|
|
30
|
-
? void 0
|
|
31
|
-
: _a.repzoApiKey,
|
|
32
|
-
{
|
|
33
|
-
env: commandEvent.env,
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
const commandLog = new Repzo.CommandLog(
|
|
37
|
-
repzo,
|
|
38
|
-
commandEvent.app,
|
|
39
|
-
commandEvent.command
|
|
40
|
-
);
|
|
41
|
-
try {
|
|
42
|
-
// console.log("sync_product");
|
|
43
|
-
const new_bench_time = new Date().toISOString();
|
|
44
|
-
const bench_time_key = "bench_time_product";
|
|
45
|
-
await commandLog.load(commandEvent.sync_id);
|
|
46
|
-
await commandLog.addDetail("Repzo SAP: Started Syncing Products").commit();
|
|
47
|
-
const nameSpace = commandEvent.nameSpace.join("_");
|
|
48
|
-
const result = {
|
|
49
|
-
sap_total: 0,
|
|
50
|
-
repzo_total: 0,
|
|
51
|
-
created: 0,
|
|
52
|
-
updated: 0,
|
|
53
|
-
failed: 0,
|
|
54
|
-
repzo_total_taxes: 0,
|
|
55
|
-
repzo_total_categories: 0,
|
|
56
|
-
repzo_total_brands: 0,
|
|
57
|
-
};
|
|
58
|
-
const failed_docs_report = [];
|
|
59
|
-
const sap_products = await get_sap_products(
|
|
60
|
-
commandEvent.app.formData.sapHostUrl,
|
|
61
|
-
{ updateAt: commandEvent.app.options_formData[bench_time_key] }
|
|
62
|
-
);
|
|
63
|
-
result.sap_total =
|
|
64
|
-
sap_products === null || sap_products === void 0
|
|
65
|
-
? void 0
|
|
66
|
-
: sap_products.length;
|
|
67
|
-
await commandLog
|
|
68
|
-
.addDetail(
|
|
69
|
-
`${result.sap_total} Items in SAP changed since ${
|
|
70
|
-
commandEvent.app.options_formData[bench_time_key] || "ever"
|
|
71
|
-
}`
|
|
72
|
-
)
|
|
73
|
-
.commit();
|
|
74
|
-
// Product Repzo
|
|
75
|
-
const repzo_products = await repzo.product.find({
|
|
76
|
-
per_page: 50000,
|
|
77
|
-
withVariants: true,
|
|
78
|
-
});
|
|
79
|
-
result.repzo_total =
|
|
80
|
-
(_b =
|
|
81
|
-
repzo_products === null || repzo_products === void 0
|
|
82
|
-
? void 0
|
|
83
|
-
: repzo_products.data) === null || _b === void 0
|
|
84
|
-
? void 0
|
|
85
|
-
: _b.length;
|
|
86
|
-
await commandLog
|
|
87
|
-
.addDetail(
|
|
88
|
-
`${
|
|
89
|
-
(_c =
|
|
90
|
-
repzo_products === null || repzo_products === void 0
|
|
91
|
-
? void 0
|
|
92
|
-
: repzo_products.data) === null || _c === void 0
|
|
93
|
-
? void 0
|
|
94
|
-
: _c.length
|
|
95
|
-
} Products in Repzo`
|
|
96
|
-
)
|
|
97
|
-
.commit();
|
|
98
|
-
// Tax
|
|
99
|
-
const repzo_taxes = await repzo.tax.find({
|
|
100
|
-
per_page: 50000,
|
|
101
|
-
disabled: false,
|
|
102
|
-
});
|
|
103
|
-
result.repzo_total_taxes =
|
|
104
|
-
(_d =
|
|
105
|
-
repzo_taxes === null || repzo_taxes === void 0
|
|
106
|
-
? void 0
|
|
107
|
-
: repzo_taxes.data) === null || _d === void 0
|
|
108
|
-
? void 0
|
|
109
|
-
: _d.length;
|
|
110
|
-
await commandLog
|
|
111
|
-
.addDetail(`${result.repzo_total_taxes} Taxes in Repzo`)
|
|
112
|
-
.commit();
|
|
113
|
-
// Category
|
|
114
|
-
const repzo_categories = await repzo.category.find({
|
|
115
|
-
per_page: 50000,
|
|
116
|
-
disabled: false,
|
|
117
|
-
});
|
|
118
|
-
result.repzo_total_categories =
|
|
119
|
-
(_e =
|
|
120
|
-
repzo_categories === null || repzo_categories === void 0
|
|
121
|
-
? void 0
|
|
122
|
-
: repzo_categories.data) === null || _e === void 0
|
|
123
|
-
? void 0
|
|
124
|
-
: _e.length;
|
|
125
|
-
await commandLog
|
|
126
|
-
.addDetail(`${result.repzo_total_categories} Product Categories in Repzo`)
|
|
127
|
-
.commit();
|
|
128
|
-
// Brand
|
|
129
|
-
const repzo_brands = await repzo.brand.find({
|
|
130
|
-
per_page: 50000,
|
|
131
|
-
disabled: false,
|
|
4
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
5
|
+
const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
|
|
6
|
+
env: commandEvent.env,
|
|
132
7
|
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
:
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
: _a.id) == `${nameSpace}_${sap_product.ITEMCODE}`
|
|
162
|
-
);
|
|
8
|
+
const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
|
|
9
|
+
try {
|
|
10
|
+
// console.log("sync_product");
|
|
11
|
+
const new_bench_time = new Date().toISOString();
|
|
12
|
+
const bench_time_key = "bench_time_product";
|
|
13
|
+
await commandLog.load(commandEvent.sync_id);
|
|
14
|
+
await commandLog.addDetail("Repzo SAP: Started Syncing Products").commit();
|
|
15
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
16
|
+
const result = {
|
|
17
|
+
sap_total: 0,
|
|
18
|
+
repzo_total: 0,
|
|
19
|
+
created: 0,
|
|
20
|
+
updated: 0,
|
|
21
|
+
failed: 0,
|
|
22
|
+
repzo_total_taxes: 0,
|
|
23
|
+
repzo_total_categories: 0,
|
|
24
|
+
repzo_total_brands: 0,
|
|
25
|
+
};
|
|
26
|
+
const failed_docs_report = [];
|
|
27
|
+
const sap_products = await get_sap_products(commandEvent.app.formData.sapHostUrl, { updateAt: commandEvent.app.options_formData[bench_time_key] });
|
|
28
|
+
result.sap_total = sap_products === null || sap_products === void 0 ? void 0 : sap_products.length;
|
|
29
|
+
await commandLog
|
|
30
|
+
.addDetail(`${result.sap_total} Items in SAP changed since ${commandEvent.app.options_formData[bench_time_key] || "ever"}`)
|
|
31
|
+
.commit();
|
|
32
|
+
// Product Repzo
|
|
33
|
+
const repzo_products = await repzo.product.find({
|
|
34
|
+
per_page: 50000,
|
|
35
|
+
withVariants: true,
|
|
163
36
|
});
|
|
37
|
+
result.repzo_total = (_b = repzo_products === null || repzo_products === void 0 ? void 0 : repzo_products.data) === null || _b === void 0 ? void 0 : _b.length;
|
|
38
|
+
await commandLog
|
|
39
|
+
.addDetail(`${(_c = repzo_products === null || repzo_products === void 0 ? void 0 : repzo_products.data) === null || _c === void 0 ? void 0 : _c.length} Products in Repzo`)
|
|
40
|
+
.commit();
|
|
164
41
|
// Tax
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return (
|
|
174
|
-
((_a =
|
|
175
|
-
tax === null || tax === void 0
|
|
176
|
-
? void 0
|
|
177
|
-
: tax.integration_meta) === null || _a === void 0
|
|
178
|
-
? void 0
|
|
179
|
-
: _a.id) == `${nameSpace}_${sap_product.ITEMTAXCODE}`
|
|
180
|
-
);
|
|
181
|
-
});
|
|
182
|
-
if (!tax) {
|
|
183
|
-
throw `Tax not found => ITEMTAXCODE: ${sap_product.ITEMTAXCODE}`;
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
const product_tax =
|
|
187
|
-
(_h = tax === null || tax === void 0 ? void 0 : tax._id) === null ||
|
|
188
|
-
_h === void 0
|
|
189
|
-
? void 0
|
|
190
|
-
: _h.toString();
|
|
42
|
+
const repzo_taxes = await repzo.tax.find({
|
|
43
|
+
per_page: 50000,
|
|
44
|
+
disabled: false,
|
|
45
|
+
});
|
|
46
|
+
result.repzo_total_taxes = (_d = repzo_taxes === null || repzo_taxes === void 0 ? void 0 : repzo_taxes.data) === null || _d === void 0 ? void 0 : _d.length;
|
|
47
|
+
await commandLog
|
|
48
|
+
.addDetail(`${result.repzo_total_taxes} Taxes in Repzo`)
|
|
49
|
+
.commit();
|
|
191
50
|
// Category
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
? void 0
|
|
196
|
-
: repzo_categories.data) === null || _j === void 0
|
|
197
|
-
? void 0
|
|
198
|
-
: _j.find((category) => {
|
|
199
|
-
var _a;
|
|
200
|
-
return (
|
|
201
|
-
((_a =
|
|
202
|
-
category === null || category === void 0
|
|
203
|
-
? void 0
|
|
204
|
-
: category.integration_meta) === null || _a === void 0
|
|
205
|
-
? void 0
|
|
206
|
-
: _a.id) == `${nameSpace}_${sap_product.ITEMGROUPCODE}`
|
|
207
|
-
);
|
|
208
|
-
});
|
|
209
|
-
if (!category) {
|
|
210
|
-
throw `Category not found => ITEMGROUPCODE: ${sap_product.ITEMGROUPCODE}`;
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
const product_category =
|
|
214
|
-
(_k =
|
|
215
|
-
category === null || category === void 0
|
|
216
|
-
? void 0
|
|
217
|
-
: category._id) === null || _k === void 0
|
|
218
|
-
? void 0
|
|
219
|
-
: _k.toString();
|
|
220
|
-
// Brand
|
|
221
|
-
const brand =
|
|
222
|
-
(_l =
|
|
223
|
-
repzo_brands === null || repzo_brands === void 0
|
|
224
|
-
? void 0
|
|
225
|
-
: repzo_brands.data) === null || _l === void 0
|
|
226
|
-
? void 0
|
|
227
|
-
: _l.find((brand) => {
|
|
228
|
-
var _a;
|
|
229
|
-
return (
|
|
230
|
-
((_a =
|
|
231
|
-
brand === null || brand === void 0
|
|
232
|
-
? void 0
|
|
233
|
-
: brand.integration_meta) === null || _a === void 0
|
|
234
|
-
? void 0
|
|
235
|
-
: _a.id) == `${nameSpace}_${sap_product["Parent Category"]}`
|
|
236
|
-
);
|
|
237
|
-
});
|
|
238
|
-
const product_brand =
|
|
239
|
-
(_m = brand === null || brand === void 0 ? void 0 : brand._id) ===
|
|
240
|
-
null || _m === void 0
|
|
241
|
-
? void 0
|
|
242
|
-
: _m.toString();
|
|
243
|
-
// measureUnit family
|
|
244
|
-
const family = await repzo.measureunitFamily.find({
|
|
245
|
-
"integration_meta.id": `${nameSpace}_${sap_product.ITEMCODE}`,
|
|
246
|
-
disabled: false,
|
|
51
|
+
const repzo_categories = await repzo.category.find({
|
|
52
|
+
per_page: 50000,
|
|
53
|
+
disabled: false,
|
|
247
54
|
});
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
:
|
|
255
|
-
|
|
256
|
-
throw `Family not found => ITEMCODE: ${sap_product.ITEMCODE}`;
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
const product_family =
|
|
260
|
-
(_q =
|
|
261
|
-
(_p = family.data[0]) === null || _p === void 0
|
|
262
|
-
? void 0
|
|
263
|
-
: _p._id) === null || _q === void 0
|
|
264
|
-
? void 0
|
|
265
|
-
: _q.toString();
|
|
266
|
-
// measureUnit
|
|
267
|
-
const measureUnit = await repzo.measureunit.find({
|
|
268
|
-
"integration_meta.UOMGROUPENTRY": sap_product.UOMGROUPENTRY,
|
|
269
|
-
name: sap_product.DEFAULTITEMUOM,
|
|
270
|
-
company_namespace: nameSpace,
|
|
271
|
-
disabled: false,
|
|
55
|
+
result.repzo_total_categories = (_e = repzo_categories === null || repzo_categories === void 0 ? void 0 : repzo_categories.data) === null || _e === void 0 ? void 0 : _e.length;
|
|
56
|
+
await commandLog
|
|
57
|
+
.addDetail(`${result.repzo_total_categories} Product Categories in Repzo`)
|
|
58
|
+
.commit();
|
|
59
|
+
// Brand
|
|
60
|
+
const repzo_brands = await repzo.brand.find({
|
|
61
|
+
per_page: 50000,
|
|
62
|
+
disabled: false,
|
|
272
63
|
});
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
64
|
+
result.repzo_total_brands = (_f = repzo_brands === null || repzo_brands === void 0 ? void 0 : repzo_brands.data) === null || _f === void 0 ? void 0 : _f.length;
|
|
65
|
+
await commandLog
|
|
66
|
+
.addDetail(`${result.repzo_total_brands} Brands in Repzo`)
|
|
67
|
+
.commit();
|
|
68
|
+
for (let i = 0; i < (sap_products === null || sap_products === void 0 ? void 0 : sap_products.length); i++) {
|
|
69
|
+
const sap_product = sap_products[i];
|
|
70
|
+
try {
|
|
71
|
+
const repzo_product = repzo_products.data.find((r_product) => {
|
|
72
|
+
var _a;
|
|
73
|
+
return ((_a = r_product === null || r_product === void 0 ? void 0 : r_product.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
|
|
74
|
+
`${nameSpace}_${sap_product.ITEMCODE}`;
|
|
75
|
+
});
|
|
76
|
+
// Tax
|
|
77
|
+
const tax = (_g = repzo_taxes === null || repzo_taxes === void 0 ? void 0 : repzo_taxes.data) === null || _g === void 0 ? void 0 : _g.find((tax) => {
|
|
78
|
+
var _a;
|
|
79
|
+
return ((_a = tax === null || tax === void 0 ? void 0 : tax.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
|
|
80
|
+
`${nameSpace}_${sap_product.ITEMTAXCODE}`;
|
|
81
|
+
});
|
|
82
|
+
if (!tax) {
|
|
83
|
+
throw `Tax not found => ITEMTAXCODE: ${sap_product.ITEMTAXCODE}`;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const product_tax = (_h = tax === null || tax === void 0 ? void 0 : tax._id) === null || _h === void 0 ? void 0 : _h.toString();
|
|
87
|
+
// Category
|
|
88
|
+
const category = (_j = repzo_categories === null || repzo_categories === void 0 ? void 0 : repzo_categories.data) === null || _j === void 0 ? void 0 : _j.find((category) => {
|
|
89
|
+
var _a;
|
|
90
|
+
return ((_a = category === null || category === void 0 ? void 0 : category.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
|
|
91
|
+
`${nameSpace}_${sap_product.ITEMGROUPCODE}`;
|
|
92
|
+
});
|
|
93
|
+
if (!category) {
|
|
94
|
+
throw `Category not found => ITEMGROUPCODE: ${sap_product.ITEMGROUPCODE}`;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const product_category = (_k = category === null || category === void 0 ? void 0 : category._id) === null || _k === void 0 ? void 0 : _k.toString();
|
|
98
|
+
// Brand
|
|
99
|
+
const brand = (_l = repzo_brands === null || repzo_brands === void 0 ? void 0 : repzo_brands.data) === null || _l === void 0 ? void 0 : _l.find((brand) => {
|
|
100
|
+
var _a;
|
|
101
|
+
return ((_a = brand === null || brand === void 0 ? void 0 : brand.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
|
|
102
|
+
`${nameSpace}_${sap_product["Parent Category"]}`;
|
|
103
|
+
});
|
|
104
|
+
const product_brand = (_m = brand === null || brand === void 0 ? void 0 : brand._id) === null || _m === void 0 ? void 0 : _m.toString();
|
|
105
|
+
// measureUnit family
|
|
106
|
+
const family = await repzo.measureunitFamily.find({
|
|
107
|
+
"integration_meta.id": `${nameSpace}_${sap_product.ITEMCODE}`,
|
|
108
|
+
disabled: false,
|
|
109
|
+
});
|
|
110
|
+
if (!(family === null || family === void 0 ? void 0 : family.data) || ((_o = family === null || family === void 0 ? void 0 : family.data) === null || _o === void 0 ? void 0 : _o.length) != 1) {
|
|
111
|
+
throw `Family not found => ITEMCODE: ${sap_product.ITEMCODE}`;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const product_family = (_q = (_p = family.data[0]) === null || _p === void 0 ? void 0 : _p._id) === null || _q === void 0 ? void 0 : _q.toString();
|
|
115
|
+
// measureUnit
|
|
116
|
+
const measureUnit = await repzo.measureunit.find({
|
|
117
|
+
"integration_meta.UOMGROUPENTRY": sap_product.UOMGROUPENTRY,
|
|
118
|
+
name: sap_product.DEFAULTITEMUOM,
|
|
119
|
+
company_namespace: nameSpace,
|
|
120
|
+
disabled: false,
|
|
121
|
+
});
|
|
122
|
+
if (!measureUnit.data || measureUnit.data.length != 1) {
|
|
123
|
+
throw `MeasureUnit not found => UOMGROUPENTRY: ${sap_product.UOMGROUPENTRY}, ITEMCODE: ${sap_product.ITEMCODE}, DEFAULTITEMUOM: ${sap_product.DEFAULTITEMUOM}`;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const product_measureUnit = (_r = measureUnit.data[0]._id) === null || _r === void 0 ? void 0 : _r.toString();
|
|
127
|
+
const body = {
|
|
128
|
+
active: true,
|
|
129
|
+
name: sap_product.ITEMDESC,
|
|
130
|
+
local_name: sap_product.ITEMDESCF,
|
|
131
|
+
barcode: sap_product.ITEMBARCODE,
|
|
132
|
+
sku: sap_product.ITEMCODE,
|
|
133
|
+
sv_tax: product_tax,
|
|
134
|
+
category: product_category,
|
|
135
|
+
brand: product_brand,
|
|
136
|
+
measureunit_family: product_family,
|
|
137
|
+
sv_measureUnit: product_measureUnit,
|
|
138
|
+
integration_meta: {
|
|
139
|
+
id: `${nameSpace}_${sap_product.ITEMCODE}`,
|
|
140
|
+
ITEMGROUPCODE: sap_product.ITEMGROUPCODE,
|
|
141
|
+
UOMGROUPENTRY: sap_product.UOMGROUPENTRY,
|
|
142
|
+
BRAND: sap_product.BRAND,
|
|
143
|
+
},
|
|
144
|
+
variants: [
|
|
145
|
+
{
|
|
146
|
+
disabled: false,
|
|
147
|
+
name: sap_product.ITEMCODE,
|
|
148
|
+
price: 0,
|
|
149
|
+
integration_meta: {
|
|
150
|
+
id: `${nameSpace}_${sap_product.ITEMCODE}`,
|
|
151
|
+
ITEMCODE: sap_product.ITEMCODE,
|
|
152
|
+
},
|
|
153
|
+
company_namespace: [nameSpace],
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
company_namespace: [nameSpace],
|
|
157
|
+
};
|
|
158
|
+
if (!repzo_product) {
|
|
159
|
+
// Create
|
|
160
|
+
try {
|
|
161
|
+
const created_product = await repzo.product.create(body);
|
|
162
|
+
result.created++;
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
// console.log("Create Product Failed >> ", e?.response, body);
|
|
166
|
+
failed_docs_report.push({
|
|
167
|
+
method: "create",
|
|
168
|
+
doc: body,
|
|
169
|
+
error_message: set_error(e),
|
|
363
170
|
});
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
171
|
+
result.failed++;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
if (is_matched(body, repzo_product)) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if ((_s = repzo_product === null || repzo_product === void 0 ? void 0 : repzo_product.variants) === null || _s === void 0 ? void 0 : _s.length) {
|
|
179
|
+
(_t = body === null || body === void 0 ? void 0 : body.variants) === null || _t === void 0 ? void 0 : _t.forEach((variant) => {
|
|
180
|
+
var _a;
|
|
181
|
+
const hasMatch = (_a = repzo_product === null || repzo_product === void 0 ? void 0 : repzo_product.variants) === null || _a === void 0 ? void 0 : _a.find((v) => { var _a, _b; return ((_a = v.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == ((_b = variant === null || variant === void 0 ? void 0 : variant.integration_meta) === null || _b === void 0 ? void 0 : _b.id); });
|
|
182
|
+
if (hasMatch) {
|
|
183
|
+
variant._id = hasMatch._id;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
// Update
|
|
188
|
+
try {
|
|
189
|
+
const updated_product = await repzo.product.update(repzo_product._id, body);
|
|
190
|
+
result.updated++;
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
// console.log("Update Product Failed >> ", e?.response?.data, body);
|
|
194
|
+
failed_docs_report.push({
|
|
195
|
+
method: "update",
|
|
196
|
+
doc_id: repzo_product === null || repzo_product === void 0 ? void 0 : repzo_product._id,
|
|
197
|
+
doc: body,
|
|
198
|
+
error_message: set_error(e),
|
|
199
|
+
});
|
|
200
|
+
result.failed++;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch (e) {
|
|
205
|
+
// console.log("FetchingData Product Failed >> ", e);
|
|
206
|
+
failed_docs_report.push({
|
|
207
|
+
method: "fetchingData",
|
|
208
|
+
doc_id: sap_product.ITEMBARCODE,
|
|
209
|
+
error_message: set_error(e),
|
|
367
210
|
});
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
try {
|
|
371
|
-
const updated_product = await repzo.product.update(
|
|
372
|
-
repzo_product._id,
|
|
373
|
-
body
|
|
374
|
-
);
|
|
375
|
-
result.updated++;
|
|
376
|
-
} catch (e) {
|
|
377
|
-
// console.log("Update Product Failed >> ", e?.response?.data, body);
|
|
378
|
-
failed_docs_report.push({
|
|
379
|
-
method: "update",
|
|
380
|
-
doc_id:
|
|
381
|
-
repzo_product === null || repzo_product === void 0
|
|
382
|
-
? void 0
|
|
383
|
-
: repzo_product._id,
|
|
384
|
-
doc: body,
|
|
385
|
-
error_message: set_error(e),
|
|
386
|
-
});
|
|
387
|
-
result.failed++;
|
|
388
|
-
}
|
|
211
|
+
result.failed++;
|
|
212
|
+
}
|
|
389
213
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
214
|
+
// console.log(result);
|
|
215
|
+
await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
|
|
216
|
+
await commandLog
|
|
217
|
+
.setStatus("success", failed_docs_report.length ? failed_docs_report : null)
|
|
218
|
+
.setBody(result)
|
|
219
|
+
.commit();
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
catch (e) {
|
|
223
|
+
//@ts-ignore
|
|
224
|
+
console.error(((_u = e === null || e === void 0 ? void 0 : e.response) === null || _u === void 0 ? void 0 : _u.data) || e);
|
|
225
|
+
await commandLog.setStatus("fail", e).commit();
|
|
226
|
+
throw e;
|
|
399
227
|
}
|
|
400
|
-
// console.log(result);
|
|
401
|
-
await update_bench_time(
|
|
402
|
-
repzo,
|
|
403
|
-
commandEvent.app._id,
|
|
404
|
-
bench_time_key,
|
|
405
|
-
new_bench_time
|
|
406
|
-
);
|
|
407
|
-
await commandLog
|
|
408
|
-
.setStatus(
|
|
409
|
-
"success",
|
|
410
|
-
failed_docs_report.length ? failed_docs_report : null
|
|
411
|
-
)
|
|
412
|
-
.setBody(result)
|
|
413
|
-
.commit();
|
|
414
|
-
return result;
|
|
415
|
-
} catch (e) {
|
|
416
|
-
//@ts-ignore
|
|
417
|
-
console.error(
|
|
418
|
-
((_u = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
419
|
-
_u === void 0
|
|
420
|
-
? void 0
|
|
421
|
-
: _u.data) || e
|
|
422
|
-
);
|
|
423
|
-
await commandLog.setStatus("fail", e).commit();
|
|
424
|
-
throw e;
|
|
425
|
-
}
|
|
426
228
|
};
|
|
427
229
|
const get_sap_products = async (serviceEndPoint, query) => {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
throw e;
|
|
439
|
-
}
|
|
230
|
+
try {
|
|
231
|
+
const sap_products = await _create(serviceEndPoint, "/Items", {
|
|
232
|
+
Active: "Y",
|
|
233
|
+
UpdateAt: date_formatting(query === null || query === void 0 ? void 0 : query.updateAt, "YYYYMMDD:HHmmss"),
|
|
234
|
+
});
|
|
235
|
+
return sap_products.Items;
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
throw e;
|
|
239
|
+
}
|
|
440
240
|
};
|
|
441
241
|
const is_matched = (body_1, body_2) => {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
(
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
242
|
+
var _a, _b, _c, _d, _e, _f;
|
|
243
|
+
try {
|
|
244
|
+
const keys = [
|
|
245
|
+
"active",
|
|
246
|
+
"name",
|
|
247
|
+
"local_name",
|
|
248
|
+
"barcode",
|
|
249
|
+
"sku",
|
|
250
|
+
"sv_tax",
|
|
251
|
+
"category",
|
|
252
|
+
"measureunit_family",
|
|
253
|
+
"sv_measureUnit",
|
|
254
|
+
"brand",
|
|
255
|
+
];
|
|
256
|
+
const integration_meta_keys = [
|
|
257
|
+
"id",
|
|
258
|
+
"ITEMGROUPCODE",
|
|
259
|
+
"UOMGROUPENTRY",
|
|
260
|
+
"BRAND",
|
|
261
|
+
];
|
|
262
|
+
const variant_keys = ["variants", "disabled", "name", "price"];
|
|
263
|
+
const variant_integration_meta_keys = ["integration_meta.id"];
|
|
264
|
+
for (let i = 0; i < keys.length; i++) {
|
|
265
|
+
const key = keys[i];
|
|
266
|
+
if (((_a = body_1[key]) === null || _a === void 0 ? void 0 : _a.toString()) !== ((_b = body_2[key]) === null || _b === void 0 ? void 0 : _b.toString())) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
for (let i = 0; i < integration_meta_keys.length; i++) {
|
|
271
|
+
const key = keys[i];
|
|
272
|
+
if (((_d = (_c = body_1 === null || body_1 === void 0 ? void 0 : body_1.integration_meta) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.toString()) !==
|
|
273
|
+
((_f = (_e = body_2 === null || body_2 === void 0 ? void 0 : body_2.integration_meta) === null || _e === void 0 ? void 0 : _e[key]) === null || _f === void 0 ? void 0 : _f.toString())) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return true;
|
|
474
278
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
if (
|
|
478
|
-
((_d =
|
|
479
|
-
(_c =
|
|
480
|
-
body_1 === null || body_1 === void 0
|
|
481
|
-
? void 0
|
|
482
|
-
: body_1.integration_meta) === null || _c === void 0
|
|
483
|
-
? void 0
|
|
484
|
-
: _c[key]) === null || _d === void 0
|
|
485
|
-
? void 0
|
|
486
|
-
: _d.toString()) !==
|
|
487
|
-
((_f =
|
|
488
|
-
(_e =
|
|
489
|
-
body_2 === null || body_2 === void 0
|
|
490
|
-
? void 0
|
|
491
|
-
: body_2.integration_meta) === null || _e === void 0
|
|
492
|
-
? void 0
|
|
493
|
-
: _e[key]) === null || _f === void 0
|
|
494
|
-
? void 0
|
|
495
|
-
: _f.toString())
|
|
496
|
-
) {
|
|
497
|
-
return false;
|
|
498
|
-
}
|
|
279
|
+
catch (e) {
|
|
280
|
+
throw e;
|
|
499
281
|
}
|
|
500
|
-
return true;
|
|
501
|
-
} catch (e) {
|
|
502
|
-
throw e;
|
|
503
|
-
}
|
|
504
282
|
};
|