@pisell/pisellos 2.2.193 → 2.2.194

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.
@@ -141,6 +141,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
141
141
  private calculatePaymentTotal;
142
142
  private normalizePaymentSource;
143
143
  private updateTempOrderPaymentStatus;
144
+ private shouldKeepPaymentStatusAfterAmountRecalc;
144
145
  private resolveWalletPassUseValue;
145
146
  private capVoucherPaymentsByRemainingAmount;
146
147
  private calculatePaidPaymentSummary;
@@ -264,7 +265,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
264
265
  private logSubmitBackendRejected;
265
266
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
266
267
  createOrder(params: CommitOrderParams['query']): {
267
- type: "virtual" | "appointment_booking";
268
+ type: "appointment_booking" | "virtual";
268
269
  platform: string;
269
270
  sales_channel: string;
270
271
  order_sales_channel: string;
@@ -41,6 +41,21 @@ import { RulesModule } from "../Rules";
41
41
  import { UnavailableReason } from "../Rules/types";
42
42
  import Decimal from 'decimal.js';
43
43
  import { cloneDeep } from 'lodash-es';
44
+ function normalizeDiscountListSignature(discountList) {
45
+ return (discountList || []).map(function (item) {
46
+ var _item$type, _item$discount_id, _item$order_discount_;
47
+ return {
48
+ type: (_item$type = item === null || item === void 0 ? void 0 : item.type) !== null && _item$type !== void 0 ? _item$type : '',
49
+ discount_id: (_item$discount_id = item === null || item === void 0 ? void 0 : item.discount_id) !== null && _item$discount_id !== void 0 ? _item$discount_id : null,
50
+ order_discount_id: (_item$order_discount_ = item === null || item === void 0 ? void 0 : item.order_discount_id) !== null && _item$order_discount_ !== void 0 ? _item$order_discount_ : null,
51
+ amount: new Decimal(Number(item === null || item === void 0 ? void 0 : item.amount) || 0).toFixed(2)
52
+ };
53
+ });
54
+ }
55
+ function isSameDiscountList(left, right) {
56
+ if (!Array.isArray(left) || !Array.isArray(right)) return false;
57
+ return JSON.stringify(normalizeDiscountListSignature(left)) === JSON.stringify(normalizeDiscountListSignature(right));
58
+ }
44
59
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
45
60
  _inherits(OrderModule, _BaseModule);
46
61
  var _super = _createSuper(OrderModule);
@@ -84,6 +99,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
84
99
  return (products || []).map(function (product) {
85
100
  var _product$metadata, _product$metadata$sou, _product$metadata2, _product$metadata3, _product$original_pri;
86
101
  if ((_product$metadata = product.metadata) !== null && _product$metadata !== void 0 && _product$metadata.is_manual_discount) return product;
102
+ var discountItems = Array.isArray(product.discount_list) ? product.discount_list : [];
103
+ var hasOnlyPersistedDiscountSnapshots = product.order_detail_id !== undefined && product.order_detail_id !== null && discountItems.length > 0 && discountItems.every(function (discount) {
104
+ return (discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== undefined && (discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null;
105
+ });
106
+ if (hasOnlyPersistedDiscountSnapshots) {
107
+ return product;
108
+ }
87
109
  var totalPerUnitDiscount = resolveEffectivePerUnitDiscount(product);
88
110
  var optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
89
111
  var sourcePrice = (_product$metadata$sou = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : '0';
@@ -963,6 +985,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
963
985
  }, {
964
986
  key: "updateTempOrderPaymentStatus",
965
987
  value: function updateTempOrderPaymentStatus(tempOrder) {
988
+ if (this.shouldKeepPaymentStatusAfterAmountRecalc(tempOrder.payment_status)) {
989
+ return;
990
+ }
966
991
  var paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
967
992
  var targetAmount = this.getPaymentTargetAmount();
968
993
  if (targetAmount.lte(0)) {
@@ -975,6 +1000,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
975
1000
  }
976
1001
  tempOrder.payment_status = paymentTotal.gte(targetAmount) ? 'paid' : 'partially_paid';
977
1002
  }
1003
+ }, {
1004
+ key: "shouldKeepPaymentStatusAfterAmountRecalc",
1005
+ value: function shouldKeepPaymentStatusAfterAmountRecalc(paymentStatus) {
1006
+ var normalizedStatus = String(paymentStatus || '').trim().toLowerCase();
1007
+ return normalizedStatus === 'refunded' || normalizedStatus === 'partially_refunded';
1008
+ }
978
1009
  }, {
979
1010
  key: "resolveWalletPassUseValue",
980
1011
  value: function resolveWalletPassUseValue(payment, amount) {
@@ -2120,8 +2151,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2120
2151
  key: "updateOrderProduct",
2121
2152
  value: function () {
2122
2153
  var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
2123
- var _targetProduct$metada2, _product_sku, _metadata, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _nextProduct$metadata, _targetProduct$metada7, _tempOrder$products$p;
2124
- var product_id, product_variant_id, updates, unique_identification_number, identity_key, product_sku, product_bundle, booking, tempOrder, identityLookup, productIndex, targetUid, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, isPersistedOrderLine, callerUpdatesManualPrice, _targetProduct$metada3, _targetProduct$metada4, _targetProduct$metada5, _targetProduct$metada6, existedMeta, normalizedProduct, preservedBookingUid, _normalizedProduct$me, _targetProduct$metada8, productUid, linked;
2154
+ var _targetProduct$metada2, _product_sku, _metadata, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _nextProduct$metadata, _targetProduct$metada8, _tempOrder$products$p;
2155
+ var product_id, product_variant_id, updates, unique_identification_number, identity_key, product_sku, product_bundle, booking, tempOrder, identityLookup, productIndex, targetUid, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, isPersistedOrderLine, callerChangesDiscountList, callerUpdatesManualPrice, _targetProduct$metada3, _targetProduct$metada4, _targetProduct$metada5, _targetProduct$metada6, _targetProduct$metada7, existedMeta, normalizedProduct, preservedBookingUid, _normalizedProduct$me, _targetProduct$metada9, productUid, linked;
2125
2156
  return _regeneratorRuntime().wrap(function _callee14$(_context16) {
2126
2157
  while (1) switch (_context16.prev = _context16.next) {
2127
2158
  case 0:
@@ -2182,7 +2213,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2182
2213
  callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, 'selling_price') || Object.prototype.hasOwnProperty.call(updates || {}, 'original_price');
2183
2214
  callerUpdatesMainMeta = (updates === null || updates === void 0 || (_metadata = updates.metadata) === null || _metadata === void 0 ? void 0 : _metadata.main_product_selling_price) !== undefined || (updates === null || updates === void 0 || (_metadata2 = updates.metadata) === null || _metadata2 === void 0 ? void 0 : _metadata2.main_product_original_price) !== undefined || (updates === null || updates === void 0 || (_metadata3 = updates.metadata) === null || _metadata3 === void 0 ? void 0 : _metadata3.source_product_price) !== undefined;
2184
2215
  isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
2185
- callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata4 = updates.metadata) === null || _metadata4 === void 0 ? void 0 : _metadata4.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata5 = updates.metadata) === null || _metadata5 === void 0 ? void 0 : _metadata5.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata6 = updates.metadata) === null || _metadata6 === void 0 ? void 0 : _metadata6.product_discount_reason) !== undefined || Array.isArray(updates === null || updates === void 0 ? void 0 : updates.discount_list) && updates.discount_list.length > 0;
2216
+ callerChangesDiscountList = Array.isArray(updates === null || updates === void 0 ? void 0 : updates.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
2217
+ callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata4 = updates.metadata) === null || _metadata4 === void 0 ? void 0 : _metadata4.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata5 = updates.metadata) === null || _metadata5 === void 0 ? void 0 : _metadata5.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata6 = updates.metadata) === null || _metadata6 === void 0 ? void 0 : _metadata6.product_discount_reason) !== undefined || callerChangesDiscountList;
2186
2218
  if (isPersistedOrderLine && !callerUpdatesManualPrice) {
2187
2219
  nextProduct.selling_price = targetProduct.selling_price;
2188
2220
  nextProduct.original_price = targetProduct.original_price;
@@ -2191,7 +2223,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2191
2223
  source_product_price: (_targetProduct$metada3 = targetProduct.metadata) === null || _targetProduct$metada3 === void 0 ? void 0 : _targetProduct$metada3.source_product_price,
2192
2224
  main_product_selling_price: (_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.main_product_selling_price,
2193
2225
  main_product_original_price: (_targetProduct$metada5 = targetProduct.metadata) === null || _targetProduct$metada5 === void 0 ? void 0 : _targetProduct$metada5.main_product_original_price,
2194
- price_schema_version: (_targetProduct$metada6 = targetProduct.metadata) === null || _targetProduct$metada6 === void 0 ? void 0 : _targetProduct$metada6.price_schema_version
2226
+ price_schema_version: (_targetProduct$metada6 = (_targetProduct$metada7 = targetProduct.metadata) === null || _targetProduct$metada7 === void 0 ? void 0 : _targetProduct$metada7.price_schema_version) !== null && _targetProduct$metada6 !== void 0 ? _targetProduct$metada6 : 2
2195
2227
  });
2196
2228
  } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
2197
2229
  existedMeta = nextProduct.metadata || {};
@@ -2205,7 +2237,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2205
2237
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
2206
2238
  normalizedProduct = mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct));
