repzo-sap-absjo 1.0.58 → 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, _s;
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 (
@@ -145,32 +155,52 @@ export const create_transfer = async (event, options) => {
145
155
  } was not found`
146
156
  );
147
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
+ }
148
172
  variants.push({
149
173
  //@ts-ignore
150
174
  ItemCode: repzo_transfer_item.variant_name,
151
175
  Quantity: repzo_transfer_item.qty / Number(repzo_measure_unit.factor),
152
176
  //@ts-ignore
153
177
  FromWarehouse:
154
- (_l = repzo_transfer.from) === null || _l === void 0
178
+ (_m = repzo_transfer.from) === null || _m === void 0
155
179
  ? void 0
156
- : _l.code,
180
+ : _m.code,
157
181
  //@ts-ignore
158
182
  ToWarehouse:
159
- (_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,
160
184
  UoMEntry:
161
- (_o = repzo_measure_unit.integration_meta) === null || _o === void 0
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
162
193
  ? void 0
163
- : _o.ALTUOMID, // (read from Uoms UoMID)
164
- UoMCode: repzo_measure_unit.name, // (read from Uoms UoMCode)
194
+ : item_measure_unit.name) || repzo_transfer_item.measure_unit_name, // (read from Uoms UoMCode)
165
195
  });
166
196
  }
167
197
  const sap_transfer = {
168
198
  StockTransferID: body.serial_number.formatted,
169
199
  SalesPersonCode: repzo_rep
170
200
  ? repzo_rep.integration_id
171
- : (_p = options.data) === null || _p === void 0
201
+ : (_q = options.data) === null || _q === void 0
172
202
  ? void 0
173
- : _p.SalesPersonCode, // "111"
203
+ : _q.SalesPersonCode, // "111"
174
204
  FromWarehouse: body.from.code,
175
205
  ToWarehouse: body.to.code,
176
206
  RepzoStockTransferLines: variants,
@@ -206,23 +236,23 @@ export const create_transfer = async (event, options) => {
206
236
  console.error((e === null || e === void 0 ? void 0 : e.response) || e);
207
237
  await actionLog.setStatus("fail", e).setBody(body).commit();
208
238
  if (
209
- (_r =
210
- (_q =
239
+ (_s =
240
+ (_r =
211
241
  options === null || options === void 0 ? void 0 : options.data) ===
212
- null || _q === void 0
242
+ null || _r === void 0
213
243
  ? void 0
214
- : _q.transfers) === null || _r === void 0
244
+ : _r.transfers) === null || _s === void 0
215
245
  ? void 0
216
- : _r.adjustInventoryInFailedTransfer
246
+ : _s.adjustInventoryInFailedTransfer
217
247
  ) {
218
248
  send_command_to_marketplace({
219
249
  command: "adjust_inventory",
220
250
  app_id: options.app_id,
221
251
  env: options.env,
222
252
  repzoApiKey:
223
- (_s = options.data) === null || _s === void 0
253
+ (_t = options.data) === null || _t === void 0
224
254
  ? void 0
225
- : _s.repzoApiKey,
255
+ : _t.repzoApiKey,
226
256
  });
227
257
  }
228
258
  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.58",
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
  }
@@ -79,11 +79,15 @@ export const create_transfer = async (event: EVENT, options: Config) => {
79
79
  // Get Repzo Products with its own Populated MeasureUnit
80
80
 
81
81
  const repzo_product_ids: { [id: string]: true } = {};
82
+ const measureunit_ids: { [id: string]: true } = {};
82
83
  repzo_transfer.variants?.forEach(
83
84
  (item: Service.Transfer.VariantTransfer) => {
84
85
  if (item?.product_id) {
85
86
  repzo_product_ids[item.product_id.toString()] = true;
86
87
  }
88
+ if (item?.measure_unit_id) {
89
+ measureunit_ids[item.measure_unit_id] = true;
90
+ }
87
91
  }
88
92
  );
89
93
  const repzo_products = await repzo.patchAction.create(
@@ -100,6 +104,11 @@ export const create_transfer = async (event: EVENT, options: Config) => {
100
104
  { per_page: 50000, populatedKeys: ["measureunit"] }
101
105
  );
102
106
 
107
+ const measureUnits = await repzo.measureunit.find({
108
+ _id: Object.keys(measureunit_ids),
109
+ per_page: 50000,
110
+ });
111
+
103
112
  // Prepare Transfer Items
104
113
  const variants: SAPTransferItem[] = [];
105
114
 
@@ -124,6 +133,14 @@ export const create_transfer = async (event: EVENT, options: Config) => {
124
133
  );
125
134
  }
126
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
+
127
144
  variants.push({
128
145
  //@ts-ignore
129
146
  ItemCode: repzo_transfer_item.variant_name,
@@ -135,8 +152,9 @@ export const create_transfer = async (event: EVENT, options: Config) => {
135
152
  //@ts-ignore
136
153
  ToWarehouse: (repzo_transfer.to as Service.Warehouse.WarehouseSchema)
137
154
  ?.code,
138
- UoMEntry: repzo_measure_unit.integration_meta?.ALTUOMID, // (read from Uoms UoMID)
139
- UoMCode: repzo_measure_unit.name, // (read from Uoms UoMCode)
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)
140
158
  });
141
159
  }
142
160