addio-admin-sdk 1.7.102 → 1.7.104
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/dist/Interfaces/Algolia/index.d.ts +1 -0
- package/dist/Interfaces/Attribute/index.d.ts +1 -0
- package/dist/Interfaces/CMS/index.d.ts +3 -0
- package/dist/Interfaces/CMS/index.js +3 -0
- package/dist/Interfaces/CMS/index.js.map +1 -1
- package/dist/Interfaces/Cart/index.d.ts +1 -0
- package/dist/Interfaces/Cart/index.js +6 -2
- package/dist/Interfaces/Cart/index.js.map +1 -1
- package/dist/Interfaces/CartReservedQuantities/index.d.ts +2 -0
- package/dist/Interfaces/Customer/IStoreCredit.d.ts +1 -0
- package/dist/Interfaces/Customer/index.d.ts +7 -0
- package/dist/Interfaces/Customer/index.js +7 -0
- package/dist/Interfaces/Customer/index.js.map +1 -1
- package/dist/Interfaces/Declination/index.js +8 -2
- package/dist/Interfaces/Declination/index.js.map +1 -1
- package/dist/Interfaces/Email/IEmail.js +7 -3
- package/dist/Interfaces/Email/IEmail.js.map +1 -1
- package/dist/Interfaces/G2/index.js +2 -0
- package/dist/Interfaces/G2/index.js.map +1 -1
- package/dist/Interfaces/Indexed/Product/index.d.ts +3 -0
- package/dist/Interfaces/Indexed/Product/index.js +43 -2
- package/dist/Interfaces/Indexed/Product/index.js.map +1 -1
- package/dist/Interfaces/Menu/index.d.ts +11 -0
- package/dist/Interfaces/Product/IImportProduct.js +94 -3
- package/dist/Interfaces/Product/IImportProduct.js.map +1 -1
- package/dist/Interfaces/Product/IInventoryItem.d.ts +11 -27
- package/dist/Interfaces/Product/IInventoryItem.js +13 -4
- package/dist/Interfaces/Product/IInventoryItem.js.map +1 -1
- package/dist/Interfaces/Product/IPricing.js +6 -0
- package/dist/Interfaces/Product/IPricing.js.map +1 -1
- package/dist/Interfaces/Product/index.d.ts +8 -0
- package/dist/Interfaces/Product/index.js +8 -0
- package/dist/Interfaces/Product/index.js.map +1 -1
- package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.js +1 -1
- package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.js.map +1 -1
- package/dist/Interfaces/Rules/IDiscountRule.d.ts +18 -0
- package/dist/Interfaces/Rules/IDiscountRule.js +19 -0
- package/dist/Interfaces/Rules/IDiscountRule.js.map +1 -1
- package/dist/Interfaces/Services/IService.d.ts +4 -0
- package/dist/Interfaces/Shipping/Shiptime/order.js +23 -0
- package/dist/Interfaces/Shipping/Shiptime/order.js.map +1 -1
- package/dist/Interfaces/Space/index.d.ts +8 -0
- package/dist/Interfaces/Space/index.js +9 -0
- package/dist/Interfaces/Space/index.js.map +1 -1
- package/dist/Interfaces/TCG/index.d.ts +12 -1
- package/dist/Interfaces/TCG/index.js +11 -0
- package/dist/Interfaces/TCG/index.js.map +1 -1
- package/dist/Interfaces/TransferRequest/index.js +3 -0
- package/dist/Interfaces/TransferRequest/index.js.map +1 -1
- package/dist/constants/services.js +1 -0
- package/dist/constants/services.js.map +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/Attribute/index.js +43 -0
- package/dist/lib/Attribute/index.js.map +1 -1
- package/dist/lib/BGJob/index.js +5 -1
- package/dist/lib/BGJob/index.js.map +1 -1
- package/dist/lib/Booking/index.d.ts +15 -0
- package/dist/lib/Booking/index.js +20 -0
- package/dist/lib/Booking/index.js.map +1 -1
- package/dist/lib/Brand/index.d.ts +9 -0
- package/dist/lib/Brand/index.js +18 -0
- package/dist/lib/Brand/index.js.map +1 -1
- package/dist/lib/Cart/index.d.ts +99 -0
- package/dist/lib/Cart/index.js +498 -9
- package/dist/lib/Cart/index.js.map +1 -1
- package/dist/lib/CartReservedQuantities/index.d.ts +29 -0
- package/dist/lib/CartReservedQuantities/index.js +41 -0
- package/dist/lib/CartReservedQuantities/index.js.map +1 -1
- package/dist/lib/Catalogue/index.d.ts +6 -0
- package/dist/lib/Catalogue/index.js +9 -0
- package/dist/lib/Catalogue/index.js.map +1 -1
- package/dist/lib/Category/index.d.ts +6 -0
- package/dist/lib/Category/index.js +15 -0
- package/dist/lib/Category/index.js.map +1 -1
- package/dist/lib/Class/index.d.ts +4 -0
- package/dist/lib/Class/index.js +8 -0
- package/dist/lib/Class/index.js.map +1 -1
- package/dist/lib/Customer/index.d.ts +12 -0
- package/dist/lib/Customer/index.js +13 -0
- package/dist/lib/Customer/index.js.map +1 -1
- package/dist/lib/Declination/index.js +2 -0
- package/dist/lib/Declination/index.js.map +1 -1
- package/dist/lib/Discount/index.d.ts +9 -0
- package/dist/lib/Discount/index.js +23 -0
- package/dist/lib/Discount/index.js.map +1 -1
- package/dist/lib/ElasticSearch/index.d.ts +5 -0
- package/dist/lib/ElasticSearch/index.js +5 -0
- package/dist/lib/ElasticSearch/index.js.map +1 -1
- package/dist/lib/Elavon/index.js +5 -0
- package/dist/lib/Elavon/index.js.map +1 -1
- package/dist/lib/Email/AbandonedCartEmail.d.ts +8 -0
- package/dist/lib/Email/AbandonedCartEmail.js +8 -0
- package/dist/lib/Email/AbandonedCartEmail.js.map +1 -1
- package/dist/lib/Email/AccountConfirmationEmail.d.ts +8 -0
- package/dist/lib/Email/AccountConfirmationEmail.js +8 -0
- package/dist/lib/Email/AccountConfirmationEmail.js.map +1 -1
- package/dist/lib/Email/AdminOrderConfirmationEmail.d.ts +8 -0
- package/dist/lib/Email/AdminOrderConfirmationEmail.js +8 -0
- package/dist/lib/Email/AdminOrderConfirmationEmail.js.map +1 -1
- package/dist/lib/Email/ApplicationEmail.d.ts +8 -0
- package/dist/lib/Email/ApplicationEmail.js +8 -0
- package/dist/lib/Email/ApplicationEmail.js.map +1 -1
- package/dist/lib/Email/BackInStockEmail.d.ts +8 -0
- package/dist/lib/Email/BackInStockEmail.js +8 -0
- package/dist/lib/Email/BackInStockEmail.js.map +1 -1
- package/dist/lib/Email/ContactEmail.d.ts +8 -0
- package/dist/lib/Email/ContactEmail.js +8 -0
- package/dist/lib/Email/ContactEmail.js.map +1 -1
- package/dist/lib/Email/CustomerBookingAdminEmail.d.ts +8 -0
- package/dist/lib/Email/CustomerBookingAdminEmail.js +8 -0
- package/dist/lib/Email/CustomerBookingAdminEmail.js.map +1 -1
- package/dist/lib/Email/CustomerBookingEmail.d.ts +8 -0
- package/dist/lib/Email/CustomerBookingEmail.js +8 -0
- package/dist/lib/Email/CustomerBookingEmail.js.map +1 -1
- package/dist/lib/Email/OrderConfirmationEmail.d.ts +8 -0
- package/dist/lib/Email/OrderConfirmationEmail.js +8 -0
- package/dist/lib/Email/OrderConfirmationEmail.js.map +1 -1
- package/dist/lib/Email/OrderDenounciationEmail.d.ts +8 -0
- package/dist/lib/Email/OrderDenounciationEmail.js +8 -0
- package/dist/lib/Email/OrderDenounciationEmail.js.map +1 -1
- package/dist/lib/Email/OrderSampleEmail.d.ts +8 -0
- package/dist/lib/Email/OrderSampleEmail.js +8 -0
- package/dist/lib/Email/OrderSampleEmail.js.map +1 -1
- package/dist/lib/Email/OtherTypeEmails.d.ts +8 -0
- package/dist/lib/Email/OtherTypeEmails.js +8 -0
- package/dist/lib/Email/OtherTypeEmails.js.map +1 -1
- package/dist/lib/Email/PasswordResetEmail.d.ts +8 -0
- package/dist/lib/Email/PasswordResetEmail.js +8 -0
- package/dist/lib/Email/PasswordResetEmail.js.map +1 -1
- package/dist/lib/Email/PhotoShootEmail.d.ts +8 -0
- package/dist/lib/Email/PhotoShootEmail.js +8 -0
- package/dist/lib/Email/PhotoShootEmail.js.map +1 -1
- package/dist/lib/Email/PickUpConfirmation.d.ts +8 -0
- package/dist/lib/Email/PickUpConfirmation.js +8 -0
- package/dist/lib/Email/PickUpConfirmation.js.map +1 -1
- package/dist/lib/Email/ShippingConfirmation.d.ts +8 -0
- package/dist/lib/Email/ShippingConfirmation.js +8 -0
- package/dist/lib/Email/ShippingConfirmation.js.map +1 -1
- package/dist/lib/Email/WelcomeEmail.d.ts +8 -0
- package/dist/lib/Email/WelcomeEmail.js +8 -0
- package/dist/lib/Email/WelcomeEmail.js.map +1 -1
- package/dist/lib/Email/index.d.ts +8 -0
- package/dist/lib/Email/index.js +8 -0
- package/dist/lib/Email/index.js.map +1 -1
- package/dist/lib/ExternalService/Ebay.d.ts +12 -0
- package/dist/lib/ExternalService/Ebay.js +22 -0
- package/dist/lib/ExternalService/Ebay.js.map +1 -1
- package/dist/lib/Indexed/IndexedCart.js +5 -0
- package/dist/lib/Indexed/IndexedCart.js.map +1 -1
- package/dist/lib/Indexed/Product.js +50 -0
- package/dist/lib/Indexed/Product.js.map +1 -1
- package/dist/lib/Inventory/index.d.ts +59 -0
- package/dist/lib/Inventory/index.js +157 -9
- package/dist/lib/Inventory/index.js.map +1 -1
- package/dist/lib/Invoice/index.d.ts +11 -0
- package/dist/lib/Invoice/index.js +11 -0
- package/dist/lib/Invoice/index.js.map +1 -1
- package/dist/lib/MarketplacePublication/index.js +308 -0
- package/dist/lib/MarketplacePublication/index.js.map +1 -1
- package/dist/lib/Menu/index.js +2 -0
- package/dist/lib/Menu/index.js.map +1 -1
- package/dist/lib/Order/index.d.ts +20 -0
- package/dist/lib/Order/index.js +23 -0
- package/dist/lib/Order/index.js.map +1 -1
- package/dist/lib/Org/index.d.ts +41 -0
- package/dist/lib/Org/index.js +41 -0
- package/dist/lib/Org/index.js.map +1 -1
- package/dist/lib/PandaPay/index.js +6 -0
- package/dist/lib/PandaPay/index.js.map +1 -1
- package/dist/lib/Paysafe/index.js +1 -0
- package/dist/lib/Paysafe/index.js.map +1 -1
- package/dist/lib/Product/index.d.ts +25 -0
- package/dist/lib/Product/index.js +55 -1
- package/dist/lib/Product/index.js.map +1 -1
- package/dist/lib/PromiseToPurchase/index.d.ts +72 -0
- package/dist/lib/PromiseToPurchase/index.js +79 -0
- package/dist/lib/PromiseToPurchase/index.js.map +1 -1
- package/dist/lib/PurchaseOrder/index.d.ts +11 -0
- package/dist/lib/PurchaseOrder/index.js +12 -0
- package/dist/lib/PurchaseOrder/index.js.map +1 -1
- package/dist/lib/Service/index.d.ts +8 -0
- package/dist/lib/Service/index.js +8 -0
- package/dist/lib/Service/index.js.map +1 -1
- package/dist/lib/Shipment/index.js +13 -0
- package/dist/lib/Shipment/index.js.map +1 -1
- package/dist/lib/Slider/index.d.ts +6 -0
- package/dist/lib/Slider/index.js +6 -0
- package/dist/lib/Slider/index.js.map +1 -1
- package/dist/lib/Space/index.d.ts +178 -0
- package/dist/lib/Space/index.js +495 -6
- package/dist/lib/Space/index.js.map +1 -1
- package/dist/lib/Supplier/index.js +5 -0
- package/dist/lib/Supplier/index.js.map +1 -1
- package/dist/lib/Tags/index.js +5 -0
- package/dist/lib/Tags/index.js.map +1 -1
- package/dist/lib/TransferRequest/index.d.ts +178 -0
- package/dist/lib/TransferRequest/index.js +236 -4
- package/dist/lib/TransferRequest/index.js.map +1 -1
- package/dist/lib/User/index.d.ts +54 -0
- package/dist/lib/User/index.js +101 -21
- package/dist/lib/User/index.js.map +1 -1
- package/dist/lib/baseService.js +26 -0
- package/dist/lib/baseService.js.map +1 -1
- package/dist/rules/GR/constants/data.js +22 -0
- package/dist/rules/GR/constants/data.js.map +1 -1
- package/dist/rules/GR/constants/products.d.ts +3 -0
- package/dist/rules/GR/constants/products.js +16 -0
- package/dist/rules/GR/constants/products.js.map +1 -1
- package/dist/rules/GR/interfaces/data.js +7 -1
- package/dist/rules/GR/interfaces/data.js.map +1 -1
- package/dist/rules/GR/utils/cart.d.ts +41 -0
- package/dist/rules/GR/utils/cart.js +107 -1
- package/dist/rules/GR/utils/cart.js.map +1 -1
- package/dist/rules/GR/utils/data.js +4 -1
- package/dist/rules/GR/utils/data.js.map +1 -1
- package/dist/rules/GR/utils/expedition.d.ts +69 -0
- package/dist/rules/GR/utils/expedition.js +399 -11
- package/dist/rules/GR/utils/expedition.js.map +1 -1
- package/dist/rules/GR/utils/g2.d.ts +33 -0
- package/dist/rules/GR/utils/g2.js +135 -3
- package/dist/rules/GR/utils/g2.js.map +1 -1
- package/dist/rules/GR/utils/invoices.d.ts +27 -0
- package/dist/rules/GR/utils/invoices.js +41 -0
- package/dist/rules/GR/utils/invoices.js.map +1 -1
- package/dist/rules/GR/utils/products.d.ts +161 -0
- package/dist/rules/GR/utils/products.js +272 -1
- package/dist/rules/GR/utils/products.js.map +1 -1
- package/dist/rules/GR/utils/upsells.d.ts +32 -0
- package/dist/rules/GR/utils/upsells.js +32 -0
- package/dist/rules/GR/utils/upsells.js.map +1 -1
- package/dist/services/database/DatabaseService.d.ts +84 -0
- package/dist/services/database/DatabaseService.js +85 -0
- package/dist/services/database/DatabaseService.js.map +1 -1
- package/dist/services/database/FirebaseProvider.js +17 -0
- package/dist/services/database/FirebaseProvider.js.map +1 -1
- package/dist/services/database/NotFirebaseProvider.d.ts +14 -0
- package/dist/services/database/NotFirebaseProvider.js +19 -0
- package/dist/services/database/NotFirebaseProvider.js.map +1 -1
- package/dist/services/g2/G2OrderSlip.d.ts +7 -0
- package/dist/services/g2/G2OrderSlip.js +18 -0
- package/dist/services/g2/G2OrderSlip.js.map +1 -1
- package/dist/services/g2/utils.d.ts +10 -0
- package/dist/services/g2/utils.js +189 -3
- package/dist/services/g2/utils.js.map +1 -1
- package/dist/services/logs/index.d.ts +3 -0
- package/dist/services/logs/index.js +6 -1
- package/dist/services/logs/index.js.map +1 -1
- package/dist/services/products/BaseClass.js +2 -0
- package/dist/services/products/BaseClass.js.map +1 -1
- package/dist/services/products/TCGService.js +17 -1
- package/dist/services/products/TCGService.js.map +1 -1
- package/dist/services/products/utils.d.ts +22 -0
- package/dist/services/products/utils.js +50 -0
- package/dist/services/products/utils.js.map +1 -1
- package/dist/utils/anonymisation.d.ts +24 -0
- package/dist/utils/anonymisation.js +30 -0
- package/dist/utils/anonymisation.js.map +1 -1
- package/dist/utils/aws.d.ts +22 -0
- package/dist/utils/aws.js +28 -0
- package/dist/utils/aws.js.map +1 -1
- package/dist/utils/booking.d.ts +8 -0
- package/dist/utils/booking.js +9 -0
- package/dist/utils/booking.js.map +1 -1
- package/dist/utils/cart.d.ts +81 -0
- package/dist/utils/cart.js +175 -10
- package/dist/utils/cart.js.map +1 -1
- package/dist/utils/context.js +2 -2
- package/dist/utils/context.js.map +1 -1
- package/dist/utils/currency.js +31 -1
- package/dist/utils/currency.js.map +1 -1
- package/dist/utils/data.js +2 -0
- package/dist/utils/data.js.map +1 -1
- package/dist/utils/discount.d.ts +118 -0
- package/dist/utils/discount.js +178 -1
- package/dist/utils/discount.js.map +1 -1
- package/dist/utils/file-admin.js +1 -0
- package/dist/utils/file-admin.js.map +1 -1
- package/dist/utils/file.js +9 -1
- package/dist/utils/file.js.map +1 -1
- package/dist/utils/firebase-admin.d.ts +9 -0
- package/dist/utils/firebase-admin.js +12 -0
- package/dist/utils/firebase-admin.js.map +1 -1
- package/dist/utils/firebase.d.ts +17 -0
- package/dist/utils/firebase.js +17 -0
- package/dist/utils/firebase.js.map +1 -1
- package/dist/utils/inventories.d.ts +52 -0
- package/dist/utils/inventories.js +77 -2
- package/dist/utils/inventories.js.map +1 -1
- package/dist/utils/locale.d.ts +9 -0
- package/dist/utils/locale.js +9 -0
- package/dist/utils/locale.js.map +1 -1
- package/dist/utils/mailchimp.js +36 -0
- package/dist/utils/mailchimp.js.map +1 -1
- package/dist/utils/mathUtils.js +9 -0
- package/dist/utils/mathUtils.js.map +1 -1
- package/dist/utils/object.d.ts +19 -0
- package/dist/utils/object.js +21 -3
- package/dist/utils/object.js.map +1 -1
- package/dist/utils/products.d.ts +7 -0
- package/dist/utils/products.js +9 -0
- package/dist/utils/products.js.map +1 -1
- package/dist/utils/promiseToPurchase.d.ts +32 -0
- package/dist/utils/promiseToPurchase.js +34 -0
- package/dist/utils/promiseToPurchase.js.map +1 -1
- package/dist/utils/prosprsearch.d.ts +16 -0
- package/dist/utils/prosprsearch.js +34 -0
- package/dist/utils/prosprsearch.js.map +1 -1
- package/dist/utils/sdc.js +7 -0
- package/dist/utils/sdc.js.map +1 -1
- package/dist/utils/searchIndexes.d.ts +37 -0
- package/dist/utils/searchIndexes.js +37 -0
- package/dist/utils/searchIndexes.js.map +1 -1
- package/dist/utils/string.js +7 -6
- package/dist/utils/string.js.map +1 -1
- package/dist/utils/tools.d.ts +4 -0
- package/dist/utils/tools.js +4 -0
- package/dist/utils/tools.js.map +1 -1
- package/dist/utils/transferRequests.d.ts +24 -0
- package/dist/utils/transferRequests.js +24 -0
- package/dist/utils/transferRequests.js.map +1 -1
- package/dist/utils/update.js +12 -0
- package/dist/utils/update.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,10 +6,12 @@ var _a;
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.TransferRequest = void 0;
|
|
8
8
|
const TransferRequest_1 = require("../../Interfaces/TransferRequest");
|
|
9
|
+
// Classes
|
|
9
10
|
const DatabaseService_1 = __importDefault(require("../../services/database/DatabaseService"));
|
|
10
11
|
const baseService_1 = require("../baseService");
|
|
11
12
|
const Inventory_1 = __importDefault(require("../Inventory"));
|
|
12
13
|
const Space_1 = __importDefault(require("../Space"));
|
|
14
|
+
// Utils
|
|
13
15
|
const toNumber_1 = __importDefault(require("lodash/toNumber"));
|
|
14
16
|
const ceil_1 = __importDefault(require("lodash/ceil"));
|
|
15
17
|
const round_1 = __importDefault(require("lodash/round"));
|
|
@@ -32,6 +34,10 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
32
34
|
this.prevProducts = [];
|
|
33
35
|
this.prevFromStore = undefined;
|
|
34
36
|
this.processData = (data) => (Object.assign(Object.assign({}, data), { transfer_updates: data.transfer_updates.map((update) => (Object.assign(Object.assign({}, update), { date: (0, data_1.formatDate)(update.date) }))) }));
|
|
37
|
+
/**
|
|
38
|
+
* Test if the transfer can be closed
|
|
39
|
+
* @returns true if the status allow to close the transfer
|
|
40
|
+
*/
|
|
35
41
|
this.checkIfTransferCanBeClosedManually = () => {
|
|
36
42
|
return this._data.status == TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL;
|
|
37
43
|
};
|
|
@@ -159,7 +165,7 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
159
165
|
catch (e) {
|
|
160
166
|
console.log('Error fetching transfer number', e);
|
|
161
167
|
}
|
|
162
|
-
await (0, tools_1.waitFor)(1000);
|
|
168
|
+
await (0, tools_1.waitFor)(1000); // wait a second before trying again, server needs to recover
|
|
163
169
|
triesLeft--;
|
|
164
170
|
}
|
|
165
171
|
if (triesLeft == 0)
|
|
@@ -178,27 +184,53 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
178
184
|
}
|
|
179
185
|
return saveResult;
|
|
180
186
|
};
|
|
187
|
+
/**
|
|
188
|
+
* Validate the quantities set before submit
|
|
189
|
+
* @param strictQty Tell if we should only allow equal quantity
|
|
190
|
+
* @returns
|
|
191
|
+
*/
|
|
181
192
|
this.validateBeforeSubmit = async (strictQty = true) => {
|
|
182
193
|
if (strictQty) {
|
|
183
194
|
return this.data().products.every((p) => typeof p.qte_validation == 'undefined' || p.qte === p.qte_validation);
|
|
184
195
|
}
|
|
185
196
|
return this.data().products.every((p) => typeof p.qte_validation == 'undefined' || p.qte_validation >= 0);
|
|
186
197
|
};
|
|
198
|
+
// --------------------------------------------------------------------
|
|
199
|
+
// #region QUANTITIES AND INVENTORY MANAGEMENT
|
|
200
|
+
/**
|
|
201
|
+
* Strip out the validation qty field in products data
|
|
202
|
+
* Do this before saving so the qte_validation doesnt get save in database
|
|
203
|
+
* @param copyQte should copy validation qty to the actual qty
|
|
204
|
+
*/
|
|
187
205
|
this.clearValidationQuantitiesFromProductData = (copyQte = false) => {
|
|
188
206
|
this._data = Object.assign(Object.assign({}, this._data), { products: this._data.products.map((p) => (Object.assign(Object.assign({}, p), { qte: copyQte ? p.qte_validation || 0 : p.qte, qte_validation: undefined }))) });
|
|
189
207
|
};
|
|
208
|
+
/**
|
|
209
|
+
* Add the validation quantities to the received amount
|
|
210
|
+
*/
|
|
190
211
|
this.addValidationQuantitiesToReceivedQuantities = () => {
|
|
191
212
|
this._data = Object.assign(Object.assign({}, this._data), { products: this._data.products.map((p) => (Object.assign(Object.assign({}, p), { qte_received: (p.qte_validation || 0) + (p.qte_received || 0), qte_validation: undefined }))) });
|
|
192
213
|
};
|
|
214
|
+
/**
|
|
215
|
+
* Return the previous quantity received for the provided sku
|
|
216
|
+
* @param sku the product sku to get
|
|
217
|
+
* @returns
|
|
218
|
+
*/
|
|
193
219
|
this.getPreviousReceivedQuantity = (sku) => {
|
|
194
220
|
const entry = this._data.transfer_updates.find((u) => (u.status == TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL || u.status == TransferRequest_1.TransferRequestStatusEnum.RECEIVED) &&
|
|
195
221
|
u.products &&
|
|
196
222
|
u.products[sku]);
|
|
197
223
|
if (entry) {
|
|
224
|
+
// if we got an entry then the sku exists inside
|
|
198
225
|
return entry.products[sku].qte_after;
|
|
199
226
|
}
|
|
200
227
|
return 0;
|
|
201
228
|
};
|
|
229
|
+
/**
|
|
230
|
+
* Return the original reuested quantity
|
|
231
|
+
* @param sku the product sku to get
|
|
232
|
+
* @returns
|
|
233
|
+
*/
|
|
202
234
|
this.getOriginalRequestedQuantity = (sku) => {
|
|
203
235
|
const product = this._data.products.find((p) => p.sku == sku);
|
|
204
236
|
if (!product)
|
|
@@ -213,10 +245,18 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
213
245
|
});
|
|
214
246
|
return result;
|
|
215
247
|
};
|
|
248
|
+
/**
|
|
249
|
+
* Get the quantity at the requested status
|
|
250
|
+
* @param sku the product sku
|
|
251
|
+
* @param status the status to look for
|
|
252
|
+
* @returns the quantity at the specified status
|
|
253
|
+
*/
|
|
216
254
|
this.getQuantityAtStatus = (sku, status) => {
|
|
217
255
|
const statusPos = (0, transferRequests_1.getOrderPositionForStatus)(status, TransferRequest_1.transferRequestStatusOrder) || 0;
|
|
256
|
+
// If status if first status in order
|
|
218
257
|
if (statusPos == 0) {
|
|
219
258
|
const updates = this._data.transfer_updates.filter((u) => u.status == status);
|
|
259
|
+
// If no updates were done to products at same status. get original request quantity. Else, keep going in logic!
|
|
220
260
|
if (!updates.some((u) => !!u.products && !!u.products && !!u.products[sku]))
|
|
221
261
|
return this.getOriginalRequestedQuantity(sku);
|
|
222
262
|
}
|
|
@@ -260,7 +300,8 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
260
300
|
if (!!!inventoryItemQuery.exists)
|
|
261
301
|
continue;
|
|
262
302
|
const inventoryItem = new Inventory_1.default(inventoryItemQuery.data, inventoryColl, this._user);
|
|
263
|
-
await inventoryItem.handleCancelInTransit(this._data.from, product.qte - product.qte_received,
|
|
303
|
+
await inventoryItem.handleCancelInTransit(this._data.from, product.qte - product.qte_received, // TODO - NEW INVENTORY UNIT : Here in old logic we didn't change to inventory unit. Normal?
|
|
304
|
+
undefined, !!this._data.associated_order);
|
|
264
305
|
}
|
|
265
306
|
}
|
|
266
307
|
catch (err) {
|
|
@@ -269,12 +310,14 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
269
310
|
}
|
|
270
311
|
};
|
|
271
312
|
this.handleChangeStoreInventory = async (newStatus) => {
|
|
313
|
+
// test if can be processed
|
|
272
314
|
if (!this._data.from)
|
|
273
315
|
return false;
|
|
274
316
|
try {
|
|
275
317
|
if (DatabaseService_1.default.getPathParent(this._collection.path) == '/')
|
|
276
318
|
return false;
|
|
277
319
|
const inventoryColl = DatabaseService_1.default.asCollectionObject(DatabaseService_1.default.getPathParent(this._collection.path), 'inventories');
|
|
320
|
+
// Fetch associated cart
|
|
278
321
|
let associatedCart;
|
|
279
322
|
if (newStatus == TransferRequest_1.TransferRequestStatusEnum.RECEIVED || newStatus == TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL) {
|
|
280
323
|
try {
|
|
@@ -297,7 +340,9 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
297
340
|
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL:
|
|
298
341
|
const qteReceivedSinceLastStatus = product.qte_received - this.getPreviousReceivedQuantity(product.sku);
|
|
299
342
|
if (qteReceivedSinceLastStatus == 0)
|
|
300
|
-
continue;
|
|
343
|
+
continue; // no need to update inventory if no quantities were received
|
|
344
|
+
// If associated cart was already processed, ignore reserved quantities (all quantities received should be added to available quantities)
|
|
345
|
+
// Else, calculate missing quantities for transfer
|
|
301
346
|
const cartWasProcessed = !!associatedCart && associatedCart.data().status > Cart_1.CartStatusEnum.CHECKOUT_PAYMENT_SUCCESS;
|
|
302
347
|
const qteToReserve = cartWasProcessed
|
|
303
348
|
? undefined
|
|
@@ -309,6 +354,7 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
309
354
|
? qteReceivedSinceLastStatus
|
|
310
355
|
: qteToReserve
|
|
311
356
|
: 0,
|
|
357
|
+
// If cart was already processed, skip web inventory update for availalble quantities
|
|
312
358
|
skipWebUpdateForAvailable: cartWasProcessed
|
|
313
359
|
});
|
|
314
360
|
break;
|
|
@@ -322,11 +368,15 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
322
368
|
return false;
|
|
323
369
|
}
|
|
324
370
|
};
|
|
371
|
+
/**
|
|
372
|
+
* Update transfer's associated cart with new reserved quantities. Called when quantities received for transfer.
|
|
373
|
+
*/
|
|
325
374
|
this.handleUpdateAssociatedCartReservedQuantities = async () => {
|
|
326
375
|
var _b, _c;
|
|
327
376
|
const associatedCart = await this.fetchAssociatedCart();
|
|
328
377
|
if (!!!associatedCart)
|
|
329
378
|
return;
|
|
379
|
+
// If cart was already processed (status > 5) skip cart quantity update
|
|
330
380
|
if (associatedCart.data().status > Cart_1.CartStatusEnum.CHECKOUT_PAYMENT_SUCCESS)
|
|
331
381
|
return;
|
|
332
382
|
let somethingHasChanged = false;
|
|
@@ -340,15 +390,18 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
340
390
|
}
|
|
341
391
|
const sellUnit = (item.other_units || []).find((o) => o.is_sale_unit);
|
|
342
392
|
const unitHasDecimals = !!sellUnit && (0, products_1.productUnitSupportsDecimals)(sellUnit.unit_slug);
|
|
393
|
+
// If reserved quantity is already same or larger than expected quantities, no need to update product
|
|
343
394
|
if (typeof item.qte_reserved == 'number' && (0, round_1.default)(item.qte_reserved, unitHasDecimals ? 2 : 0) >= item.qte) {
|
|
344
395
|
updatedCartItems.push(item);
|
|
345
396
|
continue;
|
|
346
397
|
}
|
|
398
|
+
// If no quantities were received since last status change, no need to update product
|
|
347
399
|
const qteReceivedSinceLastStatus = sameInTransfer.qte_received - this.getPreviousReceivedQuantity(sameInTransfer.sku);
|
|
348
400
|
if (!!!qteReceivedSinceLastStatus) {
|
|
349
401
|
updatedCartItems.push(item);
|
|
350
402
|
continue;
|
|
351
403
|
}
|
|
404
|
+
// Set new reserved quantities, capping at the quantity asked initially for order (rest is sent to available inventory for store when transfer is received)
|
|
352
405
|
const reservedQteInInventoryUnit = (0, inventories_1.getConvertedUnitQuantity)(item.other_units, (_b = item.qte_reserved) !== null && _b !== void 0 ? _b : 0, 'inventory_unit');
|
|
353
406
|
const qteInInventoryUnit = (0, inventories_1.getConvertedUnitQuantity)(item.other_units, (_c = item.qte) !== null && _c !== void 0 ? _c : 0, 'inventory_unit');
|
|
354
407
|
const newReservedQte = reservedQteInInventoryUnit + qteReceivedSinceLastStatus;
|
|
@@ -358,17 +411,24 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
358
411
|
if (!!!somethingHasChanged)
|
|
359
412
|
return;
|
|
360
413
|
try {
|
|
361
|
-
await associatedCart.save({ items: updatedCartItems, id: associatedCart.data().id }, undefined, true, true, true);
|
|
414
|
+
await associatedCart.save({ items: updatedCartItems, id: associatedCart.data().id }, undefined, true, true, true); // Will save partial cart only. Skips indexed cart save (does not trigger cloud functions)
|
|
362
415
|
}
|
|
363
416
|
catch (e) {
|
|
364
417
|
console.log('error on saving cart with new qte_received in items: ', e.toString());
|
|
365
418
|
}
|
|
366
419
|
};
|
|
420
|
+
/**
|
|
421
|
+
* Use provided update object to construct new products object for current transfer
|
|
422
|
+
* @param updatesToDo The product updates to apply
|
|
423
|
+
* @param updatesToDo.sku The product sku to update
|
|
424
|
+
* @param updatesToDo.ajustementQte The quantity to ajust. Must be negative if quantity REMOVED, and positive if ADDED.
|
|
425
|
+
*/
|
|
367
426
|
this.constructProductObjFromUpdates = (updatesToDo) => {
|
|
368
427
|
let updatedProducts = this._data.products.map((currentProd) => {
|
|
369
428
|
const sameInUpdates = updatesToDo.find((u) => u.sku == currentProd.sku);
|
|
370
429
|
if (!!!sameInUpdates)
|
|
371
430
|
return currentProd;
|
|
431
|
+
// Calculated new quantity with ajustmentQte, rounded up to zero
|
|
372
432
|
let newQte = currentProd.qte + sameInUpdates.ajustmentQte;
|
|
373
433
|
if (newQte < 0)
|
|
374
434
|
newQte = 0;
|
|
@@ -376,12 +436,20 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
376
436
|
});
|
|
377
437
|
return updatedProducts;
|
|
378
438
|
};
|
|
439
|
+
/**
|
|
440
|
+
* Will update content in transfer without triggering a status change, if current transfer status permits. Still adds entry to the transfer_updates array.
|
|
441
|
+
* @param updatedContent.products The array of products to update product
|
|
442
|
+
* @param updatedContent.fromStore The new from store slug value if changed
|
|
443
|
+
* @param options Options to create the associated transfer_updates entry
|
|
444
|
+
* @param cancelTransferIfAllProductsAtZero Optionnal. If transfer should be auto-cancelled if all products are now at 0 quantities
|
|
445
|
+
*/
|
|
379
446
|
this.saveUpdatesToContentOnly = async (updatedContent, options, cancelTransferIfAllProductsAtZero, updateContext = TransferRequest_1.TransferRequestUpdateContextEnum.TRANSFER_UPDATED) => {
|
|
380
447
|
if (updatedContent.products) {
|
|
381
448
|
if (!TransferRequest.transferAllowsIndependantProductUpdate(this._data)) {
|
|
382
449
|
throw new Error('Cannot update products without changing status for current transfer status.');
|
|
383
450
|
}
|
|
384
451
|
await this.save({ products: updatedContent.products }, false, true);
|
|
452
|
+
// if validation quantities found, push values to qte and remove prop
|
|
385
453
|
if (!!updatedContent.products.some((p) => typeof p.qte_validation == 'number')) {
|
|
386
454
|
this.clearValidationQuantitiesFromProductData(true);
|
|
387
455
|
}
|
|
@@ -394,11 +462,13 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
394
462
|
}
|
|
395
463
|
try {
|
|
396
464
|
const statusPositionObj = await this._getOrderObject();
|
|
465
|
+
// If flag to cancel transfer is provided and all products are now at 0 quantities, change status to cancelled. Else, keep current status
|
|
397
466
|
const shouldCancelTransfer = updatedContent.products &&
|
|
398
467
|
cancelTransferIfAllProductsAtZero &&
|
|
399
468
|
updatedContent.products.every((p) => p.qte <= 0) &&
|
|
400
469
|
TransferRequest.checkIfTransferCanBeCancelled(this._data.status, statusPositionObj);
|
|
401
470
|
const statusToUse = !!shouldCancelTransfer ? TransferRequest_1.TransferRequestStatusEnum.CANCELLED : this._data.status;
|
|
471
|
+
// Create new update entry for transfer and save
|
|
402
472
|
const newUpdates = this._generateNewTransferStatusUpdates(statusToUse, options.user, options.comment, undefined, updateContext);
|
|
403
473
|
await this.save(Object.assign({ transfer_updates: newUpdates }, (shouldCancelTransfer ? { status: statusToUse, completed: true } : {})), true, true);
|
|
404
474
|
}
|
|
@@ -409,23 +479,49 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
409
479
|
}
|
|
410
480
|
return this.data();
|
|
411
481
|
};
|
|
482
|
+
// #endregion
|
|
483
|
+
// --------------------------------------------------------------------
|
|
484
|
+
// #region SPECIFIC PROP MANAGEMENT
|
|
485
|
+
/**
|
|
486
|
+
* Change or set the draft property value
|
|
487
|
+
* @param newVal The new value to assign
|
|
488
|
+
*/
|
|
412
489
|
this.setDraftValue = (newVal) => {
|
|
413
490
|
this._data = Object.assign(Object.assign({}, this._data), { draft: newVal });
|
|
414
491
|
};
|
|
492
|
+
/**
|
|
493
|
+
* Change or set the associated_order property value
|
|
494
|
+
* @param newVal The new value to assign
|
|
495
|
+
*/
|
|
415
496
|
this.setAssociatedOrder = (newVal) => {
|
|
416
497
|
this._data = Object.assign(Object.assign({}, this._data), { associated_order: newVal });
|
|
417
498
|
};
|
|
499
|
+
/**
|
|
500
|
+
* Change or set the transport_ref property value
|
|
501
|
+
* @param newVal The new value to assign
|
|
502
|
+
* @param saveToDatabase Do we save the new value in the database
|
|
503
|
+
*/
|
|
418
504
|
this.setTransportRef = async (newVal, saveToDatabase = false) => {
|
|
419
505
|
await this.save({ transport_ref: newVal }, saveToDatabase, true);
|
|
420
506
|
};
|
|
507
|
+
/**
|
|
508
|
+
* Set the original transfer id property value
|
|
509
|
+
* @param newVal The new value to assign
|
|
510
|
+
*/
|
|
421
511
|
this.setOriginalTransferId = async (newVal) => {
|
|
422
512
|
this._data = Object.assign(Object.assign({}, this._data), { original_transfer_id: newVal });
|
|
423
513
|
};
|
|
514
|
+
/**
|
|
515
|
+
* Change the completed status to true and save to database
|
|
516
|
+
*/
|
|
424
517
|
this.setAsCompleted = async (user, comment) => {
|
|
425
518
|
this._generateNewTransferStatusUpdates(this._data.status, user, `Fermé manuellement${!!comment ? ' : ' + comment : ''}`, this._data.products, TransferRequest_1.TransferRequestUpdateContextEnum.TRANSFER_COMPLETED_MANUALLY);
|
|
519
|
+
// cancel any transit items
|
|
426
520
|
await this.handleFreeTransitInventory();
|
|
427
521
|
await this.save({ completed: true }, true, true);
|
|
428
522
|
};
|
|
523
|
+
// --------------------------------------------------------------------
|
|
524
|
+
// #region STATUS MANAGEMENT
|
|
429
525
|
this.changeStatus = async (newStatus, comment, user, saveToDatabase = true, options = {}) => {
|
|
430
526
|
const saveOptions = {
|
|
431
527
|
comment,
|
|
@@ -466,6 +562,13 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
466
562
|
throw new Error('Impossible de soumettre le(s) transfert(s)');
|
|
467
563
|
}
|
|
468
564
|
};
|
|
565
|
+
/**
|
|
566
|
+
* Generates updates array and saves transfer for the first time in the database.
|
|
567
|
+
* @param currentUser
|
|
568
|
+
* @param comment
|
|
569
|
+
* @param saveToDatabase
|
|
570
|
+
* @throws if transfer already has an ID or doesn't have a status set
|
|
571
|
+
*/
|
|
469
572
|
this.saveNewTransfer = async (currentUser, comment, saveToDatabase = true, skipRef) => {
|
|
470
573
|
if (!!this.data().id)
|
|
471
574
|
throw 'Cette demande de transfert existe déjà en base de données!';
|
|
@@ -474,10 +577,17 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
474
577
|
const newUpdates = this._generateNewTransferStatusUpdates(this.data().status, currentUser, comment);
|
|
475
578
|
let newTransferRef = undefined;
|
|
476
579
|
if (!!!skipRef) {
|
|
580
|
+
// Fetch next ref for transfer
|
|
477
581
|
newTransferRef = await this._getTransferRef();
|
|
478
582
|
}
|
|
479
583
|
return await this.save(Object.assign(Object.assign({}, this.data()), { ref: newTransferRef, transfer_updates: newUpdates }), saveToDatabase);
|
|
480
584
|
};
|
|
585
|
+
/**
|
|
586
|
+
* Get the weight of a selected sku in this transfer
|
|
587
|
+
* @param sku the product sku
|
|
588
|
+
* @param unit the unit to return
|
|
589
|
+
* @returns the weight in the requested unit
|
|
590
|
+
*/
|
|
481
591
|
this.getProductWeight = (sku, unit = 'pounds') => {
|
|
482
592
|
const item = this.data().products.find((p) => p.sku == sku);
|
|
483
593
|
if (!item)
|
|
@@ -487,11 +597,18 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
487
597
|
const value = (0, toNumber_1.default)(item.weight.value) || 0;
|
|
488
598
|
return item.weight.unit === unit ? value * item.qte : (0, weight_1.convertWeight)(value, item.weight.unit, unit) * item.qte;
|
|
489
599
|
};
|
|
600
|
+
/**
|
|
601
|
+
* Fetches applicable transfer status order object by checking space_options for current space.
|
|
602
|
+
*/
|
|
490
603
|
this._getOrderObject = async (space) => {
|
|
491
604
|
if (!space)
|
|
492
605
|
space = await Space_1.default.getCurrentSpaceWithRef(this._collection.path, this._user);
|
|
493
606
|
return space.transferRequests.getTransferStatusOrder();
|
|
494
607
|
};
|
|
608
|
+
/**
|
|
609
|
+
* Checks if provided "new" status follows current transfer status in the correct transfer status order for space.
|
|
610
|
+
* @param statusToCheck
|
|
611
|
+
*/
|
|
495
612
|
this._checkIfCanChangeToStatus = async (statusToCheck, space) => {
|
|
496
613
|
const currentStatus = this._data.status;
|
|
497
614
|
if (currentStatus == statusToCheck)
|
|
@@ -506,13 +623,24 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
506
623
|
return false;
|
|
507
624
|
}
|
|
508
625
|
};
|
|
626
|
+
/**
|
|
627
|
+
* Creates new entry for a status change, copies transfer_updates property and adds new entry to the start of copied array.
|
|
628
|
+
* @param newStatus
|
|
629
|
+
* @param user The email (or id) of Addio user that triggered the status change
|
|
630
|
+
* @param comment The user added comment for status change (can be undefined)
|
|
631
|
+
* @returns The copied array with the new value added.
|
|
632
|
+
*/
|
|
509
633
|
this._generateNewTransferStatusUpdates = (newStatus, user, comment, originalRequestProducts, context) => {
|
|
510
634
|
const updates = this._data.transfer_updates;
|
|
511
635
|
const newProducts = this._data.products;
|
|
512
636
|
const newFromStore = this._data.from;
|
|
637
|
+
// If props id is set in transfer request (meaning it was saved to database at least once),
|
|
638
|
+
// create products update obj if some changes were made
|
|
513
639
|
let prodUpdateObj = {};
|
|
640
|
+
// Id set means the transfer was saved to database
|
|
514
641
|
if (!!this._data.id || !!originalRequestProducts) {
|
|
515
642
|
if (newStatus == TransferRequest_1.TransferRequestStatusEnum.RECEIVED || newStatus == TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL) {
|
|
643
|
+
// at this step only received qty is allowed to change
|
|
516
644
|
for (let prod of newProducts) {
|
|
517
645
|
const addedQty = prod.qte_received - this.getPreviousReceivedQuantity(prod.sku);
|
|
518
646
|
if (addedQty != 0) {
|
|
@@ -525,30 +653,41 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
525
653
|
}
|
|
526
654
|
}
|
|
527
655
|
else {
|
|
656
|
+
// Use provided prevProducts, or "normal" prevProducts if undefined, for comparaison with new products
|
|
528
657
|
const prevProducts = !!originalRequestProducts ? originalRequestProducts : this.prevProducts;
|
|
529
658
|
for (let prod of newProducts) {
|
|
530
659
|
const name = prod.name;
|
|
531
660
|
const sameInPrev = prevProducts.find((p) => p.sku == prod.sku);
|
|
661
|
+
// a. If product not found in prev array, it was added to transfer, add entry to update obj
|
|
532
662
|
if (!!!sameInPrev) {
|
|
533
663
|
prodUpdateObj[prod.sku] = { qte_before: 0, qte_after: prod.qte, name };
|
|
534
664
|
}
|
|
665
|
+
// b. If product's quantities are different, add entry to update obj
|
|
535
666
|
else if (sameInPrev.qte !== prod.qte) {
|
|
536
667
|
prodUpdateObj[prod.sku] = { qte_before: sameInPrev.qte, qte_after: prod.qte, name };
|
|
537
668
|
}
|
|
538
669
|
}
|
|
670
|
+
// Always use "normal" prevProducts for check here
|
|
539
671
|
for (let prevProd of this.prevProducts) {
|
|
540
672
|
const sameInNew = newProducts.find((p) => p.sku == prevProd.sku);
|
|
673
|
+
// c. If product in prev array but not in new one, it was deleted fron transfer, add entry to update obj
|
|
541
674
|
if (!!!sameInNew) {
|
|
542
675
|
prodUpdateObj[prevProd.sku] = { qte_before: prevProd.qte, qte_after: 0, name: prevProd.name };
|
|
543
676
|
}
|
|
544
677
|
}
|
|
545
678
|
}
|
|
546
679
|
}
|
|
680
|
+
// Add new update obj at start of array
|
|
547
681
|
updates.unshift(Object.assign({ status: newStatus, date: new Date(), updated_by: user, comment: comment, products: !!Object.keys(prodUpdateObj).length ? prodUpdateObj : null, fromStore: this.prevFromStore != this._data.from && this._data.status == TransferRequest_1.TransferRequestStatusEnum.OPEN
|
|
548
682
|
? { before: this.prevFromStore || '', after: newFromStore || '' }
|
|
549
683
|
: null }, (!!context ? { context } : {})));
|
|
550
684
|
return updates;
|
|
551
685
|
};
|
|
686
|
+
/**
|
|
687
|
+
* Saves provided status to TransferRequest data. Also generates and saves new entry for `transfer_updates` array.
|
|
688
|
+
* @param newStatus
|
|
689
|
+
* @param options
|
|
690
|
+
*/
|
|
552
691
|
this._saveNewStatus = async (newStatus, options, forceCompleted = false, context = TransferRequest_1.TransferRequestUpdateContextEnum.TRANSFER_STATUS_CHANGE) => {
|
|
553
692
|
const newUpdates = this._generateNewTransferStatusUpdates(newStatus, options.user, options.comment, options.originalRequestProducts, context);
|
|
554
693
|
const completedProps = options.markAsCompleted;
|
|
@@ -566,6 +705,10 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
566
705
|
throw new Error('Error while saving the transfer reqeust.');
|
|
567
706
|
}
|
|
568
707
|
};
|
|
708
|
+
/**
|
|
709
|
+
* Checks update eligibility, then updates status to OPEN.
|
|
710
|
+
* @param options
|
|
711
|
+
*/
|
|
569
712
|
this._setAsOpen = async (options) => {
|
|
570
713
|
const newStatus = TransferRequest_1.TransferRequestStatusEnum.OPEN;
|
|
571
714
|
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
@@ -573,6 +716,10 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
573
716
|
throw new Error('Trying to change to wrong status! Returning.');
|
|
574
717
|
await this._saveNewStatus(newStatus, options);
|
|
575
718
|
};
|
|
719
|
+
/**
|
|
720
|
+
* Checks update eligibility, then updates status to TO_BE_PREPARED.
|
|
721
|
+
* @param options
|
|
722
|
+
*/
|
|
576
723
|
this._setAsToBePrepared = async (options) => {
|
|
577
724
|
const newStatus = TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED;
|
|
578
725
|
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
@@ -580,6 +727,10 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
580
727
|
throw new Error('Trying to change to wrong status! Returning.');
|
|
581
728
|
await this._saveNewStatus(newStatus, options);
|
|
582
729
|
};
|
|
730
|
+
/**
|
|
731
|
+
* Checks update eligibility, then updates status to IN_TRANSIT. Also updates inventory for the origin store.
|
|
732
|
+
* @param options
|
|
733
|
+
*/
|
|
583
734
|
this._setAsInTransit = async (options) => {
|
|
584
735
|
const newStatus = TransferRequest_1.TransferRequestStatusEnum.IN_TRANSIT;
|
|
585
736
|
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
@@ -591,18 +742,30 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
591
742
|
}
|
|
592
743
|
await this._saveNewStatus(newStatus, options);
|
|
593
744
|
};
|
|
745
|
+
/**
|
|
746
|
+
* Checks update eligibility, then updates status to RECEIVED. Also updates inventory for both stores.
|
|
747
|
+
* @param options
|
|
748
|
+
*/
|
|
594
749
|
this._setAsReceived = async (options) => {
|
|
595
750
|
const newStatus = TransferRequest_1.TransferRequestStatusEnum.RECEIVED;
|
|
596
751
|
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
597
752
|
if (!statusChangeValid)
|
|
598
753
|
throw new Error('Trying to change to wrong status! Returning.');
|
|
754
|
+
// Update inventory for items received
|
|
599
755
|
const inventoryChangesSuccess = await this.handleChangeStoreInventory(newStatus);
|
|
600
756
|
if (!!!inventoryChangesSuccess) {
|
|
601
757
|
throw "Une erreur est survenue lors de la mise à jour de l'inventaire.";
|
|
602
758
|
}
|
|
759
|
+
// Update associated cart for reserved quantities
|
|
603
760
|
await this.handleUpdateAssociatedCartReservedQuantities();
|
|
761
|
+
// Update transfer and status
|
|
604
762
|
await this._saveNewStatus(newStatus, options, true);
|
|
605
763
|
};
|
|
764
|
+
/**
|
|
765
|
+
* Checks update eligibility, then updates status to RECEIVED_PARTIAL. Also updates inventory for both stores.
|
|
766
|
+
* @param options
|
|
767
|
+
* @todo Update inventory logic to deal with partially received quantities.
|
|
768
|
+
*/
|
|
606
769
|
this._setAsReceivedPartially = async (options) => {
|
|
607
770
|
const newStatus = TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL;
|
|
608
771
|
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
@@ -612,9 +775,15 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
612
775
|
if (!!!inventoryChangesSuccess) {
|
|
613
776
|
throw "Une erreur est survenue lors de la mise à jour de l'inventaire.";
|
|
614
777
|
}
|
|
778
|
+
// Update associated cart for reserved quantities
|
|
615
779
|
await this.handleUpdateAssociatedCartReservedQuantities();
|
|
780
|
+
// Update transfer and status
|
|
616
781
|
await this._saveNewStatus(newStatus, options);
|
|
617
782
|
};
|
|
783
|
+
/**
|
|
784
|
+
* Checks if transfer can be cancelled, and if so, updates status to CANCELLED.
|
|
785
|
+
* @param options
|
|
786
|
+
*/
|
|
618
787
|
this._setAsCancelled = async (options, context) => {
|
|
619
788
|
const newStatus = TransferRequest_1.TransferRequestStatusEnum.CANCELLED;
|
|
620
789
|
const statusPositionObj = await this._getOrderObject();
|
|
@@ -624,6 +793,9 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
624
793
|
}
|
|
625
794
|
await this._saveNewStatus(newStatus, options, true, context);
|
|
626
795
|
};
|
|
796
|
+
/**
|
|
797
|
+
* Object regrouping all status change functions
|
|
798
|
+
*/
|
|
627
799
|
this.updateToStatus = {
|
|
628
800
|
open: this._setAsOpen,
|
|
629
801
|
toBePrepared: this._setAsToBePrepared,
|
|
@@ -632,6 +804,14 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
632
804
|
receivedPartial: this._setAsReceivedPartially,
|
|
633
805
|
cancelled: this._setAsCancelled
|
|
634
806
|
};
|
|
807
|
+
// #endregion
|
|
808
|
+
// --------------------------------------------------------------------
|
|
809
|
+
// #region FORMAT DATA
|
|
810
|
+
/**
|
|
811
|
+
* Get formatted ref string for the transfer.
|
|
812
|
+
* @param spaceTransferSettings
|
|
813
|
+
* @returns {string | undefined}
|
|
814
|
+
*/
|
|
635
815
|
this.getFormattedRef = (spaceTransferSettings) => {
|
|
636
816
|
if (typeof this._data.ref == 'undefined') {
|
|
637
817
|
console.log('transfer has no ref, returning!');
|
|
@@ -643,10 +823,13 @@ class TransferRequest extends baseService_1.BaseServiceClass {
|
|
|
643
823
|
const suffix = spaceTransferSettings.suffix;
|
|
644
824
|
return `${prefix ? prefix + '-' : ''}${this._data.ref}${suffix ? '-' + suffix : ''}`;
|
|
645
825
|
};
|
|
826
|
+
// Format dates in data
|
|
646
827
|
this._data = this.processData(_data);
|
|
828
|
+
// Keep products in current transfer for update reference
|
|
647
829
|
if (!!this._data.products.length) {
|
|
648
830
|
this.prevProducts = [...this._data.products];
|
|
649
831
|
}
|
|
832
|
+
// Keep from store in current transfer for update reference
|
|
650
833
|
if (!!this._data.from)
|
|
651
834
|
this.prevFromStore = this._data.from;
|
|
652
835
|
}
|
|
@@ -713,6 +896,10 @@ TransferRequest.checkIfTransferCanBeCancelled = (currentTransferStatus, statusOr
|
|
|
713
896
|
}
|
|
714
897
|
return (0, toNumber_1.default)(currentPosition) < (0, toNumber_1.default)(inTransitPosition);
|
|
715
898
|
};
|
|
899
|
+
/**
|
|
900
|
+
* Checks if provided status is included in "completed" transfer statuses list.
|
|
901
|
+
* @param statusToCheck
|
|
902
|
+
*/
|
|
716
903
|
TransferRequest.checkIfStatusCountsAsCompleted = (statusToCheck) => {
|
|
717
904
|
return [
|
|
718
905
|
TransferRequest_1.TransferRequestStatusEnum.RECEIVED,
|
|
@@ -723,13 +910,20 @@ TransferRequest.checkIfStatusCountsAsCompleted = (statusToCheck) => {
|
|
|
723
910
|
TransferRequest.transferAllowAssignFromStore = (data) => {
|
|
724
911
|
if (!!data.completed)
|
|
725
912
|
return false;
|
|
913
|
+
// Id set means the transfer was saved to database
|
|
726
914
|
return !!data.id && TransferRequest_1.TransferRequestStatusEnum.INITIATED === data.status;
|
|
727
915
|
};
|
|
728
916
|
TransferRequest.transferAllowEditFromStore = (data) => {
|
|
729
917
|
if (!!data.completed)
|
|
730
918
|
return false;
|
|
919
|
+
// Id set means the transfer was saved to database
|
|
731
920
|
return !!data.id && TransferRequest_1.TransferRequestStatusEnum.OPEN === data.status;
|
|
732
921
|
};
|
|
922
|
+
/**
|
|
923
|
+
* Test if the transfer allow adding products
|
|
924
|
+
* @param data the request data to verify
|
|
925
|
+
* @returns true if can add product
|
|
926
|
+
*/
|
|
733
927
|
TransferRequest.transferAllowAddProductOnEdit = (data) => {
|
|
734
928
|
if (!!data.completed)
|
|
735
929
|
return false;
|
|
@@ -737,13 +931,24 @@ TransferRequest.transferAllowAddProductOnEdit = (data) => {
|
|
|
737
931
|
return true;
|
|
738
932
|
return [TransferRequest_1.TransferRequestStatusEnum.INITIATED].includes(data.status);
|
|
739
933
|
};
|
|
934
|
+
/**
|
|
935
|
+
* Test if the transfer allow deleteing products
|
|
936
|
+
* @param data the request data to verify
|
|
937
|
+
* @returns true if can delete product
|
|
938
|
+
*/
|
|
740
939
|
TransferRequest.transferAllowProductDelete = (data) => {
|
|
741
940
|
if (!!data.completed)
|
|
742
941
|
return false;
|
|
942
|
+
// Id not set yet means the transfer is in creation mode. Product deletion should be allowed!
|
|
743
943
|
if (!!!data.id)
|
|
744
944
|
return true;
|
|
745
945
|
return [TransferRequest_1.TransferRequestStatusEnum.INITIATED].includes(data.status);
|
|
746
946
|
};
|
|
947
|
+
/**
|
|
948
|
+
* Test if the transfer allow editing products
|
|
949
|
+
* @param data the request data to verify
|
|
950
|
+
* @returns true if can be edited
|
|
951
|
+
*/
|
|
747
952
|
TransferRequest.transferAllowEditProductOnEdit = (data) => {
|
|
748
953
|
if (!!data.completed)
|
|
749
954
|
return false;
|
|
@@ -753,24 +958,46 @@ TransferRequest.transferAllowEditProductOnEdit = (data) => {
|
|
|
753
958
|
TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED
|
|
754
959
|
].includes(data.status);
|
|
755
960
|
};
|
|
961
|
+
/**
|
|
962
|
+
* Test if the transfer allow deleteing products when editing (not changing status)
|
|
963
|
+
* @param data the request data to verify
|
|
964
|
+
* @returns {boolean} true if can delete product
|
|
965
|
+
*/
|
|
756
966
|
TransferRequest.transferAllowDeleteProductOnEdit = (data) => {
|
|
757
967
|
if (!!data.completed)
|
|
758
968
|
return false;
|
|
969
|
+
// Id not set yet means the transfer is in creation mode. Product deletion should be allowed!
|
|
759
970
|
if (!!!data.id)
|
|
760
971
|
return true;
|
|
761
972
|
return [TransferRequest_1.TransferRequestStatusEnum.INITIATED, TransferRequest_1.TransferRequestStatusEnum.OPEN].includes(data.status);
|
|
762
973
|
};
|
|
974
|
+
/**
|
|
975
|
+
* Test if the transfer has reached a state where it should display weight
|
|
976
|
+
* @param data the request data to verify
|
|
977
|
+
* @returns {boolean}
|
|
978
|
+
*/
|
|
763
979
|
TransferRequest.transferShouldDisplayWeight = (data) => {
|
|
764
980
|
return ![TransferRequest_1.TransferRequestStatusEnum.INITIATED].includes(data.status);
|
|
765
981
|
};
|
|
982
|
+
/**
|
|
983
|
+
* Test if the transfer allows products to be updated without a status change
|
|
984
|
+
* @param data the request data to verify
|
|
985
|
+
* @returns {boolean}
|
|
986
|
+
*/
|
|
766
987
|
TransferRequest.transferAllowsIndependantProductUpdate = (data) => {
|
|
767
988
|
if (!!data.completed)
|
|
768
989
|
return false;
|
|
769
990
|
let acceptedStatuses = [TransferRequest_1.TransferRequestStatusEnum.INITIATED, TransferRequest_1.TransferRequestStatusEnum.OPEN];
|
|
991
|
+
// If no cart associated to transfer, update can be done at TO_BE_PREPARED status as well
|
|
770
992
|
if (!data.associated_order)
|
|
771
993
|
acceptedStatuses.push(TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED);
|
|
772
994
|
return acceptedStatuses.includes(data.status);
|
|
773
995
|
};
|
|
996
|
+
/**
|
|
997
|
+
* Get the total estimated weight by calculating each product's weigth times inventory quantity
|
|
998
|
+
* @param unit the unit to return
|
|
999
|
+
* @returns the weight in the requested unit
|
|
1000
|
+
*/
|
|
774
1001
|
TransferRequest.getTotalWeight = (products, unit = 'pounds') => {
|
|
775
1002
|
return (0, sumBy_1.default)(products, (item) => {
|
|
776
1003
|
if (!!!item.weight)
|
|
@@ -779,6 +1006,11 @@ TransferRequest.getTotalWeight = (products, unit = 'pounds') => {
|
|
|
779
1006
|
return item.weight.unit === unit ? value * item.qte : (0, weight_1.convertWeight)(value, item.weight.unit, unit) * item.qte;
|
|
780
1007
|
});
|
|
781
1008
|
};
|
|
1009
|
+
/**
|
|
1010
|
+
* Get the total calculated pallet quantities for all transfer items
|
|
1011
|
+
* @param items
|
|
1012
|
+
* @returns
|
|
1013
|
+
*/
|
|
782
1014
|
TransferRequest.getTotalPalletQte = (items) => {
|
|
783
1015
|
const total = (0, sumBy_1.default)(items.map((item) => {
|
|
784
1016
|
if (!!!item.other_units || !!!item.count_in_pallet_total) {
|