2207
2239
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2208
- preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada7 = targetProduct.metadata) === null || _targetProduct$metada7 === void 0 ? void 0 : _targetProduct$metada7.booking_uid);
2240
+ preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.booking_uid);
2209
2241
  if (!booking && preservedBookingUid) {
2210
2242
  normalizedProduct.booking_uid = preservedBookingUid;
2211
2243
  normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
@@ -2213,7 +2245,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2213
2245
  });
2214
2246
  }
2215
2247
  if (booking) {
2216
- productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.unique_identification_number) || unique_identification_number || createUuidV4());
2248
+ productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.unique_identification_number) || unique_identification_number || createUuidV4());
2217
2249
  normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
2218
2250
  unique_identification_number: productUid
2219
2251
  });
@@ -2235,19 +2267,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2235
2267
  }
2236
2268
  tempOrder.products[productIndex] = normalizedProduct;
2237
2269
  this.captureProductRuntime(tempOrder, updates, tempOrder.products[productIndex], (_tempOrder$products$p = tempOrder.products[productIndex].metadata) === null || _tempOrder$products$p === void 0 ? void 0 : _tempOrder$products$p.unique_identification_number);
2238
- _context16.next = 29;
2270
+ _context16.next = 30;
2239
2271
  return this.applyPromotion();
