addio-admin-sdk 1.7.186 → 1.7.187-canary-2
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/.env +6 -5
- package/dist/Interfaces/Email/IEmail.d.ts +2 -2
- package/dist/Interfaces/Email/IEmail.js +12 -26
- package/dist/Interfaces/Email/IEmail.js.map +1 -1
- package/dist/lib/Cart/index.d.ts +9 -4
- package/dist/lib/Cart/index.js +95 -59
- package/dist/lib/Cart/index.js.map +1 -1
- package/dist/lib/Inventory/index.d.ts +20 -1
- package/dist/lib/Inventory/index.js +56 -3
- package/dist/lib/Inventory/index.js.map +1 -1
- package/dist/lib/Queue/index.d.ts +40 -0
- package/dist/lib/Queue/index.js +255 -0
- package/dist/lib/Queue/index.js.map +1 -0
- package/dist/lib/TransferRequest/index.d.ts +12 -4
- package/dist/lib/TransferRequest/index.js +96 -16
- package/dist/lib/TransferRequest/index.js.map +1 -1
- package/dist/utils/cart.d.ts +5 -3
- package/dist/utils/cart.js +7 -5
- package/dist/utils/cart.js.map +1 -1
- package/dist/utils/promiseToPurchase.d.ts +35 -2
- package/dist/utils/promiseToPurchase.js +102 -1
- package/dist/utils/promiseToPurchase.js.map +1 -1
- package/dist/utils/services.d.ts +5 -3
- package/dist/utils/services.js +6 -0
- package/dist/utils/services.js.map +1 -1
- package/package.json +5 -5
- package/.claude/settings.local.json +0 -7
package/.env
CHANGED
|
@@ -2,13 +2,14 @@ NEXT_PUBLIC_FIREBASE_CONFIG_API_KEY_DEV='AIzaSyBNtwzdIe2__HJD23S87RIbWbIqKQVtFiw
|
|
|
2
2
|
NEXT_PUBLIC_FIREBASE_CONFIG_API_KEY_PROD='AIzaSyDK6WQZkCrsMGunAPHn9KkdCGPky4hTgL4'
|
|
3
3
|
NEXT_PUBLIC_MESSAGING_SENDER_ID_DEV='188490998694'
|
|
4
4
|
NEXT_PUBLIC_MESSAGING_SENDER_ID_PROD='725873016982'
|
|
5
|
-
NEXT_PUBLIC_FIREBASE_APP_ID_DEV='1:188490998694:web:eecd719e7b18f38d272567'
|
|
6
5
|
NEXT_PUBLIC_FIREBASE_APP_ID_PROD='1:725873016982:web:9b1f6d77819909e19102b7'
|
|
6
|
+
NEXT_PUBLIC_FIREBASE_APP_ID_DEV='1:188490998694:web:eecd719e7b18f38d272567'
|
|
7
7
|
NEXT_PUBLIC_MEASUREMENT_ID_DEV='G-4BB66ZRTWZ'
|
|
8
8
|
NEXT_PUBLIC_MEASUREMENT_ID_PROD='G-BB8HHZ466R'
|
|
9
|
+
|
|
9
10
|
NEXT_PUBLIC_SERVICE_DATABASE_READ_PROVIDER=nobase
|
|
10
|
-
NEXT_PUBLIC_SERVICE_DATABASE_WRITE_PROVIDER=nobase
|
|
11
|
+
NEXT_PUBLIC_SERVICE_DATABASE_WRITE_PROVIDER=nobase
|
|
11
12
|
NEXT_PUBLIC_SERVICE_DATABASE_URL=https://db-test.addiocommerce.com/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
NEXT_PUBLIC_API_URL=https://api-test.addiocommerce.com/v1
|
|
14
|
+
NEXT_PUBLIC_SERVICE_DATABASE_TOKEN='337043a374-6f0be-5eb26-05be550631'
|
|
15
|
+
LOCAL_FIRESTORE=false
|
|
@@ -7,11 +7,11 @@ export default interface IEmail {
|
|
|
7
7
|
export declare const getDefaultEmail: (locale?: string) => {
|
|
8
8
|
TemplateModel: {
|
|
9
9
|
shopping_cart_icon: string;
|
|
10
|
+
check_icon: string;
|
|
11
|
+
mail_icon: string;
|
|
10
12
|
help_label: string;
|
|
11
13
|
preferences_label: string;
|
|
12
14
|
unsubscribe_label: string;
|
|
13
|
-
check_icon: string;
|
|
14
|
-
mail_icon: string;
|
|
15
15
|
socialmedias_items: never[];
|
|
16
16
|
};
|
|
17
17
|
};
|
|
@@ -4,32 +4,18 @@ exports.getDefaultEmailTemplateBySpace = exports.getDefaultEmail = void 0;
|
|
|
4
4
|
const __1 = require("../..");
|
|
5
5
|
const locale_1 = require("../../utils/locale");
|
|
6
6
|
const getDefaultEmail = (locale = 'fr') => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
default:
|
|
21
|
-
return {
|
|
22
|
-
TemplateModel: {
|
|
23
|
-
shopping_cart_icon: `https://gng-ecr${__1.isTestEnv ? '-test' : ''}.imgix.net/1.0.0/emails_src/shopping_cart_icon.png`,
|
|
24
|
-
help_label: 'Nous joindre',
|
|
25
|
-
preferences_label: 'Préférences',
|
|
26
|
-
unsubscribe_label: 'Se désinscrire',
|
|
27
|
-
check_icon: `https://gng-ecr${__1.isTestEnv ? '-test' : ''}.imgix.net/1.0.0/emails_src/check_icon.png`,
|
|
28
|
-
mail_icon: `https://gng-ecr${__1.isTestEnv ? '-test' : ''}.imgix.net/1.0.0/emails_src/mail_icon.png`,
|
|
29
|
-
socialmedias_items: []
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
7
|
+
const baseImgUrl = `https://${__1.isTestEnv ? 'test' : 'beta'}.ecomm.titanestudio.ca/images/emails`;
|
|
8
|
+
return {
|
|
9
|
+
TemplateModel: {
|
|
10
|
+
shopping_cart_icon: `${baseImgUrl}/shopping_cart_icon.png`,
|
|
11
|
+
check_icon: `${baseImgUrl}/check_icon.png`,
|
|
12
|
+
mail_icon: `${baseImgUrl}/mail_icon.png`,
|
|
13
|
+
help_label: (0, locale_1.translateILang)({ fr: 'Nous joindre', en: 'Contact us' }, locale),
|
|
14
|
+
preferences_label: (0, locale_1.translateILang)({ fr: 'Préférences', en: 'Settings' }, locale),
|
|
15
|
+
unsubscribe_label: (0, locale_1.translateILang)({ fr: 'Se désinscrire', en: 'Unsubscribe' }, locale),
|
|
16
|
+
socialmedias_items: []
|
|
17
|
+
}
|
|
18
|
+
};
|
|
33
19
|
};
|
|
34
20
|
exports.getDefaultEmail = getDefaultEmail;
|
|
35
21
|
const getDefaultEmailTemplateBySpace = (space, locale = 'fr') => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IEmail.js","sourceRoot":"","sources":["../../../src/Interfaces/Email/IEmail.ts"],"names":[],"mappings":";;;AACA,6BAAiC;AAEjC,+
|
|
1
|
+
{"version":3,"file":"IEmail.js","sourceRoot":"","sources":["../../../src/Interfaces/Email/IEmail.ts"],"names":[],"mappings":";;;AACA,6BAAiC;AAEjC,+CAA2E;AAQpE,MAAM,eAAe,GAAG,CAAC,SAAiB,IAAI,EAAE,EAAE;IACxD,MAAM,UAAU,GAAG,WAAW,aAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,sCAAsC,CAAA;IAE/F,OAAO;QACN,aAAa,EAAE;YACd,kBAAkB,EAAE,GAAG,UAAU,yBAAyB;YAC1D,UAAU,EAAE,GAAG,UAAU,iBAAiB;YAC1C,SAAS,EAAE,GAAG,UAAU,gBAAgB;YACxC,UAAU,EAAE,IAAA,uBAAc,EAAC,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,MAAM,CAAC;YAC5E,iBAAiB,EAAE,IAAA,uBAAc,EAAC,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,MAAM,CAAC;YAChF,iBAAiB,EAAE,IAAA,uBAAc,EAAC,EAAE,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,MAAM,CAAC;YACtF,kBAAkB,EAAE,EAAE;SACtB;KACD,CAAA;AACF,CAAC,CAAA;AAdY,QAAA,eAAe,mBAc3B;AAEM,MAAM,8BAA8B,GAAG,CAAC,KAAY,EAAE,SAAiB,IAAI,EAAE,EAAE;IACrF,IAAI,YAAY,GAAsC,IAAA,uBAAe,EAAC,MAAM,CAAC,CAAC,aAAa,CAAA;IAC3F,IAAI,aAAa,GAAoC,KAAK,CAAC,IAAI,EAAE,CAAC,aAAa,CAAA;IAC/E,IAAI,CAAC,CAAC,aAAa,EAAE;QACpB,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC1C;YACC,wBAAwB;YACxB,CAAC,CAAC,aAAa;gBACf,+CAA+C;gBAC/C,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC;gBACpB,qCAAqC;gBACrC,CAAC,CAAC,CAAC,kBAAkB,EAAE,0BAA0B,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAC9G;gBACD,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;oBACrD,CAAC,CAAC,+BAA+B;wBAChC,IAAA,+BAAsB,EAAC,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;oBACnD,CAAC,CAAC,gCAAgC;wBACjC,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAA;aAC5B;QACF,CAAC,CAAC,CAAA;QACF,YAAY,mCACR,YAAY,GACZ,aAAa,CAChB,CAAA;KACD;IAED,OAAO;QACN,aAAa,EAAE,YAAY;KAC3B,CAAA;AACF,CAAC,CAAA;AA7BY,QAAA,8BAA8B,kCA6B1C"}
|
package/dist/lib/Cart/index.d.ts
CHANGED
|
@@ -162,6 +162,7 @@ export default class Cart extends BaseServiceClass<ICart> {
|
|
|
162
162
|
usedPromise?: ICartPromiseToPurchase;
|
|
163
163
|
saveToDatabase?: boolean;
|
|
164
164
|
associatedTransferRequests?: TransferRequest[];
|
|
165
|
+
forceApplyInactivePA?: boolean;
|
|
165
166
|
}) => Promise<this | undefined>;
|
|
166
167
|
private defineWhatICanBe;
|
|
167
168
|
checkDiscountConditions: (discount: IDiscountRule) => boolean;
|
|
@@ -274,8 +275,10 @@ export default class Cart extends BaseServiceClass<ICart> {
|
|
|
274
275
|
* @param escompteItems list of discount products from the dash
|
|
275
276
|
* @param customPriceList list of products with their custom pric from G2
|
|
276
277
|
* @param banksUsedForCart Optionnal. Array of banks_used applied to cart
|
|
278
|
+
* @param isCartModification Optionnal. Is it a modification process
|
|
277
279
|
*/
|
|
278
|
-
updateWithPromiseToPurchasePrices: (escompteItems: IndexedProduct[], customPriceList?: string | ICustomPriceItem[] | undefined, banksUsedForCart?: IBankUsed[]) => Promise<void>;
|
|
280
|
+
updateWithPromiseToPurchasePrices: (escompteItems: IndexedProduct[], customPriceList?: string | ICustomPriceItem[] | undefined, banksUsedForCart?: IBankUsed[], isCartModification?: boolean) => Promise<void>;
|
|
281
|
+
removePromiseToPurchaseFromCart: (customPriceList?: string | ICustomPriceItem[] | undefined) => Promise<void>;
|
|
279
282
|
/**
|
|
280
283
|
* Function canBePaidWithMyPromiseToPurchase
|
|
281
284
|
* @description Check if a cart can be paid with a promise to purchase
|
|
@@ -286,7 +289,7 @@ export default class Cart extends BaseServiceClass<ICart> {
|
|
|
286
289
|
* @param forceCartTypeid Optionnal. A cart type ID to use for bank to apply check, if should be forced
|
|
287
290
|
* @returns true if cart can be paid, false if it cannot
|
|
288
291
|
*/
|
|
289
|
-
canBePaidWithMyPromiseToPurchase: (applicableBanks: IApplicablePromiseBank[], applicableBanksHistory: IIndexedBankUsed[], customPriceList?: string | ICustomPriceItem[] | undefined, contingency?: number | undefined, forcedBankTypeId?: string) => Promise<boolean | ApplyBanksToCartErrorsEnum>;
|
|
292
|
+
canBePaidWithMyPromiseToPurchase: (applicableBanks: IApplicablePromiseBank[], applicableBanksHistory: IIndexedBankUsed[], customPriceList?: string | ICustomPriceItem[] | undefined, contingency?: number | undefined, forcedBankTypeId?: string, bypassBankAvailability?: boolean) => Promise<boolean | ApplyBanksToCartErrorsEnum>;
|
|
290
293
|
/**
|
|
291
294
|
* Function calculatePotentialRemainingAmountsAndSetBanksUsedAmounts
|
|
292
295
|
* @description Calculate the amounts that would remain in the promise's banks if we paid this cart with the promise and associates the amounts to use in the banks to the cart
|
|
@@ -295,7 +298,7 @@ export default class Cart extends BaseServiceClass<ICart> {
|
|
|
295
298
|
* @param promiseToPurchase the promise to purchase
|
|
296
299
|
* @returns an array of IBankUsed
|
|
297
300
|
*/
|
|
298
|
-
calculatePotentialRemainingAmountsAndSetBanksUsedAmounts: (remainingAmounts: IBankUsed[], applicableBanks: IApplicablePromiseBank[], forcedBankTypeId?: string | undefined) => IBankUsed[];
|
|
301
|
+
calculatePotentialRemainingAmountsAndSetBanksUsedAmounts: (remainingAmounts: IBankUsed[], applicableBanks: IApplicablePromiseBank[], forcedBankTypeId?: string | undefined, bypassBankAvailability?: boolean) => IBankUsed[];
|
|
299
302
|
private _savePromiseToPurchaseInCart;
|
|
300
303
|
setBankUsed: (bankAmountsUpdated: IBankUsed[]) => void;
|
|
301
304
|
/**
|
|
@@ -306,9 +309,11 @@ export default class Cart extends BaseServiceClass<ICart> {
|
|
|
306
309
|
* @param customPriceList a list of custom price items
|
|
307
310
|
* @param space the space
|
|
308
311
|
* @param forcedCartType Optionnal. If provided, overrides cart type found by check cart item types.
|
|
312
|
+
* @param isCartModification Optionnal. Pass true when called from the POS order modification flow so escompte lines are rebuilt even on a paid cart.
|
|
313
|
+
* @param originalPromiseToPurchase Optionnal. The PA the order was originally paid with. In modification, its banks are re-applied even if now disabled.
|
|
309
314
|
* @returns the updated cart and a boolean canBePaid determining if the cart can be paid with the promise or not
|
|
310
315
|
*/
|
|
311
|
-
canBePaidWithPA: (applicableBanks: IApplicablePromiseBank[], customerID: string, customPriceList: ICustomPriceItem[], space: Space, forcedBankTypeId?: string) => Promise<{
|
|
316
|
+
canBePaidWithPA: (applicableBanks: IApplicablePromiseBank[], customerID: string, customPriceList: ICustomPriceItem[], space: Space, forcedBankTypeId?: string, isCartModification?: boolean, originalPromiseToPurchase?: ICartPromiseToPurchase) => Promise<{
|
|
312
317
|
canBePaid: boolean;
|
|
313
318
|
canBePaidReason?: ApplyBanksToCartErrorsEnum | undefined;
|
|
314
319
|
updatedCart: ICart;
|
package/dist/lib/Cart/index.js
CHANGED
|
@@ -60,7 +60,6 @@ const g2_1 = require("../../rules/GR/utils/g2");
|
|
|
60
60
|
const cart_1 = require("../../utils/cart");
|
|
61
61
|
const promiseToPurchase_1 = require("../../utils/promiseToPurchase");
|
|
62
62
|
const PromiseToPurchase_2 = require("../../Interfaces/PromiseToPurchase");
|
|
63
|
-
const products_2 = require("../../rules/GR/utils/products");
|
|
64
63
|
const baseService_1 = require("../baseService");
|
|
65
64
|
const DatabaseService_1 = __importDefault(require("../../services/database/DatabaseService"));
|
|
66
65
|
const logs_1 = require("../../services/logs");
|
|
@@ -1899,6 +1898,7 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
1899
1898
|
}
|
|
1900
1899
|
};
|
|
1901
1900
|
this.saveCartModification = async (partial, oldItems, newItems, currentUser, options = {}) => {
|
|
1901
|
+
var _b, _c, _d, _e, _f, _g;
|
|
1902
1902
|
// default saveToDatabase to true
|
|
1903
1903
|
const shouldSaveToDB = typeof options.saveToDatabase == 'boolean' ? options.saveToDatabase : true;
|
|
1904
1904
|
try {
|
|
@@ -1906,46 +1906,45 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
1906
1906
|
const space = await Space_2.default.getCurrentSpaceWithRef(this._collection.path, this._user);
|
|
1907
1907
|
if (!!!space)
|
|
1908
1908
|
throw new Error('could not init space obj');
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1909
|
+
const beforeBanksUsed = (_c = (_b = options.usedPromise) === null || _b === void 0 ? void 0 : _b.banks_used) !== null && _c !== void 0 ? _c : [];
|
|
1910
|
+
const afterBanksUsed = (_e = (_d = this.data().promise_to_purchase) === null || _d === void 0 ? void 0 : _d.banks_used) !== null && _e !== void 0 ? _e : [];
|
|
1911
|
+
const adjustmentsToApply = (0, promiseToPurchase_1.getModificationBankAdjustments)(beforeBanksUsed, afterBanksUsed, (_f = this.data().ref) !== null && _f !== void 0 ? _f : '');
|
|
1912
|
+
if (shouldSaveToDB && !!adjustmentsToApply.length) {
|
|
1913
|
+
for (const promiseId of (0, uniq_1.default)(adjustmentsToApply.map((a) => a.promise_id))) {
|
|
1914
|
+
try {
|
|
1915
|
+
const promiseQuery = await space.promisesToPurchase.get({
|
|
1916
|
+
query: [{ field: 'id', operator: '==', value: promiseId }]
|
|
1917
|
+
});
|
|
1918
|
+
if (!!!promiseQuery || !!!promiseQuery.length)
|
|
1919
|
+
continue;
|
|
1920
|
+
const promise = promiseQuery[0];
|
|
1921
|
+
if (!options.forceApplyInactivePA && !!promise.data().ending_date)
|
|
1922
|
+
continue;
|
|
1923
|
+
let newBanks = promise.data().banks;
|
|
1924
|
+
let updated = false;
|
|
1925
|
+
for (const { bank_type_id, adjustment } of adjustmentsToApply.filter((a) => a.promise_id === promiseId)) {
|
|
1926
|
+
const bankInDB = newBanks.find((b) => b.bank_type_id === bank_type_id);
|
|
1927
|
+
if (!!!bankInDB || (!options.forceApplyInactivePA && !!!bankInDB.active))
|
|
1928
|
+
continue;
|
|
1929
|
+
const remaining = await space.promisesToPurchase.getSpecificAvailableBankAmount(promiseId, bank_type_id, promise);
|
|
1930
|
+
const bankNowEmpty = !!remaining && typeof remaining.remaining_amount === 'number'
|
|
1931
|
+
? (0, round_1.default)(remaining.remaining_amount, 3) + (0, round_1.default)(adjustment.amount, 3) < 1
|
|
1932
|
+
: false;
|
|
1933
|
+
const updatedBank = Object.assign(Object.assign(Object.assign({}, bankInDB), { adjustments: [...((_g = bankInDB.adjustments) !== null && _g !== void 0 ? _g : []), Object.assign(Object.assign({}, adjustment), { issued_by: this._user })] }), (!!bankNowEmpty ? { active: false } : {}));
|
|
1934
|
+
newBanks = newBanks.map((b) => (b.bank_type_id === bank_type_id ? updatedBank : b));
|
|
1935
|
+
updated = true;
|
|
1936
|
+
}
|
|
1937
|
+
if (!!updated) {
|
|
1938
|
+
const allBanksInactive = newBanks.every((b) => !!!b.active);
|
|
1939
|
+
await promise.save(Object.assign({ banks: newBanks }, (!!allBanksInactive && !!!promise.data().ending_date ? { ending_date: (0, moment_1.default)().toDate() } : {})));
|
|
1940
|
+
}
|
|
1933
1941
|
}
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
reason: `Modification de la commande #${this.data().ref}`,
|
|
1937
|
-
issued_at: new Date(),
|
|
1938
|
-
issued_by: !!currentUser ? currentUser : (0, services_1.getDefaultSpaceUserEmail)(space.data().id)
|
|
1939
|
-
};
|
|
1940
|
-
const remainingAmount = await space.promisesToPurchase.getSpecificAvailableBankAmount(bank.promise_id, bank.bank_type_id, promiseQuery[0]);
|
|
1941
|
-
let newRemainingAmount;
|
|
1942
|
-
if (!!remainingAmount && !!remainingAmount.remaining_amount) {
|
|
1943
|
-
newRemainingAmount = (0, round_1.default)(remainingAmount.remaining_amount, 3) + (0, round_1.default)(adjustment.amount);
|
|
1942
|
+
catch (e) {
|
|
1943
|
+
console.log('error on adjusting promise for cart modification: ', e.toString());
|
|
1944
1944
|
}
|
|
1945
|
-
await promiseQuery[0].adjustAmountLeftInPromise(adjustment, bank.bank_type_id, !!newRemainingAmount && newRemainingAmount < 1);
|
|
1946
1945
|
}
|
|
1947
1946
|
}
|
|
1948
|
-
await this.save(partial, undefined, shouldSaveToDB, true);
|
|
1947
|
+
await this.save(Object.assign(Object.assign({}, partial), { id: this._data.id }), undefined, shouldSaveToDB, true);
|
|
1949
1948
|
// INVENTORY MANAGEMENT
|
|
1950
1949
|
const data = this.data();
|
|
1951
1950
|
const storeIdToUse = !!data.current_store_id
|
|
@@ -1978,7 +1977,7 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
1978
1977
|
item: i,
|
|
1979
1978
|
qteToUpdate: i.qte,
|
|
1980
1979
|
inventoryItem: allInventoryItems.find((inv) => inv.sku == i.sku)
|
|
1981
|
-
})));
|
|
1980
|
+
})), space.options.get());
|
|
1982
1981
|
if (!!transfersWithItemsToUpdate) {
|
|
1983
1982
|
for (let updatesToDo of Object.entries(transfersWithItemsToUpdate)) {
|
|
1984
1983
|
const [transferID, specifics] = updatesToDo;
|
|
@@ -3302,8 +3301,8 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3302
3301
|
default:
|
|
3303
3302
|
return {
|
|
3304
3303
|
error: '',
|
|
3305
|
-
trackingPin: shipPayload.trackingNumbers,
|
|
3306
|
-
trackingUrl: shipPayload.carrierTrackingUrl
|
|
3304
|
+
trackingPin: shipPayload.trackingNumbers || shipPayload.tracking,
|
|
3305
|
+
trackingUrl: shipPayload.carrierTrackingUrl || shipPayload.trackingUrl
|
|
3307
3306
|
};
|
|
3308
3307
|
}
|
|
3309
3308
|
};
|
|
@@ -3328,12 +3327,14 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3328
3327
|
* @param escompteItems list of discount products from the dash
|
|
3329
3328
|
* @param customPriceList list of products with their custom pric from G2
|
|
3330
3329
|
* @param banksUsedForCart Optionnal. Array of banks_used applied to cart
|
|
3330
|
+
* @param isCartModification Optionnal. Is it a modification process
|
|
3331
3331
|
*/
|
|
3332
|
-
this.updateWithPromiseToPurchasePrices = async (escompteItems, customPriceList = undefined, banksUsedForCart) => {
|
|
3332
|
+
this.updateWithPromiseToPurchasePrices = async (escompteItems, customPriceList = undefined, banksUsedForCart, isCartModification = false) => {
|
|
3333
3333
|
var _b, _c, _d, _e;
|
|
3334
3334
|
if (!!!customPriceList || typeof customPriceList == 'string')
|
|
3335
3335
|
throw new Error('CustomPriceList is undefined!');
|
|
3336
|
-
if (
|
|
3336
|
+
if (!isCartModification &&
|
|
3337
|
+
!!this.data().status &&
|
|
3337
3338
|
this.data().status >= Cart_1.CartStatusEnum.CHECKOUT_PAYMENT_SUCCESS &&
|
|
3338
3339
|
!!this.data().paid_at) {
|
|
3339
3340
|
console.log('cannot update a paid cart with a PA, returning');
|
|
@@ -3397,6 +3398,30 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3397
3398
|
this._data = Object.assign(Object.assign({}, this._data), { items: [...updatedPriceProducts, ...associatedEscomptes] });
|
|
3398
3399
|
await this.calculateTotals();
|
|
3399
3400
|
};
|
|
3401
|
+
// Remove PA ESC supp, revert to the non PA prices and cancel the PA
|
|
3402
|
+
this.removePromiseToPurchaseFromCart = async (customPriceList = undefined) => {
|
|
3403
|
+
if (!!!customPriceList || typeof customPriceList == 'string' || customPriceList.length === 0)
|
|
3404
|
+
throw new Error('CustomPriceList is undefined!');
|
|
3405
|
+
if (!!!this._data.promise_to_purchase)
|
|
3406
|
+
return;
|
|
3407
|
+
const revertedItems = this._data.items
|
|
3408
|
+
.filter((item) => !(0, g2_1.isEscompteSuppItem)(item.sku))
|
|
3409
|
+
.map((item) => {
|
|
3410
|
+
var _b;
|
|
3411
|
+
if (!!!item.is_temp_prod &&
|
|
3412
|
+
!!!item.price_override &&
|
|
3413
|
+
!!!customPriceList.some((p) => p.sku === item.sku)) {
|
|
3414
|
+
(0, logs_1.SystemLog)({
|
|
3415
|
+
clientName: 'sdk-admin | Cart | removePromiseToPurchaseFromCart',
|
|
3416
|
+
clientToken: (_b = process.env.NEXT_PUBLIC_LOG_SYSTEM_KEY) !== null && _b !== void 0 ? _b : ''
|
|
3417
|
+
}, logs_1.LogType.ERROR, `[PA-REVERT] cart=${this._data.id} item=${item.sku} : SKU absent de la liste régulière — impossible de remettre le prix non-PA`);
|
|
3418
|
+
throw new Error(`[PA-REVERT] cart=${this._data.id} item=${item.sku} : SKU absent de la liste régulière — impossible de remettre le prix non-PA`);
|
|
3419
|
+
}
|
|
3420
|
+
return (0, g2_1.checkForCustomPriceEquivalent)(item, customPriceList);
|
|
3421
|
+
});
|
|
3422
|
+
this._data = Object.assign(Object.assign({}, this._data), { items: revertedItems, promise_to_purchase: null });
|
|
3423
|
+
await this.calculateTotals();
|
|
3424
|
+
};
|
|
3400
3425
|
/**
|
|
3401
3426
|
* Function canBePaidWithMyPromiseToPurchase
|
|
3402
3427
|
* @description Check if a cart can be paid with a promise to purchase
|
|
@@ -3407,7 +3432,7 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3407
3432
|
* @param forceCartTypeid Optionnal. A cart type ID to use for bank to apply check, if should be forced
|
|
3408
3433
|
* @returns true if cart can be paid, false if it cannot
|
|
3409
3434
|
*/
|
|
3410
|
-
this.canBePaidWithMyPromiseToPurchase = async (applicableBanks, applicableBanksHistory, customPriceList = undefined, contingency = 0, forcedBankTypeId) => {
|
|
3435
|
+
this.canBePaidWithMyPromiseToPurchase = async (applicableBanks, applicableBanksHistory, customPriceList = undefined, contingency = 0, forcedBankTypeId, bypassBankAvailability = false) => {
|
|
3411
3436
|
if (!!!customPriceList || typeof customPriceList == 'string')
|
|
3412
3437
|
throw new Error(PromiseToPurchase_2.ApplyBanksToCartErrorsEnum.CUSTOM_PRICE_LIST_UNDEFINED);
|
|
3413
3438
|
// NEW - used to have a check here if contingency was undefined, but it makes more sense to let the logic pass, even if no contingency exists (could be a volontary decision from user)
|
|
@@ -3418,14 +3443,17 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3418
3443
|
const remainingAmounts = await PromiseToPurchase_1.default.calculateRemainingAmounts(this, applicableBanks, applicableBanksHistory, space);
|
|
3419
3444
|
// If only one bank is used and said bank has no initial amount, returns empty array
|
|
3420
3445
|
// (so there is no overlap between "bank goes over allowed amount" and "bank is disabled in promise")
|
|
3421
|
-
const potentialRemainingAmounts = this.calculatePotentialRemainingAmountsAndSetBanksUsedAmounts(remainingAmounts, applicableBanks, forcedBankTypeId);
|
|
3446
|
+
const potentialRemainingAmounts = this.calculatePotentialRemainingAmountsAndSetBanksUsedAmounts(remainingAmounts, applicableBanks, forcedBankTypeId, bypassBankAvailability);
|
|
3422
3447
|
// if bank to use has no initial amount, return false
|
|
3423
3448
|
// if payment for any of the banks goes over the remaining amount + the contingency, return false
|
|
3424
|
-
if
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3449
|
+
// If the PA was applied in the creation process, allow applying the PA in modification process even if the bank is inactive
|
|
3450
|
+
if (!bypassBankAvailability) {
|
|
3451
|
+
if (!!!potentialRemainingAmounts.length) {
|
|
3452
|
+
throw new Error(PromiseToPurchase_2.ApplyBanksToCartErrorsEnum.BANK_NOT_FOUND);
|
|
3453
|
+
}
|
|
3454
|
+
if (!!potentialRemainingAmounts.find((bank) => bank.amount + contingency < 0)) {
|
|
3455
|
+
throw new Error(PromiseToPurchase_2.ApplyBanksToCartErrorsEnum.NOT_ENOUGH_REMAINING);
|
|
3456
|
+
}
|
|
3429
3457
|
}
|
|
3430
3458
|
return true;
|
|
3431
3459
|
}
|
|
@@ -3442,7 +3470,7 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3442
3470
|
* @param promiseToPurchase the promise to purchase
|
|
3443
3471
|
* @returns an array of IBankUsed
|
|
3444
3472
|
*/
|
|
3445
|
-
this.calculatePotentialRemainingAmountsAndSetBanksUsedAmounts = (remainingAmounts, applicableBanks, forcedBankTypeId) => {
|
|
3473
|
+
this.calculatePotentialRemainingAmountsAndSetBanksUsedAmounts = (remainingAmounts, applicableBanks, forcedBankTypeId, bypassBankAvailability = false) => {
|
|
3446
3474
|
let accountedForItems = new Array();
|
|
3447
3475
|
let itemsToCheck = this.data().items;
|
|
3448
3476
|
// allow payment only if the cart contains at least one item that is associated to only one bank
|
|
@@ -3484,7 +3512,8 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3484
3512
|
// check that not all banks to use are disabled in the promise to purchase
|
|
3485
3513
|
// if banks to use is disabled make remainingAmounts an empty array :
|
|
3486
3514
|
// the cart won't use bank because no bank corresponding to the cart is enabled in the promise to purchase
|
|
3487
|
-
if
|
|
3515
|
+
// If the PA was applied in the creation process, allow applying the PA in modification process even if the bank is inactive
|
|
3516
|
+
if (!bypassBankAvailability && !!remainingAmounts.length) {
|
|
3488
3517
|
const banksToUse = remainingAmounts;
|
|
3489
3518
|
const promiseBanksToUse = banksToUse
|
|
3490
3519
|
.map((bankToUse) => {
|
|
@@ -3570,7 +3599,7 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3570
3599
|
return priceToPay * item.qte;
|
|
3571
3600
|
});
|
|
3572
3601
|
}
|
|
3573
|
-
if (amountToRemove > 0 && amount < 1)
|
|
3602
|
+
if (!bypassBankAvailability && amountToRemove > 0 && amount < 1)
|
|
3574
3603
|
throw new Error(PromiseToPurchase_2.ApplyBanksToCartErrorsEnum.EMPTY_BANK);
|
|
3575
3604
|
if (amountToRemove > 0) {
|
|
3576
3605
|
// Update banks used array
|
|
@@ -3607,14 +3636,21 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3607
3636
|
* @param customPriceList a list of custom price items
|
|
3608
3637
|
* @param space the space
|
|
3609
3638
|
* @param forcedCartType Optionnal. If provided, overrides cart type found by check cart item types.
|
|
3639
|
+
* @param isCartModification Optionnal. Pass true when called from the POS order modification flow so escompte lines are rebuilt even on a paid cart.
|
|
3640
|
+
* @param originalPromiseToPurchase Optionnal. The PA the order was originally paid with. In modification, its banks are re-applied even if now disabled.
|
|
3610
3641
|
* @returns the updated cart and a boolean canBePaid determining if the cart can be paid with the promise or not
|
|
3611
3642
|
*/
|
|
3612
|
-
this.canBePaidWithPA = async (applicableBanks, customerID, customPriceList, space, forcedBankTypeId) => {
|
|
3643
|
+
this.canBePaidWithPA = async (applicableBanks, customerID, customPriceList, space, forcedBankTypeId, isCartModification = false, originalPromiseToPurchase) => {
|
|
3613
3644
|
const contingency = space.promisesToPurchase.getContingency();
|
|
3614
3645
|
const escomptesItems = await space.promisesToPurchase.getEscompteItems();
|
|
3646
|
+
// In modification, put the order's original PA banks back and ignore disabled bank
|
|
3647
|
+
const bypassBankAvailability = isCartModification && !!originalPromiseToPurchase && !!originalPromiseToPurchase.banks_used.length;
|
|
3648
|
+
const effectiveApplicableBanks = bypassBankAvailability && !!originalPromiseToPurchase
|
|
3649
|
+
? await (0, promiseToPurchase_1.getApplicableBanksWithOrderPA)(applicableBanks, originalPromiseToPurchase, space)
|
|
3650
|
+
: applicableBanks;
|
|
3615
3651
|
// Get use history for applicable banks
|
|
3616
3652
|
let applicableBanksHistory = [];
|
|
3617
|
-
for (let applicable of
|
|
3653
|
+
for (let applicable of effectiveApplicableBanks) {
|
|
3618
3654
|
const { promise_id, bank } = applicable;
|
|
3619
3655
|
// don't fetch history if no initial_amount
|
|
3620
3656
|
if (!!!bank.initial_amount)
|
|
@@ -3632,7 +3668,7 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3632
3668
|
const filteredApplicableBanksHistory = (0, flatten_1.default)(applicableBanksHistory).filter((b) => !!b);
|
|
3633
3669
|
// set possible escomptes in cart so correct amounts are used when checking available amounts
|
|
3634
3670
|
// only set escomptes in cart based on potential applicableBanks where pa is active, bank is active and initial amount is set
|
|
3635
|
-
const possibleBanksToUse =
|
|
3671
|
+
const possibleBanksToUse = effectiveApplicableBanks
|
|
3636
3672
|
.filter((b) => !!b.pa_is_active && !!b.bank.active && !!b.bank.initial_amount)
|
|
3637
3673
|
.map((b) => ({
|
|
3638
3674
|
promise_id: b.promise_id,
|
|
@@ -3640,13 +3676,13 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
3640
3676
|
bank_type_id: b.bank.bank_type_id,
|
|
3641
3677
|
amount: 0
|
|
3642
3678
|
}));
|
|
3643
|
-
await this.updateWithPromiseToPurchasePrices(escomptesItems, customPriceList, possibleBanksToUse);
|
|
3644
|
-
const canBePaidCheck = await this.canBePaidWithMyPromiseToPurchase(
|
|
3679
|
+
await this.updateWithPromiseToPurchasePrices(escomptesItems, customPriceList, possibleBanksToUse, isCartModification);
|
|
3680
|
+
const canBePaidCheck = await this.canBePaidWithMyPromiseToPurchase(effectiveApplicableBanks, filteredApplicableBanksHistory, customPriceList, contingency, forcedBankTypeId, bypassBankAvailability);
|
|
3645
3681
|
// if banks applicable length is different from banks truly applied to cart,
|
|
3646
3682
|
// adjust added escomptes with banks used for cart
|
|
3647
3683
|
if (!!this._data.promise_to_purchase &&
|
|
3648
|
-
|
|
3649
|
-
await this.updateWithPromiseToPurchasePrices(escomptesItems, customPriceList, this._data.promise_to_purchase.banks_used);
|
|
3684
|
+
effectiveApplicableBanks.length !== this._data.promise_to_purchase.banks_used.length) {
|
|
3685
|
+
await this.updateWithPromiseToPurchasePrices(escomptesItems, customPriceList, this._data.promise_to_purchase.banks_used, isCartModification);
|
|
3650
3686
|
}
|
|
3651
3687
|
const canBePaid = typeof canBePaidCheck === 'boolean';
|
|
3652
3688
|
return Object.assign(Object.assign({ canBePaid }, (!!!canBePaid ? { canBePaidReason: canBePaidCheck } : {})), { updatedCart: this.data() });
|