addio-admin-sdk 1.7.21 → 1.7.23-canary-1

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.
Files changed (56) hide show
  1. package/addio-sdk-doc.md +499 -406
  2. package/dist/Interfaces/Algolia/index.d.ts +8 -0
  3. package/dist/Interfaces/Cart/index.d.ts +2 -0
  4. package/dist/Interfaces/Cart/index.js.map +1 -1
  5. package/dist/Interfaces/Product/IInventoryItem.d.ts +10 -10
  6. package/dist/Interfaces/Schedule/index.d.ts +1 -0
  7. package/dist/Interfaces/Space/index.d.ts +16 -0
  8. package/dist/Interfaces/Space/index.js +18 -2
  9. package/dist/Interfaces/Space/index.js.map +1 -1
  10. package/dist/Interfaces/TransferRequest/index.d.ts +49 -17
  11. package/dist/Interfaces/TransferRequest/index.js +23 -16
  12. package/dist/Interfaces/TransferRequest/index.js.map +1 -1
  13. package/dist/Interfaces/Translation/index.d.ts +4 -0
  14. package/dist/Interfaces/Translation/index.js +3 -0
  15. package/dist/Interfaces/Translation/index.js.map +1 -1
  16. package/dist/lib/Cart/index.d.ts +12 -3
  17. package/dist/lib/Cart/index.js +288 -146
  18. package/dist/lib/Cart/index.js.map +1 -1
  19. package/dist/lib/Email/OrderConfirmationEmail.d.ts +1 -1
  20. package/dist/lib/Email/OrderConfirmationEmail.js +3 -2
  21. package/dist/lib/Email/OrderConfirmationEmail.js.map +1 -1
  22. package/dist/lib/Inventory/index.d.ts +20 -4
  23. package/dist/lib/Inventory/index.js +99 -49
  24. package/dist/lib/Inventory/index.js.map +1 -1
  25. package/dist/lib/Shipment/index.js +5 -4
  26. package/dist/lib/Shipment/index.js.map +1 -1
  27. package/dist/lib/Space/index.d.ts +19 -3
  28. package/dist/lib/Space/index.js +367 -248
  29. package/dist/lib/Space/index.js.map +1 -1
  30. package/dist/lib/TransferRequest/index.d.ts +82 -5
  31. package/dist/lib/TransferRequest/index.js +959 -112
  32. package/dist/lib/TransferRequest/index.js.map +1 -1
  33. package/dist/rules/GR/utils/expedition.js.map +1 -1
  34. package/dist/rules/GR/utils/invoices.js +1 -1
  35. package/dist/rules/GR/utils/products.d.ts +12 -5
  36. package/dist/rules/GR/utils/products.js +45 -29
  37. package/dist/rules/GR/utils/products.js.map +1 -1
  38. package/dist/rules/GR/utils/upsells.js +1 -1
  39. package/dist/rules/GR/utils/upsells.js.map +1 -1
  40. package/dist/services/database/DatabaseService.js.map +1 -1
  41. package/dist/utils/cart.d.ts +26 -1
  42. package/dist/utils/cart.js +128 -12
  43. package/dist/utils/cart.js.map +1 -1
  44. package/dist/utils/context.d.ts +1 -0
  45. package/dist/utils/context.js +19 -1
  46. package/dist/utils/context.js.map +1 -1
  47. package/dist/utils/inventories.d.ts +2 -1
  48. package/dist/utils/inventories.js +31 -16
  49. package/dist/utils/inventories.js.map +1 -1
  50. package/dist/utils/products.d.ts +6 -0
  51. package/dist/utils/products.js +7 -1
  52. package/dist/utils/products.js.map +1 -1
  53. package/dist/utils/transferRequests.d.ts +3 -0
  54. package/dist/utils/transferRequests.js +12 -1
  55. package/dist/utils/transferRequests.js.map +1 -1
  56. package/package.json +1 -1
@@ -97,6 +97,7 @@ var toNumber_1 = __importDefault(require("lodash/toNumber"));
97
97
  var toString_1 = __importDefault(require("lodash/toString"));
98
98
  var uniq_1 = __importDefault(require("lodash/uniq"));
99
99
  var flatten_1 = __importDefault(require("lodash/flatten"));
100
+ var chunk_1 = __importDefault(require("lodash/chunk"));
100
101
  var discount_1 = require("../../utils/discount");
101
102
  var data_1 = require("../../utils/data");
102
103
  var Cart_1 = require("../../Interfaces/Cart");