2240
- case 29:
2272
+ case 30:
2241
2273
  this.applyDiscount();
2242
2274
  this.sanitizeTempOrderProducts(tempOrder);
2243
- _context16.next = 33;
2275
+ _context16.next = 34;
2244
2276
  return this.recalculateSummary({
2245
2277
  createIfMissing: true
2246
2278
  });
2247
- case 33:
2279
+ case 34:
2248
2280
  this.persistTempOrder();
2249
2281
  return _context16.abrupt("return", tempOrder.products);
2250
- case 35:
2282
+ case 36:
2251
2283
  case "end":
2252
2284
  return _context16.stop();
2253
2285
  }
@@ -2262,7 +2294,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2262
2294
  key: "updateOrderProductQuantity",
2263
2295
  value: function () {
2264
2296
  var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
2265
- var _targetProduct$metada9;
2297
+ var _targetProduct$metada10;
2266
2298
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
2267
2299
  return _regeneratorRuntime().wrap(function _callee15$(_context17) {
2268
2300
  while (1) switch (_context17.prev = _context17.next) {
@@ -2303,7 +2335,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2303
2335
  normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
2304
2336
  num: getSafeProductNum(num),
2305
2337
  metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
2306
- unique_identification_number: ((_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.unique_identification_number) || unique_identification_number
2338
+ unique_identification_number: ((_targetProduct$metada10 = targetProduct.metadata) === null || _targetProduct$metada10 === void 0 ? void 0 : _targetProduct$metada10.unique_identification_number) || unique_identification_number
2307
2339
  })
2308
2340
  }));
