repzo-sap-absjo 1.0.11 → 1.0.12

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 CHANGED
@@ -11,6 +11,7 @@
11
11
 
12
12
  - [commands/rep] delete hard code of rep.warehouse for reps start with: [WS, RET, MT] @maramalshen
13
13
  - [commands/client] decide if client is cash or credit depend on PAYMENTTERM instead of CLIENTGROUP @maramalshen
14
+ - [actions/**] update integration_meta using repzo.updateIntegrationMeta instead of using service.update method to avoid infinity looping @maramalshen
14
15
 
15
16
  ### Fixed
16
17
 
@@ -28,17 +28,13 @@ export const create_invoice = async (event, options) => {
28
28
  ? void 0
29
29
  : _c.formatted;
30
30
  try {
31
- if (body === null || body === void 0 ? void 0 : body._id) {
32
- body.integration_meta =
33
- (body === null || body === void 0 ? void 0 : body.integration_meta) ||
34
- {};
35
- body.integration_meta.sync_to_sap_started = true;
36
- body.integration_meta.sync_to_sap_succeeded =
37
- body.integration_meta.sync_to_sap_succeeded || false;
38
- await repzo.invoice.update(body._id, {
39
- integration_meta: body.integration_meta,
40
- });
41
- }
31
+ await repzo.updateIntegrationMeta.create(
32
+ [
33
+ { key: "sync_to_sap_started", value: true },
34
+ { key: "sync_to_sap_succeeded", value: false },
35
+ ],
36
+ { _id: body._id, type: "fullinvoices" }
37
+ );
42
38
  } catch (e) {
43
39
  console.error(e);
44
40
  }
@@ -336,15 +332,10 @@ export const create_invoice = async (event, options) => {
336
332
  const result = await _create(SAP_HOST_URL, "/AddInvoice", sap_invoice);
337
333
  // console.log(result);
338
334
  try {
339
- if (body === null || body === void 0 ? void 0 : body._id) {
340
- body.integration_meta =
341
- (body === null || body === void 0 ? void 0 : body.integration_meta) ||
342
- {};
343
- body.integration_meta.sync_to_sap_succeeded = true;
344
- await repzo.invoice.update(body._id, {
345
- integration_meta: body.integration_meta,
346
- });
347
- }
335
+ await repzo.updateIntegrationMeta.create(
336
+ [{ key: "sync_to_sap_succeeded", value: true }],
337
+ { _id: body._id, type: "fullinvoices" }
338
+ );
348
339
  } catch (e) {
349
340
  console.error(e);
350
341
  }
@@ -29,17 +29,13 @@ export const create_payment = async (event, options) => {
29
29
  ? void 0
30
30
  : _c.formatted;
31
31
  try {
32
- if (body === null || body === void 0 ? void 0 : body._id) {
33
- body.integration_meta =
34
- (body === null || body === void 0 ? void 0 : body.integration_meta) ||
35
- {};
36
- body.integration_meta.sync_to_sap_started = true;
37
- body.integration_meta.sync_to_sap_succeeded =
38
- body.integration_meta.sync_to_sap_succeeded || false;
39
- await repzo.payment.update(body._id, {
40
- integration_meta: body.integration_meta,
41
- });
42
- }
32
+ await repzo.updateIntegrationMeta.create(
33
+ [
34
+ { key: "sync_to_sap_started", value: true },
35
+ { key: "sync_to_sap_succeeded", value: false },
36
+ ],
37
+ { _id: body._id, type: "payments" }
38
+ );
43
39
  } catch (e) {
44
40
  console.error(e);
45
41
  }
@@ -183,15 +179,10 @@ export const create_payment = async (event, options) => {
183
179
  const result = await _create(SAP_HOST_URL, "/AddPayment", sap_payment);
184
180
  // console.log(result);
185
181
  try {
186
- if (body === null || body === void 0 ? void 0 : body._id) {
187
- body.integration_meta =
188
- (body === null || body === void 0 ? void 0 : body.integration_meta) ||
189
- {};
190
- body.integration_meta.sync_to_sap_succeeded = true;
191
- await repzo.payment.update(body._id, {
192
- integration_meta: body.integration_meta,
193
- });
194
- }
182
+ await repzo.updateIntegrationMeta.create(
183
+ [{ key: "sync_to_sap_succeeded", value: true }],
184
+ { _id: body._id, type: "payments" }
185
+ );
195
186
  } catch (e) {
196
187
  console.error(e);
197
188
  }
@@ -27,19 +27,17 @@ export const create_proforma = async (event, options) => {
27
27
  null || _c === void 0
28
28
  ? void 0
29
29
  : _c.formatted;
30
- // try {
31
- // if (body?._id) {
32
- // body.integration_meta = body?.integration_meta || {};
33
- // body.integration_meta.sync_to_sap_started = true;
34
- // body.integration_meta.sync_to_sap_succeeded =
35
- // body.integration_meta.sync_to_sap_succeeded || false;
36
- // await repzo.proforma.update(body._id, {
37
- // integration_meta: body.integration_meta,
38
- // });
39
- // }
40
- // } catch (e) {
41
- // console.error(e);
42
- // }
30
+ try {
31
+ await repzo.updateIntegrationMeta.create(
32
+ [
33
+ { key: "sync_to_sap_started", value: true },
34
+ { key: "sync_to_sap_succeeded", value: false },
35
+ ],
36
+ { _id: body._id, type: "proformas" }
37
+ );
38
+ } catch (e) {
39
+ console.error(e);
40
+ }
43
41
  await actionLog
44
42
  .addDetail(
45
43
  `SalesOrder - ${repzo_serial_number} => ${
@@ -274,17 +272,14 @@ export const create_proforma = async (event, options) => {
274
272
  ); // .commit();
275
273
  const result = await _create(SAP_HOST_URL, "/AddOrder", sap_invoice);
276
274
  // console.log(result);
277
- // try {
278
- // if (body?._id) {
279
- // body.integration_meta = body?.integration_meta || {};
280
- // body.integration_meta.sync_to_sap_succeeded = true;
281
- // await repzo.proforma.update(body._id, {
282
- // integration_meta: body.integration_meta,
283
- // });
284
- // }
285
- // } catch (e) {
286
- // console.error(e);
287
- // }
275
+ try {
276
+ await repzo.updateIntegrationMeta.create(
277
+ [{ key: "sync_to_sap_succeeded", value: true }],
278
+ { _id: body._id, type: "proformas" }
279
+ );
280
+ } catch (e) {
281
+ console.error(e);
282
+ }
288
283
  await actionLog
289
284
  .addDetail(`SAP Responded with `, result)
290
285
  .addDetail(`Repzo => SAP: SalesOrder - ${repzo_serial_number}`)
@@ -28,17 +28,13 @@ export const create_return_invoice = async (event, options) => {
28
28
  ? void 0
29
29
  : _c.formatted;
30
30
  try {
31
- if (body === null || body === void 0 ? void 0 : body._id) {
32
- body.integration_meta =
33
- (body === null || body === void 0 ? void 0 : body.integration_meta) ||
34
- {};
35
- body.integration_meta.sync_to_sap_started = true;
36
- body.integration_meta.sync_to_sap_succeeded =
37
- body.integration_meta.sync_to_sap_succeeded || false;
38
- await repzo.invoice.update(body._id, {
39
- integration_meta: body.integration_meta,
40
- });
41
- }
31
+ await repzo.updateIntegrationMeta.create(
32
+ [
33
+ { key: "sync_to_sap_started", value: true },
34
+ { key: "sync_to_sap_succeeded", value: false },
35
+ ],
36
+ { _id: body._id, type: "fullinvoices" }
37
+ );
42
38
  } catch (e) {
43
39
  console.error(e);
44
40
  }
@@ -304,15 +300,10 @@ export const create_return_invoice = async (event, options) => {
304
300
  );
305
301
  // console.log(result);
306
302
  try {
307
- if (body === null || body === void 0 ? void 0 : body._id) {
308
- body.integration_meta =
309
- (body === null || body === void 0 ? void 0 : body.integration_meta) ||
310
- {};
311
- body.integration_meta.sync_to_sap_succeeded = true;
312
- await repzo.invoice.update(body._id, {
313
- integration_meta: body.integration_meta,
314
- });
315
- }
303
+ await repzo.updateIntegrationMeta.create(
304
+ [{ key: "sync_to_sap_succeeded", value: true }],
305
+ { _id: body._id, type: "fullinvoices" }
306
+ );
316
307
  } catch (e) {
317
308
  console.error(e);
318
309
  }
@@ -34,19 +34,17 @@ export const create_transfer = async (event, options) => {
34
34
  null || _d === void 0
35
35
  ? void 0
36
36
  : _d.formatted;
37
- // try {
38
- // if (body?._id) {
39
- // body.integration_meta = body?.integration_meta || {};
40
- // body.integration_meta.sync_to_sap_started = true;
41
- // body.integration_meta.sync_to_sap_succeeded =
42
- // body.integration_meta.sync_to_sap_succeeded || false;
43
- // await repzo.transfer.update(body._id, {
44
- // integration_meta: body.integration_meta,
45
- // });
46
- // }
47
- // } catch (e) {
48
- // console.error(e);
49
- // }
37
+ try {
38
+ await repzo.updateIntegrationMeta.create(
39
+ [
40
+ { key: "sync_to_sap_started", value: true },
41
+ { key: "sync_to_sap_succeeded", value: false },
42
+ ],
43
+ { _id: body._id, type: "transfers" }
44
+ );
45
+ } catch (e) {
46
+ console.error(e);
47
+ }
50
48
  await actionLog
51
49
  .addDetail(
52
50
  `Transfer - ${repzo_serial_number} => ${
@@ -190,13 +188,10 @@ export const create_transfer = async (event, options) => {
190
188
  );
191
189
  // console.log(result);
192
190
  try {
193
- // if (body?._id) {
194
- // body.integration_meta = body?.integration_meta || {};
195
- // body.integration_meta.sync_to_sap_succeeded = true;
196
- // await repzo.transfer.update(body._id, {
197
- // integration_meta: body.integration_meta,
198
- // });
199
- // }
191
+ await repzo.updateIntegrationMeta.create(
192
+ [{ key: "sync_to_sap_succeeded", value: true }],
193
+ { _id: body._id, type: "transfers" }
194
+ );
200
195
  } catch (e) {
201
196
  console.error(e);
202
197
  }
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.11",
4
+ "version": "1.0.12",
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.23",
48
+ "repzo": "^1.0.24",
49
49
  "uuid": "^8.3.2"
50
50
  }
51
51
  }
@@ -63,15 +63,13 @@ export const create_invoice = async (event: EVENT, options: Config) => {
63
63
 
64
64
  const repzo_serial_number = body?.serial_number?.formatted;
65
65
  try {
66
- if (body?._id) {
67
- body.integration_meta = body?.integration_meta || {};
68
- body.integration_meta.sync_to_sap_started = true;
69
- body.integration_meta.sync_to_sap_succeeded =
70
- body.integration_meta.sync_to_sap_succeeded || false;
71
- await repzo.invoice.update(body._id, {
72
- integration_meta: body.integration_meta,
73
- });
74
- }
66
+ await repzo.updateIntegrationMeta.create(
67
+ [
68
+ { key: "sync_to_sap_started", value: true },
69
+ { key: "sync_to_sap_succeeded", value: false },
70
+ ],
71
+ { _id: body._id, type: "fullinvoices" }
72
+ );
75
73
  } catch (e) {
76
74
  console.error(e);
77
75
  }
@@ -281,13 +279,10 @@ export const create_invoice = async (event: EVENT, options: Config) => {
281
279
  // console.log(result);
282
280
 
283
281
  try {
284
- if (body?._id) {
285
- body.integration_meta = body?.integration_meta || {};
286
- body.integration_meta.sync_to_sap_succeeded = true;
287
- await repzo.invoice.update(body._id, {
288
- integration_meta: body.integration_meta,
289
- });
290
- }
282
+ await repzo.updateIntegrationMeta.create(
283
+ [{ key: "sync_to_sap_succeeded", value: true }],
284
+ { _id: body._id, type: "fullinvoices" }
285
+ );
291
286
  } catch (e) {
292
287
  console.error(e);
293
288
  }
@@ -38,15 +38,13 @@ export const create_payment = async (event: EVENT, options: Config) => {
38
38
 
39
39
  const repzo_serial_number = body?.serial_number?.formatted;
40
40
  try {
41
- if (body?._id) {
42
- body.integration_meta = body?.integration_meta || {};
43
- body.integration_meta.sync_to_sap_started = true;
44
- body.integration_meta.sync_to_sap_succeeded =
45
- body.integration_meta.sync_to_sap_succeeded || false;
46
- await repzo.payment.update(body._id, {
47
- integration_meta: body.integration_meta,
48
- });
49
- }
41
+ await repzo.updateIntegrationMeta.create(
42
+ [
43
+ { key: "sync_to_sap_started", value: true },
44
+ { key: "sync_to_sap_succeeded", value: false },
45
+ ],
46
+ { _id: body._id, type: "payments" }
47
+ );
50
48
  } catch (e) {
51
49
  console.error(e);
52
50
  }
@@ -138,13 +136,10 @@ export const create_payment = async (event: EVENT, options: Config) => {
138
136
  // console.log(result);
139
137
 
140
138
  try {
141
- if (body?._id) {
142
- body.integration_meta = body?.integration_meta || {};
143
- body.integration_meta.sync_to_sap_succeeded = true;
144
- await repzo.payment.update(body._id, {
145
- integration_meta: body.integration_meta,
146
- });
147
- }
139
+ await repzo.updateIntegrationMeta.create(
140
+ [{ key: "sync_to_sap_succeeded", value: true }],
141
+ { _id: body._id, type: "payments" }
142
+ );
148
143
  } catch (e) {
149
144
  console.error(e);
150
145
  }
@@ -44,19 +44,17 @@ export const create_proforma = async (event: EVENT, options: Config) => {
44
44
  } catch (e) {}
45
45
 
46
46
  const repzo_serial_number = body?.serial_number?.formatted;
47
- // try {
48
- // if (body?._id) {
49
- // body.integration_meta = body?.integration_meta || {};
50
- // body.integration_meta.sync_to_sap_started = true;
51
- // body.integration_meta.sync_to_sap_succeeded =
52
- // body.integration_meta.sync_to_sap_succeeded || false;
53
- // await repzo.proforma.update(body._id, {
54
- // integration_meta: body.integration_meta,
55
- // });
56
- // }
57
- // } catch (e) {
58
- // console.error(e);
59
- // }
47
+ try {
48
+ await repzo.updateIntegrationMeta.create(
49
+ [
50
+ { key: "sync_to_sap_started", value: true },
51
+ { key: "sync_to_sap_succeeded", value: false },
52
+ ],
53
+ { _id: body._id, type: "proformas" }
54
+ );
55
+ } catch (e) {
56
+ console.error(e);
57
+ }
60
58
 
61
59
  await actionLog
62
60
  .addDetail(`SalesOrder - ${repzo_serial_number} => ${body?.sync_id}`)
@@ -208,17 +206,14 @@ export const create_proforma = async (event: EVENT, options: Config) => {
208
206
 
209
207
  // console.log(result);
210
208
 
211
- // try {
212
- // if (body?._id) {
213
- // body.integration_meta = body?.integration_meta || {};
214
- // body.integration_meta.sync_to_sap_succeeded = true;
215
- // await repzo.proforma.update(body._id, {
216
- // integration_meta: body.integration_meta,
217
- // });
218
- // }
219
- // } catch (e) {
220
- // console.error(e);
221
- // }
209
+ try {
210
+ await repzo.updateIntegrationMeta.create(
211
+ [{ key: "sync_to_sap_succeeded", value: true }],
212
+ { _id: body._id, type: "proformas" }
213
+ );
214
+ } catch (e) {
215
+ console.error(e);
216
+ }
222
217
 
223
218
  await actionLog
224
219
  .addDetail(`SAP Responded with `, result)
@@ -53,15 +53,13 @@ export const create_return_invoice = async (event: EVENT, options: Config) => {
53
53
 
54
54
  const repzo_serial_number = body?.serial_number?.formatted;
55
55
  try {
56
- if (body?._id) {
57
- body.integration_meta = body?.integration_meta || {};
58
- body.integration_meta.sync_to_sap_started = true;
59
- body.integration_meta.sync_to_sap_succeeded =
60
- body.integration_meta.sync_to_sap_succeeded || false;
61
- await repzo.invoice.update(body._id, {
62
- integration_meta: body.integration_meta,
63
- });
64
- }
56
+ await repzo.updateIntegrationMeta.create(
57
+ [
58
+ { key: "sync_to_sap_started", value: true },
59
+ { key: "sync_to_sap_succeeded", value: false },
60
+ ],
61
+ { _id: body._id, type: "fullinvoices" }
62
+ );
65
63
  } catch (e) {
66
64
  console.error(e);
67
65
  }
@@ -240,13 +238,10 @@ export const create_return_invoice = async (event: EVENT, options: Config) => {
240
238
  // console.log(result);
241
239
 
242
240
  try {
243
- if (body?._id) {
244
- body.integration_meta = body?.integration_meta || {};
245
- body.integration_meta.sync_to_sap_succeeded = true;
246
- await repzo.invoice.update(body._id, {
247
- integration_meta: body.integration_meta,
248
- });
249
- }
241
+ await repzo.updateIntegrationMeta.create(
242
+ [{ key: "sync_to_sap_succeeded", value: true }],
243
+ { _id: body._id, type: "fullinvoices" }
244
+ );
250
245
  } catch (e) {
251
246
  console.error(e);
252
247
  }
@@ -41,24 +41,22 @@ export const create_transfer = async (event: EVENT, options: Config) => {
41
41
  if (body?.integration_meta?.sync_to_sap_started) return;
42
42
  await actionLog.load(action_sync_id);
43
43
  const repzo_serial_number = body?.serial_number?.formatted;
44
- // try {
45
- // if (body?._id) {
46
- // body.integration_meta = body?.integration_meta || {};
47
- // body.integration_meta.sync_to_sap_started = true;
48
- // body.integration_meta.sync_to_sap_succeeded =
49
- // body.integration_meta.sync_to_sap_succeeded || false;
50
- // await repzo.transfer.update(body._id, {
51
- // integration_meta: body.integration_meta,
52
- // });
53
- // }
54
- // } catch (e) {
55
- // console.error(e);
56
- // }
44
+ try {
45
+ await repzo.updateIntegrationMeta.create(
46
+ [
47
+ { key: "sync_to_sap_started", value: true },
48
+ { key: "sync_to_sap_succeeded", value: false },
49
+ ],
50
+ { _id: body._id, type: "transfers" },
51
+ );
52
+ } catch (e) {
53
+ console.error(e);
54
+ }
57
55
 
58
56
  await actionLog
59
57
  .addDetail(`Transfer - ${repzo_serial_number} => ${body?.sync_id}`)
60
58
  .addDetail(
61
- `Repzo => SAP: Started Create Transfer - ${repzo_serial_number}`
59
+ `Repzo => SAP: Started Create Transfer - ${repzo_serial_number}`,
62
60
  )
63
61
  .commit();
64
62
 
@@ -84,7 +82,7 @@ export const create_transfer = async (event: EVENT, options: Config) => {
84
82
  if (item?.product_id) {
85
83
  repzo_product_ids[item.product_id.toString()] = true;
86
84
  }
87
- }
85
+ },
88
86
  );
89
87
  const repzo_products = await repzo.patchAction.create(
90
88
  {
@@ -97,7 +95,7 @@ export const create_transfer = async (event: EVENT, options: Config) => {
97
95
  },
98
96
  ],
99
97
  },
100
- { per_page: 50000, populatedKeys: ["measureunit"] }
98
+ { per_page: 50000, populatedKeys: ["measureunit"] },
101
99
  );
102
100
 
103
101
  // Prepare Transfer Items
@@ -108,14 +106,14 @@ export const create_transfer = async (event: EVENT, options: Config) => {
108
106
 
109
107
  const repzo_product = repzo_products?.data?.find(
110
108
  //@ts-ignore
111
- (p) => p._id.toString() == repzo_transfer_item.product_id?.toString()
109
+ (p) => p._id.toString() == repzo_transfer_item.product_id?.toString(),
112
110
  );
113
111
  if (!repzo_product) {
114
112
  // console.log(
115
113
  // `Product with _id: ${repzo_transfer_item.product_id} was not found In Repzo`,
116
114
  // );
117
115
  throw new Error(
118
- `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`,
119
117
  );
120
118
  }
121
119
 
@@ -126,7 +124,7 @@ export const create_transfer = async (event: EVENT, options: Config) => {
126
124
  // `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`,
127
125
  // );
128
126
  throw new Error(
129
- `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`
127
+ `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`,
130
128
  );
131
129
  }
132
130
 
@@ -158,24 +156,21 @@ export const create_transfer = async (event: EVENT, options: Config) => {
158
156
 
159
157
  actionLog.addDetail(
160
158
  `Repzo => SAP: Transfer - ${repzo_serial_number}`,
161
- sap_transfer
159
+ sap_transfer,
162
160
  );
163
161
 
164
162
  const result = await _create(
165
163
  SAP_HOST_URL,
166
164
  "/AddStockTransfer",
167
- sap_transfer
165
+ sap_transfer,
168
166
  );
169
167
 
170
168
  // console.log(result);
171
169
  try {
172
- // if (body?._id) {
173
- // body.integration_meta = body?.integration_meta || {};
174
- // body.integration_meta.sync_to_sap_succeeded = true;
175
- // await repzo.transfer.update(body._id, {
176
- // integration_meta: body.integration_meta,
177
- // });
178
- // }
170
+ await repzo.updateIntegrationMeta.create(
171
+ [{ key: "sync_to_sap_succeeded", value: true }],
172
+ { _id: body._id, type: "transfers" },
173
+ );
179
174
  } catch (e) {
180
175
  console.error(e);
181
176
  }