repzo-sap-absjo 1.0.15 → 1.0.18

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.
@@ -282,6 +282,8 @@ export const create_invoice = async (event, options) => {
282
282
  if (!repzo_product)
283
283
  throw `Product with _id: ${item.measureunit._id} not found in Repzo`;
284
284
  items.push({
285
+ MEO_Serial: getUniqueConcatenatedValues(item, "ref", " | "),
286
+ Promotion_Name: getUniqueConcatenatedValues(item, "name", " | "),
285
287
  ItemCode: item.variant.variant_name,
286
288
  Quantity: item.qty,
287
289
  TaxCode: repzo_tax.integration_meta.TaxCode,
@@ -367,3 +369,12 @@ export const get_invoice_from_sap = async (serviceEndPoint, query) => {
367
369
  throw e;
368
370
  }
369
371
  };
372
+ function getUniqueConcatenatedValues(item, key, delimiter) {
373
+ item.general_promotions = item.general_promotions || [];
374
+ item.used_promotions = item.used_promotions || [];
375
+ const allPromotions = [...item.general_promotions, ...item.used_promotions];
376
+ const uniqueValues = new Set(
377
+ allPromotions.map((promotion) => promotion[key]).filter((value) => value)
378
+ );
379
+ return [...uniqueValues].join(delimiter);
380
+ }
@@ -6,7 +6,7 @@ import {
6
6
  set_error,
7
7
  } from "../util.js";
8
8
  export const sync_disabled_product = async (commandEvent) => {
9
- var _a, _b, _c;
9
+ var _a, _b;
10
10
  const repzo = new Repzo(
11
11
  (_a = commandEvent.app.formData) === null || _a === void 0
12
12
  ? void 0
@@ -56,25 +56,21 @@ export const sync_disabled_product = async (commandEvent) => {
56
56
  sap_products === null || sap_products === void 0
57
57
  ? void 0
58
58
  : sap_products.map((product) => `${nameSpace}_${product.ITEMCODE}`);
59
- const repzo_products = [];
60
- const per_page = 200;
61
- const pages = Math.ceil(sap_product_query.length / per_page);
62
- for (let i = 0; i < pages; i += per_page) {
63
- const repzo_product_per_page = await repzo.product.find({
64
- active: true,
65
- per_page: 50000,
66
- "integration_meta.id": sap_product_query.slice(i, i + per_page),
67
- });
68
- if (
69
- (_b =
70
- repzo_product_per_page === null || repzo_product_per_page === void 0
71
- ? void 0
72
- : repzo_product_per_page.data) === null || _b === void 0
73
- ? void 0
74
- : _b.length
75
- )
76
- repzo_products.push(...repzo_product_per_page.data);
77
- }
59
+ const repzo_product_per_page = await repzo.patchAction.create(
60
+ {
61
+ slug: "product",
62
+ readQuery: [
63
+ { key: "active", value: [true], operator: "eq" },
64
+ {
65
+ key: "integration_meta.id",
66
+ value: sap_product_query,
67
+ operator: "in",
68
+ },
69
+ ],
70
+ },
71
+ { per_page: 50000 }
72
+ );
73
+ const repzo_products = repzo_product_per_page.data;
78
74
  result.repzo_total =
79
75
  repzo_products === null || repzo_products === void 0
80
76
  ? void 0
@@ -146,10 +142,10 @@ export const sync_disabled_product = async (commandEvent) => {
146
142
  } catch (e) {
147
143
  //@ts-ignore
148
144
  console.error(
149
- ((_c = e === null || e === void 0 ? void 0 : e.response) === null ||
150
- _c === void 0
145
+ ((_b = e === null || e === void 0 ? void 0 : e.response) === null ||
146
+ _b === void 0
151
147
  ? void 0
152
- : _c.data) || e
148
+ : _b.data) || e
153
149
  );
154
150
  await commandLog.setStatus("fail", e).commit();
155
151
  throw e;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "repzo-sap-absjo",
3
3
  "description": "repzo SAP ABS jo integration",
4
- "version": "1.0.15",
4
+ "version": "1.0.18",
5
5
  "homepage": "",
6
6
  "keywords": [],
7
7
  "author": {
@@ -45,7 +45,7 @@
45
45
  "jsonwebtoken": "^8.5.1",
46
46
  "lodash": "^4.17.21",
47
47
  "moment-timezone": "^0.5.34",
48
- "repzo": "^1.0.24",
48
+ "repzo": "^1.0.29",
49
49
  "uuid": "^8.3.2"
50
50
  }
51
51
  }
@@ -15,6 +15,8 @@ interface SAPInvoiceItem {
15
15
  UomCode: number; // 3;
16
16
  Brand: null;
17
17
  Department: string; // "D6";
18
+ MEO_Serial: string; //"used_promotion_ref1 | used_promotion_ref2"
19
+ Promotion_Name: string; //"used_promotion_name1 | used_promotion_name2"
18
20
  }
19
21
 
20
22
  interface SAPInvoice {
@@ -236,6 +238,8 @@ export const create_invoice = async (event: EVENT, options: Config) => {
236
238
  throw `Product with _id: ${item.measureunit._id} not found in Repzo`;
237
239
 
238
240
  items.push({
241
+ MEO_Serial: getUniqueConcatenatedValues(item, "ref", " | "),
242
+ Promotion_Name: getUniqueConcatenatedValues(item, "name", " | "),
239
243
  ItemCode: item.variant.variant_name,
240
244
  Quantity: item.qty,
241
245
  TaxCode: repzo_tax.integration_meta.TaxCode,
@@ -321,3 +325,20 @@ export const get_invoice_from_sap = async (
321
325
  throw e;
322
326
  }
323
327
  };
328
+
329
+ function getUniqueConcatenatedValues(
330
+ item: Service.Item.Schema,
331
+ key: "name" | "ref",
332
+ delimiter: string
333
+ ): string {
334
+ item.general_promotions = item.general_promotions || [];
335
+ item.used_promotions = item.used_promotions || [];
336
+ const allPromotions: { name: string; ref?: string; [key: string]: any }[] = [
337
+ ...item.general_promotions,
338
+ ...item.used_promotions,
339
+ ];
340
+ const uniqueValues = new Set(
341
+ allPromotions.map((promotion) => promotion[key]).filter((value) => value)
342
+ );
343
+ return [...uniqueValues].join(delimiter);
344
+ }
@@ -47,7 +47,7 @@ export const create_transfer = async (event: EVENT, options: Config) => {
47
47
  { key: "sync_to_sap_started", value: true },
48
48
  { key: "sync_to_sap_succeeded", value: false },
49
49
  ],
50
- { _id: body._id, type: "transfers" },
50
+ { _id: body._id, type: "transfers" }
51
51
  );
52
52
  } catch (e) {
53
53
  console.error(e);
@@ -56,7 +56,7 @@ export const create_transfer = async (event: EVENT, options: Config) => {
56
56
  await actionLog
57
57
  .addDetail(`Transfer - ${repzo_serial_number} => ${body?.sync_id}`)
58
58
  .addDetail(
59
- `Repzo => SAP: Started Create Transfer - ${repzo_serial_number}`,
59
+ `Repzo => SAP: Started Create Transfer - ${repzo_serial_number}`
60
60
  )
61
61
  .commit();
62
62
 
@@ -82,7 +82,7 @@ export const create_transfer = async (event: EVENT, options: Config) => {
82
82
  if (item?.product_id) {
83
83
  repzo_product_ids[item.product_id.toString()] = true;
84
84
  }
85
- },
85
+ }
86
86
  );
87
87
  const repzo_products = await repzo.patchAction.create(
88
88
  {
@@ -95,7 +95,7 @@ export const create_transfer = async (event: EVENT, options: Config) => {
95
95
  },
96
96
  ],
97
97
  },
98
- { per_page: 50000, populatedKeys: ["measureunit"] },
98
+ { per_page: 50000, populatedKeys: ["measureunit"] }
99
99
  );
100
100
 
101
101
  // Prepare Transfer Items
@@ -106,14 +106,14 @@ export const create_transfer = async (event: EVENT, options: Config) => {
106
106
 
107
107
  const repzo_product = repzo_products?.data?.find(
108
108
  //@ts-ignore
109
- (p) => p._id.toString() == repzo_transfer_item.product_id?.toString(),
109
+ (p) => p._id.toString() == repzo_transfer_item.product_id?.toString()
110
110
  );
111
111
  if (!repzo_product) {
112
112
  // console.log(
113
113
  // `Product with _id: ${repzo_transfer_item.product_id} was not found In Repzo`,
114
114
  // );
115
115
  throw new Error(
116
- `Product with _id: ${repzo_transfer_item.product_id} was not found in Repzo`,
116
+ `Product with _id: ${repzo_transfer_item.product_id} was not found in Repzo`
117
117
  );
118
118
  }
119
119
 
@@ -124,7 +124,7 @@ export const create_transfer = async (event: EVENT, options: Config) => {
124
124
  // `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`,
125
125
  // );
126
126
  throw new Error(
127
- `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`,
127
+ `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`
128
128
  );
129
129
  }
130
130
 
@@ -156,20 +156,20 @@ export const create_transfer = async (event: EVENT, options: Config) => {
156
156
 
157
157
  actionLog.addDetail(
158
158
  `Repzo => SAP: Transfer - ${repzo_serial_number}`,
159
- sap_transfer,
159
+ sap_transfer
160
160
  );
161
161
 
162
162
  const result = await _create(
163
163
  SAP_HOST_URL,
164
164
  "/AddStockTransfer",
165
- sap_transfer,
165
+ sap_transfer
166
166
  );
167
167
 
168
168
  // console.log(result);
169
169
  try {
170
170
  await repzo.updateIntegrationMeta.create(
171
171
  [{ key: "sync_to_sap_succeeded", value: true }],
172
- { _id: body._id, type: "transfers" },
172
+ { _id: body._id, type: "transfers" }
173
173
  );
174
174
  } catch (e) {
175
175
  console.error(e);
@@ -62,18 +62,21 @@ export const sync_disabled_product = async (commandEvent: CommandEvent) => {
62
62
  (product) => `${nameSpace}_${product.ITEMCODE}`
63
63
  );
64
64
 
65
- const repzo_products = [];
66
- const per_page = 200;
67
- const pages = Math.ceil(sap_product_query.length / per_page);
68
- for (let i = 0; i < pages; i += per_page) {
69
- const repzo_product_per_page = await repzo.product.find({
70
- active: true,
71
- per_page: 50000,
72
- "integration_meta.id": sap_product_query.slice(i, i + per_page),
73
- });
74
- if (repzo_product_per_page?.data?.length)
75
- repzo_products.push(...repzo_product_per_page.data);
76
- }
65
+ const repzo_product_per_page = await repzo.patchAction.create(
66
+ {
67
+ slug: "product",
68
+ readQuery: [
69
+ { key: "active", value: [true], operator: "eq" },
70
+ {
71
+ key: "integration_meta.id",
72
+ value: sap_product_query,
73
+ operator: "in",
74
+ },
75
+ ],
76
+ },
77
+ { per_page: 50000 }
78
+ );
79
+ const repzo_products = repzo_product_per_page.data;
77
80
 
78
81
  result.repzo_total = repzo_products?.length;
79
82
  await commandLog