repzo-sap-absjo 1.0.57 → 1.0.59

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, _t;
6
6
  const repzo = new Repzo(
7
7
  (_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
8
8
  { env: options.env }
@@ -76,12 +76,18 @@ export const create_transfer = async (event, options) => {
76
76
  }
77
77
  // Get Repzo Products with its own Populated MeasureUnit
78
78
  const repzo_product_ids = {};
79
+ const measureunit_ids = {};
79
80
  (_g = repzo_transfer.variants) === null || _g === void 0
80
81
  ? void 0
81
82
  : _g.forEach((item) => {
82
83
  if (item === null || item === void 0 ? void 0 : item.product_id) {
83
84
  repzo_product_ids[item.product_id.toString()] = true;
84
85
  }
86
+ if (
87
+ item === null || item === void 0 ? void 0 : item.measure_unit_id
88
+ ) {
89
+ measureunit_ids[item.measure_unit_id] = true;
90
+ }
85
91
  });
86
92
  const repzo_products = await repzo.patchAction.create(
87
93
  {
@@ -96,6 +102,10 @@ export const create_transfer = async (event, options) => {
96
102
  },
97
103
  { per_page: 50000, populatedKeys: ["measureunit"] }
98
104
  );
105
+ const measureUnits = await repzo.measureunit.find({
106
+ _id: Object.keys(measureunit_ids),
107
+ per_page: 50000,
108
+ });
99
109
  // Prepare Transfer Items
100
110
  const variants = [];
101
111
  for (
@@ -127,9 +137,6 @@ export const create_transfer = async (event, options) => {
127
137
  }
128
138
  );
129
139
  if (!repzo_product) {
130
- // console.log(
131
- // `Product with _id: ${repzo_transfer_item.product_id} was not found In Repzo`,
132
- // );
133
140
  throw new Error(
134
141
  `Product with _id: ${repzo_transfer_item.product_id} was not found in Repzo`
135
142
  );
@@ -140,9 +147,6 @@ export const create_transfer = async (event, options) => {
140
147
  ? void 0
141
148
  : repzo_measure_unit._id)
142
149
  ) {
143
- // console.log(
144
- // `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`,
145
- // );
146
150
  throw new Error(
147
151
  `Measureunit with _id: ${
148
152
  (_k = repzo_product.sv_measureUnit) === null || _k === void 0
@@ -151,27 +155,52 @@ export const create_transfer = async (event, options) => {
151
155
  } was not found`
152
156
  );
153
157
  }
158
+ let item_measure_unit;
159
+ if (repzo_transfer_item.measure_unit_id) {
160
+ item_measure_unit =
161
+ (_l =
162
+ measureUnits === null || measureUnits === void 0
163
+ ? void 0
164
+ : measureUnits.data) === null || _l === void 0
165
+ ? void 0
166
+ : _l.find(
167
+ (mu) =>
168
+ mu._id.toString() ==
169
+ repzo_measure_unit.measure_unit_id.toString()
170
+ );
171
+ }
154
172
  variants.push({
155
173
  //@ts-ignore
156
174
  ItemCode: repzo_transfer_item.variant_name,
157
175
  Quantity: repzo_transfer_item.qty / Number(repzo_measure_unit.factor),
158
176
  //@ts-ignore
159
177
  FromWarehouse:
160
- (_l = repzo_transfer.from) === null || _l === void 0
178
+ (_m = repzo_transfer.from) === null || _m === void 0
161
179
  ? void 0
162
- : _l.code,
180
+ : _m.code,
163
181
  //@ts-ignore
164
182
  ToWarehouse:
165
- (_m = repzo_transfer.to) === null || _m === void 0 ? void 0 : _m.code,
183
+ (_o = repzo_transfer.to) === null || _o === void 0 ? void 0 : _o.code,
184
+ UoMEntry:
185
+ (_p =
186
+ item_measure_unit === null || item_measure_unit === void 0
187
+ ? void 0
188
+ : item_measure_unit.integration_meta) === null || _p === void 0
189
+ ? void 0
190
+ : _p.ALTUOMID, // (read from Uoms UoMID)
191
+ UoMCode:
192
+ (item_measure_unit === null || item_measure_unit === void 0
193
+ ? void 0
194
+ : item_measure_unit.name) || repzo_transfer_item.measure_unit_name, // (read from Uoms UoMCode)
166
195
  });
167
196
  }
168
197
  const sap_transfer = {
169
198
  StockTransferID: body.serial_number.formatted,
170
199
  SalesPersonCode: repzo_rep
171
200
  ? repzo_rep.integration_id
172
- : (_o = options.data) === null || _o === void 0
201
+ : (_q = options.data) === null || _q === void 0
173
202
  ? void 0
174
- : _o.SalesPersonCode, // "111"
203
+ : _q.SalesPersonCode, // "111"
175
204
  FromWarehouse: body.from.code,
176
205
  ToWarehouse: body.to.code,
177
206
  RepzoStockTransferLines: variants,
@@ -207,23 +236,23 @@ export const create_transfer = async (event, options) => {
207
236
  console.error((e === null || e === void 0 ? void 0 : e.response) || e);
208
237
  await actionLog.setStatus("fail", e).setBody(body).commit();
209
238
  if (
210
- (_q =
211
- (_p =
239
+ (_s =
240
+ (_r =
212
241
  options === null || options === void 0 ? void 0 : options.data) ===
213
- null || _p === void 0
242
+ null || _r === void 0
214
243
  ? void 0
215
- : _p.transfers) === null || _q === void 0
244
+ : _r.transfers) === null || _s === void 0
216
245
  ? void 0
217
- : _q.adjustInventoryInFailedTransfer
246
+ : _s.adjustInventoryInFailedTransfer
218
247
  ) {
219
248
  send_command_to_marketplace({
220
249
  command: "adjust_inventory",
221
250
  app_id: options.app_id,
222
251
  env: options.env,
223
252
  repzoApiKey:
224
- (_r = options.data) === null || _r === void 0
253
+ (_t = options.data) === null || _t === void 0
225
254
  ? void 0
226
- : _r.repzoApiKey,
255
+ : _t.repzoApiKey,
227
256
  });
228
257
  }
229
258
  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.59",
5
5
  "homepage": "",
6
6
  "keywords": [],
7
7
  "author": {
@@ -47,7 +47,7 @@
47
47
  "jsonwebtoken": "^8.5.1",
48
48
  "lodash": "^4.17.21",
49
49
  "moment-timezone": "^0.5.34",
50
- "repzo": "^1.0.209",
50
+ "repzo": "^1.0.253",
51
51
  "uuid": "^8.3.2"
52
52
  }
53
53
  }
@@ -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 {
@@ -77,11 +79,15 @@ export const create_transfer = async (event: EVENT, options: Config) => {
77
79
  // Get Repzo Products with its own Populated MeasureUnit
78
80
 
79
81
  const repzo_product_ids: { [id: string]: true } = {};
82
+ const measureunit_ids: { [id: string]: true } = {};
80
83
  repzo_transfer.variants?.forEach(
81
84
  (item: Service.Transfer.VariantTransfer) => {
82
85
  if (item?.product_id) {
83
86
  repzo_product_ids[item.product_id.toString()] = true;
84
87
  }
88
+ if (item?.measure_unit_id) {
89
+ measureunit_ids[item.measure_unit_id] = true;
90
+ }
85
91
  }
86
92
  );
87
93
  const repzo_products = await repzo.patchAction.create(
@@ -98,6 +104,11 @@ export const create_transfer = async (event: EVENT, options: Config) => {
98
104
  { per_page: 50000, populatedKeys: ["measureunit"] }
99
105
  );
100
106
 
107
+ const measureUnits = await repzo.measureunit.find({
108
+ _id: Object.keys(measureunit_ids),
109
+ per_page: 50000,
110
+ });
111
+
101
112
  // Prepare Transfer Items
102
113
  const variants: SAPTransferItem[] = [];
103
114
 
@@ -109,9 +120,6 @@ export const create_transfer = async (event: EVENT, options: Config) => {
109
120
  (p) => p._id.toString() == repzo_transfer_item.product_id?.toString()
110
121
  );
111
122
  if (!repzo_product) {
112
- // console.log(
113
- // `Product with _id: ${repzo_transfer_item.product_id} was not found In Repzo`,
114
- // );
115
123
  throw new Error(
116
124
  `Product with _id: ${repzo_transfer_item.product_id} was not found in Repzo`
117
125
  );
@@ -120,14 +128,19 @@ export const create_transfer = async (event: EVENT, options: Config) => {
120
128
  const repzo_measure_unit = repzo_product.sv_measureUnit;
121
129
 
122
130
  if (!repzo_measure_unit?._id) {
123
- // console.log(
124
- // `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`,
125
- // );
126
131
  throw new Error(
127
132
  `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`
128
133
  );
129
134
  }
130
135
 
136
+ let item_measure_unit: Service.MeasureUnit.Data | undefined;
137
+ if (repzo_transfer_item.measure_unit_id) {
138
+ item_measure_unit = measureUnits?.data?.find(
139
+ (mu) =>
140
+ mu._id.toString() == repzo_measure_unit.measure_unit_id.toString()
141
+ );
142
+ }
143
+
131
144
  variants.push({
132
145
  //@ts-ignore
133
146
  ItemCode: repzo_transfer_item.variant_name,
@@ -139,6 +152,9 @@ export const create_transfer = async (event: EVENT, options: Config) => {
139
152
  //@ts-ignore
140
153
  ToWarehouse: (repzo_transfer.to as Service.Warehouse.WarehouseSchema)
141
154
  ?.code,
155
+ UoMEntry: item_measure_unit?.integration_meta?.ALTUOMID, // (read from Uoms UoMID)
156
+ UoMCode:
157
+ item_measure_unit?.name || repzo_transfer_item.measure_unit_name, // (read from Uoms UoMCode)
142
158
  });
143
159
  }
144
160
 
@@ -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;