addio-admin-sdk 1.7.144 → 1.7.146
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/.babelrc +17 -17
- package/.env +15 -0
- package/.env.dev +14 -14
- package/.github/workflows/run_unit_test.yaml +48 -48
- package/addio-sdk-doc.md +1473 -1473
- package/changelog.md +564 -564
- package/dist/Interfaces/Address/index.d.ts +21 -21
- package/dist/Interfaces/Address/index.js +16 -16
- package/dist/Interfaces/Algolia/index.d.ts +177 -177
- package/dist/Interfaces/Algolia/index.js +2 -2
- package/dist/Interfaces/Attachement/index.d.ts +5 -5
- package/dist/Interfaces/Attachement/index.js +2 -2
- package/dist/Interfaces/Attribute/index.d.ts +53 -53
- package/dist/Interfaces/Attribute/index.js +10 -10
- package/dist/Interfaces/BGJob/index.d.ts +56 -56
- package/dist/Interfaces/BGJob/index.js +25 -25
- package/dist/Interfaces/BaseClass/index.d.ts +8 -8
- package/dist/Interfaces/BaseClass/index.js +2 -2
- package/dist/Interfaces/Blog/IBlogArticle.d.ts +18 -18
- package/dist/Interfaces/Blog/IBlogArticle.js +2 -2
- package/dist/Interfaces/Blog/IBlogAuthor.d.ts +7 -7
- package/dist/Interfaces/Blog/IBlogAuthor.js +2 -2
- package/dist/Interfaces/Blog/IBlogCategory.d.ts +9 -9
- package/dist/Interfaces/Blog/IBlogCategory.js +2 -2
- package/dist/Interfaces/Blog/IBlogComment.d.ts +13 -13
- package/dist/Interfaces/Blog/IBlogComment.js +2 -2
- package/dist/Interfaces/Blog/IBlogKeywords.d.ts +9 -9
- package/dist/Interfaces/Blog/IBlogKeywords.js +2 -2
- package/dist/Interfaces/Booking/index.d.ts +74 -74
- package/dist/Interfaces/Booking/index.js +17 -17
- package/dist/Interfaces/Brand/index.d.ts +15 -15
- package/dist/Interfaces/Brand/index.js +2 -2
- package/dist/Interfaces/CMS/index.d.ts +28 -28
- package/dist/Interfaces/CMS/index.js +5 -5
- package/dist/Interfaces/Cart/IElavonPayload.d.ts +93 -93
- package/dist/Interfaces/Cart/IElavonPayload.js +17 -17
- package/dist/Interfaces/Cart/IPandaPayload.d.ts +64 -64
- package/dist/Interfaces/Cart/IPandaPayload.js +18 -18
- package/dist/Interfaces/Cart/IPaymentCard.d.ts +22 -22
- package/dist/Interfaces/Cart/IPaymentCard.js +44 -44
- package/dist/Interfaces/Cart/IPaypalPayload.d.ts +9 -9
- package/dist/Interfaces/Cart/IPaypalPayload.js +2 -2
- package/dist/Interfaces/Cart/IPaysafePayload.d.ts +72 -72
- package/dist/Interfaces/Cart/IPaysafePayload.js +2 -2
- package/dist/Interfaces/Cart/IStripePayload.d.ts +66 -66
- package/dist/Interfaces/Cart/IStripePayload.js +2 -2
- package/dist/Interfaces/Cart/index.d.ts +444 -444
- package/dist/Interfaces/Cart/index.js +197 -197
- package/dist/Interfaces/CartReservedQuantities/index.d.ts +10 -10
- package/dist/Interfaces/CartReservedQuantities/index.js +2 -2
- package/dist/Interfaces/CashDrawers/index.d.ts +37 -37
- package/dist/Interfaces/CashDrawers/index.js +19 -19
- package/dist/Interfaces/Catalogue/index.d.ts +68 -68
- package/dist/Interfaces/Catalogue/index.js +37 -37
- package/dist/Interfaces/Category/index.d.ts +33 -33
- package/dist/Interfaces/Category/index.js +2 -2
- package/dist/Interfaces/Chart/index.d.ts +11 -11
- package/dist/Interfaces/Chart/index.js +2 -2
- package/dist/Interfaces/Class/index.d.ts +8 -8
- package/dist/Interfaces/Class/index.js +2 -2
- package/dist/Interfaces/Consent/index.d.ts +6 -6
- package/dist/Interfaces/Consent/index.js +2 -2
- package/dist/Interfaces/Context/IContextProps.d.ts +4 -4
- package/dist/Interfaces/Context/IContextProps.js +2 -2
- package/dist/Interfaces/Context/IContextState.d.ts +15 -15
- package/dist/Interfaces/Context/IContextState.js +2 -2
- package/dist/Interfaces/Customer/ICustomerBadge.d.ts +2 -2
- package/dist/Interfaces/Customer/ICustomerBadge.js +2 -2
- package/dist/Interfaces/Customer/ICustomerRating.d.ts +10 -10
- package/dist/Interfaces/Customer/ICustomerRating.js +2 -2
- package/dist/Interfaces/Customer/IStoreCredit.d.ts +13 -13
- package/dist/Interfaces/Customer/IStoreCredit.js +2 -2
- package/dist/Interfaces/Customer/index.d.ts +104 -104
- package/dist/Interfaces/Customer/index.js +148 -148
- package/dist/Interfaces/Declination/index.d.ts +117 -117
- package/dist/Interfaces/Declination/index.js +66 -66
- package/dist/Interfaces/Document/index.d.ts +8 -8
- package/dist/Interfaces/Document/index.js +2 -2
- package/dist/Interfaces/Elastic/index.d.ts +89 -89
- package/dist/Interfaces/Elastic/index.js +2 -2
- package/dist/Interfaces/Email/CustomGR/I3DPrintEmail.d.ts +11 -11
- package/dist/Interfaces/Email/CustomGR/I3DPrintEmail.js +2 -2
- package/dist/Interfaces/Email/CustomGR/IBorrowToolsEmail.d.ts +15 -15
- package/dist/Interfaces/Email/CustomGR/IBorrowToolsEmail.js +2 -2
- package/dist/Interfaces/Email/CustomGR/IPickupMaterialsEmail.d.ts +12 -12
- package/dist/Interfaces/Email/CustomGR/IPickupMaterialsEmail.js +2 -2
- package/dist/Interfaces/Email/CustomGR/IPreMeetingFormEmail.d.ts +36 -36
- package/dist/Interfaces/Email/CustomGR/IPreMeetingFormEmail.js +2 -2
- package/dist/Interfaces/Email/CustomGR/ISponsorRequestEmail.d.ts +12 -12
- package/dist/Interfaces/Email/CustomGR/ISponsorRequestEmail.js +2 -2
- package/dist/Interfaces/Email/CustomGR/ITransportEmail.d.ts +12 -12
- package/dist/Interfaces/Email/CustomGR/ITransportEmail.js +2 -2
- package/dist/Interfaces/Email/CustomGR/ITransportQuoteEmail.d.ts +12 -12
- package/dist/Interfaces/Email/CustomGR/ITransportQuoteEmail.js +2 -2
- package/dist/Interfaces/Email/CustomGR/IVegetalsEmail.d.ts +16 -16
- package/dist/Interfaces/Email/CustomGR/IVegetalsEmail.js +2 -2
- package/dist/Interfaces/Email/CustomGR/IWishlistEmail.d.ts +15 -15
- package/dist/Interfaces/Email/CustomGR/IWishlistEmail.js +2 -2
- package/dist/Interfaces/Email/IAbandonnedCartEmail.d.ts +29 -29
- package/dist/Interfaces/Email/IAbandonnedCartEmail.js +2 -2
- package/dist/Interfaces/Email/IAccountConfirmationEmail.d.ts +22 -22
- package/dist/Interfaces/Email/IAccountConfirmationEmail.js +2 -2
- package/dist/Interfaces/Email/IApplicationEmail.d.ts +19 -19
- package/dist/Interfaces/Email/IApplicationEmail.js +2 -2
- package/dist/Interfaces/Email/IBackInStockEmail.d.ts +21 -21
- package/dist/Interfaces/Email/IBackInStockEmail.js +2 -2
- package/dist/Interfaces/Email/IContactEmail.d.ts +20 -20
- package/dist/Interfaces/Email/IContactEmail.js +2 -2
- package/dist/Interfaces/Email/ICustomerBookingAdminEmail.d.ts +15 -15
- package/dist/Interfaces/Email/ICustomerBookingAdminEmail.js +2 -2
- package/dist/Interfaces/Email/ICustomerBookingEmail.d.ts +14 -14
- package/dist/Interfaces/Email/ICustomerBookingEmail.js +2 -2
- package/dist/Interfaces/Email/IEmail.d.ts +20 -20
- package/dist/Interfaces/Email/IEmail.js +60 -60
- package/dist/Interfaces/Email/IOrderConfirmationEmail.d.ts +47 -47
- package/dist/Interfaces/Email/IOrderConfirmationEmail.js +2 -2
- package/dist/Interfaces/Email/IPasswordResetEmail.d.ts +17 -17
- package/dist/Interfaces/Email/IPasswordResetEmail.js +2 -2
- package/dist/Interfaces/Email/IPhotoShootEmail.d.ts +14 -14
- package/dist/Interfaces/Email/IPhotoShootEmail.js +2 -2
- package/dist/Interfaces/Email/IPickupConfirmation.d.ts +23 -23
- package/dist/Interfaces/Email/IPickupConfirmation.js +2 -2
- package/dist/Interfaces/Email/IShippingConfirmation.d.ts +23 -23
- package/dist/Interfaces/Email/IShippingConfirmation.js +2 -2
- package/dist/Interfaces/Email/IWelcomeEmail.d.ts +19 -19
- package/dist/Interfaces/Email/IWelcomeEmail.js +2 -2
- package/dist/Interfaces/ExportSchema/index.d.ts +7 -7
- package/dist/Interfaces/ExportSchema/index.js +2 -2
- package/dist/Interfaces/ExternalService/BaseExternalService.d.ts +12 -12
- package/dist/Interfaces/ExternalService/BaseExternalService.js +2 -2
- package/dist/Interfaces/ExternalService/ExternalProductsService.d.ts +4 -4
- package/dist/Interfaces/ExternalService/ExternalProductsService.js +2 -2
- package/dist/Interfaces/ExternalService/index.d.ts +9 -9
- package/dist/Interfaces/ExternalService/index.js +2 -2
- package/dist/Interfaces/FirstOrderTracking/index.d.ts +5 -5
- package/dist/Interfaces/FirstOrderTracking/index.js +2 -2
- package/dist/Interfaces/G2/index.d.ts +556 -556
- package/dist/Interfaces/G2/index.js +38 -38
- package/dist/Interfaces/Indexed/Product/IIndexedLastSavedProduct.d.ts +20 -20
- package/dist/Interfaces/Indexed/Product/IIndexedLastSavedProduct.js +2 -2
- package/dist/Interfaces/Indexed/Product/index.d.ts +105 -105
- package/dist/Interfaces/Indexed/Product/index.js +253 -253
- package/dist/Interfaces/Inventory/index.d.ts +19 -19
- package/dist/Interfaces/Inventory/index.js +8 -8
- package/dist/Interfaces/Invoice/index.d.ts +4 -4
- package/dist/Interfaces/Invoice/index.js +2 -2
- package/dist/Interfaces/MarketplacePublication/MarketplaceOrderData.d.ts +3 -3
- package/dist/Interfaces/MarketplacePublication/MarketplaceOrderData.js +2 -2
- package/dist/Interfaces/MarketplacePublication/index.d.ts +23 -23
- package/dist/Interfaces/MarketplacePublication/index.js +22 -22
- package/dist/Interfaces/Menu/index.d.ts +40 -40
- package/dist/Interfaces/Menu/index.js +16 -16
- package/dist/Interfaces/Note/index.d.ts +10 -10
- package/dist/Interfaces/Note/index.js +7 -7
- package/dist/Interfaces/Operations/ICreatedBy.d.ts +6 -6
- package/dist/Interfaces/Operations/ICreatedBy.js +2 -2
- package/dist/Interfaces/Operations/IUpdate.d.ts +5 -5
- package/dist/Interfaces/Operations/IUpdate.js +2 -2
- package/dist/Interfaces/Order/index.d.ts +4 -4
- package/dist/Interfaces/Order/index.js +2 -2
- package/dist/Interfaces/Org/IRelUser.d.ts +9 -9
- package/dist/Interfaces/Org/IRelUser.js +2 -2
- package/dist/Interfaces/Org/index.d.ts +29 -29
- package/dist/Interfaces/Org/index.js +12 -12
- package/dist/Interfaces/Payment/index.d.ts +26 -26
- package/dist/Interfaces/Payment/index.js +14 -14
- package/dist/Interfaces/Product/IAttributeFamily.d.ts +6 -6
- package/dist/Interfaces/Product/IAttributeFamily.js +2 -2
- package/dist/Interfaces/Product/IImportProduct.d.ts +42 -42
- package/dist/Interfaces/Product/IImportProduct.js +882 -882
- package/dist/Interfaces/Product/IInventoryItem.d.ts +74 -74
- package/dist/Interfaces/Product/IInventoryItem.js +38 -38
- package/dist/Interfaces/Product/IPricing.d.ts +177 -177
- package/dist/Interfaces/Product/IPricing.js +180 -180
- package/dist/Interfaces/Product/index.d.ts +138 -138
- package/dist/Interfaces/Product/index.js +64 -64
- package/dist/Interfaces/ProductAttribute/index.d.ts +11 -11
- package/dist/Interfaces/ProductAttribute/index.js +2 -2
- package/dist/Interfaces/PromiseToPurchase/BankType.d.ts +41 -41
- package/dist/Interfaces/PromiseToPurchase/BankType.js +41 -41
- package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.d.ts +33 -33
- package/dist/Interfaces/PromiseToPurchase/IIndexedBankUsed.js +15 -15
- package/dist/Interfaces/PromiseToPurchase/IIndexedCustomerPromiseToPurchase.d.ts +19 -19
- package/dist/Interfaces/PromiseToPurchase/IIndexedCustomerPromiseToPurchase.js +2 -2
- package/dist/Interfaces/PromiseToPurchase/index.d.ts +50 -50
- package/dist/Interfaces/PromiseToPurchase/index.js +13 -13
- package/dist/Interfaces/PurchaseOrder/index.d.ts +17 -17
- package/dist/Interfaces/PurchaseOrder/index.js +2 -2
- package/dist/Interfaces/Query/IBrandQueryOptions.d.ts +11 -11
- package/dist/Interfaces/Query/IBrandQueryOptions.js +2 -2
- package/dist/Interfaces/Query/ICategoryQueryOptions.d.ts +11 -11
- package/dist/Interfaces/Query/ICategoryQueryOptions.js +2 -2
- package/dist/Interfaces/Query/IProductQueryOptions.d.ts +16 -16
- package/dist/Interfaces/Query/IProductQueryOptions.js +2 -2
- package/dist/Interfaces/Quote/index.d.ts +5 -5
- package/dist/Interfaces/Quote/index.js +2 -2
- package/dist/Interfaces/Refunds/index.d.ts +106 -106
- package/dist/Interfaces/Refunds/index.js +2 -2
- package/dist/Interfaces/Rules/IDiscountRule.d.ts +155 -155
- package/dist/Interfaces/Rules/IDiscountRule.js +114 -114
- package/dist/Interfaces/Schedule/index.d.ts +48 -48
- package/dist/Interfaces/Schedule/index.js +2 -2
- package/dist/Interfaces/Services/IAddServiceResponse.d.ts +4 -4
- package/dist/Interfaces/Services/IAddServiceResponse.js +2 -2
- package/dist/Interfaces/Services/IService.d.ts +16 -16
- package/dist/Interfaces/Services/IService.js +2 -2
- package/dist/Interfaces/Services/IServiceSecret.d.ts +8 -8
- package/dist/Interfaces/Services/IServiceSecret.js +2 -2
- package/dist/Interfaces/Shipping/Shipstation/carriers.d.ts +10 -10
- package/dist/Interfaces/Shipping/Shipstation/carriers.js +2 -2
- package/dist/Interfaces/Shipping/Shipstation/order.d.ts +227 -227
- package/dist/Interfaces/Shipping/Shipstation/order.js +2 -2
- package/dist/Interfaces/Shipping/Shipstation/quote.d.ts +31 -31
- package/dist/Interfaces/Shipping/Shipstation/quote.js +2 -2
- package/dist/Interfaces/Shipping/Shiptime/order.d.ts +54 -54
- package/dist/Interfaces/Shipping/Shiptime/order.js +71 -71
- package/dist/Interfaces/Shipping/Shiptime/quote.d.ts +111 -111
- package/dist/Interfaces/Shipping/Shiptime/quote.js +2 -2
- package/dist/Interfaces/Slider/GR.d.ts +114 -114
- package/dist/Interfaces/Slider/GR.js +271 -271
- package/dist/Interfaces/Slider/index.d.ts +30 -30
- package/dist/Interfaces/Slider/index.js +2 -2
- package/dist/Interfaces/Space/IExternalService.d.ts +53 -53
- package/dist/Interfaces/Space/IExternalService.js +44 -44
- package/dist/Interfaces/Space/IMember.d.ts +16 -16
- package/dist/Interfaces/Space/IMember.js +9 -9
- package/dist/Interfaces/Space/index.d.ts +407 -405
- package/dist/Interfaces/Space/index.js +174 -174
- package/dist/Interfaces/Space/index.js.map +1 -1
- package/dist/Interfaces/Specials/gr.d.ts +61 -61
- package/dist/Interfaces/Specials/gr.js +2 -2
- package/dist/Interfaces/StockNotification/index.d.ts +7 -7
- package/dist/Interfaces/StockNotification/index.js +2 -2
- package/dist/Interfaces/Store/index.d.ts +63 -63
- package/dist/Interfaces/Store/index.js +27 -27
- package/dist/Interfaces/Supplier/ICommand.d.ts +11 -11
- package/dist/Interfaces/Supplier/ICommand.js +2 -2
- package/dist/Interfaces/Supplier/index.d.ts +36 -36
- package/dist/Interfaces/Supplier/index.js +24 -24
- package/dist/Interfaces/TCG/index.d.ts +161 -161
- package/dist/Interfaces/TCG/index.js +54 -54
- package/dist/Interfaces/Tag/index.d.ts +18 -18
- package/dist/Interfaces/Tag/index.js +2 -2
- package/dist/Interfaces/Tax/index.d.ts +13 -13
- package/dist/Interfaces/Tax/index.js +2 -2
- package/dist/Interfaces/TransferRequest/index.d.ts +103 -103
- package/dist/Interfaces/TransferRequest/index.js +46 -46
- package/dist/Interfaces/Translation/index.d.ts +8 -8
- package/dist/Interfaces/Translation/index.js +5 -5
- package/dist/Interfaces/Update/index.d.ts +10 -10
- package/dist/Interfaces/Update/index.js +2 -2
- package/dist/Interfaces/User/IUser.d.ts +65 -65
- package/dist/Interfaces/User/IUser.js +8 -8
- package/dist/Interfaces/Version/index.d.ts +11 -11
- package/dist/Interfaces/Version/index.js +2 -2
- package/dist/Interfaces/Wishlist/index.d.ts +7 -7
- package/dist/Interfaces/Wishlist/index.js +2 -2
- package/dist/constants/Interfaces/IBaseApi.d.ts +15 -15
- package/dist/constants/Interfaces/IBaseApi.js +2 -2
- package/dist/constants/Interfaces/IEndpointResult.d.ts +9 -9
- package/dist/constants/Interfaces/IEndpointResult.js +2 -2
- package/dist/constants/enums.d.ts +6 -6
- package/dist/constants/enums.js +10 -10
- package/dist/constants/services.d.ts +2 -2
- package/dist/constants/services.js +117 -117
- package/dist/constants/version.d.ts +2 -2
- package/dist/constants/version.js +5 -5
- package/dist/index.d.ts +50 -50
- package/dist/index.js +266 -266
- package/dist/lib/Attribute/index.d.ts +14 -14
- package/dist/lib/Attribute/index.js +186 -186
- package/dist/lib/BGJob/index.d.ts +9 -9
- package/dist/lib/BGJob/index.js +216 -216
- package/dist/lib/BackgroundWorker/index.d.ts +34 -34
- package/dist/lib/BackgroundWorker/index.js +59 -59
- package/dist/lib/Blog/BlogArticle.d.ts +5 -5
- package/dist/lib/Blog/BlogArticle.js +10 -10
- package/dist/lib/Blog/BlogAuthor.d.ts +5 -5
- package/dist/lib/Blog/BlogAuthor.js +10 -10
- package/dist/lib/Blog/BlogCategory.d.ts +5 -5
- package/dist/lib/Blog/BlogCategory.js +10 -10
- package/dist/lib/Blog/BlogKeyword.d.ts +5 -5
- package/dist/lib/Blog/BlogKeyword.js +10 -10
- package/dist/lib/Booking/index.d.ts +85 -85
- package/dist/lib/Booking/index.js +596 -596
- package/dist/lib/Brand/index.d.ts +26 -26
- package/dist/lib/Brand/index.js +131 -131
- package/dist/lib/Cart/index.d.ts +335 -335
- package/dist/lib/Cart/index.js +3981 -3977
- package/dist/lib/Cart/index.js.map +1 -1
- package/dist/lib/CartReservedQuantities/index.d.ts +49 -49
- package/dist/lib/CartReservedQuantities/index.js +159 -159
- package/dist/lib/CashDrawerShift/index.d.ts +83 -83
- package/dist/lib/CashDrawerShift/index.js +205 -205
- package/dist/lib/Catalogue/index.d.ts +15 -15
- package/dist/lib/Catalogue/index.js +78 -78
- package/dist/lib/Category/index.d.ts +34 -34
- package/dist/lib/Category/index.js +230 -230
- package/dist/lib/Class/index.d.ts +16 -16
- package/dist/lib/Class/index.js +66 -66
- package/dist/lib/Consent/index.d.ts +4 -4
- package/dist/lib/Consent/index.js +29 -29
- package/dist/lib/Customer/index.d.ts +30 -30
- package/dist/lib/Customer/index.js +92 -92
- package/dist/lib/Declination/index.d.ts +9 -9
- package/dist/lib/Declination/index.js +26 -26
- package/dist/lib/Discount/index.d.ts +27 -27
- package/dist/lib/Discount/index.js +493 -493
- package/dist/lib/ElasticSearch/index.d.ts +13 -13
- package/dist/lib/ElasticSearch/index.js +50 -50
- package/dist/lib/Elavon/index.d.ts +18 -18
- package/dist/lib/Elavon/index.js +135 -135
- package/dist/lib/Email/AbandonedCartEmail.d.ts +16 -16
- package/dist/lib/Email/AbandonedCartEmail.js +24 -24
- package/dist/lib/Email/AccountConfirmationEmail.d.ts +19 -19
- package/dist/lib/Email/AccountConfirmationEmail.js +30 -30
- package/dist/lib/Email/AdminOrderConfirmationEmail.d.ts +16 -16
- package/dist/lib/Email/AdminOrderConfirmationEmail.js +24 -24
- package/dist/lib/Email/ApplicationEmail.d.ts +16 -16
- package/dist/lib/Email/ApplicationEmail.js +24 -24
- package/dist/lib/Email/BackInStockEmail.d.ts +16 -16
- package/dist/lib/Email/BackInStockEmail.js +24 -24
- package/dist/lib/Email/ContactEmail.d.ts +16 -16
- package/dist/lib/Email/ContactEmail.js +24 -24
- package/dist/lib/Email/CustomerBookingAdminEmail.d.ts +16 -16
- package/dist/lib/Email/CustomerBookingAdminEmail.js +24 -24
- package/dist/lib/Email/CustomerBookingEmail.d.ts +16 -16
- package/dist/lib/Email/CustomerBookingEmail.js +24 -24
- package/dist/lib/Email/OrderConfirmationEmail.d.ts +16 -16
- package/dist/lib/Email/OrderConfirmationEmail.js +24 -24
- package/dist/lib/Email/OrderDenounciationEmail.d.ts +16 -16
- package/dist/lib/Email/OrderDenounciationEmail.js +24 -24
- package/dist/lib/Email/OrderSampleEmail.d.ts +16 -16
- package/dist/lib/Email/OrderSampleEmail.js +24 -24
- package/dist/lib/Email/OtherTypeEmails.d.ts +16 -16
- package/dist/lib/Email/OtherTypeEmails.js +27 -27
- package/dist/lib/Email/PasswordResetEmail.d.ts +16 -16
- package/dist/lib/Email/PasswordResetEmail.js +24 -24
- package/dist/lib/Email/PhotoShootEmail.d.ts +16 -16
- package/dist/lib/Email/PhotoShootEmail.js +24 -24
- package/dist/lib/Email/PickUpConfirmation.d.ts +16 -16
- package/dist/lib/Email/PickUpConfirmation.js +24 -24
- package/dist/lib/Email/ShippingConfirmation.d.ts +16 -16
- package/dist/lib/Email/ShippingConfirmation.js +24 -24
- package/dist/lib/Email/WelcomeEmail.d.ts +16 -16
- package/dist/lib/Email/WelcomeEmail.js +24 -24
- package/dist/lib/Email/index.d.ts +16 -16
- package/dist/lib/Email/index.js +31 -31
- package/dist/lib/ExternalService/Ebay.d.ts +74 -74
- package/dist/lib/ExternalService/Ebay.js +124 -124
- package/dist/lib/ExternalService/index.d.ts +5 -5
- package/dist/lib/ExternalService/index.js +10 -10
- package/dist/lib/FirstOrderTracking/index.d.ts +5 -5
- package/dist/lib/FirstOrderTracking/index.js +10 -10
- package/dist/lib/Indexed/IndexedCart.d.ts +13 -13
- package/dist/lib/Indexed/IndexedCart.js +91 -91
- package/dist/lib/Indexed/Product.d.ts +17 -17
- package/dist/lib/Indexed/Product.js +98 -98
- package/dist/lib/Inventory/index.d.ts +112 -112
- package/dist/lib/Inventory/index.js +492 -492
- package/dist/lib/Invoice/index.d.ts +16 -16
- package/dist/lib/Invoice/index.js +21 -21
- package/dist/lib/MarketplacePublication/index.d.ts +9 -9
- package/dist/lib/MarketplacePublication/index.js +426 -426
- package/dist/lib/Menu/index.d.ts +11 -11
- package/dist/lib/Menu/index.js +107 -107
- package/dist/lib/MongoDB/BaseAPI.d.ts +18 -18
- package/dist/lib/MongoDB/BaseAPI.js +200 -200
- package/dist/lib/Note/index.d.ts +4 -4
- package/dist/lib/Note/index.js +6 -6
- package/dist/lib/Order/index.d.ts +27 -27
- package/dist/lib/Order/index.js +56 -56
- package/dist/lib/Org/index.d.ts +68 -68
- package/dist/lib/Org/index.js +216 -216
- package/dist/lib/PandaPay/index.d.ts +16 -16
- package/dist/lib/PandaPay/index.js +176 -176
- package/dist/lib/Paysafe/index.d.ts +11 -11
- package/dist/lib/Paysafe/index.js +41 -41
- package/dist/lib/Product/index.d.ts +182 -182
- package/dist/lib/Product/index.js +847 -847
- package/dist/lib/ProductAttribute/index.d.ts +15 -15
- package/dist/lib/ProductAttribute/index.js +45 -45
- package/dist/lib/PromiseToPurchase/index.d.ts +109 -109
- package/dist/lib/PromiseToPurchase/index.js +343 -343
- package/dist/lib/PurchaseOrder/index.d.ts +20 -20
- package/dist/lib/PurchaseOrder/index.js +28 -28
- package/dist/lib/Queue/index.d.ts +40 -40
- package/dist/lib/Queue/index.js +254 -254
- package/dist/lib/Schedule/index.d.ts +5 -5
- package/dist/lib/Schedule/index.js +12 -12
- package/dist/lib/Service/Enum/ServiceEnum.d.ts +3 -3
- package/dist/lib/Service/Enum/ServiceEnum.js +7 -7
- package/dist/lib/Service/index.d.ts +13 -13
- package/dist/lib/Service/index.js +21 -21
- package/dist/lib/Shipment/index.d.ts +28 -28
- package/dist/lib/Shipment/index.js +370 -370
- package/dist/lib/Slider/index.d.ts +22 -22
- package/dist/lib/Slider/index.js +119 -119
- package/dist/lib/Space/index.d.ts +1150 -1150
- package/dist/lib/Space/index.js +5792 -5792
- package/dist/lib/StockNotification/index.d.ts +4 -4
- package/dist/lib/StockNotification/index.js +6 -6
- package/dist/lib/Store/index.d.ts +5 -5
- package/dist/lib/Store/index.js +12 -12
- package/dist/lib/Supplier/Command.d.ts +5 -5
- package/dist/lib/Supplier/Command.js +10 -10
- package/dist/lib/Supplier/index.d.ts +25 -25
- package/dist/lib/Supplier/index.js +27 -27
- package/dist/lib/Tags/index.d.ts +6 -6
- package/dist/lib/Tags/index.js +26 -26
- package/dist/lib/Tax/index.d.ts +8 -8
- package/dist/lib/Tax/index.js +54 -54
- package/dist/lib/TransferRequest/index.d.ts +290 -290
- package/dist/lib/TransferRequest/index.js +1026 -1026
- package/dist/lib/Update/index.d.ts +10 -10
- package/dist/lib/Update/index.js +22 -22
- package/dist/lib/User/index.d.ts +89 -89
- package/dist/lib/User/index.js +328 -328
- package/dist/lib/Wishlist/index.d.ts +5 -5
- package/dist/lib/Wishlist/index.js +10 -10
- package/dist/lib/base.d.ts +14 -14
- package/dist/lib/base.js +62 -62
- package/dist/lib/baseService.d.ts +17 -17
- package/dist/lib/baseService.js +69 -69
- package/dist/rules/GR/constants/data.d.ts +26 -26
- package/dist/rules/GR/constants/data.js +81 -81
- package/dist/rules/GR/constants/expedition.d.ts +4 -4
- package/dist/rules/GR/constants/expedition.js +9 -9
- package/dist/rules/GR/constants/products.d.ts +22 -22
- package/dist/rules/GR/constants/products.js +263 -263
- package/dist/rules/GR/interfaces/cart.d.ts +84 -84
- package/dist/rules/GR/interfaces/cart.js +41 -41
- package/dist/rules/GR/interfaces/data.d.ts +101 -101
- package/dist/rules/GR/interfaces/data.js +114 -114
- package/dist/rules/GR/interfaces/products.d.ts +61 -61
- package/dist/rules/GR/interfaces/products.js +10 -10
- package/dist/rules/GR/utils/cart.d.ts +95 -95
- package/dist/rules/GR/utils/cart.js +839 -836
- package/dist/rules/GR/utils/cart.js.map +1 -1
- package/dist/rules/GR/utils/data.d.ts +3 -3
- package/dist/rules/GR/utils/data.js +28 -28
- package/dist/rules/GR/utils/expedition.d.ts +140 -140
- package/dist/rules/GR/utils/expedition.js +2016 -2016
- package/dist/rules/GR/utils/g2.d.ts +209 -209
- package/dist/rules/GR/utils/g2.js +999 -999
- package/dist/rules/GR/utils/invoices.d.ts +51 -51
- package/dist/rules/GR/utils/invoices.js +215 -215
- package/dist/rules/GR/utils/products.d.ts +277 -277
- package/dist/rules/GR/utils/products.js +1350 -1350
- package/dist/rules/GR/utils/upsells.d.ts +111 -111
- package/dist/rules/GR/utils/upsells.js +215 -215
- package/dist/services/database/BaseProvider.d.ts +29 -29
- package/dist/services/database/BaseProvider.js +28 -28
- package/dist/services/database/BatchUtils.d.ts +14 -14
- package/dist/services/database/BatchUtils.js +43 -43
- package/dist/services/database/Config.d.ts +2 -2
- package/dist/services/database/Config.js +5 -5
- package/dist/services/database/DatabaseService.d.ts +125 -125
- package/dist/services/database/DatabaseService.js +237 -237
- package/dist/services/database/FirebaseProvider.d.ts +17 -17
- package/dist/services/database/FirebaseProvider.js +235 -235
- package/dist/services/database/NotFirebaseProvider.d.ts +49 -49
- package/dist/services/database/NotFirebaseProvider.js +262 -262
- package/dist/services/g2/G2OrderSlip.d.ts +49 -49
- package/dist/services/g2/G2OrderSlip.js +228 -228
- package/dist/services/g2/utils.d.ts +19 -19
- package/dist/services/g2/utils.js +953 -953
- package/dist/services/logs/index.d.ts +23 -23
- package/dist/services/logs/index.js +66 -66
- package/dist/services/marketplace/BaseMarketServiceClass.d.ts +52 -52
- package/dist/services/marketplace/BaseMarketServiceClass.js +111 -111
- package/dist/services/marketplace/CardtraderServiceClass.d.ts +17 -17
- package/dist/services/marketplace/CardtraderServiceClass.js +139 -139
- package/dist/services/marketplace/utils.d.ts +14 -14
- package/dist/services/marketplace/utils.js +29 -29
- package/dist/services/products/BaseClass.d.ts +50 -50
- package/dist/services/products/BaseClass.js +66 -66
- package/dist/services/products/TCGService.d.ts +32 -32
- package/dist/services/products/TCGService.js +555 -555
- package/dist/services/products/utils.d.ts +31 -31
- package/dist/services/products/utils.js +144 -144
- package/dist/utils/algolia.d.ts +46 -46
- package/dist/utils/algolia.js +21 -21
- package/dist/utils/anonymisation.d.ts +54 -54
- package/dist/utils/anonymisation.js +280 -280
- package/dist/utils/array.d.ts +5 -5
- package/dist/utils/array.js +14 -14
- package/dist/utils/aws.d.ts +36 -36
- package/dist/utils/aws.js +154 -154
- package/dist/utils/booking.d.ts +30 -30
- package/dist/utils/booking.js +127 -127
- package/dist/utils/cart.d.ts +259 -259
- package/dist/utils/cart.js +1145 -1145
- package/dist/utils/categories.d.ts +2 -2
- package/dist/utils/categories.js +54 -54
- package/dist/utils/cmv.d.ts +10 -10
- package/dist/utils/cmv.js +107 -107
- package/dist/utils/console.d.ts +6 -6
- package/dist/utils/console.js +59 -59
- package/dist/utils/context.d.ts +20 -20
- package/dist/utils/context.js +61 -61
- package/dist/utils/currency.d.ts +6 -6
- package/dist/utils/currency.js +91 -91
- package/dist/utils/data.d.ts +31 -31
- package/dist/utils/data.js +296 -296
- package/dist/utils/date.d.ts +1 -1
- package/dist/utils/date.js +16 -16
- package/dist/utils/dimensions.d.ts +3 -3
- package/dist/utils/dimensions.js +16 -16
- package/dist/utils/discount.d.ts +164 -164
- package/dist/utils/discount.js +1111 -1111
- package/dist/utils/errors.d.ts +113 -113
- package/dist/utils/errors.js +113 -113
- package/dist/utils/file-admin.d.ts +8 -8
- package/dist/utils/file-admin.js +39 -39
- package/dist/utils/file.d.ts +39 -39
- package/dist/utils/file.js +208 -208
- package/dist/utils/firebase-admin.d.ts +11 -11
- package/dist/utils/firebase-admin.js +73 -73
- package/dist/utils/firebase.d.ts +58 -58
- package/dist/utils/firebase.js +148 -148
- package/dist/utils/import.d.ts +1 -1
- package/dist/utils/import.js +21 -21
- package/dist/utils/inventories.d.ts +101 -101
- package/dist/utils/inventories.js +467 -467
- package/dist/utils/locale.d.ts +24 -24
- package/dist/utils/locale.js +89 -89
- package/dist/utils/mailchimp.d.ts +58 -58
- package/dist/utils/mailchimp.js +531 -531
- package/dist/utils/mathUtils.d.ts +17 -17
- package/dist/utils/mathUtils.js +324 -324
- package/dist/utils/mongodb.d.ts +1 -1
- package/dist/utils/mongodb.js +22 -22
- package/dist/utils/object.d.ts +32 -32
- package/dist/utils/object.js +133 -133
- package/dist/utils/payment.d.ts +10 -10
- package/dist/utils/payment.js +23 -23
- package/dist/utils/products.d.ts +39 -39
- package/dist/utils/products.js +195 -195
- package/dist/utils/promiseToPurchase.d.ts +88 -88
- package/dist/utils/promiseToPurchase.js +229 -229
- package/dist/utils/prosprsearch.d.ts +42 -42
- package/dist/utils/prosprsearch.js +216 -216
- package/dist/utils/refunds.d.ts +2 -2
- package/dist/utils/refunds.js +21 -21
- package/dist/utils/sdc.d.ts +10 -10
- package/dist/utils/sdc.js +1309 -1309
- package/dist/utils/searchIndexes.d.ts +58 -58
- package/dist/utils/searchIndexes.js +247 -247
- package/dist/utils/services.d.ts +42 -42
- package/dist/utils/services.js +409 -409
- package/dist/utils/shipment.d.ts +110 -110
- package/dist/utils/shipment.js +345 -345
- package/dist/utils/simpletexting.d.ts +2 -2
- package/dist/utils/simpletexting.js +45 -45
- package/dist/utils/sliders.d.ts +4 -4
- package/dist/utils/sliders.js +24 -24
- package/dist/utils/string.d.ts +16 -16
- package/dist/utils/string.js +192 -192
- package/dist/utils/tcgService.d.ts +74 -74
- package/dist/utils/tcgService.js +308 -308
- package/dist/utils/tools.d.ts +5 -5
- package/dist/utils/tools.js +13 -13
- package/dist/utils/transferRequests.d.ts +43 -43
- package/dist/utils/transferRequests.js +67 -67
- package/dist/utils/update.d.ts +7 -7
- package/dist/utils/update.js +137 -137
- package/dist/utils/weight.d.ts +3 -3
- package/dist/utils/weight.js +16 -16
- package/dist/utils/zones.d.ts +11 -11
- package/dist/utils/zones.js +218 -218
- package/package.json +107 -107
- package/publish.sh +143 -143
- package/readme.md +182 -182
|
@@ -1,1027 +1,1027 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
var _a;
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.TransferRequest = void 0;
|
|
8
|
-
const TransferRequest_1 = require("../../Interfaces/TransferRequest");
|
|
9
|
-
// Classes
|
|
10
|
-
const DatabaseService_1 = __importDefault(require("../../services/database/DatabaseService"));
|
|
11
|
-
const baseService_1 = require("../baseService");
|
|
12
|
-
const Inventory_1 = __importDefault(require("../Inventory"));
|
|
13
|
-
const Space_1 = __importDefault(require("../Space"));
|
|
14
|
-
// Utils
|
|
15
|
-
const toNumber_1 = __importDefault(require("lodash/toNumber"));
|
|
16
|
-
const ceil_1 = __importDefault(require("lodash/ceil"));
|
|
17
|
-
const round_1 = __importDefault(require("lodash/round"));
|
|
18
|
-
const data_1 = require("../../utils/data");
|
|
19
|
-
const inventories_1 = require("../../utils/inventories");
|
|
20
|
-
const transferRequests_1 = require("../../utils/transferRequests");
|
|
21
|
-
const sumBy_1 = __importDefault(require("lodash/sumBy"));
|
|
22
|
-
const weight_1 = require("../../utils/weight");
|
|
23
|
-
const algolia_1 = require("../../utils/algolia");
|
|
24
|
-
const __1 = require("../..");
|
|
25
|
-
const console_1 = require("../../utils/console");
|
|
26
|
-
const context_1 = require("../../utils/context");
|
|
27
|
-
const tools_1 = require("../../utils/tools");
|
|
28
|
-
const products_1 = require("../../rules/GR/utils/products");
|
|
29
|
-
const Cart_1 = require("../../Interfaces/Cart");
|
|
30
|
-
class TransferRequest extends baseService_1.BaseServiceClass {
|
|
31
|
-
constructor(_data, _collection, _user) {
|
|
32
|
-
super(_data, _collection, _user);
|
|
33
|
-
this._listener = null;
|
|
34
|
-
this.prevProducts = [];
|
|
35
|
-
this.prevFromStore = undefined;
|
|
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
|
-
*/
|
|
41
|
-
this.checkIfTransferCanBeClosedManually = () => {
|
|
42
|
-
return this._data.status == TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL;
|
|
43
|
-
};
|
|
44
|
-
this.transferAllowAssignFromStore = () => TransferRequest.transferAllowAssignFromStore(this._data);
|
|
45
|
-
this.transferAllowEditFromStore = () => TransferRequest.transferAllowEditFromStore(this._data);
|
|
46
|
-
this.transferAllowAddProductOnEdit = () => TransferRequest.transferAllowAddProductOnEdit(this._data);
|
|
47
|
-
this.transferAllowProductDelete = () => TransferRequest.transferAllowProductDelete(this._data);
|
|
48
|
-
this.transferAllowEditProductOnEdit = () => TransferRequest.transferAllowEditProductOnEdit(this._data);
|
|
49
|
-
this.transferAllowDeleteProductOnEdit = () => TransferRequest.transferAllowProductDelete(this._data);
|
|
50
|
-
this.transferShouldDisplayWeight = () => TransferRequest.transferShouldDisplayWeight(this._data);
|
|
51
|
-
this.transferAllowsIndependantProductUpdate = () => TransferRequest.transferAllowsIndependantProductUpdate(this._data);
|
|
52
|
-
this.fetchAssociatedCart = async () => {
|
|
53
|
-
if (!!!this._data.associated_order)
|
|
54
|
-
return;
|
|
55
|
-
let associatedCart = undefined;
|
|
56
|
-
try {
|
|
57
|
-
const space = await Space_1.default.getCurrentSpaceWithRef(this._collection.path, this._user);
|
|
58
|
-
const cartQuery = await space.carts.get({
|
|
59
|
-
query: [{ field: 'ref', operator: '==', value: this._data.associated_order }]
|
|
60
|
-
});
|
|
61
|
-
if (!!cartQuery && !!cartQuery.length)
|
|
62
|
-
associatedCart = cartQuery[0];
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
console.log('could not fetch cart associated to transfer: ', e.toString());
|
|
66
|
-
}
|
|
67
|
-
return associatedCart;
|
|
68
|
-
};
|
|
69
|
-
this.addProduct = (sku, parent_slug, qte, name, image, other_units, weight, count_in_pallet_total) => {
|
|
70
|
-
const data = this.data();
|
|
71
|
-
if (!TransferRequest.transferAllowEditProductOnEdit(this._data))
|
|
72
|
-
return false;
|
|
73
|
-
let updatedProducts = data.products;
|
|
74
|
-
if (!updatedProducts.find((p) => p.sku == sku)) {
|
|
75
|
-
updatedProducts.push({
|
|
76
|
-
sku,
|
|
77
|
-
parent_slug,
|
|
78
|
-
qte,
|
|
79
|
-
name,
|
|
80
|
-
image,
|
|
81
|
-
other_units,
|
|
82
|
-
weight,
|
|
83
|
-
count_in_pallet_total,
|
|
84
|
-
qte_received: 0
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
updatedProducts = updatedProducts.map((p) => {
|
|
89
|
-
if (p.sku !== sku)
|
|
90
|
-
return p;
|
|
91
|
-
return Object.assign(Object.assign({}, p), { qte: p.qte + qte <= 1 ? 1 : p.qte + qte });
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
this._data = Object.assign(Object.assign({}, data), { products: updatedProducts });
|
|
95
|
-
return true;
|
|
96
|
-
};
|
|
97
|
-
this.editProduct = (sku, newQte) => {
|
|
98
|
-
const data = this.data();
|
|
99
|
-
if (!TransferRequest.transferAllowEditProductOnEdit(this._data))
|
|
100
|
-
return false;
|
|
101
|
-
this._data = Object.assign(Object.assign({}, data), { products: data.products.map((p) => {
|
|
102
|
-
if (p.sku !== sku)
|
|
103
|
-
return p;
|
|
104
|
-
return Object.assign(Object.assign({}, p), { qte: newQte });
|
|
105
|
-
}) });
|
|
106
|
-
return true;
|
|
107
|
-
};
|
|
108
|
-
this.deleteProduct = (sku) => {
|
|
109
|
-
const data = this.data();
|
|
110
|
-
if (!TransferRequest.transferAllowProductDelete(this._data))
|
|
111
|
-
return false;
|
|
112
|
-
this._data = Object.assign(Object.assign({}, data), { products: data.products.filter((p) => p.sku !== sku) });
|
|
113
|
-
return true;
|
|
114
|
-
};
|
|
115
|
-
this.data = () => this._data;
|
|
116
|
-
this.isListening = () => !!this._listener;
|
|
117
|
-
this.killListener = () => {
|
|
118
|
-
if (!!!this._listener)
|
|
119
|
-
return false;
|
|
120
|
-
this._listener = null;
|
|
121
|
-
return true;
|
|
122
|
-
};
|
|
123
|
-
this.listen = (callback) => {
|
|
124
|
-
if (!!this._listener)
|
|
125
|
-
return false;
|
|
126
|
-
DatabaseService_1.default.registerListener((snap) => {
|
|
127
|
-
if (snap === null)
|
|
128
|
-
this._listener = null;
|
|
129
|
-
if (snap.length === 0)
|
|
130
|
-
this._listener = null;
|
|
131
|
-
snap.map((s) => {
|
|
132
|
-
if (s.id == this.data().id) {
|
|
133
|
-
this._data = this.processData(s.data);
|
|
134
|
-
if (!!callback)
|
|
135
|
-
callback();
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}, this._collection.path, { id: this.data().id });
|
|
139
|
-
return true;
|
|
140
|
-
};
|
|
141
|
-
this._getTransferRef = async () => {
|
|
142
|
-
let newRef = undefined;
|
|
143
|
-
try {
|
|
144
|
-
const space = await Space_1.default.getCurrentSpaceWithRef(this._collection.path, this._user);
|
|
145
|
-
const token = (0, context_1.getSpaceTokenFromSpaceOnly)(space);
|
|
146
|
-
const api = __1.API_URL;
|
|
147
|
-
let triesLeft = 3;
|
|
148
|
-
while (triesLeft > 0) {
|
|
149
|
-
try {
|
|
150
|
-
const resp = await fetch(`${api}/transfers/refnumber`, {
|
|
151
|
-
method: 'GET',
|
|
152
|
-
headers: {
|
|
153
|
-
'Content-Type': 'application/json',
|
|
154
|
-
Authorization: `Bearer ${token}`
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
if (resp.status >= 200 && resp.status < 300) {
|
|
158
|
-
const data = await resp.json();
|
|
159
|
-
if (data.status == 'success') {
|
|
160
|
-
newRef = (0, toNumber_1.default)(data.result);
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
catch (e) {
|
|
166
|
-
console.log('Error fetching transfer number', e);
|
|
167
|
-
}
|
|
168
|
-
await (0, tools_1.waitFor)(1000); // wait a second before trying again, server needs to recover
|
|
169
|
-
triesLeft--;
|
|
170
|
-
}
|
|
171
|
-
if (triesLeft == 0)
|
|
172
|
-
throw new Error('could not get a Ref number');
|
|
173
|
-
return newRef;
|
|
174
|
-
}
|
|
175
|
-
catch (e) {
|
|
176
|
-
console.log('error on fetching new transfer ref: ', e.toString());
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
this.save = async (partial, saveToDatabase = true, merge = true) => {
|
|
181
|
-
const saveResult = await super.save(partial, undefined, saveToDatabase, undefined, merge);
|
|
182
|
-
if (typeof saveResult === 'string') {
|
|
183
|
-
this._data = Object.assign(Object.assign({}, this._data), { id: saveResult });
|
|
184
|
-
}
|
|
185
|
-
return saveResult;
|
|
186
|
-
};
|
|
187
|
-
/**
|
|
188
|
-
* Validate the quantities set before submit
|
|
189
|
-
* @param strictQty Tell if we should only allow equal quantity
|
|
190
|
-
* @returns
|
|
191
|
-
*/
|
|
192
|
-
this.validateBeforeSubmit = async (strictQty = true) => {
|
|
193
|
-
if (strictQty) {
|
|
194
|
-
return this.data().products.every((p) => typeof p.qte_validation == 'undefined' || p.qte === p.qte_validation);
|
|
195
|
-
}
|
|
196
|
-
return this.data().products.every((p) => typeof p.qte_validation == 'undefined' || p.qte_validation >= 0);
|
|
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
|
-
*/
|
|
205
|
-
this.clearValidationQuantitiesFromProductData = (copyQte = false) => {
|
|
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 }))) });
|
|
207
|
-
};
|
|
208
|
-
/**
|
|
209
|
-
* Add the validation quantities to the received amount
|
|
210
|
-
*/
|
|
211
|
-
this.addValidationQuantitiesToReceivedQuantities = () => {
|
|
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 }))) });
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* Return the previous quantity received for the provided sku
|
|
216
|
-
* @param sku the product sku to get
|
|
217
|
-
* @returns
|
|
218
|
-
*/
|
|
219
|
-
this.getPreviousReceivedQuantity = (sku) => {
|
|
220
|
-
const entry = this._data.transfer_updates.find((u) => (u.status == TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL || u.status == TransferRequest_1.TransferRequestStatusEnum.RECEIVED) &&
|
|
221
|
-
u.products &&
|
|
222
|
-
u.products[sku]);
|
|
223
|
-
if (entry) {
|
|
224
|
-
// if we got an entry then the sku exists inside
|
|
225
|
-
return entry.products[sku].qte_after;
|
|
226
|
-
}
|
|
227
|
-
return 0;
|
|
228
|
-
};
|
|
229
|
-
/**
|
|
230
|
-
* Return the original reuested quantity
|
|
231
|
-
* @param sku the product sku to get
|
|
232
|
-
* @returns
|
|
233
|
-
*/
|
|
234
|
-
this.getOriginalRequestedQuantity = (sku) => {
|
|
235
|
-
const product = this._data.products.find((p) => p.sku == sku);
|
|
236
|
-
if (!product)
|
|
237
|
-
return 0;
|
|
238
|
-
let result = product.qte;
|
|
239
|
-
this._data.transfer_updates.map((u) => {
|
|
240
|
-
if (u.status != TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL &&
|
|
241
|
-
u.status != TransferRequest_1.TransferRequestStatusEnum.RECEIVED &&
|
|
242
|
-
u.products &&
|
|
243
|
-
u.products[sku])
|
|
244
|
-
result = u.products[sku].qte_before;
|
|
245
|
-
});
|
|
246
|
-
return result;
|
|
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
|
-
*/
|
|
254
|
-
this.getQuantityAtStatus = (sku, status) => {
|
|
255
|
-
const statusPos = (0, transferRequests_1.getOrderPositionForStatus)(status, TransferRequest_1.transferRequestStatusOrder) || 0;
|
|
256
|
-
// If status if first status in order
|
|
257
|
-
if (statusPos == 0) {
|
|
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!
|
|
260
|
-
if (!updates.some((u) => !!u.products && !!u.products && !!u.products[sku]))
|
|
261
|
-
return this.getOriginalRequestedQuantity(sku);
|
|
262
|
-
}
|
|
263
|
-
const product = this._data.products.find((p) => p.sku == sku);
|
|
264
|
-
if (!product)
|
|
265
|
-
return 0;
|
|
266
|
-
let result = product.qte;
|
|
267
|
-
for (let i of this._data.transfer_updates) {
|
|
268
|
-
if (((0, transferRequests_1.getOrderPositionForStatus)(i.status, TransferRequest_1.transferRequestStatusOrder) || 0) <= statusPos &&
|
|
269
|
-
i.products &&
|
|
270
|
-
i.products[sku]) {
|
|
271
|
-
result = i.products[sku].qte_after;
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return result;
|
|
276
|
-
};
|
|
277
|
-
this.getInventoryQuantitiesStillMissingForCartTransfer = (associatedCart, itemSku, otherUnits) => {
|
|
278
|
-
var _b;
|
|
279
|
-
if (!!!associatedCart)
|
|
280
|
-
return 0;
|
|
281
|
-
const sameProd = associatedCart.data().items.find((i) => i.sku == itemSku);
|
|
282
|
-
if (!!!sameProd)
|
|
283
|
-
return 0;
|
|
284
|
-
const alreadyReservedQuantities = (_b = sameProd.qte_reserved) !== null && _b !== void 0 ? _b : 0;
|
|
285
|
-
const quantitiesNeededForCart = sameProd.qte - alreadyReservedQuantities;
|
|
286
|
-
const convertedToInventoryForCartQuantities = (0, inventories_1.getConvertedUnitQuantity)(otherUnits, quantitiesNeededForCart, 'inventory_unit');
|
|
287
|
-
return convertedToInventoryForCartQuantities;
|
|
288
|
-
};
|
|
289
|
-
this.handleFreeTransitInventory = async () => {
|
|
290
|
-
if (!this._data.from || this._data.status != TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL)
|
|
291
|
-
return false;
|
|
292
|
-
try {
|
|
293
|
-
if (DatabaseService_1.default.getPathParent(this._collection.path) == '/')
|
|
294
|
-
return false;
|
|
295
|
-
const inventoryColl = DatabaseService_1.default.asCollectionObject(DatabaseService_1.default.getPathParent(this._collection.path), 'inventories');
|
|
296
|
-
for (const product of this._data.products) {
|
|
297
|
-
if (product.qte_received >= product.qte)
|
|
298
|
-
continue;
|
|
299
|
-
const inventoryItemQuery = await DatabaseService_1.default.getDocument(inventoryColl.path, product.sku);
|
|
300
|
-
if (!!!inventoryItemQuery.exists)
|
|
301
|
-
continue;
|
|
302
|
-
const inventoryItem = new Inventory_1.default(inventoryItemQuery.data, inventoryColl, this._user);
|
|
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);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
catch (err) {
|
|
308
|
-
console.log('err', err);
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
this.handleChangeStoreInventory = async (newStatus) => {
|
|
313
|
-
// test if can be processed
|
|
314
|
-
if (!this._data.from)
|
|
315
|
-
return false;
|
|
316
|
-
try {
|
|
317
|
-
if (DatabaseService_1.default.getPathParent(this._collection.path) == '/')
|
|
318
|
-
return false;
|
|
319
|
-
const inventoryColl = DatabaseService_1.default.asCollectionObject(DatabaseService_1.default.getPathParent(this._collection.path), 'inventories');
|
|
320
|
-
// Fetch associated cart
|
|
321
|
-
let associatedCart;
|
|
322
|
-
if (newStatus == TransferRequest_1.TransferRequestStatusEnum.RECEIVED || newStatus == TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL) {
|
|
323
|
-
try {
|
|
324
|
-
associatedCart = await this.fetchAssociatedCart();
|
|
325
|
-
}
|
|
326
|
-
catch (e) {
|
|
327
|
-
console.log('error on fetching cart for transfer: ', e.toString());
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
for (const product of this._data.products) {
|
|
331
|
-
const inventoryItemQuery = await DatabaseService_1.default.getDocument(inventoryColl.path, product.sku);
|
|
332
|
-
if (!!!inventoryItemQuery.exists)
|
|
333
|
-
continue;
|
|
334
|
-
const inventoryItem = new Inventory_1.default(inventoryItemQuery.data, inventoryColl, this._user);
|
|
335
|
-
switch (newStatus) {
|
|
336
|
-
case TransferRequest_1.TransferRequestStatusEnum.IN_TRANSIT:
|
|
337
|
-
await inventoryItem.handleTransferInTransit(this._data.from, product.qte, undefined, !!this._data.associated_order);
|
|
338
|
-
break;
|
|
339
|
-
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED:
|
|
340
|
-
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL:
|
|
341
|
-
const qteReceivedSinceLastStatus = product.qte_received - this.getPreviousReceivedQuantity(product.sku);
|
|
342
|
-
if (qteReceivedSinceLastStatus == 0)
|
|
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
|
|
346
|
-
const cartWasProcessed = !!associatedCart && associatedCart.data().status > Cart_1.CartStatusEnum.CHECKOUT_PAYMENT_SUCCESS;
|
|
347
|
-
const qteToReserve = cartWasProcessed
|
|
348
|
-
? undefined
|
|
349
|
-
: this.getInventoryQuantitiesStillMissingForCartTransfer(associatedCart, product.sku, inventoryItem.data().other_units);
|
|
350
|
-
await inventoryItem.handleTransferReceived(this._data.from, this._data.to, qteReceivedSinceLastStatus, undefined, {
|
|
351
|
-
forOrder: !!this._data.associated_order,
|
|
352
|
-
maxProcessingQte: typeof qteToReserve == 'number' && qteToReserve >= 0
|
|
353
|
-
? qteToReserve > qteReceivedSinceLastStatus
|
|
354
|
-
? qteReceivedSinceLastStatus
|
|
355
|
-
: qteToReserve
|
|
356
|
-
: 0,
|
|
357
|
-
// If cart was already processed, skip web inventory update for availalble quantities
|
|
358
|
-
skipWebUpdateForAvailable: cartWasProcessed
|
|
359
|
-
});
|
|
360
|
-
break;
|
|
361
|
-
}
|
|
362
|
-
continue;
|
|
363
|
-
}
|
|
364
|
-
return true;
|
|
365
|
-
}
|
|
366
|
-
catch (err) {
|
|
367
|
-
console.log('err', err);
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
/**
|
|
372
|
-
* Update transfer's associated cart with new reserved quantities. Called when quantities received for transfer.
|
|
373
|
-
*/
|
|
374
|
-
this.handleUpdateAssociatedCartReservedQuantities = async () => {
|
|
375
|
-
var _b, _c;
|
|
376
|
-
const associatedCart = await this.fetchAssociatedCart();
|
|
377
|
-
if (!!!associatedCart)
|
|
378
|
-
return;
|
|
379
|
-
// If cart was already processed (status > 5) skip cart quantity update
|
|
380
|
-
if (associatedCart.data().status > Cart_1.CartStatusEnum.CHECKOUT_PAYMENT_SUCCESS)
|
|
381
|
-
return;
|
|
382
|
-
let somethingHasChanged = false;
|
|
383
|
-
let cartItems = associatedCart.data().items;
|
|
384
|
-
let updatedCartItems = [];
|
|
385
|
-
for (let item of cartItems) {
|
|
386
|
-
const sameInTransfer = this._data.products.find((p) => p.sku == item.sku);
|
|
387
|
-
if (!!!sameInTransfer) {
|
|
388
|
-
updatedCartItems.push(item);
|
|
389
|
-
continue;
|
|
390
|
-
}
|
|
391
|
-
const sellUnit = (item.other_units || []).find((o) => o.is_sale_unit);
|
|
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
|
|
394
|
-
if (typeof item.qte_reserved == 'number' && (0, round_1.default)(item.qte_reserved, unitHasDecimals ? 2 : 0) >= item.qte) {
|
|
395
|
-
updatedCartItems.push(item);
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
// If no quantities were received since last status change, no need to update product
|
|
399
|
-
const qteReceivedSinceLastStatus = sameInTransfer.qte_received - this.getPreviousReceivedQuantity(sameInTransfer.sku);
|
|
400
|
-
if (!!!qteReceivedSinceLastStatus) {
|
|
401
|
-
updatedCartItems.push(item);
|
|
402
|
-
continue;
|
|
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)
|
|
405
|
-
const reservedQteInInventoryUnit = (0, inventories_1.getConvertedUnitQuantity)(item.other_units, (_b = item.qte_reserved) !== null && _b !== void 0 ? _b : 0, 'inventory_unit');
|
|
406
|
-
const qteInInventoryUnit = (0, inventories_1.getConvertedUnitQuantity)(item.other_units, (_c = item.qte) !== null && _c !== void 0 ? _c : 0, 'inventory_unit');
|
|
407
|
-
const newReservedQte = reservedQteInInventoryUnit + qteReceivedSinceLastStatus;
|
|
408
|
-
updatedCartItems.push(Object.assign(Object.assign({}, item), { qte_reserved: (0, inventories_1.getConvertedUnitQuantity)(item.other_units, newReservedQte > qteInInventoryUnit ? qteInInventoryUnit : newReservedQte, 'sale_unit', true) }));
|
|
409
|
-
somethingHasChanged = true;
|
|
410
|
-
}
|
|
411
|
-
if (!!!somethingHasChanged)
|
|
412
|
-
return;
|
|
413
|
-
try {
|
|
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)
|
|
415
|
-
}
|
|
416
|
-
catch (e) {
|
|
417
|
-
console.log('error on saving cart with new qte_received in items: ', e.toString());
|
|
418
|
-
}
|
|
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
|
-
*/
|
|
426
|
-
this.constructProductObjFromUpdates = (updatesToDo) => {
|
|
427
|
-
let updatedProducts = this._data.products.map((currentProd) => {
|
|
428
|
-
const sameInUpdates = updatesToDo.find((u) => u.sku == currentProd.sku);
|
|
429
|
-
if (!!!sameInUpdates)
|
|
430
|
-
return currentProd;
|
|
431
|
-
// Calculated new quantity with ajustmentQte, rounded up to zero
|
|
432
|
-
let newQte = currentProd.qte + sameInUpdates.ajustmentQte;
|
|
433
|
-
if (newQte < 0)
|
|
434
|
-
newQte = 0;
|
|
435
|
-
return Object.assign(Object.assign({}, currentProd), { qte: newQte });
|
|
436
|
-
});
|
|
437
|
-
return updatedProducts;
|
|
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
|
-
*/
|
|
446
|
-
this.saveUpdatesToContentOnly = async (updatedContent, options, cancelTransferIfAllProductsAtZero, updateContext = TransferRequest_1.TransferRequestUpdateContextEnum.TRANSFER_UPDATED) => {
|
|
447
|
-
if (updatedContent.products) {
|
|
448
|
-
if (!TransferRequest.transferAllowsIndependantProductUpdate(this._data)) {
|
|
449
|
-
throw new Error('Cannot update products without changing status for current transfer status.');
|
|
450
|
-
}
|
|
451
|
-
await this.save({ products: updatedContent.products }, false, true);
|
|
452
|
-
// if validation quantities found, push values to qte and remove prop
|
|
453
|
-
if (!!updatedContent.products.some((p) => typeof p.qte_validation == 'number')) {
|
|
454
|
-
this.clearValidationQuantitiesFromProductData(true);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
if (updatedContent.fromStore) {
|
|
458
|
-
if (!TransferRequest.transferAllowEditFromStore(this._data)) {
|
|
459
|
-
throw new Error('Cannot update origin store for this transfer.');
|
|
460
|
-
}
|
|
461
|
-
await this.save({ from: updatedContent.fromStore }, false, true);
|
|
462
|
-
}
|
|
463
|
-
try {
|
|
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
|
|
466
|
-
const shouldCancelTransfer = updatedContent.products &&
|
|
467
|
-
cancelTransferIfAllProductsAtZero &&
|
|
468
|
-
updatedContent.products.every((p) => p.qte <= 0) &&
|
|
469
|
-
TransferRequest.checkIfTransferCanBeCancelled(this._data.status, statusPositionObj);
|
|
470
|
-
const statusToUse = !!shouldCancelTransfer ? TransferRequest_1.TransferRequestStatusEnum.CANCELLED : this._data.status;
|
|
471
|
-
// Create new update entry for transfer and save
|
|
472
|
-
const newUpdates = this._generateNewTransferStatusUpdates(statusToUse, options.user, options.comment, undefined, updateContext);
|
|
473
|
-
await this.save(Object.assign({ transfer_updates: newUpdates }, (shouldCancelTransfer ? { status: statusToUse, completed: true } : {})), true, true);
|
|
474
|
-
}
|
|
475
|
-
catch (e) {
|
|
476
|
-
const errorStr = 'error on updating products independantly from status: ' + e.toString();
|
|
477
|
-
console.log(errorStr);
|
|
478
|
-
throw new Error(errorStr);
|
|
479
|
-
}
|
|
480
|
-
return this.data();
|
|
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
|
-
*/
|
|
489
|
-
this.setDraftValue = (newVal) => {
|
|
490
|
-
this._data = Object.assign(Object.assign({}, this._data), { draft: newVal });
|
|
491
|
-
};
|
|
492
|
-
/**
|
|
493
|
-
* Change or set the associated_order property value
|
|
494
|
-
* @param newVal The new value to assign
|
|
495
|
-
*/
|
|
496
|
-
this.setAssociatedOrder = (newVal) => {
|
|
497
|
-
this._data = Object.assign(Object.assign({}, this._data), { associated_order: newVal });
|
|
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
|
-
*/
|
|
504
|
-
this.setTransportRef = async (newVal, saveToDatabase = false) => {
|
|
505
|
-
await this.save({ transport_ref: newVal }, saveToDatabase, true);
|
|
506
|
-
};
|
|
507
|
-
/**
|
|
508
|
-
* Set the original transfer id property value
|
|
509
|
-
* @param newVal The new value to assign
|
|
510
|
-
*/
|
|
511
|
-
this.setOriginalTransferId = async (newVal) => {
|
|
512
|
-
this._data = Object.assign(Object.assign({}, this._data), { original_transfer_id: newVal });
|
|
513
|
-
};
|
|
514
|
-
/**
|
|
515
|
-
* Change the completed status to true and save to database
|
|
516
|
-
*/
|
|
517
|
-
this.setAsCompleted = async (user, comment) => {
|
|
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
|
|
520
|
-
await this.handleFreeTransitInventory();
|
|
521
|
-
await this.save({ completed: true }, true, true);
|
|
522
|
-
};
|
|
523
|
-
// --------------------------------------------------------------------
|
|
524
|
-
// #region STATUS MANAGEMENT
|
|
525
|
-
this.changeStatus = async (newStatus, comment, user, saveToDatabase = true, options = {}) => {
|
|
526
|
-
const saveOptions = {
|
|
527
|
-
comment,
|
|
528
|
-
user,
|
|
529
|
-
saveToDatabase,
|
|
530
|
-
originalRequestProducts: options.originalRequestProducts,
|
|
531
|
-
space: options.space
|
|
532
|
-
};
|
|
533
|
-
let fncToCall;
|
|
534
|
-
switch (newStatus) {
|
|
535
|
-
case TransferRequest_1.TransferRequestStatusEnum.OPEN:
|
|
536
|
-
fncToCall = this.updateToStatus.open;
|
|
537
|
-
break;
|
|
538
|
-
case TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED:
|
|
539
|
-
fncToCall = this.updateToStatus.toBePrepared;
|
|
540
|
-
break;
|
|
541
|
-
case TransferRequest_1.TransferRequestStatusEnum.IN_TRANSIT:
|
|
542
|
-
fncToCall = this.updateToStatus.inTransit;
|
|
543
|
-
break;
|
|
544
|
-
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED:
|
|
545
|
-
fncToCall = this.updateToStatus.received;
|
|
546
|
-
break;
|
|
547
|
-
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL:
|
|
548
|
-
saveOptions.markAsCompleted = options.setAsCompleted;
|
|
549
|
-
fncToCall = this.updateToStatus.receivedPartial;
|
|
550
|
-
break;
|
|
551
|
-
case TransferRequest_1.TransferRequestStatusEnum.CANCELLED:
|
|
552
|
-
fncToCall = this.updateToStatus.cancelled;
|
|
553
|
-
break;
|
|
554
|
-
}
|
|
555
|
-
if (!!!fncToCall)
|
|
556
|
-
throw new Error('No status update function associated to provided status! Returning.');
|
|
557
|
-
try {
|
|
558
|
-
await fncToCall(saveOptions, options.context);
|
|
559
|
-
return this.data();
|
|
560
|
-
}
|
|
561
|
-
catch (e) {
|
|
562
|
-
throw new Error('Impossible de soumettre le(s) transfert(s)');
|
|
563
|
-
}
|
|
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
|
-
*/
|
|
572
|
-
this.saveNewTransfer = async (currentUser, comment, saveToDatabase = true, skipRef) => {
|
|
573
|
-
if (!!this.data().id)
|
|
574
|
-
throw 'Cette demande de transfert existe déjà en base de données!';
|
|
575
|
-
if (!!!this.data().status)
|
|
576
|
-
throw "Cette demande n'a pas encore de statut initial, et ne peut être sauvegardée!";
|
|
577
|
-
const newUpdates = this._generateNewTransferStatusUpdates(this.data().status, currentUser, comment);
|
|
578
|
-
let newTransferRef = undefined;
|
|
579
|
-
if (!!!skipRef) {
|
|
580
|
-
// Fetch next ref for transfer
|
|
581
|
-
newTransferRef = await this._getTransferRef();
|
|
582
|
-
}
|
|
583
|
-
return await this.save(Object.assign(Object.assign({}, this.data()), { ref: newTransferRef, transfer_updates: newUpdates }), saveToDatabase);
|
|
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
|
-
*/
|
|
591
|
-
this.getProductWeight = (sku, unit = 'pounds') => {
|
|
592
|
-
const item = this.data().products.find((p) => p.sku == sku);
|
|
593
|
-
if (!item)
|
|
594
|
-
return 0;
|
|
595
|
-
if (!!!item.weight)
|
|
596
|
-
return 0;
|
|
597
|
-
const value = (0, toNumber_1.default)(item.weight.value) || 0;
|
|
598
|
-
return item.weight.unit === unit ? value * item.qte : (0, weight_1.convertWeight)(value, item.weight.unit, unit) * item.qte;
|
|
599
|
-
};
|
|
600
|
-
/**
|
|
601
|
-
* Fetches applicable transfer status order object by checking space_options for current space.
|
|
602
|
-
*/
|
|
603
|
-
this._getOrderObject = async (space) => {
|
|
604
|
-
if (!space)
|
|
605
|
-
space = await Space_1.default.getCurrentSpaceWithRef(this._collection.path, this._user);
|
|
606
|
-
return space.transferRequests.getTransferStatusOrder();
|
|
607
|
-
};
|
|
608
|
-
/**
|
|
609
|
-
* Checks if provided "new" status follows current transfer status in the correct transfer status order for space.
|
|
610
|
-
* @param statusToCheck
|
|
611
|
-
*/
|
|
612
|
-
this._checkIfCanChangeToStatus = async (statusToCheck, space) => {
|
|
613
|
-
const currentStatus = this._data.status;
|
|
614
|
-
if (currentStatus == statusToCheck)
|
|
615
|
-
return true;
|
|
616
|
-
try {
|
|
617
|
-
const orderObj = await this._getOrderObject(space);
|
|
618
|
-
const possibleNextStatus = (0, transferRequests_1.getTransferStatusAfter)(currentStatus, orderObj);
|
|
619
|
-
return possibleNextStatus !== null && possibleNextStatus.values.includes(statusToCheck);
|
|
620
|
-
}
|
|
621
|
-
catch (e) {
|
|
622
|
-
console.log('error on checking status change: ', e.toString());
|
|
623
|
-
return false;
|
|
624
|
-
}
|
|
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
|
-
*/
|
|
633
|
-
this._generateNewTransferStatusUpdates = (newStatus, user, comment, originalRequestProducts, context) => {
|
|
634
|
-
const updates = this._data.transfer_updates;
|
|
635
|
-
const newProducts = this._data.products;
|
|
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
|
|
639
|
-
let prodUpdateObj = {};
|
|
640
|
-
// Id set means the transfer was saved to database
|
|
641
|
-
if (!!this._data.id || !!originalRequestProducts) {
|
|
642
|
-
if (newStatus == TransferRequest_1.TransferRequestStatusEnum.RECEIVED || newStatus == TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL) {
|
|
643
|
-
// at this step only received qty is allowed to change
|
|
644
|
-
for (let prod of newProducts) {
|
|
645
|
-
const addedQty = prod.qte_received - this.getPreviousReceivedQuantity(prod.sku);
|
|
646
|
-
if (addedQty != 0) {
|
|
647
|
-
prodUpdateObj[prod.sku] = {
|
|
648
|
-
qte_before: prod.qte_received - addedQty,
|
|
649
|
-
qte_after: prod.qte_received,
|
|
650
|
-
name: prod.name
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
else {
|
|
656
|
-
// Use provided prevProducts, or "normal" prevProducts if undefined, for comparaison with new products
|
|
657
|
-
const prevProducts = !!originalRequestProducts ? originalRequestProducts : this.prevProducts;
|
|
658
|
-
for (let prod of newProducts) {
|
|
659
|
-
const name = prod.name;
|
|
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
|
|
662
|
-
if (!!!sameInPrev) {
|
|
663
|
-
prodUpdateObj[prod.sku] = { qte_before: 0, qte_after: prod.qte, name };
|
|
664
|
-
}
|
|
665
|
-
// b. If product's quantities are different, add entry to update obj
|
|
666
|
-
else if (sameInPrev.qte !== prod.qte) {
|
|
667
|
-
prodUpdateObj[prod.sku] = { qte_before: sameInPrev.qte, qte_after: prod.qte, name };
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
// Always use "normal" prevProducts for check here
|
|
671
|
-
for (let prevProd of this.prevProducts) {
|
|
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
|
|
674
|
-
if (!!!sameInNew) {
|
|
675
|
-
prodUpdateObj[prevProd.sku] = { qte_before: prevProd.qte, qte_after: 0, name: prevProd.name };
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
// Add new update obj at start of array
|
|
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
|
|
682
|
-
? { before: this.prevFromStore || '', after: newFromStore || '' }
|
|
683
|
-
: null }, (!!context ? { context } : {})));
|
|
684
|
-
return updates;
|
|
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
|
-
*/
|
|
691
|
-
this._saveNewStatus = async (newStatus, options, forceCompleted = false, context = TransferRequest_1.TransferRequestUpdateContextEnum.TRANSFER_STATUS_CHANGE) => {
|
|
692
|
-
const newUpdates = this._generateNewTransferStatusUpdates(newStatus, options.user, options.comment, options.originalRequestProducts, context);
|
|
693
|
-
const completedProps = options.markAsCompleted;
|
|
694
|
-
const canSetAsCompleted = !!completedProps && TransferRequest.checkIfStatusCountsAsCompleted(newStatus);
|
|
695
|
-
if (!!completedProps && !canSetAsCompleted) {
|
|
696
|
-
console.log('Could not set completed property to true since provided new status was not found in "elligible" array!');
|
|
697
|
-
}
|
|
698
|
-
try {
|
|
699
|
-
const response = await this.save(Object.assign({ status: newStatus, transfer_updates: newUpdates }, (forceCompleted || canSetAsCompleted ? { completed: true } : {})), options.saveToDatabase);
|
|
700
|
-
if (!!!response)
|
|
701
|
-
throw new Error('Error while saving the transfer reqeust.');
|
|
702
|
-
}
|
|
703
|
-
catch (e) {
|
|
704
|
-
console.error('Error while saving the transfer reqeust.');
|
|
705
|
-
throw new Error('Error while saving the transfer reqeust.');
|
|
706
|
-
}
|
|
707
|
-
};
|
|
708
|
-
/**
|
|
709
|
-
* Checks update eligibility, then updates status to OPEN.
|
|
710
|
-
* @param options
|
|
711
|
-
*/
|
|
712
|
-
this._setAsOpen = async (options) => {
|
|
713
|
-
const newStatus = TransferRequest_1.TransferRequestStatusEnum.OPEN;
|
|
714
|
-
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
715
|
-
if (!statusChangeValid)
|
|
716
|
-
throw new Error('Trying to change to wrong status! Returning.');
|
|
717
|
-
await this._saveNewStatus(newStatus, options);
|
|
718
|
-
};
|
|
719
|
-
/**
|
|
720
|
-
* Checks update eligibility, then updates status to TO_BE_PREPARED.
|
|
721
|
-
* @param options
|
|
722
|
-
*/
|
|
723
|
-
this._setAsToBePrepared = async (options) => {
|
|
724
|
-
const newStatus = TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED;
|
|
725
|
-
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
726
|
-
if (!statusChangeValid)
|
|
727
|
-
throw new Error('Trying to change to wrong status! Returning.');
|
|
728
|
-
await this._saveNewStatus(newStatus, options);
|
|
729
|
-
};
|
|
730
|
-
/**
|
|
731
|
-
* Checks update eligibility, then updates status to IN_TRANSIT. Also updates inventory for the origin store.
|
|
732
|
-
* @param options
|
|
733
|
-
*/
|
|
734
|
-
this._setAsInTransit = async (options) => {
|
|
735
|
-
const newStatus = TransferRequest_1.TransferRequestStatusEnum.IN_TRANSIT;
|
|
736
|
-
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
737
|
-
if (!statusChangeValid)
|
|
738
|
-
throw new Error('Trying to change to wrong status! Returning.');
|
|
739
|
-
const inventoryChangesSuccess = await this.handleChangeStoreInventory(newStatus);
|
|
740
|
-
if (!!!inventoryChangesSuccess) {
|
|
741
|
-
throw "Une erreur est survenue lors de la mise à jour de l'inventaire.";
|
|
742
|
-
}
|
|
743
|
-
await this._saveNewStatus(newStatus, options);
|
|
744
|
-
};
|
|
745
|
-
/**
|
|
746
|
-
* Checks update eligibility, then updates status to RECEIVED. Also updates inventory for both stores.
|
|
747
|
-
* @param options
|
|
748
|
-
*/
|
|
749
|
-
this._setAsReceived = async (options) => {
|
|
750
|
-
const newStatus = TransferRequest_1.TransferRequestStatusEnum.RECEIVED;
|
|
751
|
-
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
752
|
-
if (!statusChangeValid)
|
|
753
|
-
throw new Error('Trying to change to wrong status! Returning.');
|
|
754
|
-
// Update inventory for items received
|
|
755
|
-
const inventoryChangesSuccess = await this.handleChangeStoreInventory(newStatus);
|
|
756
|
-
if (!!!inventoryChangesSuccess) {
|
|
757
|
-
throw "Une erreur est survenue lors de la mise à jour de l'inventaire.";
|
|
758
|
-
}
|
|
759
|
-
// Update associated cart for reserved quantities
|
|
760
|
-
await this.handleUpdateAssociatedCartReservedQuantities();
|
|
761
|
-
// Update transfer and status
|
|
762
|
-
await this._saveNewStatus(newStatus, options, true);
|
|
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
|
-
*/
|
|
769
|
-
this._setAsReceivedPartially = async (options) => {
|
|
770
|
-
const newStatus = TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL;
|
|
771
|
-
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
772
|
-
if (!statusChangeValid)
|
|
773
|
-
throw new Error('Trying to change to wrong status! Returning.');
|
|
774
|
-
const inventoryChangesSuccess = await this.handleChangeStoreInventory(newStatus);
|
|
775
|
-
if (!!!inventoryChangesSuccess) {
|
|
776
|
-
throw "Une erreur est survenue lors de la mise à jour de l'inventaire.";
|
|
777
|
-
}
|
|
778
|
-
// Update associated cart for reserved quantities
|
|
779
|
-
await this.handleUpdateAssociatedCartReservedQuantities();
|
|
780
|
-
// Update transfer and status
|
|
781
|
-
await this._saveNewStatus(newStatus, options);
|
|
782
|
-
};
|
|
783
|
-
/**
|
|
784
|
-
* Checks if transfer can be cancelled, and if so, updates status to CANCELLED.
|
|
785
|
-
* @param options
|
|
786
|
-
*/
|
|
787
|
-
this._setAsCancelled = async (options, context) => {
|
|
788
|
-
const newStatus = TransferRequest_1.TransferRequestStatusEnum.CANCELLED;
|
|
789
|
-
const statusPositionObj = await this._getOrderObject();
|
|
790
|
-
const canBeCancelled = TransferRequest.checkIfTransferCanBeCancelled(this._data.status, statusPositionObj);
|
|
791
|
-
if (!canBeCancelled) {
|
|
792
|
-
throw new Error('transfer cannot be cancelled, status is same of after IN_TRANSIT');
|
|
793
|
-
}
|
|
794
|
-
await this._saveNewStatus(newStatus, options, true, context);
|
|
795
|
-
};
|
|
796
|
-
/**
|
|
797
|
-
* Object regrouping all status change functions
|
|
798
|
-
*/
|
|
799
|
-
this.updateToStatus = {
|
|
800
|
-
open: this._setAsOpen,
|
|
801
|
-
toBePrepared: this._setAsToBePrepared,
|
|
802
|
-
inTransit: this._setAsInTransit,
|
|
803
|
-
received: this._setAsReceived,
|
|
804
|
-
receivedPartial: this._setAsReceivedPartially,
|
|
805
|
-
cancelled: this._setAsCancelled
|
|
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
|
-
*/
|
|
815
|
-
this.getFormattedRef = (spaceTransferSettings) => {
|
|
816
|
-
if (typeof this._data.ref == 'undefined') {
|
|
817
|
-
console.log('transfer has no ref, returning!');
|
|
818
|
-
return;
|
|
819
|
-
}
|
|
820
|
-
if (!!!spaceTransferSettings)
|
|
821
|
-
return this._data.ref.toString();
|
|
822
|
-
const prefix = spaceTransferSettings.prefix;
|
|
823
|
-
const suffix = spaceTransferSettings.suffix;
|
|
824
|
-
return `${prefix ? prefix + '-' : ''}${this._data.ref}${suffix ? '-' + suffix : ''}`;
|
|
825
|
-
};
|
|
826
|
-
// Format dates in data
|
|
827
|
-
this._data = this.processData(_data);
|
|
828
|
-
// Keep products in current transfer for update reference
|
|
829
|
-
if (!!this._data.products.length) {
|
|
830
|
-
this.prevProducts = [...this._data.products];
|
|
831
|
-
}
|
|
832
|
-
// Keep from store in current transfer for update reference
|
|
833
|
-
if (!!this._data.from)
|
|
834
|
-
this.prevFromStore = this._data.from;
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
exports.TransferRequest = TransferRequest;
|
|
838
|
-
_a = TransferRequest;
|
|
839
|
-
TransferRequest.fetch = async ({ app, api, hpp = 10, page = 0, query = '', filters = '', indice = 'transfer_request', f = '', space, useProspr = false }) => {
|
|
840
|
-
try {
|
|
841
|
-
let prosprSearch = false;
|
|
842
|
-
if (!!space) {
|
|
843
|
-
const prosprService = space
|
|
844
|
-
.data()
|
|
845
|
-
.external_services.find((es) => es.external_service_name.toLowerCase().trim() === 'prosprsearch');
|
|
846
|
-
prosprSearch = !!prosprService && prosprService.is_active;
|
|
847
|
-
}
|
|
848
|
-
const algolia = (0, algolia_1.createClient)({
|
|
849
|
-
app,
|
|
850
|
-
indexId: `${__1.isTestEnv ? 'test' : 'prod'}_${indice}`,
|
|
851
|
-
key: !!useProspr ? api : prosprSearch && !!space ? space.preferences.prosprsearch.app() : api,
|
|
852
|
-
prospr: !!prosprSearch || !!useProspr
|
|
853
|
-
});
|
|
854
|
-
const results = await algolia.search(query, {
|
|
855
|
-
hitsPerPage: hpp,
|
|
856
|
-
facetFilters: filters,
|
|
857
|
-
filters: f,
|
|
858
|
-
page,
|
|
859
|
-
facets: ['*']
|
|
860
|
-
});
|
|
861
|
-
return results;
|
|
862
|
-
}
|
|
863
|
-
catch (error) {
|
|
864
|
-
(0, console_1.errorMessage)(error);
|
|
865
|
-
throw error;
|
|
866
|
-
}
|
|
867
|
-
};
|
|
868
|
-
TransferRequest.getStatusLabel = (status) => {
|
|
869
|
-
switch (status) {
|
|
870
|
-
case TransferRequest_1.TransferRequestStatusEnum.INITIATED:
|
|
871
|
-
return 'Initialisée';
|
|
872
|
-
case TransferRequest_1.TransferRequestStatusEnum.OPEN:
|
|
873
|
-
return 'Ouverte';
|
|
874
|
-
case TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED:
|
|
875
|
-
return 'À préparer';
|
|
876
|
-
case TransferRequest_1.TransferRequestStatusEnum.IN_TRANSIT:
|
|
877
|
-
return 'En transit';
|
|
878
|
-
case TransferRequest_1.TransferRequestStatusEnum.CANCELLED:
|
|
879
|
-
return 'Annulée';
|
|
880
|
-
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL:
|
|
881
|
-
return 'Reçue partiellement';
|
|
882
|
-
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED:
|
|
883
|
-
return 'Reçue';
|
|
884
|
-
}
|
|
885
|
-
};
|
|
886
|
-
TransferRequest.checkIfTransferCanBeCancelled = (currentTransferStatus, statusOrderObj) => {
|
|
887
|
-
const currentPosition = (0, transferRequests_1.getOrderPositionForStatus)(currentTransferStatus, statusOrderObj);
|
|
888
|
-
if (typeof currentPosition != 'number') {
|
|
889
|
-
console.log('could not compare status since currentPosition was not found');
|
|
890
|
-
return false;
|
|
891
|
-
}
|
|
892
|
-
const inTransitPosition = (0, transferRequests_1.getOrderPositionForStatus)(TransferRequest_1.TransferRequestStatusEnum.IN_TRANSIT, statusOrderObj);
|
|
893
|
-
if (typeof inTransitPosition != 'number') {
|
|
894
|
-
console.log('could not compare status since inTransitPosition was not found');
|
|
895
|
-
return false;
|
|
896
|
-
}
|
|
897
|
-
return (0, toNumber_1.default)(currentPosition) < (0, toNumber_1.default)(inTransitPosition);
|
|
898
|
-
};
|
|
899
|
-
/**
|
|
900
|
-
* Checks if provided status is included in "completed" transfer statuses list.
|
|
901
|
-
* @param statusToCheck
|
|
902
|
-
*/
|
|
903
|
-
TransferRequest.checkIfStatusCountsAsCompleted = (statusToCheck) => {
|
|
904
|
-
return [
|
|
905
|
-
TransferRequest_1.TransferRequestStatusEnum.RECEIVED,
|
|
906
|
-
TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL,
|
|
907
|
-
TransferRequest_1.TransferRequestStatusEnum.CANCELLED
|
|
908
|
-
].includes(statusToCheck);
|
|
909
|
-
};
|
|
910
|
-
TransferRequest.transferAllowAssignFromStore = (data) => {
|
|
911
|
-
if (!!data.completed)
|
|
912
|
-
return false;
|
|
913
|
-
// Id set means the transfer was saved to database
|
|
914
|
-
return !!data.id && TransferRequest_1.TransferRequestStatusEnum.INITIATED === data.status;
|
|
915
|
-
};
|
|
916
|
-
TransferRequest.transferAllowEditFromStore = (data) => {
|
|
917
|
-
if (!!data.completed)
|
|
918
|
-
return false;
|
|
919
|
-
// Id set means the transfer was saved to database
|
|
920
|
-
return !!data.id && TransferRequest_1.TransferRequestStatusEnum.OPEN === data.status;
|
|
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
|
-
*/
|
|
927
|
-
TransferRequest.transferAllowAddProductOnEdit = (data) => {
|
|
928
|
-
if (!!data.completed)
|
|
929
|
-
return false;
|
|
930
|
-
if (data.draft)
|
|
931
|
-
return true;
|
|
932
|
-
return [TransferRequest_1.TransferRequestStatusEnum.INITIATED].includes(data.status);
|
|
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
|
-
*/
|
|
939
|
-
TransferRequest.transferAllowProductDelete = (data) => {
|
|
940
|
-
if (!!data.completed)
|
|
941
|
-
return false;
|
|
942
|
-
// Id not set yet means the transfer is in creation mode. Product deletion should be allowed!
|
|
943
|
-
if (!!!data.id)
|
|
944
|
-
return true;
|
|
945
|
-
return [TransferRequest_1.TransferRequestStatusEnum.INITIATED].includes(data.status);
|
|
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
|
-
*/
|
|
952
|
-
TransferRequest.transferAllowEditProductOnEdit = (data) => {
|
|
953
|
-
if (!!data.completed)
|
|
954
|
-
return false;
|
|
955
|
-
return [
|
|
956
|
-
TransferRequest_1.TransferRequestStatusEnum.INITIATED,
|
|
957
|
-
TransferRequest_1.TransferRequestStatusEnum.OPEN,
|
|
958
|
-
TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED
|
|
959
|
-
].includes(data.status);
|
|
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
|
-
*/
|
|
966
|
-
TransferRequest.transferAllowDeleteProductOnEdit = (data) => {
|
|
967
|
-
if (!!data.completed)
|
|
968
|
-
return false;
|
|
969
|
-
// Id not set yet means the transfer is in creation mode. Product deletion should be allowed!
|
|
970
|
-
if (!!!data.id)
|
|
971
|
-
return true;
|
|
972
|
-
return [TransferRequest_1.TransferRequestStatusEnum.INITIATED, TransferRequest_1.TransferRequestStatusEnum.OPEN].includes(data.status);
|
|
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
|
-
*/
|
|
979
|
-
TransferRequest.transferShouldDisplayWeight = (data) => {
|
|
980
|
-
return ![TransferRequest_1.TransferRequestStatusEnum.INITIATED].includes(data.status);
|
|
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
|
-
*/
|
|
987
|
-
TransferRequest.transferAllowsIndependantProductUpdate = (data) => {
|
|
988
|
-
if (!!data.completed)
|
|
989
|
-
return false;
|
|
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
|
|
992
|
-
if (!data.associated_order)
|
|
993
|
-
acceptedStatuses.push(TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED);
|
|
994
|
-
return acceptedStatuses.includes(data.status);
|
|
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
|
-
*/
|
|
1001
|
-
TransferRequest.getTotalWeight = (products, unit = 'pounds') => {
|
|
1002
|
-
return (0, sumBy_1.default)(products, (item) => {
|
|
1003
|
-
if (!!!item.weight)
|
|
1004
|
-
return 0;
|
|
1005
|
-
const value = (0, toNumber_1.default)(item.weight.value) || 0;
|
|
1006
|
-
return item.weight.unit === unit ? value * item.qte : (0, weight_1.convertWeight)(value, item.weight.unit, unit) * item.qte;
|
|
1007
|
-
});
|
|
1008
|
-
};
|
|
1009
|
-
/**
|
|
1010
|
-
* Get the total calculated pallet quantities for all transfer items
|
|
1011
|
-
* @param items
|
|
1012
|
-
* @returns
|
|
1013
|
-
*/
|
|
1014
|
-
TransferRequest.getTotalPalletQte = (items) => {
|
|
1015
|
-
const total = (0, sumBy_1.default)(items.map((item) => {
|
|
1016
|
-
if (!!!item.other_units || !!!item.count_in_pallet_total) {
|
|
1017
|
-
return 0;
|
|
1018
|
-
}
|
|
1019
|
-
const paletteUnit = item.other_units.find((u) => u.unit_slug === 'pal');
|
|
1020
|
-
if (!!!paletteUnit || !!!paletteUnit.fitting_unit) {
|
|
1021
|
-
return 0;
|
|
1022
|
-
}
|
|
1023
|
-
return item.qte / paletteUnit.fitting_unit;
|
|
1024
|
-
}));
|
|
1025
|
-
return (0, ceil_1.default)(total);
|
|
1026
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
var _a;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.TransferRequest = void 0;
|
|
8
|
+
const TransferRequest_1 = require("../../Interfaces/TransferRequest");
|
|
9
|
+
// Classes
|
|
10
|
+
const DatabaseService_1 = __importDefault(require("../../services/database/DatabaseService"));
|
|
11
|
+
const baseService_1 = require("../baseService");
|
|
12
|
+
const Inventory_1 = __importDefault(require("../Inventory"));
|
|
13
|
+
const Space_1 = __importDefault(require("../Space"));
|
|
14
|
+
// Utils
|
|
15
|
+
const toNumber_1 = __importDefault(require("lodash/toNumber"));
|
|
16
|
+
const ceil_1 = __importDefault(require("lodash/ceil"));
|
|
17
|
+
const round_1 = __importDefault(require("lodash/round"));
|
|
18
|
+
const data_1 = require("../../utils/data");
|
|
19
|
+
const inventories_1 = require("../../utils/inventories");
|
|
20
|
+
const transferRequests_1 = require("../../utils/transferRequests");
|
|
21
|
+
const sumBy_1 = __importDefault(require("lodash/sumBy"));
|
|
22
|
+
const weight_1 = require("../../utils/weight");
|
|
23
|
+
const algolia_1 = require("../../utils/algolia");
|
|
24
|
+
const __1 = require("../..");
|
|
25
|
+
const console_1 = require("../../utils/console");
|
|
26
|
+
const context_1 = require("../../utils/context");
|
|
27
|
+
const tools_1 = require("../../utils/tools");
|
|
28
|
+
const products_1 = require("../../rules/GR/utils/products");
|
|
29
|
+
const Cart_1 = require("../../Interfaces/Cart");
|
|
30
|
+
class TransferRequest extends baseService_1.BaseServiceClass {
|
|
31
|
+
constructor(_data, _collection, _user) {
|
|
32
|
+
super(_data, _collection, _user);
|
|
33
|
+
this._listener = null;
|
|
34
|
+
this.prevProducts = [];
|
|
35
|
+
this.prevFromStore = undefined;
|
|
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
|
+
*/
|
|
41
|
+
this.checkIfTransferCanBeClosedManually = () => {
|
|
42
|
+
return this._data.status == TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL;
|
|
43
|
+
};
|
|
44
|
+
this.transferAllowAssignFromStore = () => TransferRequest.transferAllowAssignFromStore(this._data);
|
|
45
|
+
this.transferAllowEditFromStore = () => TransferRequest.transferAllowEditFromStore(this._data);
|
|
46
|
+
this.transferAllowAddProductOnEdit = () => TransferRequest.transferAllowAddProductOnEdit(this._data);
|
|
47
|
+
this.transferAllowProductDelete = () => TransferRequest.transferAllowProductDelete(this._data);
|
|
48
|
+
this.transferAllowEditProductOnEdit = () => TransferRequest.transferAllowEditProductOnEdit(this._data);
|
|
49
|
+
this.transferAllowDeleteProductOnEdit = () => TransferRequest.transferAllowProductDelete(this._data);
|
|
50
|
+
this.transferShouldDisplayWeight = () => TransferRequest.transferShouldDisplayWeight(this._data);
|
|
51
|
+
this.transferAllowsIndependantProductUpdate = () => TransferRequest.transferAllowsIndependantProductUpdate(this._data);
|
|
52
|
+
this.fetchAssociatedCart = async () => {
|
|
53
|
+
if (!!!this._data.associated_order)
|
|
54
|
+
return;
|
|
55
|
+
let associatedCart = undefined;
|
|
56
|
+
try {
|
|
57
|
+
const space = await Space_1.default.getCurrentSpaceWithRef(this._collection.path, this._user);
|
|
58
|
+
const cartQuery = await space.carts.get({
|
|
59
|
+
query: [{ field: 'ref', operator: '==', value: this._data.associated_order }]
|
|
60
|
+
});
|
|
61
|
+
if (!!cartQuery && !!cartQuery.length)
|
|
62
|
+
associatedCart = cartQuery[0];
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.log('could not fetch cart associated to transfer: ', e.toString());
|
|
66
|
+
}
|
|
67
|
+
return associatedCart;
|
|
68
|
+
};
|
|
69
|
+
this.addProduct = (sku, parent_slug, qte, name, image, other_units, weight, count_in_pallet_total) => {
|
|
70
|
+
const data = this.data();
|
|
71
|
+
if (!TransferRequest.transferAllowEditProductOnEdit(this._data))
|
|
72
|
+
return false;
|
|
73
|
+
let updatedProducts = data.products;
|
|
74
|
+
if (!updatedProducts.find((p) => p.sku == sku)) {
|
|
75
|
+
updatedProducts.push({
|
|
76
|
+
sku,
|
|
77
|
+
parent_slug,
|
|
78
|
+
qte,
|
|
79
|
+
name,
|
|
80
|
+
image,
|
|
81
|
+
other_units,
|
|
82
|
+
weight,
|
|
83
|
+
count_in_pallet_total,
|
|
84
|
+
qte_received: 0
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
updatedProducts = updatedProducts.map((p) => {
|
|
89
|
+
if (p.sku !== sku)
|
|
90
|
+
return p;
|
|
91
|
+
return Object.assign(Object.assign({}, p), { qte: p.qte + qte <= 1 ? 1 : p.qte + qte });
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
this._data = Object.assign(Object.assign({}, data), { products: updatedProducts });
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
this.editProduct = (sku, newQte) => {
|
|
98
|
+
const data = this.data();
|
|
99
|
+
if (!TransferRequest.transferAllowEditProductOnEdit(this._data))
|
|
100
|
+
return false;
|
|
101
|
+
this._data = Object.assign(Object.assign({}, data), { products: data.products.map((p) => {
|
|
102
|
+
if (p.sku !== sku)
|
|
103
|
+
return p;
|
|
104
|
+
return Object.assign(Object.assign({}, p), { qte: newQte });
|
|
105
|
+
}) });
|
|
106
|
+
return true;
|
|
107
|
+
};
|
|
108
|
+
this.deleteProduct = (sku) => {
|
|
109
|
+
const data = this.data();
|
|
110
|
+
if (!TransferRequest.transferAllowProductDelete(this._data))
|
|
111
|
+
return false;
|
|
112
|
+
this._data = Object.assign(Object.assign({}, data), { products: data.products.filter((p) => p.sku !== sku) });
|
|
113
|
+
return true;
|
|
114
|
+
};
|
|
115
|
+
this.data = () => this._data;
|
|
116
|
+
this.isListening = () => !!this._listener;
|
|
117
|
+
this.killListener = () => {
|
|
118
|
+
if (!!!this._listener)
|
|
119
|
+
return false;
|
|
120
|
+
this._listener = null;
|
|
121
|
+
return true;
|
|
122
|
+
};
|
|
123
|
+
this.listen = (callback) => {
|
|
124
|
+
if (!!this._listener)
|
|
125
|
+
return false;
|
|
126
|
+
DatabaseService_1.default.registerListener((snap) => {
|
|
127
|
+
if (snap === null)
|
|
128
|
+
this._listener = null;
|
|
129
|
+
if (snap.length === 0)
|
|
130
|
+
this._listener = null;
|
|
131
|
+
snap.map((s) => {
|
|
132
|
+
if (s.id == this.data().id) {
|
|
133
|
+
this._data = this.processData(s.data);
|
|
134
|
+
if (!!callback)
|
|
135
|
+
callback();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}, this._collection.path, { id: this.data().id });
|
|
139
|
+
return true;
|
|
140
|
+
};
|
|
141
|
+
this._getTransferRef = async () => {
|
|
142
|
+
let newRef = undefined;
|
|
143
|
+
try {
|
|
144
|
+
const space = await Space_1.default.getCurrentSpaceWithRef(this._collection.path, this._user);
|
|
145
|
+
const token = (0, context_1.getSpaceTokenFromSpaceOnly)(space);
|
|
146
|
+
const api = __1.API_URL;
|
|
147
|
+
let triesLeft = 3;
|
|
148
|
+
while (triesLeft > 0) {
|
|
149
|
+
try {
|
|
150
|
+
const resp = await fetch(`${api}/transfers/refnumber`, {
|
|
151
|
+
method: 'GET',
|
|
152
|
+
headers: {
|
|
153
|
+
'Content-Type': 'application/json',
|
|
154
|
+
Authorization: `Bearer ${token}`
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
if (resp.status >= 200 && resp.status < 300) {
|
|
158
|
+
const data = await resp.json();
|
|
159
|
+
if (data.status == 'success') {
|
|
160
|
+
newRef = (0, toNumber_1.default)(data.result);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
console.log('Error fetching transfer number', e);
|
|
167
|
+
}
|
|
168
|
+
await (0, tools_1.waitFor)(1000); // wait a second before trying again, server needs to recover
|
|
169
|
+
triesLeft--;
|
|
170
|
+
}
|
|
171
|
+
if (triesLeft == 0)
|
|
172
|
+
throw new Error('could not get a Ref number');
|
|
173
|
+
return newRef;
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
console.log('error on fetching new transfer ref: ', e.toString());
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
this.save = async (partial, saveToDatabase = true, merge = true) => {
|
|
181
|
+
const saveResult = await super.save(partial, undefined, saveToDatabase, undefined, merge);
|
|
182
|
+
if (typeof saveResult === 'string') {
|
|
183
|
+
this._data = Object.assign(Object.assign({}, this._data), { id: saveResult });
|
|
184
|
+
}
|
|
185
|
+
return saveResult;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Validate the quantities set before submit
|
|
189
|
+
* @param strictQty Tell if we should only allow equal quantity
|
|
190
|
+
* @returns
|
|
191
|
+
*/
|
|
192
|
+
this.validateBeforeSubmit = async (strictQty = true) => {
|
|
193
|
+
if (strictQty) {
|
|
194
|
+
return this.data().products.every((p) => typeof p.qte_validation == 'undefined' || p.qte === p.qte_validation);
|
|
195
|
+
}
|
|
196
|
+
return this.data().products.every((p) => typeof p.qte_validation == 'undefined' || p.qte_validation >= 0);
|
|
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
|
+
*/
|
|
205
|
+
this.clearValidationQuantitiesFromProductData = (copyQte = false) => {
|
|
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 }))) });
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Add the validation quantities to the received amount
|
|
210
|
+
*/
|
|
211
|
+
this.addValidationQuantitiesToReceivedQuantities = () => {
|
|
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 }))) });
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Return the previous quantity received for the provided sku
|
|
216
|
+
* @param sku the product sku to get
|
|
217
|
+
* @returns
|
|
218
|
+
*/
|
|
219
|
+
this.getPreviousReceivedQuantity = (sku) => {
|
|
220
|
+
const entry = this._data.transfer_updates.find((u) => (u.status == TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL || u.status == TransferRequest_1.TransferRequestStatusEnum.RECEIVED) &&
|
|
221
|
+
u.products &&
|
|
222
|
+
u.products[sku]);
|
|
223
|
+
if (entry) {
|
|
224
|
+
// if we got an entry then the sku exists inside
|
|
225
|
+
return entry.products[sku].qte_after;
|
|
226
|
+
}
|
|
227
|
+
return 0;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Return the original reuested quantity
|
|
231
|
+
* @param sku the product sku to get
|
|
232
|
+
* @returns
|
|
233
|
+
*/
|
|
234
|
+
this.getOriginalRequestedQuantity = (sku) => {
|
|
235
|
+
const product = this._data.products.find((p) => p.sku == sku);
|
|
236
|
+
if (!product)
|
|
237
|
+
return 0;
|
|
238
|
+
let result = product.qte;
|
|
239
|
+
this._data.transfer_updates.map((u) => {
|
|
240
|
+
if (u.status != TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL &&
|
|
241
|
+
u.status != TransferRequest_1.TransferRequestStatusEnum.RECEIVED &&
|
|
242
|
+
u.products &&
|
|
243
|
+
u.products[sku])
|
|
244
|
+
result = u.products[sku].qte_before;
|
|
245
|
+
});
|
|
246
|
+
return result;
|
|
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
|
+
*/
|
|
254
|
+
this.getQuantityAtStatus = (sku, status) => {
|
|
255
|
+
const statusPos = (0, transferRequests_1.getOrderPositionForStatus)(status, TransferRequest_1.transferRequestStatusOrder) || 0;
|
|
256
|
+
// If status if first status in order
|
|
257
|
+
if (statusPos == 0) {
|
|
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!
|
|
260
|
+
if (!updates.some((u) => !!u.products && !!u.products && !!u.products[sku]))
|
|
261
|
+
return this.getOriginalRequestedQuantity(sku);
|
|
262
|
+
}
|
|
263
|
+
const product = this._data.products.find((p) => p.sku == sku);
|
|
264
|
+
if (!product)
|
|
265
|
+
return 0;
|
|
266
|
+
let result = product.qte;
|
|
267
|
+
for (let i of this._data.transfer_updates) {
|
|
268
|
+
if (((0, transferRequests_1.getOrderPositionForStatus)(i.status, TransferRequest_1.transferRequestStatusOrder) || 0) <= statusPos &&
|
|
269
|
+
i.products &&
|
|
270
|
+
i.products[sku]) {
|
|
271
|
+
result = i.products[sku].qte_after;
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
};
|
|
277
|
+
this.getInventoryQuantitiesStillMissingForCartTransfer = (associatedCart, itemSku, otherUnits) => {
|
|
278
|
+
var _b;
|
|
279
|
+
if (!!!associatedCart)
|
|
280
|
+
return 0;
|
|
281
|
+
const sameProd = associatedCart.data().items.find((i) => i.sku == itemSku);
|
|
282
|
+
if (!!!sameProd)
|
|
283
|
+
return 0;
|
|
284
|
+
const alreadyReservedQuantities = (_b = sameProd.qte_reserved) !== null && _b !== void 0 ? _b : 0;
|
|
285
|
+
const quantitiesNeededForCart = sameProd.qte - alreadyReservedQuantities;
|
|
286
|
+
const convertedToInventoryForCartQuantities = (0, inventories_1.getConvertedUnitQuantity)(otherUnits, quantitiesNeededForCart, 'inventory_unit');
|
|
287
|
+
return convertedToInventoryForCartQuantities;
|
|
288
|
+
};
|
|
289
|
+
this.handleFreeTransitInventory = async () => {
|
|
290
|
+
if (!this._data.from || this._data.status != TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL)
|
|
291
|
+
return false;
|
|
292
|
+
try {
|
|
293
|
+
if (DatabaseService_1.default.getPathParent(this._collection.path) == '/')
|
|
294
|
+
return false;
|
|
295
|
+
const inventoryColl = DatabaseService_1.default.asCollectionObject(DatabaseService_1.default.getPathParent(this._collection.path), 'inventories');
|
|
296
|
+
for (const product of this._data.products) {
|
|
297
|
+
if (product.qte_received >= product.qte)
|
|
298
|
+
continue;
|
|
299
|
+
const inventoryItemQuery = await DatabaseService_1.default.getDocument(inventoryColl.path, product.sku);
|
|
300
|
+
if (!!!inventoryItemQuery.exists)
|
|
301
|
+
continue;
|
|
302
|
+
const inventoryItem = new Inventory_1.default(inventoryItemQuery.data, inventoryColl, this._user);
|
|
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);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
catch (err) {
|
|
308
|
+
console.log('err', err);
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
this.handleChangeStoreInventory = async (newStatus) => {
|
|
313
|
+
// test if can be processed
|
|
314
|
+
if (!this._data.from)
|
|
315
|
+
return false;
|
|
316
|
+
try {
|
|
317
|
+
if (DatabaseService_1.default.getPathParent(this._collection.path) == '/')
|
|
318
|
+
return false;
|
|
319
|
+
const inventoryColl = DatabaseService_1.default.asCollectionObject(DatabaseService_1.default.getPathParent(this._collection.path), 'inventories');
|
|
320
|
+
// Fetch associated cart
|
|
321
|
+
let associatedCart;
|
|
322
|
+
if (newStatus == TransferRequest_1.TransferRequestStatusEnum.RECEIVED || newStatus == TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL) {
|
|
323
|
+
try {
|
|
324
|
+
associatedCart = await this.fetchAssociatedCart();
|
|
325
|
+
}
|
|
326
|
+
catch (e) {
|
|
327
|
+
console.log('error on fetching cart for transfer: ', e.toString());
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
for (const product of this._data.products) {
|
|
331
|
+
const inventoryItemQuery = await DatabaseService_1.default.getDocument(inventoryColl.path, product.sku);
|
|
332
|
+
if (!!!inventoryItemQuery.exists)
|
|
333
|
+
continue;
|
|
334
|
+
const inventoryItem = new Inventory_1.default(inventoryItemQuery.data, inventoryColl, this._user);
|
|
335
|
+
switch (newStatus) {
|
|
336
|
+
case TransferRequest_1.TransferRequestStatusEnum.IN_TRANSIT:
|
|
337
|
+
await inventoryItem.handleTransferInTransit(this._data.from, product.qte, undefined, !!this._data.associated_order);
|
|
338
|
+
break;
|
|
339
|
+
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED:
|
|
340
|
+
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL:
|
|
341
|
+
const qteReceivedSinceLastStatus = product.qte_received - this.getPreviousReceivedQuantity(product.sku);
|
|
342
|
+
if (qteReceivedSinceLastStatus == 0)
|
|
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
|
|
346
|
+
const cartWasProcessed = !!associatedCart && associatedCart.data().status > Cart_1.CartStatusEnum.CHECKOUT_PAYMENT_SUCCESS;
|
|
347
|
+
const qteToReserve = cartWasProcessed
|
|
348
|
+
? undefined
|
|
349
|
+
: this.getInventoryQuantitiesStillMissingForCartTransfer(associatedCart, product.sku, inventoryItem.data().other_units);
|
|
350
|
+
await inventoryItem.handleTransferReceived(this._data.from, this._data.to, qteReceivedSinceLastStatus, undefined, {
|
|
351
|
+
forOrder: !!this._data.associated_order,
|
|
352
|
+
maxProcessingQte: typeof qteToReserve == 'number' && qteToReserve >= 0
|
|
353
|
+
? qteToReserve > qteReceivedSinceLastStatus
|
|
354
|
+
? qteReceivedSinceLastStatus
|
|
355
|
+
: qteToReserve
|
|
356
|
+
: 0,
|
|
357
|
+
// If cart was already processed, skip web inventory update for availalble quantities
|
|
358
|
+
skipWebUpdateForAvailable: cartWasProcessed
|
|
359
|
+
});
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
catch (err) {
|
|
367
|
+
console.log('err', err);
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
/**
|
|
372
|
+
* Update transfer's associated cart with new reserved quantities. Called when quantities received for transfer.
|
|
373
|
+
*/
|
|
374
|
+
this.handleUpdateAssociatedCartReservedQuantities = async () => {
|
|
375
|
+
var _b, _c;
|
|
376
|
+
const associatedCart = await this.fetchAssociatedCart();
|
|
377
|
+
if (!!!associatedCart)
|
|
378
|
+
return;
|
|
379
|
+
// If cart was already processed (status > 5) skip cart quantity update
|
|
380
|
+
if (associatedCart.data().status > Cart_1.CartStatusEnum.CHECKOUT_PAYMENT_SUCCESS)
|
|
381
|
+
return;
|
|
382
|
+
let somethingHasChanged = false;
|
|
383
|
+
let cartItems = associatedCart.data().items;
|
|
384
|
+
let updatedCartItems = [];
|
|
385
|
+
for (let item of cartItems) {
|
|
386
|
+
const sameInTransfer = this._data.products.find((p) => p.sku == item.sku);
|
|
387
|
+
if (!!!sameInTransfer) {
|
|
388
|
+
updatedCartItems.push(item);
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
const sellUnit = (item.other_units || []).find((o) => o.is_sale_unit);
|
|
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
|
|
394
|
+
if (typeof item.qte_reserved == 'number' && (0, round_1.default)(item.qte_reserved, unitHasDecimals ? 2 : 0) >= item.qte) {
|
|
395
|
+
updatedCartItems.push(item);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
// If no quantities were received since last status change, no need to update product
|
|
399
|
+
const qteReceivedSinceLastStatus = sameInTransfer.qte_received - this.getPreviousReceivedQuantity(sameInTransfer.sku);
|
|
400
|
+
if (!!!qteReceivedSinceLastStatus) {
|
|
401
|
+
updatedCartItems.push(item);
|
|
402
|
+
continue;
|
|
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)
|
|
405
|
+
const reservedQteInInventoryUnit = (0, inventories_1.getConvertedUnitQuantity)(item.other_units, (_b = item.qte_reserved) !== null && _b !== void 0 ? _b : 0, 'inventory_unit');
|
|
406
|
+
const qteInInventoryUnit = (0, inventories_1.getConvertedUnitQuantity)(item.other_units, (_c = item.qte) !== null && _c !== void 0 ? _c : 0, 'inventory_unit');
|
|
407
|
+
const newReservedQte = reservedQteInInventoryUnit + qteReceivedSinceLastStatus;
|
|
408
|
+
updatedCartItems.push(Object.assign(Object.assign({}, item), { qte_reserved: (0, inventories_1.getConvertedUnitQuantity)(item.other_units, newReservedQte > qteInInventoryUnit ? qteInInventoryUnit : newReservedQte, 'sale_unit', true) }));
|
|
409
|
+
somethingHasChanged = true;
|
|
410
|
+
}
|
|
411
|
+
if (!!!somethingHasChanged)
|
|
412
|
+
return;
|
|
413
|
+
try {
|
|
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)
|
|
415
|
+
}
|
|
416
|
+
catch (e) {
|
|
417
|
+
console.log('error on saving cart with new qte_received in items: ', e.toString());
|
|
418
|
+
}
|
|
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
|
+
*/
|
|
426
|
+
this.constructProductObjFromUpdates = (updatesToDo) => {
|
|
427
|
+
let updatedProducts = this._data.products.map((currentProd) => {
|
|
428
|
+
const sameInUpdates = updatesToDo.find((u) => u.sku == currentProd.sku);
|
|
429
|
+
if (!!!sameInUpdates)
|
|
430
|
+
return currentProd;
|
|
431
|
+
// Calculated new quantity with ajustmentQte, rounded up to zero
|
|
432
|
+
let newQte = currentProd.qte + sameInUpdates.ajustmentQte;
|
|
433
|
+
if (newQte < 0)
|
|
434
|
+
newQte = 0;
|
|
435
|
+
return Object.assign(Object.assign({}, currentProd), { qte: newQte });
|
|
436
|
+
});
|
|
437
|
+
return updatedProducts;
|
|
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
|
+
*/
|
|
446
|
+
this.saveUpdatesToContentOnly = async (updatedContent, options, cancelTransferIfAllProductsAtZero, updateContext = TransferRequest_1.TransferRequestUpdateContextEnum.TRANSFER_UPDATED) => {
|
|
447
|
+
if (updatedContent.products) {
|
|
448
|
+
if (!TransferRequest.transferAllowsIndependantProductUpdate(this._data)) {
|
|
449
|
+
throw new Error('Cannot update products without changing status for current transfer status.');
|
|
450
|
+
}
|
|
451
|
+
await this.save({ products: updatedContent.products }, false, true);
|
|
452
|
+
// if validation quantities found, push values to qte and remove prop
|
|
453
|
+
if (!!updatedContent.products.some((p) => typeof p.qte_validation == 'number')) {
|
|
454
|
+
this.clearValidationQuantitiesFromProductData(true);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (updatedContent.fromStore) {
|
|
458
|
+
if (!TransferRequest.transferAllowEditFromStore(this._data)) {
|
|
459
|
+
throw new Error('Cannot update origin store for this transfer.');
|
|
460
|
+
}
|
|
461
|
+
await this.save({ from: updatedContent.fromStore }, false, true);
|
|
462
|
+
}
|
|
463
|
+
try {
|
|
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
|
|
466
|
+
const shouldCancelTransfer = updatedContent.products &&
|
|
467
|
+
cancelTransferIfAllProductsAtZero &&
|
|
468
|
+
updatedContent.products.every((p) => p.qte <= 0) &&
|
|
469
|
+
TransferRequest.checkIfTransferCanBeCancelled(this._data.status, statusPositionObj);
|
|
470
|
+
const statusToUse = !!shouldCancelTransfer ? TransferRequest_1.TransferRequestStatusEnum.CANCELLED : this._data.status;
|
|
471
|
+
// Create new update entry for transfer and save
|
|
472
|
+
const newUpdates = this._generateNewTransferStatusUpdates(statusToUse, options.user, options.comment, undefined, updateContext);
|
|
473
|
+
await this.save(Object.assign({ transfer_updates: newUpdates }, (shouldCancelTransfer ? { status: statusToUse, completed: true } : {})), true, true);
|
|
474
|
+
}
|
|
475
|
+
catch (e) {
|
|
476
|
+
const errorStr = 'error on updating products independantly from status: ' + e.toString();
|
|
477
|
+
console.log(errorStr);
|
|
478
|
+
throw new Error(errorStr);
|
|
479
|
+
}
|
|
480
|
+
return this.data();
|
|
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
|
+
*/
|
|
489
|
+
this.setDraftValue = (newVal) => {
|
|
490
|
+
this._data = Object.assign(Object.assign({}, this._data), { draft: newVal });
|
|
491
|
+
};
|
|
492
|
+
/**
|
|
493
|
+
* Change or set the associated_order property value
|
|
494
|
+
* @param newVal The new value to assign
|
|
495
|
+
*/
|
|
496
|
+
this.setAssociatedOrder = (newVal) => {
|
|
497
|
+
this._data = Object.assign(Object.assign({}, this._data), { associated_order: newVal });
|
|
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
|
+
*/
|
|
504
|
+
this.setTransportRef = async (newVal, saveToDatabase = false) => {
|
|
505
|
+
await this.save({ transport_ref: newVal }, saveToDatabase, true);
|
|
506
|
+
};
|
|
507
|
+
/**
|
|
508
|
+
* Set the original transfer id property value
|
|
509
|
+
* @param newVal The new value to assign
|
|
510
|
+
*/
|
|
511
|
+
this.setOriginalTransferId = async (newVal) => {
|
|
512
|
+
this._data = Object.assign(Object.assign({}, this._data), { original_transfer_id: newVal });
|
|
513
|
+
};
|
|
514
|
+
/**
|
|
515
|
+
* Change the completed status to true and save to database
|
|
516
|
+
*/
|
|
517
|
+
this.setAsCompleted = async (user, comment) => {
|
|
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
|
|
520
|
+
await this.handleFreeTransitInventory();
|
|
521
|
+
await this.save({ completed: true }, true, true);
|
|
522
|
+
};
|
|
523
|
+
// --------------------------------------------------------------------
|
|
524
|
+
// #region STATUS MANAGEMENT
|
|
525
|
+
this.changeStatus = async (newStatus, comment, user, saveToDatabase = true, options = {}) => {
|
|
526
|
+
const saveOptions = {
|
|
527
|
+
comment,
|
|
528
|
+
user,
|
|
529
|
+
saveToDatabase,
|
|
530
|
+
originalRequestProducts: options.originalRequestProducts,
|
|
531
|
+
space: options.space
|
|
532
|
+
};
|
|
533
|
+
let fncToCall;
|
|
534
|
+
switch (newStatus) {
|
|
535
|
+
case TransferRequest_1.TransferRequestStatusEnum.OPEN:
|
|
536
|
+
fncToCall = this.updateToStatus.open;
|
|
537
|
+
break;
|
|
538
|
+
case TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED:
|
|
539
|
+
fncToCall = this.updateToStatus.toBePrepared;
|
|
540
|
+
break;
|
|
541
|
+
case TransferRequest_1.TransferRequestStatusEnum.IN_TRANSIT:
|
|
542
|
+
fncToCall = this.updateToStatus.inTransit;
|
|
543
|
+
break;
|
|
544
|
+
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED:
|
|
545
|
+
fncToCall = this.updateToStatus.received;
|
|
546
|
+
break;
|
|
547
|
+
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL:
|
|
548
|
+
saveOptions.markAsCompleted = options.setAsCompleted;
|
|
549
|
+
fncToCall = this.updateToStatus.receivedPartial;
|
|
550
|
+
break;
|
|
551
|
+
case TransferRequest_1.TransferRequestStatusEnum.CANCELLED:
|
|
552
|
+
fncToCall = this.updateToStatus.cancelled;
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
if (!!!fncToCall)
|
|
556
|
+
throw new Error('No status update function associated to provided status! Returning.');
|
|
557
|
+
try {
|
|
558
|
+
await fncToCall(saveOptions, options.context);
|
|
559
|
+
return this.data();
|
|
560
|
+
}
|
|
561
|
+
catch (e) {
|
|
562
|
+
throw new Error('Impossible de soumettre le(s) transfert(s)');
|
|
563
|
+
}
|
|
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
|
+
*/
|
|
572
|
+
this.saveNewTransfer = async (currentUser, comment, saveToDatabase = true, skipRef) => {
|
|
573
|
+
if (!!this.data().id)
|
|
574
|
+
throw 'Cette demande de transfert existe déjà en base de données!';
|
|
575
|
+
if (!!!this.data().status)
|
|
576
|
+
throw "Cette demande n'a pas encore de statut initial, et ne peut être sauvegardée!";
|
|
577
|
+
const newUpdates = this._generateNewTransferStatusUpdates(this.data().status, currentUser, comment);
|
|
578
|
+
let newTransferRef = undefined;
|
|
579
|
+
if (!!!skipRef) {
|
|
580
|
+
// Fetch next ref for transfer
|
|
581
|
+
newTransferRef = await this._getTransferRef();
|
|
582
|
+
}
|
|
583
|
+
return await this.save(Object.assign(Object.assign({}, this.data()), { ref: newTransferRef, transfer_updates: newUpdates }), saveToDatabase);
|
|
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
|
+
*/
|
|
591
|
+
this.getProductWeight = (sku, unit = 'pounds') => {
|
|
592
|
+
const item = this.data().products.find((p) => p.sku == sku);
|
|
593
|
+
if (!item)
|
|
594
|
+
return 0;
|
|
595
|
+
if (!!!item.weight)
|
|
596
|
+
return 0;
|
|
597
|
+
const value = (0, toNumber_1.default)(item.weight.value) || 0;
|
|
598
|
+
return item.weight.unit === unit ? value * item.qte : (0, weight_1.convertWeight)(value, item.weight.unit, unit) * item.qte;
|
|
599
|
+
};
|
|
600
|
+
/**
|
|
601
|
+
* Fetches applicable transfer status order object by checking space_options for current space.
|
|
602
|
+
*/
|
|
603
|
+
this._getOrderObject = async (space) => {
|
|
604
|
+
if (!space)
|
|
605
|
+
space = await Space_1.default.getCurrentSpaceWithRef(this._collection.path, this._user);
|
|
606
|
+
return space.transferRequests.getTransferStatusOrder();
|
|
607
|
+
};
|
|
608
|
+
/**
|
|
609
|
+
* Checks if provided "new" status follows current transfer status in the correct transfer status order for space.
|
|
610
|
+
* @param statusToCheck
|
|
611
|
+
*/
|
|
612
|
+
this._checkIfCanChangeToStatus = async (statusToCheck, space) => {
|
|
613
|
+
const currentStatus = this._data.status;
|
|
614
|
+
if (currentStatus == statusToCheck)
|
|
615
|
+
return true;
|
|
616
|
+
try {
|
|
617
|
+
const orderObj = await this._getOrderObject(space);
|
|
618
|
+
const possibleNextStatus = (0, transferRequests_1.getTransferStatusAfter)(currentStatus, orderObj);
|
|
619
|
+
return possibleNextStatus !== null && possibleNextStatus.values.includes(statusToCheck);
|
|
620
|
+
}
|
|
621
|
+
catch (e) {
|
|
622
|
+
console.log('error on checking status change: ', e.toString());
|
|
623
|
+
return false;
|
|
624
|
+
}
|
|
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
|
+
*/
|
|
633
|
+
this._generateNewTransferStatusUpdates = (newStatus, user, comment, originalRequestProducts, context) => {
|
|
634
|
+
const updates = this._data.transfer_updates;
|
|
635
|
+
const newProducts = this._data.products;
|
|
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
|
|
639
|
+
let prodUpdateObj = {};
|
|
640
|
+
// Id set means the transfer was saved to database
|
|
641
|
+
if (!!this._data.id || !!originalRequestProducts) {
|
|
642
|
+
if (newStatus == TransferRequest_1.TransferRequestStatusEnum.RECEIVED || newStatus == TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL) {
|
|
643
|
+
// at this step only received qty is allowed to change
|
|
644
|
+
for (let prod of newProducts) {
|
|
645
|
+
const addedQty = prod.qte_received - this.getPreviousReceivedQuantity(prod.sku);
|
|
646
|
+
if (addedQty != 0) {
|
|
647
|
+
prodUpdateObj[prod.sku] = {
|
|
648
|
+
qte_before: prod.qte_received - addedQty,
|
|
649
|
+
qte_after: prod.qte_received,
|
|
650
|
+
name: prod.name
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
// Use provided prevProducts, or "normal" prevProducts if undefined, for comparaison with new products
|
|
657
|
+
const prevProducts = !!originalRequestProducts ? originalRequestProducts : this.prevProducts;
|
|
658
|
+
for (let prod of newProducts) {
|
|
659
|
+
const name = prod.name;
|
|
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
|
|
662
|
+
if (!!!sameInPrev) {
|
|
663
|
+
prodUpdateObj[prod.sku] = { qte_before: 0, qte_after: prod.qte, name };
|
|
664
|
+
}
|
|
665
|
+
// b. If product's quantities are different, add entry to update obj
|
|
666
|
+
else if (sameInPrev.qte !== prod.qte) {
|
|
667
|
+
prodUpdateObj[prod.sku] = { qte_before: sameInPrev.qte, qte_after: prod.qte, name };
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
// Always use "normal" prevProducts for check here
|
|
671
|
+
for (let prevProd of this.prevProducts) {
|
|
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
|
|
674
|
+
if (!!!sameInNew) {
|
|
675
|
+
prodUpdateObj[prevProd.sku] = { qte_before: prevProd.qte, qte_after: 0, name: prevProd.name };
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
// Add new update obj at start of array
|
|
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
|
|
682
|
+
? { before: this.prevFromStore || '', after: newFromStore || '' }
|
|
683
|
+
: null }, (!!context ? { context } : {})));
|
|
684
|
+
return updates;
|
|
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
|
+
*/
|
|
691
|
+
this._saveNewStatus = async (newStatus, options, forceCompleted = false, context = TransferRequest_1.TransferRequestUpdateContextEnum.TRANSFER_STATUS_CHANGE) => {
|
|
692
|
+
const newUpdates = this._generateNewTransferStatusUpdates(newStatus, options.user, options.comment, options.originalRequestProducts, context);
|
|
693
|
+
const completedProps = options.markAsCompleted;
|
|
694
|
+
const canSetAsCompleted = !!completedProps && TransferRequest.checkIfStatusCountsAsCompleted(newStatus);
|
|
695
|
+
if (!!completedProps && !canSetAsCompleted) {
|
|
696
|
+
console.log('Could not set completed property to true since provided new status was not found in "elligible" array!');
|
|
697
|
+
}
|
|
698
|
+
try {
|
|
699
|
+
const response = await this.save(Object.assign({ status: newStatus, transfer_updates: newUpdates }, (forceCompleted || canSetAsCompleted ? { completed: true } : {})), options.saveToDatabase);
|
|
700
|
+
if (!!!response)
|
|
701
|
+
throw new Error('Error while saving the transfer reqeust.');
|
|
702
|
+
}
|
|
703
|
+
catch (e) {
|
|
704
|
+
console.error('Error while saving the transfer reqeust.');
|
|
705
|
+
throw new Error('Error while saving the transfer reqeust.');
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
/**
|
|
709
|
+
* Checks update eligibility, then updates status to OPEN.
|
|
710
|
+
* @param options
|
|
711
|
+
*/
|
|
712
|
+
this._setAsOpen = async (options) => {
|
|
713
|
+
const newStatus = TransferRequest_1.TransferRequestStatusEnum.OPEN;
|
|
714
|
+
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
715
|
+
if (!statusChangeValid)
|
|
716
|
+
throw new Error('Trying to change to wrong status! Returning.');
|
|
717
|
+
await this._saveNewStatus(newStatus, options);
|
|
718
|
+
};
|
|
719
|
+
/**
|
|
720
|
+
* Checks update eligibility, then updates status to TO_BE_PREPARED.
|
|
721
|
+
* @param options
|
|
722
|
+
*/
|
|
723
|
+
this._setAsToBePrepared = async (options) => {
|
|
724
|
+
const newStatus = TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED;
|
|
725
|
+
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
726
|
+
if (!statusChangeValid)
|
|
727
|
+
throw new Error('Trying to change to wrong status! Returning.');
|
|
728
|
+
await this._saveNewStatus(newStatus, options);
|
|
729
|
+
};
|
|
730
|
+
/**
|
|
731
|
+
* Checks update eligibility, then updates status to IN_TRANSIT. Also updates inventory for the origin store.
|
|
732
|
+
* @param options
|
|
733
|
+
*/
|
|
734
|
+
this._setAsInTransit = async (options) => {
|
|
735
|
+
const newStatus = TransferRequest_1.TransferRequestStatusEnum.IN_TRANSIT;
|
|
736
|
+
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
737
|
+
if (!statusChangeValid)
|
|
738
|
+
throw new Error('Trying to change to wrong status! Returning.');
|
|
739
|
+
const inventoryChangesSuccess = await this.handleChangeStoreInventory(newStatus);
|
|
740
|
+
if (!!!inventoryChangesSuccess) {
|
|
741
|
+
throw "Une erreur est survenue lors de la mise à jour de l'inventaire.";
|
|
742
|
+
}
|
|
743
|
+
await this._saveNewStatus(newStatus, options);
|
|
744
|
+
};
|
|
745
|
+
/**
|
|
746
|
+
* Checks update eligibility, then updates status to RECEIVED. Also updates inventory for both stores.
|
|
747
|
+
* @param options
|
|
748
|
+
*/
|
|
749
|
+
this._setAsReceived = async (options) => {
|
|
750
|
+
const newStatus = TransferRequest_1.TransferRequestStatusEnum.RECEIVED;
|
|
751
|
+
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
752
|
+
if (!statusChangeValid)
|
|
753
|
+
throw new Error('Trying to change to wrong status! Returning.');
|
|
754
|
+
// Update inventory for items received
|
|
755
|
+
const inventoryChangesSuccess = await this.handleChangeStoreInventory(newStatus);
|
|
756
|
+
if (!!!inventoryChangesSuccess) {
|
|
757
|
+
throw "Une erreur est survenue lors de la mise à jour de l'inventaire.";
|
|
758
|
+
}
|
|
759
|
+
// Update associated cart for reserved quantities
|
|
760
|
+
await this.handleUpdateAssociatedCartReservedQuantities();
|
|
761
|
+
// Update transfer and status
|
|
762
|
+
await this._saveNewStatus(newStatus, options, true);
|
|
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
|
+
*/
|
|
769
|
+
this._setAsReceivedPartially = async (options) => {
|
|
770
|
+
const newStatus = TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL;
|
|
771
|
+
const statusChangeValid = await this._checkIfCanChangeToStatus(newStatus, options.space);
|
|
772
|
+
if (!statusChangeValid)
|
|
773
|
+
throw new Error('Trying to change to wrong status! Returning.');
|
|
774
|
+
const inventoryChangesSuccess = await this.handleChangeStoreInventory(newStatus);
|
|
775
|
+
if (!!!inventoryChangesSuccess) {
|
|
776
|
+
throw "Une erreur est survenue lors de la mise à jour de l'inventaire.";
|
|
777
|
+
}
|
|
778
|
+
// Update associated cart for reserved quantities
|
|
779
|
+
await this.handleUpdateAssociatedCartReservedQuantities();
|
|
780
|
+
// Update transfer and status
|
|
781
|
+
await this._saveNewStatus(newStatus, options);
|
|
782
|
+
};
|
|
783
|
+
/**
|
|
784
|
+
* Checks if transfer can be cancelled, and if so, updates status to CANCELLED.
|
|
785
|
+
* @param options
|
|
786
|
+
*/
|
|
787
|
+
this._setAsCancelled = async (options, context) => {
|
|
788
|
+
const newStatus = TransferRequest_1.TransferRequestStatusEnum.CANCELLED;
|
|
789
|
+
const statusPositionObj = await this._getOrderObject();
|
|
790
|
+
const canBeCancelled = TransferRequest.checkIfTransferCanBeCancelled(this._data.status, statusPositionObj);
|
|
791
|
+
if (!canBeCancelled) {
|
|
792
|
+
throw new Error('transfer cannot be cancelled, status is same of after IN_TRANSIT');
|
|
793
|
+
}
|
|
794
|
+
await this._saveNewStatus(newStatus, options, true, context);
|
|
795
|
+
};
|
|
796
|
+
/**
|
|
797
|
+
* Object regrouping all status change functions
|
|
798
|
+
*/
|
|
799
|
+
this.updateToStatus = {
|
|
800
|
+
open: this._setAsOpen,
|
|
801
|
+
toBePrepared: this._setAsToBePrepared,
|
|
802
|
+
inTransit: this._setAsInTransit,
|
|
803
|
+
received: this._setAsReceived,
|
|
804
|
+
receivedPartial: this._setAsReceivedPartially,
|
|
805
|
+
cancelled: this._setAsCancelled
|
|
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
|
+
*/
|
|
815
|
+
this.getFormattedRef = (spaceTransferSettings) => {
|
|
816
|
+
if (typeof this._data.ref == 'undefined') {
|
|
817
|
+
console.log('transfer has no ref, returning!');
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
if (!!!spaceTransferSettings)
|
|
821
|
+
return this._data.ref.toString();
|
|
822
|
+
const prefix = spaceTransferSettings.prefix;
|
|
823
|
+
const suffix = spaceTransferSettings.suffix;
|
|
824
|
+
return `${prefix ? prefix + '-' : ''}${this._data.ref}${suffix ? '-' + suffix : ''}`;
|
|
825
|
+
};
|
|
826
|
+
// Format dates in data
|
|
827
|
+
this._data = this.processData(_data);
|
|
828
|
+
// Keep products in current transfer for update reference
|
|
829
|
+
if (!!this._data.products.length) {
|
|
830
|
+
this.prevProducts = [...this._data.products];
|
|
831
|
+
}
|
|
832
|
+
// Keep from store in current transfer for update reference
|
|
833
|
+
if (!!this._data.from)
|
|
834
|
+
this.prevFromStore = this._data.from;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
exports.TransferRequest = TransferRequest;
|
|
838
|
+
_a = TransferRequest;
|
|
839
|
+
TransferRequest.fetch = async ({ app, api, hpp = 10, page = 0, query = '', filters = '', indice = 'transfer_request', f = '', space, useProspr = false }) => {
|
|
840
|
+
try {
|
|
841
|
+
let prosprSearch = false;
|
|
842
|
+
if (!!space) {
|
|
843
|
+
const prosprService = space
|
|
844
|
+
.data()
|
|
845
|
+
.external_services.find((es) => es.external_service_name.toLowerCase().trim() === 'prosprsearch');
|
|
846
|
+
prosprSearch = !!prosprService && prosprService.is_active;
|
|
847
|
+
}
|
|
848
|
+
const algolia = (0, algolia_1.createClient)({
|
|
849
|
+
app,
|
|
850
|
+
indexId: `${__1.isTestEnv ? 'test' : 'prod'}_${indice}`,
|
|
851
|
+
key: !!useProspr ? api : prosprSearch && !!space ? space.preferences.prosprsearch.app() : api,
|
|
852
|
+
prospr: !!prosprSearch || !!useProspr
|
|
853
|
+
});
|
|
854
|
+
const results = await algolia.search(query, {
|
|
855
|
+
hitsPerPage: hpp,
|
|
856
|
+
facetFilters: filters,
|
|
857
|
+
filters: f,
|
|
858
|
+
page,
|
|
859
|
+
facets: ['*']
|
|
860
|
+
});
|
|
861
|
+
return results;
|
|
862
|
+
}
|
|
863
|
+
catch (error) {
|
|
864
|
+
(0, console_1.errorMessage)(error);
|
|
865
|
+
throw error;
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
TransferRequest.getStatusLabel = (status) => {
|
|
869
|
+
switch (status) {
|
|
870
|
+
case TransferRequest_1.TransferRequestStatusEnum.INITIATED:
|
|
871
|
+
return 'Initialisée';
|
|
872
|
+
case TransferRequest_1.TransferRequestStatusEnum.OPEN:
|
|
873
|
+
return 'Ouverte';
|
|
874
|
+
case TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED:
|
|
875
|
+
return 'À préparer';
|
|
876
|
+
case TransferRequest_1.TransferRequestStatusEnum.IN_TRANSIT:
|
|
877
|
+
return 'En transit';
|
|
878
|
+
case TransferRequest_1.TransferRequestStatusEnum.CANCELLED:
|
|
879
|
+
return 'Annulée';
|
|
880
|
+
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL:
|
|
881
|
+
return 'Reçue partiellement';
|
|
882
|
+
case TransferRequest_1.TransferRequestStatusEnum.RECEIVED:
|
|
883
|
+
return 'Reçue';
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
TransferRequest.checkIfTransferCanBeCancelled = (currentTransferStatus, statusOrderObj) => {
|
|
887
|
+
const currentPosition = (0, transferRequests_1.getOrderPositionForStatus)(currentTransferStatus, statusOrderObj);
|
|
888
|
+
if (typeof currentPosition != 'number') {
|
|
889
|
+
console.log('could not compare status since currentPosition was not found');
|
|
890
|
+
return false;
|
|
891
|
+
}
|
|
892
|
+
const inTransitPosition = (0, transferRequests_1.getOrderPositionForStatus)(TransferRequest_1.TransferRequestStatusEnum.IN_TRANSIT, statusOrderObj);
|
|
893
|
+
if (typeof inTransitPosition != 'number') {
|
|
894
|
+
console.log('could not compare status since inTransitPosition was not found');
|
|
895
|
+
return false;
|
|
896
|
+
}
|
|
897
|
+
return (0, toNumber_1.default)(currentPosition) < (0, toNumber_1.default)(inTransitPosition);
|
|
898
|
+
};
|
|
899
|
+
/**
|
|
900
|
+
* Checks if provided status is included in "completed" transfer statuses list.
|
|
901
|
+
* @param statusToCheck
|
|
902
|
+
*/
|
|
903
|
+
TransferRequest.checkIfStatusCountsAsCompleted = (statusToCheck) => {
|
|
904
|
+
return [
|
|
905
|
+
TransferRequest_1.TransferRequestStatusEnum.RECEIVED,
|
|
906
|
+
TransferRequest_1.TransferRequestStatusEnum.RECEIVED_PARTIAL,
|
|
907
|
+
TransferRequest_1.TransferRequestStatusEnum.CANCELLED
|
|
908
|
+
].includes(statusToCheck);
|
|
909
|
+
};
|
|
910
|
+
TransferRequest.transferAllowAssignFromStore = (data) => {
|
|
911
|
+
if (!!data.completed)
|
|
912
|
+
return false;
|
|
913
|
+
// Id set means the transfer was saved to database
|
|
914
|
+
return !!data.id && TransferRequest_1.TransferRequestStatusEnum.INITIATED === data.status;
|
|
915
|
+
};
|
|
916
|
+
TransferRequest.transferAllowEditFromStore = (data) => {
|
|
917
|
+
if (!!data.completed)
|
|
918
|
+
return false;
|
|
919
|
+
// Id set means the transfer was saved to database
|
|
920
|
+
return !!data.id && TransferRequest_1.TransferRequestStatusEnum.OPEN === data.status;
|
|
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
|
+
*/
|
|
927
|
+
TransferRequest.transferAllowAddProductOnEdit = (data) => {
|
|
928
|
+
if (!!data.completed)
|
|
929
|
+
return false;
|
|
930
|
+
if (data.draft)
|
|
931
|
+
return true;
|
|
932
|
+
return [TransferRequest_1.TransferRequestStatusEnum.INITIATED].includes(data.status);
|
|
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
|
+
*/
|
|
939
|
+
TransferRequest.transferAllowProductDelete = (data) => {
|
|
940
|
+
if (!!data.completed)
|
|
941
|
+
return false;
|
|
942
|
+
// Id not set yet means the transfer is in creation mode. Product deletion should be allowed!
|
|
943
|
+
if (!!!data.id)
|
|
944
|
+
return true;
|
|
945
|
+
return [TransferRequest_1.TransferRequestStatusEnum.INITIATED].includes(data.status);
|
|
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
|
+
*/
|
|
952
|
+
TransferRequest.transferAllowEditProductOnEdit = (data) => {
|
|
953
|
+
if (!!data.completed)
|
|
954
|
+
return false;
|
|
955
|
+
return [
|
|
956
|
+
TransferRequest_1.TransferRequestStatusEnum.INITIATED,
|
|
957
|
+
TransferRequest_1.TransferRequestStatusEnum.OPEN,
|
|
958
|
+
TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED
|
|
959
|
+
].includes(data.status);
|
|
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
|
+
*/
|
|
966
|
+
TransferRequest.transferAllowDeleteProductOnEdit = (data) => {
|
|
967
|
+
if (!!data.completed)
|
|
968
|
+
return false;
|
|
969
|
+
// Id not set yet means the transfer is in creation mode. Product deletion should be allowed!
|
|
970
|
+
if (!!!data.id)
|
|
971
|
+
return true;
|
|
972
|
+
return [TransferRequest_1.TransferRequestStatusEnum.INITIATED, TransferRequest_1.TransferRequestStatusEnum.OPEN].includes(data.status);
|
|
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
|
+
*/
|
|
979
|
+
TransferRequest.transferShouldDisplayWeight = (data) => {
|
|
980
|
+
return ![TransferRequest_1.TransferRequestStatusEnum.INITIATED].includes(data.status);
|
|
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
|
+
*/
|
|
987
|
+
TransferRequest.transferAllowsIndependantProductUpdate = (data) => {
|
|
988
|
+
if (!!data.completed)
|
|
989
|
+
return false;
|
|
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
|
|
992
|
+
if (!data.associated_order)
|
|
993
|
+
acceptedStatuses.push(TransferRequest_1.TransferRequestStatusEnum.TO_BE_PREPARED);
|
|
994
|
+
return acceptedStatuses.includes(data.status);
|
|
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
|
+
*/
|
|
1001
|
+
TransferRequest.getTotalWeight = (products, unit = 'pounds') => {
|
|
1002
|
+
return (0, sumBy_1.default)(products, (item) => {
|
|
1003
|
+
if (!!!item.weight)
|
|
1004
|
+
return 0;
|
|
1005
|
+
const value = (0, toNumber_1.default)(item.weight.value) || 0;
|
|
1006
|
+
return item.weight.unit === unit ? value * item.qte : (0, weight_1.convertWeight)(value, item.weight.unit, unit) * item.qte;
|
|
1007
|
+
});
|
|
1008
|
+
};
|
|
1009
|
+
/**
|
|
1010
|
+
* Get the total calculated pallet quantities for all transfer items
|
|
1011
|
+
* @param items
|
|
1012
|
+
* @returns
|
|
1013
|
+
*/
|
|
1014
|
+
TransferRequest.getTotalPalletQte = (items) => {
|
|
1015
|
+
const total = (0, sumBy_1.default)(items.map((item) => {
|
|
1016
|
+
if (!!!item.other_units || !!!item.count_in_pallet_total) {
|
|
1017
|
+
return 0;
|
|
1018
|
+
}
|
|
1019
|
+
const paletteUnit = item.other_units.find((u) => u.unit_slug === 'pal');
|
|
1020
|
+
if (!!!paletteUnit || !!!paletteUnit.fitting_unit) {
|
|
1021
|
+
return 0;
|
|
1022
|
+
}
|
|
1023
|
+
return item.qte / paletteUnit.fitting_unit;
|
|
1024
|
+
}));
|
|
1025
|
+
return (0, ceil_1.default)(total);
|
|
1026
|
+
};
|
|
1027
1027
|
//# sourceMappingURL=index.js.map
|