repzo-sap-absjo 1.0.57 → 1.0.58

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.
@@ -2,7 +2,7 @@ import Repzo from "repzo";
2
2
  import { _create, send_command_to_marketplace } from "../util.js";
3
3
  import { v4 as uuid } from "uuid";
4
4
  export const create_transfer = async (event, options) => {
5
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
6
6
  const repzo = new Repzo(
7
7
  (_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
8
8
  { env: options.env }
@@ -127,9 +127,6 @@ export const create_transfer = async (event, options) => {
127
127
  }
128
128
  );
129
129
  if (!repzo_product) {
130
- // console.log(
131
- // `Product with _id: ${repzo_transfer_item.product_id} was not found In Repzo`,
132
- // );
133
130
  throw new Error(
134
131
  `Product with _id: ${repzo_transfer_item.product_id} was not found in Repzo`
135
132
  );
@@ -140,9 +137,6 @@ export const create_transfer = async (event, options) => {
140
137
  ? void 0
141
138
  : repzo_measure_unit._id)
142
139
  ) {
143
- // console.log(
144
- // `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`,
145
- // );
146
140
  throw new Error(
147
141
  `Measureunit with _id: ${
148
142
  (_k = repzo_product.sv_measureUnit) === null || _k === void 0
@@ -163,15 +157,20 @@ export const create_transfer = async (event, options) => {
163
157
  //@ts-ignore
164
158
  ToWarehouse:
165
159
  (_m = repzo_transfer.to) === null || _m === void 0 ? void 0 : _m.code,
160
+ UoMEntry:
161
+ (_o = repzo_measure_unit.integration_meta) === null || _o === void 0
162
+ ? void 0
163
+ : _o.ALTUOMID, // (read from Uoms UoMID)
164
+ UoMCode: repzo_measure_unit.name, // (read from Uoms UoMCode)
166
165
  });
167
166
  }
168
167
  const sap_transfer = {
169
168
  StockTransferID: body.serial_number.formatted,
170
169
  SalesPersonCode: repzo_rep
171
170
  ? repzo_rep.integration_id
172
- : (_o = options.data) === null || _o === void 0
171
+ : (_p = options.data) === null || _p === void 0
173
172
  ? void 0
174
- : _o.SalesPersonCode, // "111"
173
+ : _p.SalesPersonCode, // "111"
175
174
  FromWarehouse: body.from.code,
176
175
  ToWarehouse: body.to.code,
177
176
  RepzoStockTransferLines: variants,
@@ -207,23 +206,23 @@ export const create_transfer = async (event, options) => {
207
206
  console.error((e === null || e === void 0 ? void 0 : e.response) || e);
208
207
  await actionLog.setStatus("fail", e).setBody(body).commit();
209
208
  if (
210
- (_q =
211
- (_p =
209
+ (_r =
210
+ (_q =
212
211
  options === null || options === void 0 ? void 0 : options.data) ===
213
- null || _p === void 0
212
+ null || _q === void 0
214
213
  ? void 0
215
- : _p.transfers) === null || _q === void 0
214
+ : _q.transfers) === null || _r === void 0
216
215
  ? void 0
217
- : _q.adjustInventoryInFailedTransfer
216
+ : _r.adjustInventoryInFailedTransfer
218
217
  ) {
219
218
  send_command_to_marketplace({
220
219
  command: "adjust_inventory",
221
220
  app_id: options.app_id,
222
221
  env: options.env,
223
222
  repzoApiKey:
224
- (_r = options.data) === null || _r === void 0
223
+ (_s = options.data) === null || _s === void 0
225
224
  ? void 0
226
- : _r.repzoApiKey,
225
+ : _s.repzoApiKey,
227
226
  });
228
227
  }
229
228
  throw e;
@@ -147,7 +147,7 @@ export const adjust_inventory = async (commandEvent) => {
147
147
  //@ts-ignore
148
148
  variants: sap_inventory.items
149
149
  .map((sap_item) => {
150
- var _a, _b, _c, _d;
150
+ var _a, _b, _c, _d, _e, _f;
151
151
  try {
152
152
  const variant =
153
153
  (_a =
@@ -194,14 +194,27 @@ export const adjust_inventory = async (commandEvent) => {
194
194
  // );
195
195
  throw `MeasureUnit with UNITNAME: ${sap_item.UNITNAME} & ALTUOMID: ${sap_item.UNITID} was not found`;
196
196
  }
197
- const qty = sap_item.QTY; //* measureUnit.factor *;
197
+ let qty;
198
+ if (
199
+ (_d =
200
+ (_c = commandEvent.app.formData) === null || _c === void 0
201
+ ? void 0
202
+ : _c.usePiecesAndIgnoreMeasureunitFactor) === null ||
203
+ _d === void 0
204
+ ? void 0
205
+ : _d.usePcsForAdjustInventory
206
+ ) {
207
+ qty = sap_item.QTY;
208
+ } else {
209
+ qty = measureUnit.factor * sap_item.QTY;
210
+ }
198
211
  const match_item_in_repzo_inventory =
199
- (_c =
212
+ (_e =
200
213
  repzo_inventory === null || repzo_inventory === void 0
201
214
  ? void 0
202
- : repzo_inventory.data) === null || _c === void 0
215
+ : repzo_inventory.data) === null || _e === void 0
203
216
  ? void 0
204
- : _c.find(
217
+ : _e.find(
205
218
  (repzo_item) =>
206
219
  repzo_item.variant_id.toString() ==
207
220
  variant._id.toString()
@@ -222,9 +235,9 @@ export const adjust_inventory = async (commandEvent) => {
222
235
  doc: {
223
236
  ...sap_item,
224
237
  STOREID:
225
- (_d = sap_inventories[i]) === null || _d === void 0
238
+ (_f = sap_inventories[i]) === null || _f === void 0
226
239
  ? void 0
227
- : _d.STOREID,
240
+ : _f.STOREID,
228
241
  },
229
242
  error_message: set_error(e),
230
243
  });
@@ -347,7 +360,7 @@ export const adjust_inventory = async (commandEvent) => {
347
360
  });
348
361
  });
349
362
  let variants = Object.values(shared_inventory).map((sap_item) => {
350
- var _a, _b, _c;
363
+ var _a, _b, _c, _d, _e;
351
364
  try {
352
365
  const variant =
353
366
  (_a =
@@ -394,14 +407,27 @@ export const adjust_inventory = async (commandEvent) => {
394
407
  // );
395
408
  throw `MeasureUnit with UNITNAME: ${sap_item.UNITNAME} & ALTUOMID: ${sap_item.UNITID} was not found`;
396
409
  }
397
- const qty = sap_item.QTY; //* measureUnit.factor
410
+ let qty;
411
+ if (
412
+ (_d =
413
+ (_c = commandEvent.app.formData) === null || _c === void 0
414
+ ? void 0
415
+ : _c.usePiecesAndIgnoreMeasureunitFactor) === null ||
416
+ _d === void 0
417
+ ? void 0
418
+ : _d.usePcsForAdjustInventory
419
+ ) {
420
+ qty = sap_item.QTY;
421
+ } else {
422
+ qty = measureUnit.factor * sap_item.QTY;
423
+ }
398
424
  const match_item_in_repzo_inventory =
399
- (_c =
425
+ (_e =
400
426
  repzo_inventory === null || repzo_inventory === void 0
401
427
  ? void 0
402
- : repzo_inventory.data) === null || _c === void 0
428
+ : repzo_inventory.data) === null || _e === void 0
403
429
  ? void 0
404
- : _c.find(
430
+ : _e.find(
405
431
  (repzo_item) =>
406
432
  repzo_item.variant_id.toString() ==
407
433
  variant._id.toString()
@@ -22,7 +22,9 @@ export const sync_price_list = async (commandEvent) => {
22
22
  _t,
23
23
  _u,
24
24
  _v,
25
- _w;
25
+ _w,
26
+ _x,
27
+ _y;
26
28
  const repzo = new Repzo(
27
29
  (_a = commandEvent.app.formData) === null || _a === void 0
28
30
  ? void 0
@@ -426,75 +428,90 @@ export const sync_price_list = async (commandEvent) => {
426
428
  result.PL_items.failed++;
427
429
  continue;
428
430
  }
429
- const repzo_product_uoms =
430
- (_s =
431
- repzo_UoMs === null || repzo_UoMs === void 0
431
+ let price;
432
+ if (
433
+ (_t =
434
+ (_s = commandEvent.app.formData) === null || _s === void 0
432
435
  ? void 0
433
- : repzo_UoMs.data) === null || _s === void 0
436
+ : _s.usePiecesAndIgnoreMeasureunitFactor) === null ||
437
+ _t === void 0
434
438
  ? void 0
435
- : _s.filter((uom) => {
436
- var _a, _b, _c, _d;
437
- return (
438
- ((_a = uom === null || uom === void 0 ? void 0 : uom._id) ===
439
- null || _a === void 0
440
- ? void 0
441
- : _a.toString()) ==
442
- ((_b =
443
- repzo_product === null || repzo_product === void 0
439
+ : _t.usePcsForPriceList
440
+ ) {
441
+ price = Math.ceil(item.PLITEMPRICEVALUE * 1000);
442
+ } else {
443
+ const repzo_product_uoms =
444
+ (_u =
445
+ repzo_UoMs === null || repzo_UoMs === void 0
446
+ ? void 0
447
+ : repzo_UoMs.data) === null || _u === void 0
448
+ ? void 0
449
+ : _u.filter((uom) => {
450
+ var _a, _b, _c, _d;
451
+ return (
452
+ ((_a =
453
+ uom === null || uom === void 0 ? void 0 : uom._id) ===
454
+ null || _a === void 0
455
+ ? void 0
456
+ : _a.toString()) ==
457
+ ((_b =
458
+ repzo_product === null || repzo_product === void 0
459
+ ? void 0
460
+ : repzo_product.sv_measureUnit) === null ||
461
+ _b === void 0
444
462
  ? void 0
445
- : repzo_product.sv_measureUnit) === null ||
446
- _b === void 0
463
+ : _b.toString()) ||
464
+ ((_c = repzo_product.measureunit_family) === null ||
465
+ _c === void 0
447
466
  ? void 0
448
- : _b.toString()) ||
449
- ((_c = repzo_product.measureunit_family) === null ||
450
- _c === void 0
467
+ : _c.includes(
468
+ (_d =
469
+ uom === null || uom === void 0
470
+ ? void 0
471
+ : uom._id) === null || _d === void 0
472
+ ? void 0
473
+ : _d.toString()
474
+ ))
475
+ );
476
+ });
477
+ const repzo_product_uom = repzo_product_uoms.find(
478
+ (uom) => uom.name == item.PLITEMUNIT
479
+ );
480
+ if (!repzo_product_uom) {
481
+ failed_docs_report.push({
482
+ method: "create",
483
+ // doc: priceLists_withItems[priceList_name],
484
+ error_message: set_error(
485
+ `Price List: ${item.PLDID} of MeasureUnit with _id: ${
486
+ (_v =
487
+ repzo_product === null || repzo_product === void 0
488
+ ? void 0
489
+ : repzo_product.sv_measureUnit) === null || _v === void 0
451
490
  ? void 0
452
- : _c.includes(
453
- (_d =
454
- uom === null || uom === void 0 ? void 0 : uom._id) ===
455
- null || _d === void 0
456
- ? void 0
457
- : _d.toString()
458
- ))
491
+ : _v.toString()
492
+ } was not found or disabled`
493
+ ),
494
+ });
495
+ result.PL_items.failed++;
496
+ continue;
497
+ }
498
+ price =
499
+ repzo_product_uom &&
500
+ (repzo_product_uom === null || repzo_product_uom === void 0
501
+ ? void 0
502
+ : repzo_product_uom.factor) == 1
503
+ ? Math.ceil(item.PLITEMPRICEVALUE * 1000)
504
+ : Math.ceil(
505
+ (item.PLITEMPRICEVALUE * 1000) / repzo_product_uom.factor
459
506
  );
460
- });
461
- const repzo_product_uom = repzo_product_uoms.find(
462
- (uom) => uom.name == item.PLITEMUNIT
463
- );
464
- if (!repzo_product_uom) {
465
- failed_docs_report.push({
466
- method: "create",
467
- // doc: priceLists_withItems[priceList_name],
468
- error_message: set_error(
469
- `Price List: ${item.PLDID} of MeasureUnit with _id: ${
470
- (_t =
471
- repzo_product === null || repzo_product === void 0
472
- ? void 0
473
- : repzo_product.sv_measureUnit) === null || _t === void 0
474
- ? void 0
475
- : _t.toString()
476
- } was not found or disabled`
477
- ),
478
- });
479
- result.PL_items.failed++;
480
- continue;
481
507
  }
482
- const price =
483
- repzo_product_uom &&
484
- (repzo_product_uom === null || repzo_product_uom === void 0
485
- ? void 0
486
- : repzo_product_uom.factor) == 1
487
- ? Math.ceil(item.PLITEMPRICEVALUE * 1000)
488
- : Math.ceil(
489
- item.PLITEMPRICEVALUE * 1000 // / repzo_product_uom.factor // @changed to unipal
490
- );
491
508
  const variant =
492
- (_u =
509
+ (_w =
493
510
  repzo_product === null || repzo_product === void 0
494
511
  ? void 0
495
- : repzo_product.variants) === null || _u === void 0
512
+ : repzo_product.variants) === null || _w === void 0
496
513
  ? void 0
497
- : _u.find((variant) => {
514
+ : _w.find((variant) => {
498
515
  var _a;
499
516
  return (
500
517
  ((_a =
@@ -531,12 +548,12 @@ export const sync_price_list = async (commandEvent) => {
531
548
  };
532
549
  // console.log(data);
533
550
  const is_found_in_repzo_db =
534
- (_v =
551
+ (_x =
535
552
  repzo_price_list_items === null || repzo_price_list_items === void 0
536
553
  ? void 0
537
- : repzo_price_list_items.data) === null || _v === void 0
554
+ : repzo_price_list_items.data) === null || _x === void 0
538
555
  ? void 0
539
- : _v.find((item) => {
556
+ : _x.find((item) => {
540
557
  var _a, _b;
541
558
  return (
542
559
  ((_a =
@@ -619,10 +636,10 @@ export const sync_price_list = async (commandEvent) => {
619
636
  } catch (e) {
620
637
  //@ts-ignore
621
638
  console.error(
622
- ((_w = e === null || e === void 0 ? void 0 : e.response) === null ||
623
- _w === void 0
639
+ ((_y = e === null || e === void 0 ? void 0 : e.response) === null ||
640
+ _y === void 0
624
641
  ? void 0
625
- : _w.data) || e
642
+ : _y.data) || e
626
643
  );
627
644
  await commandLog.setStatus("fail", e).commit();
628
645
  throw e;
package/lib/types.d.ts CHANGED
@@ -99,6 +99,10 @@ export interface FormData {
99
99
  itemCode: string;
100
100
  uom: string;
101
101
  }[];
102
+ usePiecesAndIgnoreMeasureunitFactor?: {
103
+ usePcsForPriceList: boolean;
104
+ usePcsForAdjustInventory: boolean;
105
+ };
102
106
  virtualWarehouses?: {
103
107
  consider_virtual_warehouse: boolean;
104
108
  absolute_qty_for_virtual_warehouses_before_accumulation: boolean;
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.57",
4
+ "version": "1.0.58",
5
5
  "homepage": "",
6
6
  "keywords": [],
7
7
  "author": {
@@ -16,6 +16,8 @@ interface SAPTransferItem {
16
16
  Quantity: string | number; // "1";
17
17
  FromWarehouse: string | number; // "1";
18
18
  ToWarehouse: string | number; // "12";
19
+ UoMEntry?: string | number; // "2";
20
+ UoMCode?: string; // "PCS";
19
21
  }
20
22
 
21
23
  interface SAPTransfer {
@@ -109,9 +111,6 @@ export const create_transfer = async (event: EVENT, options: Config) => {
109
111
  (p) => p._id.toString() == repzo_transfer_item.product_id?.toString()
110
112
  );
111
113
  if (!repzo_product) {
112
- // console.log(
113
- // `Product with _id: ${repzo_transfer_item.product_id} was not found In Repzo`,
114
- // );
115
114
  throw new Error(
116
115
  `Product with _id: ${repzo_transfer_item.product_id} was not found in Repzo`
117
116
  );
@@ -120,9 +119,6 @@ export const create_transfer = async (event: EVENT, options: Config) => {
120
119
  const repzo_measure_unit = repzo_product.sv_measureUnit;
121
120
 
122
121
  if (!repzo_measure_unit?._id) {
123
- // console.log(
124
- // `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`,
125
- // );
126
122
  throw new Error(
127
123
  `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`
128
124
  );
@@ -139,6 +135,8 @@ export const create_transfer = async (event: EVENT, options: Config) => {
139
135
  //@ts-ignore
140
136
  ToWarehouse: (repzo_transfer.to as Service.Warehouse.WarehouseSchema)
141
137
  ?.code,
138
+ UoMEntry: repzo_measure_unit.integration_meta?.ALTUOMID, // (read from Uoms UoMID)
139
+ UoMCode: repzo_measure_unit.name, // (read from Uoms UoMCode)
142
140
  });
143
141
  }
144
142
 
@@ -160,7 +160,15 @@ export const adjust_inventory = async (commandEvent: CommandEvent) => {
160
160
  throw `MeasureUnit with UNITNAME: ${sap_item.UNITNAME} & ALTUOMID: ${sap_item.UNITID} was not found`;
161
161
  }
162
162
 
163
- const qty = sap_item.QTY; //* measureUnit.factor *;
163
+ let qty: number;
164
+ if (
165
+ commandEvent.app.formData?.usePiecesAndIgnoreMeasureunitFactor
166
+ ?.usePcsForAdjustInventory
167
+ ) {
168
+ qty = sap_item.QTY;
169
+ } else {
170
+ qty = measureUnit.factor * sap_item.QTY;
171
+ }
164
172
 
165
173
  const match_item_in_repzo_inventory =
166
174
  repzo_inventory?.data?.find(
@@ -294,7 +302,15 @@ export const adjust_inventory = async (commandEvent: CommandEvent) => {
294
302
  throw `MeasureUnit with UNITNAME: ${sap_item.UNITNAME} & ALTUOMID: ${sap_item.UNITID} was not found`;
295
303
  }
296
304
 
297
- const qty = sap_item.QTY; //* measureUnit.factor
305
+ let qty: number;
306
+ if (
307
+ commandEvent.app.formData?.usePiecesAndIgnoreMeasureunitFactor
308
+ ?.usePcsForAdjustInventory
309
+ ) {
310
+ qty = sap_item.QTY;
311
+ } else {
312
+ qty = measureUnit.factor * sap_item.QTY;
313
+ }
298
314
 
299
315
  const match_item_in_repzo_inventory = repzo_inventory?.data?.find(
300
316
  (repzo_item) =>
@@ -318,36 +318,45 @@ export const sync_price_list = async (commandEvent: CommandEvent) => {
318
318
  continue;
319
319
  }
320
320
 
321
- const repzo_product_uoms = repzo_UoMs?.data?.filter(
322
- (uom) =>
323
- uom?._id?.toString() == repzo_product?.sv_measureUnit?.toString() ||
324
- repzo_product.measureunit_family?.includes(uom?._id?.toString())
325
- );
321
+ let price: number;
322
+ if (
323
+ commandEvent.app.formData?.usePiecesAndIgnoreMeasureunitFactor
324
+ ?.usePcsForPriceList
325
+ ) {
326
+ price = Math.ceil(item.PLITEMPRICEVALUE * 1000);
327
+ } else {
328
+ const repzo_product_uoms = repzo_UoMs?.data?.filter(
329
+ (uom) =>
330
+ uom?._id?.toString() ==
331
+ repzo_product?.sv_measureUnit?.toString() ||
332
+ repzo_product.measureunit_family?.includes(uom?._id?.toString())
333
+ );
326
334
 
327
- const repzo_product_uom = repzo_product_uoms.find(
328
- (uom) => uom.name == item.PLITEMUNIT
329
- );
335
+ const repzo_product_uom = repzo_product_uoms.find(
336
+ (uom) => uom.name == item.PLITEMUNIT
337
+ );
330
338
 
331
- if (!repzo_product_uom) {
332
- failed_docs_report.push({
333
- method: "create",
334
- // doc: priceLists_withItems[priceList_name],
335
- error_message: set_error(
336
- `Price List: ${
337
- item.PLDID
338
- } of MeasureUnit with _id: ${repzo_product?.sv_measureUnit?.toString()} was not found or disabled`
339
- ),
340
- });
341
- result.PL_items.failed++;
342
- continue;
343
- }
339
+ if (!repzo_product_uom) {
340
+ failed_docs_report.push({
341
+ method: "create",
342
+ // doc: priceLists_withItems[priceList_name],
343
+ error_message: set_error(
344
+ `Price List: ${
345
+ item.PLDID
346
+ } of MeasureUnit with _id: ${repzo_product?.sv_measureUnit?.toString()} was not found or disabled`
347
+ ),
348
+ });
349
+ result.PL_items.failed++;
350
+ continue;
351
+ }
344
352
 
345
- const price =
346
- repzo_product_uom && repzo_product_uom?.factor == 1
347
- ? Math.ceil(item.PLITEMPRICEVALUE * 1000)
348
- : Math.ceil(
349
- item.PLITEMPRICEVALUE * 1000 // / repzo_product_uom.factor // @changed to unipal
350
- );
353
+ price =
354
+ repzo_product_uom && repzo_product_uom?.factor == 1
355
+ ? Math.ceil(item.PLITEMPRICEVALUE * 1000)
356
+ : Math.ceil(
357
+ (item.PLITEMPRICEVALUE * 1000) / repzo_product_uom.factor
358
+ );
359
+ }
351
360
 
352
361
  const variant = repzo_product?.variants?.find(
353
362
  (variant: any) =>
package/src/types.ts CHANGED
@@ -96,6 +96,10 @@ export interface FormData {
96
96
  SalPersCode?: string; // "111";
97
97
  SalesPersonCode?: string; // "111";
98
98
  measureUnitInjections?: { itemCode: string; uom: string }[];
99
+ usePiecesAndIgnoreMeasureunitFactor?: {
100
+ usePcsForPriceList: boolean;
101
+ usePcsForAdjustInventory: boolean;
102
+ };
99
103
  virtualWarehouses?: {
100
104
  consider_virtual_warehouse: boolean;
101
105
  absolute_qty_for_virtual_warehouses_before_accumulation: boolean;