repzo-sap-absjo 1.0.19 → 1.0.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/changelog.md +1 -0
- package/lib/actions/create_invoice.js +5 -17
- package/lib/commands/basic.js +1 -0
- package/lib/commands/index.d.ts +9 -0
- package/lib/commands/index.js +3 -0
- package/lib/commands/price_list.js +7 -2
- package/lib/commands/price_list_disabled.d.ts +12 -0
- package/lib/commands/price_list_disabled.js +216 -0
- package/lib/index.d.ts +9 -0
- package/lib/test/commands/basic.js +7 -0
- package/lib/test/commands/price_list_disabled.d.ts +1 -0
- package/lib/test/commands/price_list_disabled.js +359 -0
- package/lib/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/actions/create_invoice.ts +5 -25
- package/src/commands/basic.ts +2 -1
- package/src/commands/index.ts +3 -0
- package/src/commands/price_list.ts +7 -2
- package/src/commands/price_list_disabled.ts +194 -0
- package/src/test/commands/basic.ts +7 -0
- package/src/test/commands/price_list_disabled.ts +362 -0
- package/src/types.ts +1 -0
package/changelog.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
- [actions/***] add 2 keys in integration_meta: sync_to_sap_started & sync_to_sap_succeeded @maramalshen
|
|
8
8
|
- [commands/product] assign Foreign Name (ITEMDESCF) in SAP to local_name in Repzo @maramalshen
|
|
9
9
|
- [actions/payment] add the field UserId where it equals USERID of the SAP API REP @maramalshen
|
|
10
|
+
- [commands/price_list_disabled] new command: Disabled PriceListItems from Repzo if it is not found on SAP @maramalshen
|
|
10
11
|
|
|
11
12
|
### Changed
|
|
12
13
|
|
|
@@ -16,14 +16,12 @@ export const create_invoice = async (event, options) => {
|
|
|
16
16
|
const actionLog = new Repzo.ActionLogs(repzo, action_sync_id);
|
|
17
17
|
let body;
|
|
18
18
|
try {
|
|
19
|
-
console.log("create_invoice");
|
|
19
|
+
// console.log("create_invoice");
|
|
20
20
|
await actionLog.load(action_sync_id);
|
|
21
21
|
body = event.body;
|
|
22
22
|
try {
|
|
23
23
|
if (body) body = JSON.parse(body);
|
|
24
|
-
} catch (e) {
|
|
25
|
-
console.error("Error parsing event body:", e); // Debug log added
|
|
26
|
-
}
|
|
24
|
+
} catch (e) {}
|
|
27
25
|
const repzo_serial_number =
|
|
28
26
|
(_c = body === null || body === void 0 ? void 0 : body.serial_number) ===
|
|
29
27
|
null || _c === void 0
|
|
@@ -38,7 +36,7 @@ export const create_invoice = async (event, options) => {
|
|
|
38
36
|
{ _id: body._id, type: "fullinvoices" }
|
|
39
37
|
);
|
|
40
38
|
} catch (e) {
|
|
41
|
-
console.error(
|
|
39
|
+
console.error(e);
|
|
42
40
|
}
|
|
43
41
|
await actionLog
|
|
44
42
|
.addDetail(
|
|
@@ -334,14 +332,14 @@ export const create_invoice = async (event, options) => {
|
|
|
334
332
|
sap_invoice
|
|
335
333
|
);
|
|
336
334
|
const result = await _create(SAP_HOST_URL, "/AddInvoice", sap_invoice);
|
|
337
|
-
console.log(
|
|
335
|
+
// console.log(result);
|
|
338
336
|
try {
|
|
339
337
|
await repzo.updateIntegrationMeta.create(
|
|
340
338
|
[{ key: "sync_to_sap_succeeded", value: true }],
|
|
341
339
|
{ _id: body._id, type: "fullinvoices" }
|
|
342
340
|
);
|
|
343
341
|
} catch (e) {
|
|
344
|
-
console.error(
|
|
342
|
+
console.error(e);
|
|
345
343
|
}
|
|
346
344
|
await actionLog
|
|
347
345
|
.addDetail(`SAP Responded with `, result)
|
|
@@ -359,20 +357,15 @@ export const create_invoice = async (event, options) => {
|
|
|
359
357
|
};
|
|
360
358
|
export const get_invoice_from_sap = async (serviceEndPoint, query) => {
|
|
361
359
|
try {
|
|
362
|
-
console.log("Inside get_invoice_from_sap function"); // Debug log
|
|
363
|
-
console.log("Service End Point:", serviceEndPoint); // Debug log
|
|
364
|
-
console.log("Query:", query); // Debug log
|
|
365
360
|
const sap_openInvoices = await _create(serviceEndPoint, "/OpenInvoices", {
|
|
366
361
|
updatedAt: query === null || query === void 0 ? void 0 : query.updatedAt,
|
|
367
362
|
Status: query === null || query === void 0 ? void 0 : query.Status,
|
|
368
363
|
InvoiceId: query === null || query === void 0 ? void 0 : query.InvoiceId,
|
|
369
364
|
});
|
|
370
|
-
console.log("SAP Open Invoices:", sap_openInvoices); // Debug log
|
|
371
365
|
return sap_openInvoices === null || sap_openInvoices === void 0
|
|
372
366
|
? void 0
|
|
373
367
|
: sap_openInvoices.OpenInvoices;
|
|
374
368
|
} catch (e) {
|
|
375
|
-
console.error("Error in get_invoice_from_sap:", e); // Debug log
|
|
376
369
|
throw e;
|
|
377
370
|
}
|
|
378
371
|
};
|
|
@@ -380,13 +373,8 @@ function getUniqueConcatenatedValues(item, key, delimiter) {
|
|
|
380
373
|
item.general_promotions = item.general_promotions || [];
|
|
381
374
|
item.used_promotions = item.used_promotions || [];
|
|
382
375
|
const allPromotions = [...item.general_promotions, ...item.used_promotions];
|
|
383
|
-
console.log("Inside getUniqueConcatenatedValues function"); // Debug log
|
|
384
|
-
console.log("Item:", item); // Debug log
|
|
385
|
-
console.log("Key:", key); // Debug log
|
|
386
|
-
console.log("Delimiter:", delimiter); // Debug log
|
|
387
376
|
const uniqueValues = new Set(
|
|
388
377
|
allPromotions.map((promotion) => promotion[key]).filter((value) => value)
|
|
389
378
|
);
|
|
390
|
-
console.log("Unique Values:", uniqueValues); // Debug log
|
|
391
379
|
return [...uniqueValues].join(delimiter);
|
|
392
380
|
}
|
package/lib/commands/basic.js
CHANGED
package/lib/commands/index.d.ts
CHANGED
|
@@ -19,5 +19,14 @@ export declare const commands: (CommandEvent: CommandEvent) => Promise<
|
|
|
19
19
|
sap_UoMs_total: number;
|
|
20
20
|
repzo_products_total: number;
|
|
21
21
|
}
|
|
22
|
+
| {
|
|
23
|
+
repzo_PL_total: number;
|
|
24
|
+
sap_PL_items_total: number;
|
|
25
|
+
repzo_PL_items_total: number;
|
|
26
|
+
repzo_PL_items: {
|
|
27
|
+
removed: number;
|
|
28
|
+
failed: number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
22
31
|
>;
|
|
23
32
|
export declare const commandsList: Command[];
|
package/lib/commands/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import { sync_bank } from "./bank.js";
|
|
|
13
13
|
import { sync_product } from "./product.js";
|
|
14
14
|
import { sync_disabled_product } from "./product_disabled.js";
|
|
15
15
|
import { sync_price_list } from "./price_list.js";
|
|
16
|
+
import { sync_price_list_disabled } from "./price_list_disabled.js";
|
|
16
17
|
import { sync_client } from "./client.js";
|
|
17
18
|
import { sync_disabled_client } from "./client_disabled.js";
|
|
18
19
|
import { adjust_inventory } from "./adjust_inventory.js";
|
|
@@ -49,6 +50,8 @@ export const commands = async (CommandEvent) => {
|
|
|
49
50
|
return await sync_disabled_product(CommandEvent);
|
|
50
51
|
case "price_list":
|
|
51
52
|
return await sync_price_list(CommandEvent);
|
|
53
|
+
case "price_list_disabled":
|
|
54
|
+
return await sync_price_list_disabled(CommandEvent);
|
|
52
55
|
case "client":
|
|
53
56
|
return await sync_client(CommandEvent);
|
|
54
57
|
case "disabled_client":
|
|
@@ -325,7 +325,7 @@ export const sync_price_list = async (commandEvent) => {
|
|
|
325
325
|
continue;
|
|
326
326
|
}
|
|
327
327
|
const repzo_price_list_items = await repzo.priceListItem.find({
|
|
328
|
-
disabled: false,
|
|
328
|
+
// disabled: false,
|
|
329
329
|
pricelist_id:
|
|
330
330
|
repzo_PriceList === null || repzo_PriceList === void 0
|
|
331
331
|
? void 0
|
|
@@ -518,6 +518,7 @@ export const sync_price_list = async (commandEvent) => {
|
|
|
518
518
|
variant_id: variant._id,
|
|
519
519
|
pricelist_id: repzo_PriceList._id,
|
|
520
520
|
price: price,
|
|
521
|
+
disabled: false,
|
|
521
522
|
};
|
|
522
523
|
// console.log(data);
|
|
523
524
|
const is_found_in_repzo_db =
|
|
@@ -559,7 +560,11 @@ export const sync_price_list = async (commandEvent) => {
|
|
|
559
560
|
result.PL_items.failed++;
|
|
560
561
|
}
|
|
561
562
|
} else {
|
|
562
|
-
if (
|
|
563
|
+
if (
|
|
564
|
+
is_found_in_repzo_db.price == body.price &&
|
|
565
|
+
!is_found_in_repzo_db.disabled
|
|
566
|
+
)
|
|
567
|
+
continue;
|
|
563
568
|
// Update
|
|
564
569
|
try {
|
|
565
570
|
const updated_PL_item = await repzo.priceListItem.update(
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CommandEvent } from "../types";
|
|
2
|
+
export declare const sync_price_list_disabled: (
|
|
3
|
+
commandEvent: CommandEvent
|
|
4
|
+
) => Promise<{
|
|
5
|
+
repzo_PL_total: number;
|
|
6
|
+
sap_PL_items_total: number;
|
|
7
|
+
repzo_PL_items_total: number;
|
|
8
|
+
repzo_PL_items: {
|
|
9
|
+
removed: number;
|
|
10
|
+
failed: number;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import Repzo from "repzo";
|
|
2
|
+
import { _create, update_bench_time, set_error } from "../util.js";
|
|
3
|
+
export const sync_price_list_disabled = async (commandEvent) => {
|
|
4
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
5
|
+
const repzo = new Repzo(
|
|
6
|
+
(_a = commandEvent.app.formData) === null || _a === void 0
|
|
7
|
+
? void 0
|
|
8
|
+
: _a.repzoApiKey,
|
|
9
|
+
{
|
|
10
|
+
env: commandEvent.env,
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
const commandLog = new Repzo.CommandLog(
|
|
14
|
+
repzo,
|
|
15
|
+
commandEvent.app,
|
|
16
|
+
commandEvent.command
|
|
17
|
+
);
|
|
18
|
+
try {
|
|
19
|
+
// console.log("sync_price_list_disabled");
|
|
20
|
+
const new_bench_time = new Date().toISOString();
|
|
21
|
+
const bench_time_key = "bench_time_price_list_disabled";
|
|
22
|
+
await commandLog.load(commandEvent.sync_id);
|
|
23
|
+
await commandLog
|
|
24
|
+
.addDetail("Repzo SAP: Started Syncing Disabled Price Lists")
|
|
25
|
+
.commit();
|
|
26
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
27
|
+
const result = {
|
|
28
|
+
repzo_PL_total: 0,
|
|
29
|
+
sap_PL_items_total: 0,
|
|
30
|
+
repzo_PL_items_total: 0,
|
|
31
|
+
repzo_PL_items: { removed: 0, failed: 0 },
|
|
32
|
+
};
|
|
33
|
+
const failed_docs_report = [];
|
|
34
|
+
// Get Repzo Price Lists
|
|
35
|
+
const repzo_price_lists = await repzo.priceList.find({
|
|
36
|
+
per_page: 50000,
|
|
37
|
+
disabled: false,
|
|
38
|
+
});
|
|
39
|
+
result.repzo_PL_total =
|
|
40
|
+
(_b =
|
|
41
|
+
repzo_price_lists === null || repzo_price_lists === void 0
|
|
42
|
+
? void 0
|
|
43
|
+
: repzo_price_lists.data) === null || _b === void 0
|
|
44
|
+
? void 0
|
|
45
|
+
: _b.length;
|
|
46
|
+
await commandLog
|
|
47
|
+
.addDetail(
|
|
48
|
+
`${
|
|
49
|
+
(_c =
|
|
50
|
+
repzo_price_lists === null || repzo_price_lists === void 0
|
|
51
|
+
? void 0
|
|
52
|
+
: repzo_price_lists.data) === null || _c === void 0
|
|
53
|
+
? void 0
|
|
54
|
+
: _c.length
|
|
55
|
+
} Active Price Lists in Repzo`
|
|
56
|
+
)
|
|
57
|
+
.commit();
|
|
58
|
+
// Start Code Here ***********************************************************
|
|
59
|
+
for (
|
|
60
|
+
let i = 0;
|
|
61
|
+
i <
|
|
62
|
+
((_d =
|
|
63
|
+
repzo_price_lists === null || repzo_price_lists === void 0
|
|
64
|
+
? void 0
|
|
65
|
+
: repzo_price_lists.data) === null || _d === void 0
|
|
66
|
+
? void 0
|
|
67
|
+
: _d.length);
|
|
68
|
+
i++
|
|
69
|
+
) {
|
|
70
|
+
const repzo_price_list = repzo_price_lists.data[i];
|
|
71
|
+
await commandLog
|
|
72
|
+
.addDetail(`Syncing Repzo Price List: ${repzo_price_list.name}`)
|
|
73
|
+
.commit();
|
|
74
|
+
if (
|
|
75
|
+
!((_e =
|
|
76
|
+
repzo_price_list === null || repzo_price_list === void 0
|
|
77
|
+
? void 0
|
|
78
|
+
: repzo_price_list.integration_meta) === null || _e === void 0
|
|
79
|
+
? void 0
|
|
80
|
+
: _e.id)
|
|
81
|
+
)
|
|
82
|
+
continue;
|
|
83
|
+
const sap_price_list_id =
|
|
84
|
+
repzo_price_list.integration_meta.id.split("_")[1];
|
|
85
|
+
if (!sap_price_list_id) continue;
|
|
86
|
+
const sap_price_list_items = await get_sap_price_list(
|
|
87
|
+
commandEvent.app.formData.sapHostUrl,
|
|
88
|
+
{
|
|
89
|
+
updateAt: "20000101:000000",
|
|
90
|
+
PLDID: sap_price_list_id,
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
result.sap_PL_items_total +=
|
|
94
|
+
(sap_price_list_items === null || sap_price_list_items === void 0
|
|
95
|
+
? void 0
|
|
96
|
+
: sap_price_list_items.length) || 0;
|
|
97
|
+
// await commandLog
|
|
98
|
+
// .addDetail(
|
|
99
|
+
// `${sap_price_list_items.length} Price List Item in PL: ${sap_price_list_id} in SAP`,
|
|
100
|
+
// )
|
|
101
|
+
// .commit();
|
|
102
|
+
const sap_items = {};
|
|
103
|
+
sap_price_list_items.forEach((sap_item) => {
|
|
104
|
+
const key = `${nameSpace}_${sap_item.PLDID}_${sap_item.PLITEMID}`;
|
|
105
|
+
sap_items[key] = sap_item;
|
|
106
|
+
});
|
|
107
|
+
const repzo_price_list_items = await repzo.priceListItem.find({
|
|
108
|
+
disabled: false,
|
|
109
|
+
pricelist_id:
|
|
110
|
+
repzo_price_list === null || repzo_price_list === void 0
|
|
111
|
+
? void 0
|
|
112
|
+
: repzo_price_list._id,
|
|
113
|
+
per_page: 50000,
|
|
114
|
+
});
|
|
115
|
+
result.repzo_PL_items_total +=
|
|
116
|
+
((_f =
|
|
117
|
+
repzo_price_list_items === null || repzo_price_list_items === void 0
|
|
118
|
+
? void 0
|
|
119
|
+
: repzo_price_list_items.data) === null || _f === void 0
|
|
120
|
+
? void 0
|
|
121
|
+
: _f.length) || 0;
|
|
122
|
+
// await commandLog
|
|
123
|
+
// .addDetail(
|
|
124
|
+
// `${repzo_price_list_items?.data?.length} Price List Item in PL: ${repzo_price_list.name} in Repzo`,
|
|
125
|
+
// )
|
|
126
|
+
// .commit();
|
|
127
|
+
for (
|
|
128
|
+
let j = 0;
|
|
129
|
+
j <
|
|
130
|
+
((_g =
|
|
131
|
+
repzo_price_list_items === null || repzo_price_list_items === void 0
|
|
132
|
+
? void 0
|
|
133
|
+
: repzo_price_list_items.data) === null || _g === void 0
|
|
134
|
+
? void 0
|
|
135
|
+
: _g.length);
|
|
136
|
+
j++
|
|
137
|
+
) {
|
|
138
|
+
const repzo_item = repzo_price_list_items.data[j];
|
|
139
|
+
const repzo_item_integration_meta_id =
|
|
140
|
+
(_h =
|
|
141
|
+
repzo_item === null || repzo_item === void 0
|
|
142
|
+
? void 0
|
|
143
|
+
: repzo_item.integration_meta) === null || _h === void 0
|
|
144
|
+
? void 0
|
|
145
|
+
: _h.id;
|
|
146
|
+
if (!repzo_item_integration_meta_id) continue;
|
|
147
|
+
if (sap_items[repzo_item_integration_meta_id]) continue;
|
|
148
|
+
// disable Repzo PriceListItem
|
|
149
|
+
try {
|
|
150
|
+
await repzo.priceListItem.remove(repzo_item._id);
|
|
151
|
+
// console.log({
|
|
152
|
+
// repzo_item_integration_meta_id,
|
|
153
|
+
// _id: repzo_item._id,
|
|
154
|
+
// });
|
|
155
|
+
result.repzo_PL_items.removed++;
|
|
156
|
+
} catch (e) {
|
|
157
|
+
console.log(
|
|
158
|
+
"Disable Price List Item Failed >> ",
|
|
159
|
+
(_j = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
160
|
+
_j === void 0
|
|
161
|
+
? void 0
|
|
162
|
+
: _j.data,
|
|
163
|
+
repzo_item
|
|
164
|
+
);
|
|
165
|
+
failed_docs_report.push({
|
|
166
|
+
method: "update",
|
|
167
|
+
doc_id:
|
|
168
|
+
repzo_item === null || repzo_item === void 0
|
|
169
|
+
? void 0
|
|
170
|
+
: repzo_item._id,
|
|
171
|
+
doc: repzo_item,
|
|
172
|
+
error_message: set_error(e),
|
|
173
|
+
});
|
|
174
|
+
result.repzo_PL_items.failed++;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// ***************************************************************************
|
|
179
|
+
// console.log(result);
|
|
180
|
+
await update_bench_time(
|
|
181
|
+
repzo,
|
|
182
|
+
commandEvent.app._id,
|
|
183
|
+
bench_time_key,
|
|
184
|
+
new_bench_time
|
|
185
|
+
);
|
|
186
|
+
await commandLog
|
|
187
|
+
.setStatus(
|
|
188
|
+
"success",
|
|
189
|
+
failed_docs_report.length ? failed_docs_report : null
|
|
190
|
+
)
|
|
191
|
+
.setBody(result)
|
|
192
|
+
.commit();
|
|
193
|
+
return result;
|
|
194
|
+
} catch (e) {
|
|
195
|
+
//@ts-ignore
|
|
196
|
+
console.error(
|
|
197
|
+
((_k = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
198
|
+
_k === void 0
|
|
199
|
+
? void 0
|
|
200
|
+
: _k.data) || e
|
|
201
|
+
);
|
|
202
|
+
await commandLog.setStatus("fail", e).commit();
|
|
203
|
+
throw e;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const get_sap_price_list = async (serviceEndPoint, query) => {
|
|
207
|
+
try {
|
|
208
|
+
const sap_price_lists = await _create(serviceEndPoint, "/PriceList", {
|
|
209
|
+
UpdateAt: query === null || query === void 0 ? void 0 : query.updateAt,
|
|
210
|
+
PLDID: query === null || query === void 0 ? void 0 : query.PLDID,
|
|
211
|
+
});
|
|
212
|
+
return sap_price_lists.PriceList;
|
|
213
|
+
} catch (e) {
|
|
214
|
+
throw e;
|
|
215
|
+
}
|
|
216
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -25,5 +25,14 @@ export declare const Commands: (
|
|
|
25
25
|
sap_UoMs_total: number;
|
|
26
26
|
repzo_products_total: number;
|
|
27
27
|
}
|
|
28
|
+
| {
|
|
29
|
+
repzo_PL_total: number;
|
|
30
|
+
sap_PL_items_total: number;
|
|
31
|
+
repzo_PL_items_total: number;
|
|
32
|
+
repzo_PL_items: {
|
|
33
|
+
removed: number;
|
|
34
|
+
failed: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
28
37
|
>;
|
|
29
38
|
export declare const CommandsList: import("./types.js").Command[];
|
|
@@ -223,6 +223,12 @@ let commandEvent = {
|
|
|
223
223
|
description: "Sync Price Lists From SAP to Repzo",
|
|
224
224
|
_id: "639972d6e8a1cfdd26deaa7e",
|
|
225
225
|
},
|
|
226
|
+
{
|
|
227
|
+
command: "price_list_disabled",
|
|
228
|
+
name: "Sync Disabled Price List Items",
|
|
229
|
+
description: "Sync Disabled Price List Items From SAP to Repzo",
|
|
230
|
+
_id: "639972d6e8a1cfdd26deaa7e",
|
|
231
|
+
},
|
|
226
232
|
{
|
|
227
233
|
command: "client",
|
|
228
234
|
name: "Sync Clients",
|
|
@@ -321,6 +327,7 @@ let commandEvent = {
|
|
|
321
327
|
bench_time_product: "2022-12-18T05:48:21.443Z",
|
|
322
328
|
bench_time_product_disabled: "2022-12-14T06:53:26.903Z",
|
|
323
329
|
bench_time_price_list: "2022-12-14T11:41:36.811Z",
|
|
330
|
+
bench_time_price_list_disabled: "2022-12-14T11:41:36.811Z",
|
|
324
331
|
bench_time_client: "2022-12-18T05:28:57.853Z",
|
|
325
332
|
bench_time_disabled_client: "2022-12-18T05:40:29.169Z",
|
|
326
333
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|