repzo-sap-absjo 1.0.9 → 1.0.11

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
@@ -5,6 +5,7 @@
5
5
  ### Added
6
6
 
7
7
  - [actions/***] add 2 keys in integration_meta: sync_to_sap_started & sync_to_sap_succeeded @maramalshen
8
+ - [commands/product] assign Foreign Name (ITEMDESCF) in SAP to local_name in Repzo @maramalshen
8
9
 
9
10
  ### Changed
10
11
 
@@ -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;
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
6
6
  const repzo = new Repzo(
7
7
  (_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
8
8
  { env: options.env }
@@ -16,16 +16,24 @@ export const create_transfer = async (event, options) => {
16
16
  let body;
17
17
  try {
18
18
  // console.log("create_transfer");
19
- await actionLog.load(action_sync_id);
20
19
  body = event.body;
21
20
  try {
22
21
  if (body) body = JSON.parse(body);
23
22
  } catch (e) {}
24
- const repzo_serial_number =
25
- (_c = body === null || body === void 0 ? void 0 : body.serial_number) ===
23
+ if (
24
+ (_c =
25
+ body === null || body === void 0 ? void 0 : body.integration_meta) ===
26
26
  null || _c === void 0
27
27
  ? void 0
28
- : _c.formatted;
28
+ : _c.sync_to_sap_started
29
+ )
30
+ return;
31
+ await actionLog.load(action_sync_id);
32
+ const repzo_serial_number =
33
+ (_d = body === null || body === void 0 ? void 0 : body.serial_number) ===
34
+ null || _d === void 0
35
+ ? void 0
36
+ : _d.formatted;
29
37
  // try {
30
38
  // if (body?._id) {
31
39
  // body.integration_meta = body?.integration_meta || {};
@@ -50,7 +58,7 @@ export const create_transfer = async (event, options) => {
50
58
  )
51
59
  .commit();
52
60
  const SAP_HOST_URL =
53
- (_d = options.data) === null || _d === void 0 ? void 0 : _d.sapHostUrl;
61
+ (_e = options.data) === null || _e === void 0 ? void 0 : _e.sapHostUrl;
54
62
  if (!SAP_HOST_URL)
55
63
  throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
56
64
  const repzo_transfer = body;
@@ -58,21 +66,21 @@ export const create_transfer = async (event, options) => {
58
66
  let repzo_rep;
59
67
  if (repzo_transfer.creator.type == "rep") {
60
68
  repzo_rep = await repzo.rep.get(
61
- (_e =
69
+ (_f =
62
70
  repzo_transfer === null || repzo_transfer === void 0
63
71
  ? void 0
64
- : repzo_transfer.creator) === null || _e === void 0
72
+ : repzo_transfer.creator) === null || _f === void 0
65
73
  ? void 0
66
- : _e._id
74
+ : _f._id
67
75
  );
68
76
  if (!repzo_rep)
69
77
  throw `Rep with _id: ${repzo_transfer.creator._id} not found in Repzo`;
70
78
  }
71
79
  // Get Repzo Products with its own Populated MeasureUnit
72
80
  const repzo_product_ids = {};
73
- (_f = repzo_transfer.variants) === null || _f === void 0
81
+ (_g = repzo_transfer.variants) === null || _g === void 0
74
82
  ? void 0
75
- : _f.forEach((item) => {
83
+ : _g.forEach((item) => {
76
84
  if (item === null || item === void 0 ? void 0 : item.product_id) {
77
85
  repzo_product_ids[item.product_id.toString()] = true;
78
86
  }
@@ -95,19 +103,19 @@ export const create_transfer = async (event, options) => {
95
103
  for (
96
104
  let i = 0;
97
105
  i <
98
- ((_g = repzo_transfer.variants) === null || _g === void 0
106
+ ((_h = repzo_transfer.variants) === null || _h === void 0
99
107
  ? void 0
100
- : _g.length);
108
+ : _h.length);
101
109
  i++
102
110
  ) {
103
111
  const repzo_transfer_item = repzo_transfer.variants[i];
104
112
  const repzo_product =
105
- (_h =
113
+ (_j =
106
114
  repzo_products === null || repzo_products === void 0
107
115
  ? void 0
108
- : repzo_products.data) === null || _h === void 0
116
+ : repzo_products.data) === null || _j === void 0
109
117
  ? void 0
110
- : _h.find(
118
+ : _j.find(
111
119
  //@ts-ignore
112
120
  (p) => {
113
121
  var _a;
@@ -139,9 +147,9 @@ export const create_transfer = async (event, options) => {
139
147
  // );
140
148
  throw new Error(
141
149
  `Measureunit with _id: ${
142
- (_j = repzo_product.sv_measureUnit) === null || _j === void 0
150
+ (_k = repzo_product.sv_measureUnit) === null || _k === void 0
143
151
  ? void 0
144
- : _j.toString()
152
+ : _k.toString()
145
153
  } was not found`
146
154
  );
147
155
  }
@@ -151,21 +159,21 @@ export const create_transfer = async (event, options) => {
151
159
  Quantity: repzo_transfer_item.qty / Number(repzo_measure_unit.factor),
152
160
  //@ts-ignore
153
161
  FromWarehouse:
154
- (_k = repzo_transfer.from) === null || _k === void 0
162
+ (_l = repzo_transfer.from) === null || _l === void 0
155
163
  ? void 0
156
- : _k.code,
164
+ : _l.code,
157
165
  //@ts-ignore
158
166
  ToWarehouse:
159
- (_l = repzo_transfer.to) === null || _l === void 0 ? void 0 : _l.code,
167
+ (_m = repzo_transfer.to) === null || _m === void 0 ? void 0 : _m.code,
160
168
  });
161
169
  }
162
170
  const sap_transfer = {
163
171
  StockTransferID: body.serial_number.formatted,
164
172
  SalesPersonCode: repzo_rep
165
173
  ? repzo_rep.integration_id
166
- : (_m = options.data) === null || _m === void 0
174
+ : (_o = options.data) === null || _o === void 0
167
175
  ? void 0
168
- : _m.SalesPersonCode,
176
+ : _o.SalesPersonCode,
169
177
  FromWarehouse: body.from.code,
170
178
  ToWarehouse: body.to.code,
171
179
  RepzoStockTransferLines: variants,
@@ -204,23 +212,23 @@ export const create_transfer = async (event, options) => {
204
212
  console.error((e === null || e === void 0 ? void 0 : e.response) || e);
205
213
  await actionLog.setStatus("fail", e).setBody(body).commit();
206
214
  if (
207
- (_p =
208
- (_o =
215
+ (_q =
216
+ (_p =
209
217
  options === null || options === void 0 ? void 0 : options.data) ===
210
- null || _o === void 0
218
+ null || _p === void 0
211
219
  ? void 0
212
- : _o.transfers) === null || _p === void 0
220
+ : _p.transfers) === null || _q === void 0
213
221
  ? void 0
214
- : _p.adjustInventoryInFailedTransfer
222
+ : _q.adjustInventoryInFailedTransfer
215
223
  ) {
216
224
  send_command_to_marketplace({
217
225
  command: "adjust_inventory",
218
226
  app_id: options.app_id,
219
227
  env: options.env,
220
228
  repzoApiKey:
221
- (_q = options.data) === null || _q === void 0
229
+ (_r = options.data) === null || _r === void 0
222
230
  ? void 0
223
- : _q.repzoApiKey,
231
+ : _r.repzoApiKey,
224
232
  });
225
233
  }
226
234
  throw e;
@@ -224,6 +224,7 @@ export const sync_product = async (commandEvent) => {
224
224
  const body = {
225
225
  active: true,
226
226
  name: sap_product.ITEMDESC,
227
+ local_name: sap_product.ITEMDESCF,
227
228
  barcode: sap_product.ITEMBARCODE,
228
229
  sku: sap_product.ITEMCODE,
229
230
  sv_tax: product_tax,
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.9",
4
+ "version": "1.0.11",
5
5
  "homepage": "",
6
6
  "keywords": [],
7
7
  "author": {
@@ -33,13 +33,13 @@ export const create_transfer = async (event: EVENT, options: Config) => {
33
33
  let body: Service.Transfer.Schema | any;
34
34
  try {
35
35
  // console.log("create_transfer");
36
- await actionLog.load(action_sync_id);
37
36
 
38
37
  body = event.body;
39
38
  try {
40
39
  if (body) body = JSON.parse(body);
41
40
  } catch (e) {}
42
-
41
+ if (body?.integration_meta?.sync_to_sap_started) return;
42
+ await actionLog.load(action_sync_id);
43
43
  const repzo_serial_number = body?.serial_number?.formatted;
44
44
  // try {
45
45
  // if (body?._id) {
@@ -186,6 +186,7 @@ export const sync_product = async (commandEvent: CommandEvent) => {
186
186
  {
187
187
  active: true,
188
188
  name: sap_product.ITEMDESC,
189
+ local_name: sap_product.ITEMDESCF,
189
190
  barcode: sap_product.ITEMBARCODE,
190
191
  sku: sap_product.ITEMCODE,
191
192
  sv_tax: product_tax,