2309
2341
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
@@ -179,7 +179,7 @@ export function buildManualProductDiscountItem(params) {
179
179
  var diff = origin.minus(selling);
180
180
  var quantity = resolveSafeProductNum(params.quantity);
181
181
  return {
182
- amount: diff.abs().toDecimalPlaces(2).toNumber(),
182
+ amount: diff.toDecimalPlaces(2).toNumber(),
183
183
  type: 'product',
184
184
  discount: {
185
185
  message: (_params$message = params.message) !== null && _params$message !== void 0 ? _params$message : '',
@@ -43,30 +43,5 @@ export declare class SalesSummaryModule extends BaseModule implements Module, Sa
43
43
  rounding_amount: string;
44
44
  pay_service_charge_amount: string;
45
45
  is_price_include_tax?: number | undefined;
46
- } | {
47
- tax_title: string;
48
- tax_rate: number | undefined;
49
- product_quantity: number;
50
- product_original_amount: string;
51
- product_amount: string;
52
- product_expect_amount: string;
53
- product_tax_fee: string;
54
- shipping_fee: string;
55
- shipping_tax_fee: string;
56
- tax_fee: string;
57
- surcharge_fee: string;
58
- surcharges: any;
59
- discount_amount: string;
60
- deposit_amount: string;
61
- deposit: import("./types").DepositInfo | undefined;
62
- expect_amount: string;
63
- total_amount: string;
64
- total_refund_amount: string;
65
- customer_paid_amount: string;
66
- order_paid_amount: string;
67
- amount_gap: string;
68
- rounding_amount: string;
69
- pay_service_charge_amount: string;
70
- is_price_include_tax: number;
71
46
  }>;
72
47
  }
@@ -1,4 +1,5 @@
1
1
  export interface SalesSummaryProduct {
2
+ order_detail_id?: number | string | null;
2
3
  product_id: number | null;
3
4
  product_variant_id: number;
4
5
  num: number;
@@ -1,4 +1,4 @@
1
- import type { DepositInfo, SalesSummaryData, SalesSummaryProduct } from './types';
1
+ import type { SalesSummaryData, SalesSummaryProduct } from './types';
2
2
  export declare function createEmptySalesSummary(): SalesSummaryData;
3
3
  export declare function calculateSalesSummary(params: {
4
4
  products: SalesSummaryProduct[];
@@ -8,27 +8,4 @@ export declare function calculateSalesSummary(params: {
8
8
  scheduleById?: Record<string, any>;
9
9
  isInScheduleByDate?: any;
10
10
  shopDiscount?: string | number;
11
- }): SalesSummaryData | {
12
- product_quantity: number;
13
- product_original_amount: string;
14
- product_amount: string;
15
- product_expect_amount: string;
16
- product_tax_fee: string;
17
- shipping_fee: string;
18
- shipping_tax_fee: string;
19
- tax_fee: string;
20
- surcharge_fee: string;
21
- surcharges: any;
22
- discount_amount: string;
23
- deposit_amount: string;
24
- deposit: DepositInfo | undefined;
25
- expect_amount: string;
26
- total_amount: string;
27
- total_refund_amount: string;
28
- customer_paid_amount: string;
29
- order_paid_amount: string;
30
- amount_gap: string;
31
- rounding_amount: string;
32
- pay_service_charge_amount: string;
33
- is_price_include_tax: number;
34
- };
11
+ }): SalesSummaryData;