@@ -133,6 +134,9 @@ var DatabaseService_1 = __importDefault(require("../../services/database/Databas
133
134
  var logs_1 = require("../../services/logs");
134
135
  var cart_2 = require("../../rules/GR/utils/cart");
135
136
  var cart_3 = require("../../rules/GR/interfaces/cart");
137
+ var TransferRequest_1 = require("../TransferRequest");
138
+ var TransferRequest_2 = require("../../Interfaces/TransferRequest");
139
+ var inventories_1 = require("../../utils/inventories");
136
140
  var Cart = (function (_super) {
137
141
  __extends(Cart, _super);
138
142
  function Cart(data, collection, user, resetErrors) {
@@ -175,10 +179,10 @@ var Cart = (function (_super) {
175
179
  }
176
180
  });
177
181
  }); };
178
- _this.cancelCart = function (user) { return __awaiter(_this, void 0, void 0, function () {
179
- var userInfo, editedCart, space, e_1, error_2;
180
- return __generator(this, function (_b) {
181
- switch (_b.label) {
182
+ _this.cancelCart = function (user, associatedTransfers) { return __awaiter(_this, void 0, void 0, function () {
183
+ var userInfo, editedCart, space, e_1, _b, _c, transfer, transferObj, e_2, e_3, error_2;
184
+ return __generator(this, function (_d) {
185
+ switch (_d.label) {
182
186
  case 0:
183
187
  if (!!user) {
184
188
  userInfo = {
@@ -191,39 +195,83 @@ var Cart = (function (_super) {
191
195
  };
192
196
  }
193
197
  editedCart = __assign(__assign(__assign(__assign({ status: Cart_1.CartStatusEnum.EXT_REFUND }, (!!userInfo ? { canceled_by: userInfo } : {})), (!!this._data.check_marketing_emails ? { check_marketing_emails: false } : {})), (!!this._data.check_sms_to_send ? { check_sms_to_send: false } : {})), (!!this._data.check_retarget_marketing_emails ? { check_retarget_marketing_emails: false } : {}));
194
- if (!(!!this._data.items && !!this._data.items.length)) return [3, 5];
195
- _b.label = 1;
198
+ space = undefined;
199
+ if (!(!!this._data.items && !!this._data.items.length)) return [3, 6];
200
+ _d.label = 1;
196
201
  case 1:
197
- _b.trys.push([1, 4, , 5]);
202
+ _d.trys.push([1, 5, , 6]);
203
+ if (!!!!space) return [3, 3];
198
204
  return [4, Space_1.default.getCurrentSpaceWithRef(this._collection.path, this._user)];
199
205
  case 2:
200
- space = _b.sent();
206
+ space = _d.sent();
207
+ _d.label = 3;
208
+ case 3:
201
209
  if (!!!this._data.current_store_id && this._data.status >= Cart_1.CartStatusEnum.CART_READY_TO_PROCESS)
202
210
  throw new Error('No store associated to cart');
203
- return [4, space.inventory.ajust(this._data.items, 'cancelled', this._data.cart_type, this._data.current_store_id || '', this._data.status < Cart_1.CartStatusEnum.CART_READY_TO_PROCESS)];
204
- case 3:
205
- _b.sent();
206
- return [3, 5];
211
+ return [4, space.inventory.ajust(this._data.items, 'cancelled', this._data.cart_type, {
212
+ currentStoreId: this._data.current_store_id || '',
213
+ onlyWeb: this._data.status < Cart_1.CartStatusEnum.CART_READY_TO_PROCESS,
214
+ associatedTransfersToCart: !!associatedTransfers ? associatedTransfers.all : undefined
215
+ })];
207
216
  case 4:
208
- e_1 = _b.sent();
209
- console.error(e_1);
210
- return [3, 5];
217
+ _d.sent();
218
+ return [3, 6];
211
219
  case 5:
212
- _b.trys.push([5, 7, , 8]);
213
- return [4, this.save(editedCart, true)];
220
+ e_1 = _d.sent();
221
+ console.error(e_1);
222
+ return [3, 6];
214
223
  case 6:
215
- _b.sent();
216
- return [2, true];
224
+ if (!(!!associatedTransfers && !!associatedTransfers.toCancel)) return [3, 17];
225
+ _d.label = 7;
217
226
  case 7:
218
- error_2 = _b.sent();
227
+ _d.trys.push([7, 16, , 17]);
228
+ if (!!!!space) return [3, 9];
229
+ return [4, Space_1.default.getCurrentSpaceWithRef(this._collection.path, this._user)];
230
+ case 8:
231
+ space = _d.sent();
232
+ _d.label = 9;
233
+ case 9:
234
+ _b = 0, _c = associatedTransfers.toCancel;
235
+ _d.label = 10;
236
+ case 10:
237
+ if (!(_b < _c.length)) return [3, 15];
238
+ transfer = _c[_b];
239
+ _d.label = 11;
240
+ case 11:
241
+ _d.trys.push([11, 13, , 14]);
242
+ transferObj = new TransferRequest_1.TransferRequest(transfer, DatabaseService_1.default.asCollectionObject(space.getRef().path, space.getRef().id + '/transfer_requests'), this._user);
243
+ return [4, transferObj.changeStatus(TransferRequest_2.TransferRequestStatusEnum.CANCELLED, "Annul\u00E9 automatiquement \u00E0 l'annulation de la commande ref #".concat(this._data.ref), this._user, true, true)];
244
+ case 12:
245
+ _d.sent();
246
+ return [3, 14];
247
+ case 13:
248
+ e_2 = _d.sent();
249
+ console.log('error on canceling transfer: ', e_2.toString());
250
+ return [3, 14];
251
+ case 14:
252
+ _b++;
253
+ return [3, 10];
254
+ case 15: return [3, 17];
255
+ case 16:
256
+ e_3 = _d.sent();
257
+ console.log('error on fetching space: ', e_3.toString());
258
+ return [3, 17];
259
+ case 17:
260
+ _d.trys.push([17, 19, , 20]);
261
+ return [4, this.save(editedCart, true)];
262
+ case 18:
263
+ _d.sent();
264
+ return [2, true];
265
+ case 19:
266
+ error_2 = _d.sent();
219
267
  console.log('error on saving cancelled cart', error_2);
220
268
  return [2, false];
221
- case 8: return [2];
269
+ case 20: return [2];
222
270
  }
223
271
  });
224
272
  }); };
225
273
  _this.updateCartOnLoginFetch = function (customerData, space, orgID) { return __awaiter(_this, void 0, void 0, function () {
226
- var actionsDoneOnCart, e_2, cartCustumerInfo, newInfo, _b, promise_to_purchase, items, rest, e_3, e_4;
274
+ var actionsDoneOnCart, e_4, cartCustumerInfo, newInfo, _b, promise_to_purchase, items, rest, e_5, e_6;
227
275
  return __generator(this, function (_c) {
228
276
  switch (_c.label) {
229
277
  case 0:
@@ -241,8 +289,8 @@ var Cart = (function (_super) {
241
289
  actionsDoneOnCart = _c.sent();
242
290
  return [3, 5];
243
291
  case 4:
244
- e_2 = _c.sent();
245
- console.log('error on verifyCartItems in /signin endpoint: ', e_2.toString());
292
+ e_4 = _c.sent();
293
+ console.log('error on verifyCartItems in /signin endpoint: ', e_4.toString());
246
294
  return [3, 5];
247
295
  case 5:
248
296
  cartCustumerInfo = this.data().customer_info;
@@ -270,7 +318,7 @@ var Cart = (function (_super) {
270
318
  _c.sent();
271
319
  return [3, 9];
272
320
  case 8:
273
- e_3 = _c.sent();
321
+ e_5 = _c.sent();
274
322
  console.error('Error on recalculateTotals when fetching customer cart');
275
323
  return [3, 9];
276
324
  case 9: return [4, this.save()];
@@ -278,15 +326,15 @@ var Cart = (function (_super) {
278
326
  _c.sent();
279
327
  return [2, this._data];
280
328
  case 11:
281
- e_4 = _c.sent();
282
- console.log('error on updating cart after fetch : ', e_4.toString());
329
+ e_6 = _c.sent();
330
+ console.log('error on updating cart after fetch : ', e_6.toString());
283
331
  return [3, 12];
284
332
  case 12: return [2];
285
333
  }
286
334
  });
287
335
  }); };
288
336
  _this.data = function () { return _this._data; };
289
- _this.save = function (partial, options, saveToDatabase, onlyPartial) {
337
+ _this.save = function (partial, options, saveToDatabase, onlyPartial, noEvent) {
290
338
  if (onlyPartial === void 0) { onlyPartial = false; }
291
339
  return __awaiter(_this, void 0, void 0, function () {
292
340
  var partialCartToSave, space, cart_promos_applied, rest, res;
@@ -322,7 +370,7 @@ var Cart = (function (_super) {
322
370
  case 2:
323
371
  _c.sent();
324
372
  _c.label = 3;
325
- case 3: return [4, _super.prototype.save.call(this, !!onlyPartial && !!partial ? __assign({}, partial) : __assign({}, partialCartToSave), options, saveToDatabase, true, undefined, undefined, !!onlyPartial && !!partial)];
373
+ case 3: return [4, _super.prototype.save.call(this, !!onlyPartial && !!partial ? __assign({}, partial) : __assign({}, partialCartToSave), options, saveToDatabase, true, undefined, undefined, !!onlyPartial && !!partial, noEvent)];
326
374
  case 4:
327
375
  res = _c.sent();
328
376
  if (!!res && typeof res === 'string')
@@ -526,9 +574,11 @@ var Cart = (function (_super) {
526
574
  return 0;
527
575
  if (!!!item.shipping_info)
528
576
  return 0;
577
+ var convertedQuantities = (0, inventories_1.getConvertedUnitQuantity)(item.other_units, item.qte, 'inventory_unit');
529
578
  return item.shipping_info.unit_weight === unit
530
- ? ((0, toNumber_1.default)(item.shipping_info.weight) || 0) * item.qte
531
- : (0, weight_1.convertWeight)((0, toNumber_1.default)(item.shipping_info.weight) || 0, item.shipping_info.unit_weight, unit) * item.qte;
579
+ ? ((0, toNumber_1.default)(item.shipping_info.weight) || 0) * convertedQuantities
580
+ : (0, weight_1.convertWeight)((0, toNumber_1.default)(item.shipping_info.weight) || 0, item.shipping_info.unit_weight, unit) *
581
+ convertedQuantities;
532
582
  });
533
583
  };
534
584
  _this.addItemsToCart = function (items) { return __awaiter(_this, void 0, void 0, function () {
@@ -565,7 +615,7 @@ var Cart = (function (_super) {
565
615
  });
566
616
  }); };
567
617
  _this.verifyCartItems = function (space, orgID, saveToDatabase) { return __awaiter(_this, void 0, void 0, function () {
568
- var actionsDone, isGR, proCustomerTitle, proID, customPriceList, token, allItemSlugs, customPriceListQuery, e_5, verifiedItems, _loop_1, _b, _c, cartItem, err_1;
618
+ var actionsDone, isGR, proCustomerTitle, proID, customPriceList, token, allItemSlugs, customPriceListQuery, e_7, verifiedItems, _loop_1, _b, _c, cartItem, err_1;
569
619
  return __generator(this, function (_d) {
570
620
  switch (_d.label) {
571
621
  case 0:
@@ -603,8 +653,8 @@ var Cart = (function (_super) {
603
653
  customPriceList = customPriceListQuery;
604
654
  return [3, 4];
605
655
  case 3:
606
- e_5 = _d.sent();
607
- console.log('error on fetching custom price list: ', e_5.toString());
656
+ e_7 = _d.sent();
657
+ console.log('error on fetching custom price list: ', e_7.toString());
608
658
  return [3, 4];
609
659
  case 4:
610
660
  if (!!__1.isTestEnv)
@@ -1088,7 +1138,7 @@ var Cart = (function (_super) {
1088
1138
  return (0, round_1.default)(taxAmount, 2);
1089
1139
  };
1090
1140
  _this.setProCustomerInfo = function (customer) { return __awaiter(_this, void 0, void 0, function () {
1091
- var proInfo, newCustomerInfo, e_6;
1141
+ var proInfo, newCustomerInfo, e_8;
1092
1142
  var _b, _c, _d, _e, _f, _g, _h;
1093
1143
  return __generator(this, function (_j) {
1094
1144
  switch (_j.label) {
@@ -1103,7 +1153,7 @@ var Cart = (function (_super) {
1103
1153
  _j.sent();
1104
1154
  return [3, 4];
1105
1155
  case 3:
1106
- e_6 = _j.sent();
1156
+ e_8 = _j.sent();
1107
1157
  return [3, 4];
1108
1158
  case 4: return [2];
1109
1159
  }
@@ -1201,7 +1251,7 @@ var Cart = (function (_super) {
1201
1251
  if (saveToDatabase === void 0) { saveToDatabase = true; }
1202
1252
  if (indexCart === void 0) { indexCart = true; }
1203
1253
  return __awaiter(_this, void 0, void 0, function () {
1204
- var stripe_payload, pandapay_payload, paysafe_payload, delay1, err_2, delay2, algoService, prosprService, algolia, prospr, customer, customerQuery, e_7, indexedCartData, error_6, error_7, err_3;
1254
+ var stripe_payload, pandapay_payload, paysafe_payload, delay1, err_2, delay2, algoService, prosprService, algolia, prospr, customer, customerQuery, e_9, indexedCartData, error_6, error_7, err_3;
1205
1255
  return __generator(this, function (_b) {
1206
1256
  switch (_b.label) {
1207
1257
  case 0:
@@ -1283,11 +1333,15 @@ var Cart = (function (_super) {
1283
1333
  }
1284
1334
  return [3, 9];
1285
1335
  case 8:
1286
- e_7 = _b.sent();
1287
- console.log('error while fetching customer: ', e_7.toString());
1336
+ e_9 = _b.sent();
1337
+ console.log('error while fetching customer: ', e_9.toString());
1288
1338
  return [3, 9];
1289
1339
  case 9:
1290
- indexedCartData = (0, cart_1.getIndexedCartData)(cart.data(), space, true, !!customer ? customer.data() : undefined, (0, moment_1.default)().toDate());
1340
+ indexedCartData = (0, cart_1.getIndexedCartData)(cart.data(), space, {
1341
+ setPaidAtIfUndefined: true,
1342
+ customer: !!customer ? customer.data() : undefined,
1343
+ createdAt: (0, moment_1.default)().toDate()
1344
+ });
1291
1345
  if (!!!algolia) return [3, 13];
1292
1346
  _b.label = 10;
1293
1347
  case 10:
@@ -1356,7 +1410,7 @@ var Cart = (function (_super) {
1356
1410
  _this.createOrderWithSuccessfulPaymentPayload = function (_b) {
1357
1411
  var paypal_payload = _b.paypal_payload, stripe_payload = _b.stripe_payload, pandapay_payload = _b.pandapay_payload, paysafe_payload = _b.paysafe_payload, _c = _b.charge_credit, charge_credit = _c === void 0 ? false : _c, _d = _b.other_payment_method, other_payment_method = _d === void 0 ? undefined : _d, _e = _b.multi_payment_methods, multi_payment_methods = _e === void 0 ? undefined : _e, isDev = _b.isDev, _f = _b.saveToDatabase, saveToDatabase = _f === void 0 ? true : _f;
1358
1412
  return __awaiter(_this, void 0, void 0, function () {
1359
- var space, getPaymentRef, multiPaymentMethods, newRef, incrementSpaceRef, delay1, customerId, e_8, isPOSTransactionnal, partialCartPaidData, delay2, newCartId, delay3, invoiceRef, delay4, skipRef, g2OrderRef, delay5, error_8, delay6, e_9, error_9;
1413
+ var space, getPaymentRef, multiPaymentMethods, newRef, incrementSpaceRef, delay1, customerId, e_10, isPOSTransactionnal, partialCartPaidData, delay2, newCartId, delay3, invoiceRef, delay4, skipRef, g2OrderRef, delay5, error_8, delay6, e_11, error_9;
1360
1414
  var _this = this;
1361
1415
  var _g, _h;
1362
1416
  return __generator(this, function (_j) {
@@ -1466,8 +1520,8 @@ var Cart = (function (_super) {
1466
1520
  _j.sent();
1467
1521
  return [3, 10];
1468
1522
  case 9:
1469
- e_8 = _j.sent();
1470
- console.log("Could not update last_activity prop for customer: ".concat(customerId, ", ").concat(e_8));
1523
+ e_10 = _j.sent();
1524
+ console.log("Could not update last_activity prop for customer: ".concat(customerId, ", ").concat(e_10));
1471
1525
  return [3, 10];
1472
1526
  case 10:
1473
1527
  isPOSTransactionnal = this.data().cart_type === Cart_1.CartTypeEnum.POS_TRANSACTIONNAL;
@@ -1535,7 +1589,9 @@ var Cart = (function (_super) {
1535
1589
  _j.label = 20;
1536
1590
  case 20:
1537
1591
  _j.trys.push([20, 22, , 24]);
1538
- return [4, space.inventory.ajust(this.data().items, 'paid', this.data().cart_type, this.data().current_store_id || '')];
1592
+ return [4, space.inventory.ajust(this.data().items, 'paid', this.data().cart_type, {
1593
+ currentStoreId: this.data().current_store_id || ''
1594
+ })];
1539
1595
  case 21:
1540
1596
  _j.sent();
1541
1597
  return [3, 24];
@@ -1559,8 +1615,8 @@ var Cart = (function (_super) {
1559
1615
  _j.sent();
1560
1616
  return [3, 28];
1561
1617
  case 27:
1562
- e_9 = _j.sent();
1563
- console.log('error on checking for empty banks after payment: ', e_9.toString());
1618
+ e_11 = _j.sent();
1619
+ console.log('error on checking for empty banks after payment: ', e_11.toString());
1564
1620
  return [3, 28];
1565
1621
  case 28:
1566
1622
  console.log('checkForEmptyBanks delay: ', (0, moment_1.default)().diff(delay6, 'seconds'));
@@ -1582,7 +1638,7 @@ var Cart = (function (_super) {
1582
1638
  _this.setCartAsCompleted = function (saveToDatabase, user, store) {
1583
1639
  if (saveToDatabase === void 0) { saveToDatabase = true; }
1584
1640
  return __awaiter(_this, void 0, void 0, function () {
1585
- var space, delay1, skipRef, delay2, delay3, e_10;
1641
+ var space, delay1, skipRef, delay2, delay3, e_12;
1586
1642
  return __generator(this, function (_b) {
1587
1643
  switch (_b.label) {
1588
1644
  case 0:
@@ -1630,38 +1686,41 @@ var Cart = (function (_super) {
1630
1686
  console.log('====================');
1631
1687
  return [2, this];
1632
1688
  case 8:
1633
- e_10 = _b.sent();
1634
- console.log('error on setting cart as completed : ', e_10.toString());
1689
+ e_12 = _b.sent();
1690
+ console.log('error on setting cart as completed : ', e_12.toString());
1635
1691
  return [3, 9];
1636
1692
  case 9: return [2];
1637
1693
  }
1638
1694
  });
1639
1695
  });
1640
1696
  };
1641
- _this.saveCartModification = function (partial, oldItems, newItems, currentUser, usedPromise, saveToDatabase) {
1642
- if (saveToDatabase === void 0) { saveToDatabase = true; }
1697
+ _this.saveCartModification = function (partial, oldItems, newItems, currentUser, options) {
1698
+ if (options === void 0) { options = {}; }
1643
1699
  return __awaiter(_this, void 0, void 0, function () {
1644
- var itemsForInventory, space, _loop_2, this_1, _b, _c, bank, data, storeIdToUse, e_11;
1645
- return __generator(this, function (_d) {
1646
- switch (_d.label) {
1700
+ var shouldSaveToDB, itemsForInventory, space, _loop_2, this_1, _b, _c, bank, data, storeIdToUse, allInventoryItems_1, _d, _e, batchItems, invQuery, e_13, transfersWithItemsToUpdate, _loop_3, _f, _g, updatesToDo, e_14;
1701
+ return __generator(this, function (_h) {
1702
+ switch (_h.label) {
1647
1703
  case 0:
1648
- _d.trys.push([0, 7, , 8]);
1704
+ shouldSaveToDB = typeof options.saveToDatabase == 'boolean' ? options.saveToDatabase : true;
1705
+ _h.label = 1;
1706
+ case 1:
1707
+ _h.trys.push([1, 18, , 19]);
1649
1708
  itemsForInventory = (0, cart_1.getModifiedItems)(newItems, oldItems);
1650
1709
  return [4, Space_1.default.getCurrentSpaceWithRef(this._collection.path, this._user)];
1651
- case 1:
1652
- space = _d.sent();
1710
+ case 2:
1711
+ space = _h.sent();
1653
1712
  if (!!!space)
1654
1713
  throw new Error('could not init space obj');
1655
- if (!!!usedPromise) return [3, 5];
1714
+ if (!!!options.usedPromise) return [3, 6];
1656
1715
  _loop_2 = function (bank) {
1657
1716
  var promiseQuery, bankInDB, amountTotal, taxes, itemsWithoutInstallation, adjustment, remainingAmount, newRemainingAmount;
1658
- return __generator(this, function (_e) {
1659
- switch (_e.label) {
1717
+ return __generator(this, function (_j) {
1718
+ switch (_j.label) {
1660
1719
  case 0: return [4, space.promisesToPurchase.get({
1661
1720
  query: [{ field: 'id', operator: '==', value: bank.promise_id }]
1662
1721
  })];
1663
1722
  case 1:
1664
- promiseQuery = _e.sent();
1723
+ promiseQuery = _j.sent();
1665
1724
  if (!!!promiseQuery || !!!promiseQuery.length)
1666
1725
  return [2, "continue"];
1667
1726
  if (!!promiseQuery[0].data().ending_date)
@@ -1687,47 +1746,122 @@ var Cart = (function (_super) {
1687
1746
  };
1688
1747
  return [4, space.promisesToPurchase.getSpecificAvailableBankAmount(bank.promise_id, bank.bank_type_id, promiseQuery[0])];
1689
1748
  case 2:
1690
- remainingAmount = _e.sent();
1749
+ remainingAmount = _j.sent();
1691
1750
  newRemainingAmount = void 0;
1692
1751
  if (!!remainingAmount && !!remainingAmount.remaining_amount) {
1693
1752
  newRemainingAmount = (0, round_1.default)(remainingAmount.remaining_amount, 3) + (0, round_1.default)(adjustment.amount);
1694
1753
  }
1695
1754
  return [4, promiseQuery[0].adjustAmountLeftInPromise(adjustment, bank.bank_type_id, !!newRemainingAmount && newRemainingAmount < 1)];
1696
1755
  case 3:
1697
- _e.sent();
1756
+ _j.sent();
1698
1757
  return [2];
1699
1758
  }
1700
1759
  });
1701
1760
  };
1702
1761
  this_1 = this;
1703
- _b = 0, _c = usedPromise.banks_used;
1704
- _d.label = 2;
1705
- case 2:
1706
- if (!(_b < _c.length)) return [3, 5];
1762
+ _b = 0, _c = options.usedPromise.banks_used;
1763
+ _h.label = 3;
1764
+ case 3:
1765
+ if (!(_b < _c.length)) return [3, 6];
1707
1766
  bank = _c[_b];
1708
1767
  return [5, _loop_2(bank)];
1709
- case 3:
1710
- _d.sent();
1711
- _d.label = 4;
1712
1768
  case 4:
1769
+ _h.sent();
1770
+ _h.label = 5;
1771
+ case 5:
1713
1772
  _b++;
1714
- return [3, 2];
1715
- case 5: return [4, this.save(partial, undefined, !!saveToDatabase, true)];
1716
- case 6:
1717
- _d.sent();
1773
+ return [3, 3];
1774
+ case 6: return [4, this.save(partial, undefined, shouldSaveToDB, true)];
1775
+ case 7:
1776
+ _h.sent();
1718
1777
  data = this.data();
1719
1778
  storeIdToUse = !!data.current_store_id
1720
1779
  ? data.current_store_id
1721
1780
  : !!data.processed_by
1722
1781
  ? data.processed_by.at_store_id
1723
1782
  : '';
1724
- space.inventory.ajust(itemsForInventory, 'modified', this.data().cart_type, storeIdToUse, this.data().status === 5);
1725
- return [2, this];
1726
- case 7:
1727
- e_11 = _d.sent();
1728
- console.log('error on saving cart modification : ', e_11.toString());
1783
+ allInventoryItems_1 = [];
1784
+ _d = 0, _e = (0, chunk_1.default)(itemsForInventory, 10);
1785
+ _h.label = 8;
1786
+ case 8:
1787
+ if (!(_d < _e.length)) return [3, 13];
1788
+ batchItems = _e[_d];
1789
+ _h.label = 9;
1790
+ case 9:
1791
+ _h.trys.push([9, 11, , 12]);
1792
+ return [4, space.inventoryItems.get({
1793
+ query: [{ field: 'sku', operator: 'in', value: batchItems.map(function (i) { return i.sku; }) }]
1794
+ })];
1795
+ case 10:
1796
+ invQuery = _h.sent();
1797
+ allInventoryItems_1.push.apply(allInventoryItems_1, invQuery);
1798
+ return [3, 12];
1799
+ case 11:
1800
+ e_13 = _h.sent();
1801
+ console.log('error on fetching inventory for items: ', e_13.toString());
1802
+ return [3, 12];
1803
+ case 12:
1804
+ _d++;
1729
1805
  return [3, 8];
1730
- case 8: return [2];
1806
+ case 13:
1807
+ space.inventory.ajust(itemsForInventory, 'modified', this.data().cart_type, {
1808
+ currentStoreId: storeIdToUse,
1809
+ onlyWeb: this.data().status === 5,
1810
+ previousItems: oldItems
1811
+ });
1812
+ if (!!!options.associatedTransferRequests) return [3, 17];
1813
+ transfersWithItemsToUpdate = (0, cart_1.getItemsToUpdateByTransfer)(options.associatedTransferRequests, itemsForInventory.map(function (i) { return ({
1814
+ item: i,
1815
+ qteToUpdate: i.qte,
1816
+ inventoryItem: allInventoryItems_1.find(function (inv) { return inv.sku == i.sku; })
1817
+ }); }));
1818
+ if (!!!transfersWithItemsToUpdate) return [3, 17];
1819
+ _loop_3 = function (updatesToDo) {
1820
+ var transferID, specifics, sameTransfer, updatedProducts, e_15;
1821
+ return __generator(this, function (_k) {
1822
+ switch (_k.label) {
1823
+ case 0:
1824
+ transferID = updatesToDo[0], specifics = updatesToDo[1];
1825
+ sameTransfer = options.associatedTransferRequests.find(function (t) { return t.data().id == transferID; });
1826
+ if (!!!sameTransfer)
1827
+ return [2, "continue"];
1828
+ updatedProducts = sameTransfer.constructProductObjFromUpdates(specifics);
1829
+ _k.label = 1;
1830
+ case 1:
1831
+ _k.trys.push([1, 3, , 4]);
1832
+ return [4, sameTransfer.saveUpdatesToProductsOnly(updatedProducts, {
1833
+ comment: 'Transfert mis à jour automatiquement à la modification de la commande associée.',
1834
+ user: currentUser || ''
1835
+ }, true)];
1836
+ case 2:
1837
+ _k.sent();
1838
+ return [3, 4];
1839
+ case 3:
1840
+ e_15 = _k.sent();
1841
+ console.log('error on updating transfer for cart: ', e_15.toString());
1842
+ return [3, 4];
1843
+ case 4: return [2];
1844
+ }
1845
+ });
1846
+ };
1847
+ _f = 0, _g = Object.entries(transfersWithItemsToUpdate);
1848
+ _h.label = 14;
1849
+ case 14:
1850
+ if (!(_f < _g.length)) return [3, 17];
1851
+ updatesToDo = _g[_f];
1852
+ return [5, _loop_3(updatesToDo)];
1853
+ case 15:
1854
+ _h.sent();
1855
+ _h.label = 16;
1856
+ case 16:
1857
+ _f++;
1858
+ return [3, 14];
1859
+ case 17: return [2, this];
1860
+ case 18:
1861
+ e_14 = _h.sent();
1862
+ console.log('error on saving cart modification : ', e_14.toString());
1863
+ return [3, 19];
1864
+ case 19: return [2];
1731
1865
  }
1732
1866
  });
1733
1867
  });
@@ -1891,7 +2025,7 @@ var Cart = (function (_super) {
1891
2025
  });
1892
2026
  }); };
1893
2027
  _this.setDiscountRules = function (removePaymentIncentive) { return __awaiter(_this, void 0, void 0, function () {
1894
- var space, allDiscountRules, discountsToAdd, _loop_3, this_2, _b, allDiscountRules_1, discount;
2028
+ var space, allDiscountRules, discountsToAdd, _loop_4, this_2, _b, allDiscountRules_1, discount;
1895
2029
  return __generator(this, function (_c) {
1896
2030
  switch (_c.label) {
1897
2031
  case 0:
@@ -1911,7 +2045,7 @@ var Cart = (function (_super) {
1911
2045
  case 2:
1912
2046
  allDiscountRules = _c.sent();
1913
2047
  discountsToAdd = [];
1914
- _loop_3 = function (discount) {
2048
+ _loop_4 = function (discount) {
1915
2049
  var discountData = discount.data();
1916
2050
  if (!!discountData.draft)
1917
2051
  return "continue";
@@ -1931,7 +2065,7 @@ var Cart = (function (_super) {
1931
2065
  this_2 = this;
1932
2066
  for (_b = 0, allDiscountRules_1 = allDiscountRules; _b < allDiscountRules_1.length; _b++) {
1933
2067
  discount = allDiscountRules_1[_b];
1934
- _loop_3(discount);
2068
+ _loop_4(discount);
1935
2069
  }
1936
2070
  this._data = __assign(__assign({}, this._data), { discount_rules: __spreadArray(__spreadArray([], (!!this._data.is_booking && !!this._data.discount_rules ? this._data.discount_rules : []), true), discountsToAdd, true) });
1937
2071
  return [2];
@@ -2025,9 +2159,9 @@ var Cart = (function (_super) {
2025
2159
  }) || 0;
2026
2160
  if (!!item.tier_pricing) {
2027
2161
  var isFirst = true;
2028
- var _loop_4 = function (aTier) {
2162
+ var _loop_5 = function (aTier) {
2029
2163
  if (isFirst && (0, toNumber_1.default)(aTier.from) > totalQte) {
2030
- var _loop_5 = function (anItem) {
2164
+ var _loop_6 = function (anItem) {
2031
2165
  _this._updateItems(_this._data.items.map(function (i) {
2032
2166
  if (i.sku !== anItem.sku)
2033
2167
  return i;
@@ -2036,13 +2170,13 @@ var Cart = (function (_super) {
2036
2170
  };
2037
2171
  for (var _d = 0, allSameCategory_1 = allSameCategory; _d < allSameCategory_1.length; _d++) {
2038
2172
  var anItem = allSameCategory_1[_d];
2039
- _loop_5(anItem);
2173
+ _loop_6(anItem);
2040
2174
  }
2041
2175
  isFirst = false;
2042
2176
  return "continue";
2043
2177
  }
2044
2178
  if ((0, toNumber_1.default)(aTier.from) <= totalQte && (!!!aTier.to || (0, toNumber_1.default)(aTier.to) >= totalQte)) {
2045
- var _loop_6 = function (anItem) {
2179
+ var _loop_7 = function (anItem) {
2046
2180
  _this._updateItems(_this._data.items.map(function (i) {
2047
2181
  if (i.sku !== anItem.sku)
2048
2182
  return i;
@@ -2063,13 +2197,13 @@ var Cart = (function (_super) {
2063
2197
  };
2064
2198
  for (var _e = 0, allSameCategory_2 = allSameCategory; _e < allSameCategory_2.length; _e++) {
2065
2199
  var anItem = allSameCategory_2[_e];
2066
- _loop_6(anItem);
2200
+ _loop_7(anItem);
2067
2201
  }
2068
2202
  }
2069
2203
  };
2070
2204
  for (var _b = 0, _c = item.tier_pricing; _b < _c.length; _b++) {
2071
2205
  var aTier = _c[_b];
2072
- _loop_4(aTier);
2206
+ _loop_5(aTier);
2073
2207
  }
2074
2208
  }
2075
2209
  return _this._data.items;
@@ -2103,7 +2237,7 @@ var Cart = (function (_super) {
2103
2237
  return defaultCartTaxes;
2104
2238
  };
2105
2239
  _this.calculateTotals = function (currency, forcedPromos) { return __awaiter(_this, void 0, void 0, function () {
2106
- var space, allTaxes, e_12, shippingAddress, currentTaxes, addressForTaxes, currentShippingProvince_1, newCartTaxes, newTaxes, err_5;
2240
+ var space, allTaxes, e_16, shippingAddress, currentTaxes, addressForTaxes, currentShippingProvince_1, newCartTaxes, newTaxes, err_5;
2107
2241
  var _b, _c, _d;
2108
2242
  return __generator(this, function (_e) {
2109
2243
  switch (_e.label) {
@@ -2131,12 +2265,12 @@ var Cart = (function (_super) {
2131
2265
  _e.label = 5;
2132
2266
  case 5: return [3, 8];
2133
2267
  case 6:
2134
- e_12 = _e.sent();
2135
- console.log('error on fetching taxe rates from space: ', e_12.toString());
2268
+ e_16 = _e.sent();
2269
+ console.log('error on fetching taxe rates from space: ', e_16.toString());
2136
2270
  return [4, (0, logs_1.SystemLog)({
2137
2271
  clientName: "sdk-admin | Cart | calculateTotals, space: ".concat((0, services_1.getSpaceInitialsByID)(space.data().id)),
2138
2272
  clientToken: (_c = process.env.NEXT_PUBLIC_LOG_SYSTEM_KEY) !== null && _c !== void 0 ? _c : ''
2139
- }, logs_1.LogType.ERROR, "error on fetching taxe rates from space: ".concat(e_12.toString()))];
2273
+ }, logs_1.LogType.ERROR, "error on fetching taxe rates from space: ".concat(e_16.toString()))];
2140
2274
  case 7:
2141
2275
  _e.sent();
2142
2276
  return [3, 8];
@@ -2242,7 +2376,7 @@ var Cart = (function (_super) {
2242
2376
  return 2;
2243
2377
  });
2244
2378
  var feePromosTotal = 0;
2245
- var _loop_7 = function (aPromo) {
2379
+ var _loop_8 = function (aPromo) {
2246
2380
  if (_this._data.subtotal > 0 &&
2247
2381
  !!aPromo &&
2248
2382
  (aPromo.applies_to === Cart_1.CartPromoAppliesToEnum.SUBTOTAL ||
@@ -2324,7 +2458,7 @@ var Cart = (function (_super) {
2324
2458
  };
2325
2459
  for (var _c = 0, cartPromos_1 = cartPromos; _c < cartPromos_1.length; _c++) {
2326
2460
  var aPromo = cartPromos_1[_c];
2327
- _loop_7(aPromo);
2461
+ _loop_8(aPromo);
2328
2462
  }
2329
2463
  }
2330
2464
  else {
@@ -2350,7 +2484,7 @@ var Cart = (function (_super) {
2350
2484
  return total;
2351
2485
  };
2352
2486
  _this.getAssociatedTransferRequests = function () { return __awaiter(_this, void 0, void 0, function () {
2353
- var space, cartTransferRequestQuery, e_13;
2487
+ var space, cartTransferRequestQuery, e_17;
2354
2488
  return __generator(this, function (_b) {
2355
2489
  switch (_b.label) {
2356
2490
  case 0:
@@ -2363,8 +2497,8 @@ var Cart = (function (_super) {
2363
2497
  cartTransferRequestQuery = _b.sent();
2364
2498
  return [2, cartTransferRequestQuery];
2365
2499
  case 3:
2366
- e_13 = _b.sent();
2367
- console.error(e_13);
2500
+ e_17 = _b.sent();
2501
+ console.error(e_17);
2368
2502
  return [2, []];
2369
2503
  case 4: return [2];
2370
2504
  }
@@ -2707,7 +2841,7 @@ var Cart = (function (_super) {
2707
2841
  });
2708
2842
  }); };
2709
2843
  _this.addEmptyBox = function () { return __awaiter(_this, void 0, void 0, function () {
2710
- var e_14;
2844
+ var e_18;
2711
2845
  return __generator(this, function (_b) {
2712
2846
  switch (_b.label) {
2713
2847
  case 0:
@@ -2730,8 +2864,8 @@ var Cart = (function (_super) {
2730
2864
  _b.sent();
2731
2865
  return [3, 3];
2732
2866
  case 2:
2733
- e_14 = _b.sent();
2734
- throw new Error(e_14);
2867
+ e_18 = _b.sent();
2868
+ throw new Error(e_18);
2735
2869
  case 3: return [2];
2736
2870
  }
2737
2871
  });
@@ -2946,7 +3080,7 @@ var Cart = (function (_super) {
2946
3080
  });
2947
3081
  }); };
2948
3082
  _this.setBoxTypeAtIndex = function (boxType, boxIndex) { return __awaiter(_this, void 0, void 0, function () {
2949
- var e_15;
3083
+ var e_19;
2950
3084
  var _this = this;
2951
3085
  return __generator(this, function (_b) {
2952
3086
  switch (_b.label) {
@@ -2967,8 +3101,8 @@ var Cart = (function (_super) {
2967
3101
  _b.sent();
2968
3102
  return [2, true];
2969
3103
  case 2:
2970
- e_15 = _b.sent();
2971
- throw new Error(e_15);
3104
+ e_19 = _b.sent();
3105
+ throw new Error(e_19);
2972
3106
  case 3: return [2];
2973
3107
  }
2974
3108
  });
@@ -3238,7 +3372,7 @@ var Cart = (function (_super) {
3238
3372
  _this.updateWithPromiseToPurchasePrices = function (escompteItems, customPriceList, banksUsedForCart) {
3239
3373
  if (customPriceList === void 0) { customPriceList = undefined; }
3240
3374
  return __awaiter(_this, void 0, void 0, function () {
3241
- var updatedPriceProducts, associatedEscomptes, _loop_8, index;
3375
+ var updatedPriceProducts, associatedEscomptes, _loop_9, index;
3242
3376
  return __generator(this, function (_b) {
3243
3377
  switch (_b.label) {
3244
3378
  case 0:
@@ -3259,7 +3393,7 @@ var Cart = (function (_super) {
3259
3393
  return (!!shouldCheckPriceList ? (0, g2_1.checkForCustomPriceEquivalent)(item, customPriceList) : item);
3260
3394
  });
3261
3395
  associatedEscomptes = new Array();
3262
- _loop_8 = function (index) {
3396
+ _loop_9 = function (index) {
3263
3397
  var item = updatedPriceProducts[index];
3264
3398
  if (!!!item.promise_to_purchase_association_ids ||
3265
3399
  item.promise_to_purchase_association_ids.length == 0 ||
@@ -3276,7 +3410,7 @@ var Cart = (function (_super) {
3276
3410
  associatedEscomptes.push(escompteSuppCartItem);
3277
3411
  };
3278
3412
  for (index = 0; index < updatedPriceProducts.length; index++) {
3279
- _loop_8(index);
3413
+ _loop_9(index);
3280
3414
  }
3281
3415
  this._data = __assign(__assign({}, this._data), { items: __spreadArray(__spreadArray([], updatedPriceProducts, true), associatedEscomptes, true) });
3282
3416
  return [4, this.calculateTotals()];
@@ -3291,7 +3425,7 @@ var Cart = (function (_super) {
3291
3425
  if (customPriceList === void 0) { customPriceList = undefined; }
3292
3426
  if (contingency === void 0) { contingency = 0; }
3293
3427
  return __awaiter(_this, void 0, void 0, function () {
3294
- var space, remainingAmounts, potentialRemainingAmounts, e_16;
3428
+ var space, remainingAmounts, potentialRemainingAmounts, e_20;
3295
3429
  return __generator(this, function (_b) {
3296
3430
  switch (_b.label) {
3297
3431
  case 0:
@@ -3318,9 +3452,9 @@ var Cart = (function (_super) {
3318
3452
  }
3319
3453
  return [2, true];
3320
3454
  case 5:
3321
- e_16 = _b.sent();
3322
- console.log('error on checking if pa can be used for cart: ', e_16.message);
3323
- return [2, e_16.message];
3455
+ e_20 = _b.sent();
3456
+ console.log('error on checking if pa can be used for cart: ', e_20.message);
3457
+ return [2, e_20.message];
3324
3458
  case 6: return [2];
3325
3459
  }
3326
3460
  });
@@ -3385,7 +3519,7 @@ var Cart = (function (_super) {
3385
3519
  if (!!allBanksAreInactive) {
3386
3520
  throw new Error(PromiseToPurchase_2.ApplyBanksToCartErrorsEnum.BANK_NOT_FOUND);
3387
3521
  }
3388
- var _loop_9 = function (bankToUse) {
3522
+ var _loop_10 = function (bankToUse) {
3389
3523
  var sameInApplicable = applicableBanks.find(function (ab) { return ab.bank.bank_type_id === bankToUse.bank_type_id; });
3390
3524
  if (!!sameInApplicable && (!!!sameInApplicable.pa_is_active || !!!sameInApplicable.bank.active)) {
3391
3525
  remainingAmounts = remainingAmounts
@@ -3399,7 +3533,7 @@ var Cart = (function (_super) {
3399
3533
  };
3400
3534
  for (var _f = 0, promiseBanksToUse_1 = promiseBanksToUse; _f < promiseBanksToUse_1.length; _f++) {
3401
3535
  var bankToUse = promiseBanksToUse_1[_f];
3402
- _loop_9(bankToUse);
3536
+ _loop_10(bankToUse);
3403
3537
  }
3404
3538
  if (promiseBanksToUse.find(function (bankToUse) { return !!bankToUse && !!!bankToUse.initial_amount; })) {
3405
3539
  remainingAmounts = new Array();
@@ -3407,7 +3541,7 @@ var Cart = (function (_super) {
3407
3541
  }
3408
3542
  var banksUsed = new Array();
3409
3543
  var potentialRemainingAmounts = [];
3410
- var _loop_10 = function (bank) {
3544
+ var _loop_11 = function (bank) {
3411
3545
  var amountToRemove = 0;
3412
3546
  var bank_type_id = bank.bank_type_id, amount = bank.amount, rest = __rest(bank, ["bank_type_id", "amount"]);
3413
3547
  if (!!forcedBankTypeId) {
@@ -3458,7 +3592,7 @@ var Cart = (function (_super) {
3458
3592
  };
3459
3593
  for (var _g = 0, remainingAmounts_1 = remainingAmounts; _g < remainingAmounts_1.length; _g++) {
3460
3594
  var bank = remainingAmounts_1[_g];
3461
- _loop_10(bank);
3595
+ _loop_11(bank);
3462
3596
  }
3463
3597
  _this.setBankUsed(banksUsed);
3464
3598
  return potentialRemainingAmounts;
@@ -3493,7 +3627,7 @@ var Cart = (function (_super) {
3493
3627
  } });
3494
3628
  };
3495
3629
  _this.canBePaidWithPA = function (applicableBanks, customerID, customPriceList, space, forcedBankTypeId) { return __awaiter(_this, void 0, void 0, function () {
3496
- var contingency, escomptesItems, applicableBanksHistory, _b, applicableBanks_1, applicable, promise_id, bank, bankHistory, e_17, filteredApplicableBanksHistory, possibleBanksToUse, canBePaidCheck, canBePaid;
3630
+ var contingency, escomptesItems, applicableBanksHistory, _b, applicableBanks_1, applicable, promise_id, bank, bankHistory, e_21, filteredApplicableBanksHistory, possibleBanksToUse, canBePaidCheck, canBePaid;
3497
3631
  return __generator(this, function (_c) {
3498
3632
  switch (_c.label) {
3499
3633
  case 0:
@@ -3521,8 +3655,8 @@ var Cart = (function (_super) {
3521
3655
  }
3522
3656
  return [3, 6];
3523
3657
  case 5:
3524
- e_17 = _c.sent();
3525
- console.log('error on fetching bank history for bank ', bank.bank_type_id, ': ', e_17.toString());
3658
+ e_21 = _c.sent();
3659
+ console.log('error on fetching bank history for bank ', bank.bank_type_id, ': ', e_21.toString());
3526
3660
  return [3, 6];
3527
3661
  case 6:
3528
3662
  _b++;
@@ -3556,7 +3690,7 @@ var Cart = (function (_super) {
3556
3690
  });
3557
3691
  }); };
3558
3692
  _this.checkForEmptyBanksAfterPayment = function (space) { return __awaiter(_this, void 0, void 0, function () {
3559
- var promisesInCart, banksToDeactivate, _loop_11, this_3, _b, _c, bank, e_18;
3693
+ var promisesInCart, banksToDeactivate, _loop_12, this_3, _b, _c, bank, e_22;
3560
3694
  var _this = this;
3561
3695
  var _d, _e, _f, _g, _h, _j;
3562
3696
  return __generator(this, function (_k) {
@@ -3566,8 +3700,8 @@ var Cart = (function (_super) {
3566
3700
  if (!!!promisesInCart)
3567
3701
  return [2];
3568
3702
  banksToDeactivate = {};
3569
- _loop_11 = function (bank) {
3570
- var promiseQuery, promise, sameBankInPromise, bankUseHistory, historyQuery, e_19, remaining_amount, remainingAmount, promiseAlreadySetInObj, e_20;
3703
+ _loop_12 = function (bank) {
3704
+ var promiseQuery, promise, sameBankInPromise, bankUseHistory, historyQuery, e_23, remaining_amount, remainingAmount, promiseAlreadySetInObj, e_24;
3571
3705
  var _l;
3572
3706
  return __generator(this, function (_m) {
3573
3707
  switch (_m.label) {
@@ -3611,12 +3745,12 @@ var Cart = (function (_super) {
3611
3745
  _m.label = 6;
3612
3746
  case 6: return [3, 9];
3613
3747
  case 7:
3614
- e_19 = _m.sent();
3615
- console.log('error on fetching history for banks: ', e_19.toString());
3748
+ e_23 = _m.sent();
3749
+ console.log('error on fetching history for banks: ', e_23.toString());
3616
3750
  return [4, (0, logs_1.SystemLog)({
3617
3751
  clientName: "sdk-admin | Cart | checkForEmptyBanks, space: ".concat((0, services_1.getSpaceInitialsByID)(space.data().id)),
3618
3752
  clientToken: (_e = process.env.NEXT_PUBLIC_LOG_SYSTEM_KEY) !== null && _e !== void 0 ? _e : ''
3619
- }, logs_1.LogType.ERROR, "Cart ref: ".concat(this_3._data.ref, " |\u00A0Error on fetching history for banks: ").concat(e_19.toString()))];
3753
+ }, logs_1.LogType.ERROR, "Cart ref: ".concat(this_3._data.ref, " |\u00A0Error on fetching history for banks: ").concat(e_23.toString()))];
3620
3754
  case 8:
3621
3755
  _m.sent();
3622
3756
  return [3, 9];
@@ -3647,12 +3781,12 @@ var Cart = (function (_super) {
3647
3781
  _m.label = 13;
3648
3782
  case 13: return [3, 16];
3649
3783
  case 14:
3650
- e_20 = _m.sent();
3651
- console.log('error on fetching promises for bank: ', e_20.toString());
3784
+ e_24 = _m.sent();
3785
+ console.log('error on fetching promises for bank: ', e_24.toString());
3652
3786
  return [4, (0, logs_1.SystemLog)({
3653
3787
  clientName: "sdk-admin | Cart | checkForEmptyBanks, space: ".concat((0, services_1.getSpaceInitialsByID)(space.data().id)),
3654
3788
  clientToken: (_h = process.env.NEXT_PUBLIC_LOG_SYSTEM_KEY) !== null && _h !== void 0 ? _h : ''
3655
- }, logs_1.LogType.ERROR, "Cart id: ".concat(this_3._data.id, " & ref: ").concat(this_3._data.ref, " & customer: ").concat(this_3._data.customer_id, " |\u00A0Error on fetching promises for bank: ").concat(e_20.toString()))];
3789
+ }, logs_1.LogType.ERROR, "Cart id: ".concat(this_3._data.id, " & ref: ").concat(this_3._data.ref, " & customer: ").concat(this_3._data.customer_id, " |\u00A0Error on fetching promises for bank: ").concat(e_24.toString()))];
3656
3790
  case 15:
3657
3791
  _m.sent();
3658
3792
  return [3, 16];
@@ -3666,7 +3800,7 @@ var Cart = (function (_super) {
3666
3800
  case 1:
3667
3801
  if (!(_b < _c.length)) return [3, 4];
3668
3802
  bank = _c[_b];
3669
- return [5, _loop_11(bank)];
3803
+ return [5, _loop_12(bank)];
3670
3804
  case 2:
3671
3805
  _k.sent();
3672
3806
  _k.label = 3;
@@ -3688,12 +3822,12 @@ var Cart = (function (_super) {
3688
3822
  _k.sent();
3689
3823
  return [3, 8];
3690
3824
  case 6:
3691
- e_18 = _k.sent();
3692
- console.log('error on saving promises with empty banks: ', e_18.toString());
3825
+ e_22 = _k.sent();
3826
+ console.log('error on saving promises with empty banks: ', e_22.toString());
3693
3827
  return [4, (0, logs_1.SystemLog)({
3694
3828
  clientName: "sdk-admin | Cart | checkForEmptyBanks, space: ".concat((0, services_1.getSpaceInitialsByID)(space.data().id)),
3695
3829
  clientToken: (_j = process.env.NEXT_PUBLIC_LOG_SYSTEM_KEY) !== null && _j !== void 0 ? _j : ''
3696
- }, logs_1.LogType.ERROR, "Cart ref: ".concat(this._data.ref, " |\u00A0Error on saving promises with empty banks: ").concat(e_18.toString()))];
3830
+ }, logs_1.LogType.ERROR, "Cart ref: ".concat(this._data.ref, " |\u00A0Error on saving promises with empty banks: ").concat(e_22.toString()))];
3697
3831
  case 7:
3698
3832
  _k.sent();
3699
3833
  return [3, 8];
@@ -3733,7 +3867,7 @@ var Cart = (function (_super) {
3733
3867
  });
3734
3868
  }); };
3735
3869
  _this.changeProcessingStoreForCart = function (newProcessedAtStore, space, currentUser) { return __awaiter(_this, void 0, void 0, function () {
3736
- var cartUpdated, prevStoreId, newStoreId, s_1, newPartialCart, updatedByData, e_21;
3870
+ var cartUpdated, prevStoreId, newStoreId, s_1, newPartialCart, updatedByData, e_25;
3737
3871
  return __generator(this, function (_b) {
3738
3872
  switch (_b.label) {
3739
3873
  case 0:
@@ -3750,7 +3884,11 @@ var Cart = (function (_super) {
3750
3884
  _b.label = 1;
3751
3885
  case 1:
3752
3886
  _b.trys.push([1, 3, , 4]);
3753
- return [4, space.inventory.ajust(this.data().items, 'updatedProcessingStore', this.data().cart_type, prevStoreId, false, newStoreId)];
3887
+ return [4, space.inventory.ajust(this.data().items, 'updatedProcessingStore', this.data().cart_type, {
3888
+ currentStoreId: prevStoreId,
3889
+ onlyWeb: false,
3890
+ fromStoreId: newStoreId
3891
+ })];
3754
3892
  case 2:
3755
3893
  _b.sent();
3756
3894
  return [3, 4];
@@ -3776,8 +3914,8 @@ var Cart = (function (_super) {
3776
3914
  cartUpdated = true;
3777
3915
  return [3, 8];
3778
3916
  case 7:
3779
- e_21 = _b.sent();
3780
- console.log('error on saving to database: ', e_21.toString());
3917
+ e_25 = _b.sent();
3918
+ console.log('error on saving to database: ', e_25.toString());
3781
3919
  return [3, 8];
3782
3920
  case 8: return [3, 10];
3783
3921
  case 9:
@@ -3788,7 +3926,7 @@ var Cart = (function (_super) {
3788
3926
  });
3789
3927
  }); };
3790
3928
  _this.setCartWithInvoiceRef = function (space, saveToDatabase, newCartRef) { return __awaiter(_this, void 0, void 0, function () {
3791
- var invoiceRef, newData, e_22;
3929
+ var invoiceRef, newData, e_26;
3792
3930
  return __generator(this, function (_b) {
3793
3931
  switch (_b.label) {
3794
3932
  case 0:
@@ -3808,8 +3946,8 @@ var Cart = (function (_super) {
3808
3946
  _b.sent();
3809
3947
  return [3, 5];
3810
3948
  case 4:
3811
- e_22 = _b.sent();
3812
- console.log('error on adding invoice_ref to cart: ', e_22.toString());
3949
+ e_26 = _b.sent();
3950
+ console.log('error on adding invoice_ref to cart: ', e_26.toString());
3813
3951
  return [2];
3814
3952
  case 5: return [2, invoiceRef];
3815
3953
  }
@@ -3818,7 +3956,7 @@ var Cart = (function (_super) {
3818
3956
  _this.setG2ExternalOrderRef = function (space, saveToDatabase, newlyCreatedCartData) {
3819
3957
  if (saveToDatabase === void 0) { saveToDatabase = true; }
3820
3958
  return __awaiter(_this, void 0, void 0, function () {
3821
- var G2Service, cartDataToUse, g2OrderRef, api, orgID, token, savedCartInG2, response, e_23, errorStr, errorCode;
3959
+ var G2Service, cartDataToUse, g2OrderRef, api, orgID, token, savedCartInG2, response, e_27, errorStr, errorCode;
3822
3960
  var _b;
3823
3961
  return __generator(this, function (_c) {
3824
3962
  switch (_c.label) {
@@ -3863,16 +4001,16 @@ var Cart = (function (_super) {
3863
4001
  _c.label = 7;
3864
4002
  case 7: return [3, 10];
3865
4003
  case 8:
3866
- e_23 = _c.sent();
4004
+ e_27 = _c.sent();
3867
4005
  errorStr = !!g2OrderRef
3868
4006
  ? "could not save G2 order #".concat(g2OrderRef, " to cart ref ").concat(this.data().ref)
3869
4007
  : "on save to G2 for cart ref ".concat(this.data().ref);
3870
4008
  errorCode = !!g2OrderRef ? G2_1.G2OrderSaveErrors.ADDIO_SAVE_CART_ERROR : G2_1.G2OrderSaveErrors.G2_ERROR;
3871
- console.log("".concat(__1.isTestEnv ? 'TESTENV - ' : '', "G2 ORDER BUG ").concat(errorStr, ":"), e_23.toString());
4009
+ console.log("".concat(__1.isTestEnv ? 'TESTENV - ' : '', "G2 ORDER BUG ").concat(errorStr, ":"), e_27.toString());
3872
4010
  return [4, (0, logs_1.SystemLog)({
3873
4011
  clientName: "sdk-admin | Cart | setG2ExternalOrderRef | ".concat((0, services_1.getSpaceInitialsByID)(space.data().id)),
3874
4012
  clientToken: (_b = process.env.NEXT_PUBLIC_LOG_SYSTEM_KEY) !== null && _b !== void 0 ? _b : ''
3875
- }, logs_1.LogType.ERROR, "".concat(__1.isTestEnv ? 'TESTENV - ' : '', "G2 ORDER BUG %%").concat(this.data().ref, "%%").concat(g2OrderRef, "%%").concat(errorCode, "%%").concat(errorStr, ": ").concat(e_23.toString()))];
4013
+ }, logs_1.LogType.ERROR, "".concat(__1.isTestEnv ? 'TESTENV - ' : '', "G2 ORDER BUG %%").concat(this.data().ref, "%%").concat(g2OrderRef, "%%").concat(errorCode, "%%").concat(errorStr, ": ").concat(e_27.toString()))];
3876
4014
  case 9:
3877
4015
  _c.sent();
3878
4016
  return [2, undefined];
@@ -3882,7 +4020,7 @@ var Cart = (function (_super) {
3882
4020
  });
3883
4021
  };
3884
4022
  _this.setCartAsRefunded = function (partial, itemsToReturnInventory, storeId) { return __awaiter(_this, void 0, void 0, function () {
3885
- var space, e_24, saved;
4023
+ var space, e_28, saved;
3886
4024
  return __generator(this, function (_b) {
3887
4025
  switch (_b.label) {
3888
4026
  case 0:
@@ -3895,13 +4033,17 @@ var Cart = (function (_super) {
3895
4033
  space = _b.sent();
3896
4034
  if (!!!this._data.current_store_id)
3897
4035
  throw new Error('No store associated to cart');
3898
- return [4, space.inventory.ajust(itemsToReturnInventory, 'refunded', this._data.cart_type, storeId, false, this._data.current_store_id)];
4036
+ return [4, space.inventory.ajust(itemsToReturnInventory, 'refunded', this._data.cart_type, {
4037
+ currentStoreId: storeId,
4038
+ onlyWeb: false,
4039
+ fromStoreId: this._data.current_store_id
4040
+ })];
3899
4041
  case 3:
3900
4042
  _b.sent();
3901
4043
  return [3, 5];
3902
4044
  case 4:
3903
- e_24 = _b.sent();
3904
- console.error(e_24);
4045
+ e_28 = _b.sent();
4046
+ console.error(e_28);
3905
4047
  return [3, 5];
3906
4048
  case 5:
3907
4049
  try {