@pisell/pisellos 2.2.193 → 2.2.195

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.
@@ -83,6 +83,7 @@ export function buildNormalProductCacheItemFromOrderLine(input) {
83
83
  var bundle = mapOrderBundleToOtherBundle(Array.isArray(product.product_bundle) ? product.product_bundle : []);
84
84
  var originExtend = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 || (_product$metadata2 = _product$metadata2.origin) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2._extend;
85
85
  var productOptionString = buildProductOptionStringFromOrderLine(product);
86
+ var discountList = product.discount_list || [];
86
87
  var other = {
87
88
  product_id: resolvedId,
88
89
  product_variant_id: (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : 0,
@@ -132,6 +133,7 @@ export function buildNormalProductCacheItemFromOrderLine(input) {
132
133
  } : {}), {}, {
133
134
  note: product.note,
134
135
  order_detail_id: (_product$order_detail = product.order_detail_id) !== null && _product$order_detail !== void 0 ? _product$order_detail : null,
136
+ discount_list: discountList,
135
137
  new: 0,
136
138
  autoClose: true,
137
139
  _extend: extend
@@ -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;
@@ -41,6 +41,27 @@ 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
+ }
59
+ function isManualProductDiscountProduct(product) {
60
+ var _product$metadata, _product$metadata2;
61
+ return (product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.is_manual_discount) === true || (product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.is_manual_discount) === 1 || ((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (item) {
62
+ return (item === null || item === void 0 ? void 0 : item.type) === 'product';
63
+ });
64
+ }
44
65
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
45
66
  _inherits(OrderModule, _BaseModule);
46
67
  var _super = _createSuper(OrderModule);
@@ -82,11 +103,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
82
103
  key: "applyProductDiscountPrices",
83
104
  value: function applyProductDiscountPrices(products) {
84
105
  return (products || []).map(function (product) {
85
- var _product$metadata, _product$metadata$sou, _product$metadata2, _product$metadata3, _product$original_pri;
86
- if ((_product$metadata = product.metadata) !== null && _product$metadata !== void 0 && _product$metadata.is_manual_discount) return product;
106
+ var _product$metadata$sou, _product$metadata3, _product$metadata4, _product$original_pri;
107
+ if (isManualProductDiscountProduct(product)) return product;
108
+ var discountItems = Array.isArray(product.discount_list) ? product.discount_list : [];
109
+ var hasOnlyPersistedDiscountSnapshots = product.order_detail_id !== undefined && product.order_detail_id !== null && discountItems.length > 0 && discountItems.every(function (discount) {
110
+ 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;
111
+ });
112
+ if (hasOnlyPersistedDiscountSnapshots) {
113
+ return product;
114
+ }
87
115
  var totalPerUnitDiscount = resolveEffectivePerUnitDiscount(product);
88
116
  var optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
89
- 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';
117
+ var sourcePrice = (_product$metadata$sou = (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.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';
90
118
  var newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
91
119
  var newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
92
120
  if (product.metadata) {
@@ -426,6 +454,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
426
454
  var _ref2;
427
455
  var uid = getOrderProductLineUid(product);
428
456
  var previous = (_ref2 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref2 !== void 0 ? _ref2 : previousProductsByUid.get("__index__:".concat(index));
457
+ if (isManualProductDiscountProduct(previous)) {
458
+ return previous;
459
+ }
429
460
  var mergedProduct = previous ? mergeOrderProductDisplayFields(previous, product) : product;
430
461
  return _objectSpread(_objectSpread({}, mergedProduct), {}, {
431
462
  discount_list: normalizeOrderProductDiscountList(syncManualProductDiscountProductNum(mergedProduct.discount_list, mergedProduct.num))
@@ -963,6 +994,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
963
994
  }, {
964
995
  key: "updateTempOrderPaymentStatus",
965
996
  value: function updateTempOrderPaymentStatus(tempOrder) {
997
+ if (this.shouldKeepPaymentStatusAfterAmountRecalc(tempOrder.payment_status)) {
998
+ return;
999
+ }
966
1000
  var paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
967
1001
  var targetAmount = this.getPaymentTargetAmount();
968
1002
  if (targetAmount.lte(0)) {
@@ -975,6 +1009,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
975
1009
  }
976
1010
  tempOrder.payment_status = paymentTotal.gte(targetAmount) ? 'paid' : 'partially_paid';
977
1011
  }
1012
+ }, {
1013
+ key: "shouldKeepPaymentStatusAfterAmountRecalc",
1014
+ value: function shouldKeepPaymentStatusAfterAmountRecalc(paymentStatus) {
1015
+ var normalizedStatus = String(paymentStatus || '').trim().toLowerCase();
1016
+ return normalizedStatus === 'refunded' || normalizedStatus === 'partially_refunded';
1017
+ }
978
1018
  }, {
979
1019
  key: "resolveWalletPassUseValue",
980
1020
  value: function resolveWalletPassUseValue(payment, amount) {
@@ -1450,11 +1490,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1450
1490
  }, {
1451
1491
  key: "removeLinkedBookingsForProduct",
1452
1492
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
1453
- var _product$metadata4,
1454
- _product$metadata5,
1493
+ var _product$metadata5,
1494
+ _product$metadata6,
1455
1495
  _this7 = this;
1456
- var productUid = (product === null || product === void 0 || (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
1457
- var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.booking_uid);
1496
+ var productUid = (product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
1497
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
1458
1498
  if (!productUid && !bookingUid) return;
1459
1499
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
1460
1500
  var currentBookingUid = _this7.getBookingUniqueIdentificationNumber(booking);
@@ -1989,7 +2029,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1989
2029
  value: function () {
1990
2030
  var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(product, booking) {
1991
2031
  var _this10 = this;
1992
- var tempOrder, linked, productToAdd, incomingFingerprint, normalizedIncoming, hasIncomingGoodPass, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct;
2032
+ var tempOrder, linked, productToAdd, incomingFingerprint, normalizedIncoming, hasIncomingGoodPass, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
1993
2033
  return _regeneratorRuntime().wrap(function _callee13$(_context15) {
1994
2034
  while (1) switch (_context15.prev = _context15.next) {
1995
2035
  case 0:
@@ -2054,7 +2094,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2054
2094
  })
2055
2095
  })));
2056
2096
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2057
- tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
2097
+ nextNum = getSafeProductNum(targetProduct.num + normalizedProduct.num);
2098
+ targetIsManualProductDiscount = isManualProductDiscountProduct(targetProduct);
2099
+ nextDiscountList = targetIsManualProductDiscount ? normalizeOrderProductDiscountList(syncManualProductDiscountProductNum(targetProduct.discount_list, nextNum)) : normalizedProduct.discount_list;
2100
+ tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
2101
+ discount_list: nextDiscountList,
2058
2102
  metadata: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.metadata || {}), normalizedProduct.metadata || {}), {}, {
2059
2103
  unique_identification_number: targetUid
2060
2104
  }),
@@ -2064,10 +2108,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2064
2108
  option: []
2065
2109
  }), {}, {
2066
2110
  option: getProductSkuOptions(normalizedProduct)
2067
- }),
2111
+ })
2112
+ }, targetIsManualProductDiscount ? {
2113
+ selling_price: targetProduct.selling_price,
2114
+ original_price: targetProduct.original_price,
2115
+ payment_price: targetProduct.payment_price,
2116
+ metadata: _objectSpread(_objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), targetProduct.metadata || {}), {}, {
2117
+ unique_identification_number: targetUid
2118
+ })
2119
+ } : {}), {}, {
2068
2120
  note: targetProduct.note,
2069
2121
  order_detail_id: targetProduct.order_detail_id,
2070
- num: getSafeProductNum(targetProduct.num + normalizedProduct.num)
2122
+ num: nextNum
2071
2123
  });
2072
2124
  this.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
2073
2125
  }
@@ -2120,8 +2172,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2120
2172
  key: "updateOrderProduct",
2121
2173
  value: function () {
2122
2174
  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;
2175
+ var _targetProduct$metada2, _product_sku, _metadata, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _nextProduct$metadata, _targetProduct$metada8, _tempOrder$products$p;
2176
+ 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
2177
  return _regeneratorRuntime().wrap(function _callee14$(_context16) {
2126
2178
  while (1) switch (_context16.prev = _context16.next) {
2127
2179
  case 0:
@@ -2182,7 +2234,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2182
2234
  callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, 'selling_price') || Object.prototype.hasOwnProperty.call(updates || {}, 'original_price');
2183
2235
  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
2236
  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;
2237
+ 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);
2238
+ 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
2239
  if (isPersistedOrderLine && !callerUpdatesManualPrice) {
2187
2240
  nextProduct.selling_price = targetProduct.selling_price;
2188
2241
  nextProduct.original_price = targetProduct.original_price;
@@ -2191,7 +2244,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2191
2244
  source_product_price: (_targetProduct$metada3 = targetProduct.metadata) === null || _targetProduct$metada3 === void 0 ? void 0 : _targetProduct$metada3.source_product_price,
2192
2245
  main_product_selling_price: (_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.main_product_selling_price,
2193
2246
  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
2247
+ 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
2248
  });
2196
2249
  } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
2197
2250
  existedMeta = nextProduct.metadata || {};
@@ -2205,7 +2258,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2205
2258
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
2206
2259
  normalizedProduct = mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct));
2207
2260
  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);
2261
+ 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
2262
  if (!booking && preservedBookingUid) {
2210
2263
  normalizedProduct.booking_uid = preservedBookingUid;
2211
2264
  normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
@@ -2213,7 +2266,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2213
2266
  });
2214
2267
  }
2215
2268
  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());
2269
+ 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
2270
  normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
2218
2271
  unique_identification_number: productUid
2219
2272
  });
@@ -2235,19 +2288,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2235
2288
  }
2236
2289
  tempOrder.products[productIndex] = normalizedProduct;
2237
2290
  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;
2291
+ _context16.next = 30;
2239
2292
  return this.applyPromotion();
2240
- case 29:
2293
+ case 30:
2241
2294
  this.applyDiscount();
2242
2295
  this.sanitizeTempOrderProducts(tempOrder);
2243
- _context16.next = 33;
2296
+ _context16.next = 34;
2244
2297
  return this.recalculateSummary({
2245
2298
  createIfMissing: true
2246
2299
  });
2247
- case 33:
2300
+ case 34:
2248
2301
  this.persistTempOrder();
2249
2302
  return _context16.abrupt("return", tempOrder.products);
2250
- case 35:
2303
+ case 36:
2251
2304
  case "end":
2252
2305
  return _context16.stop();
2253
2306
  }
@@ -2262,7 +2315,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2262
2315
  key: "updateOrderProductQuantity",
2263
2316
  value: function () {
2264
2317
  var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
2265
- var _targetProduct$metada9;
2318
+ var _targetProduct$metada10;
2266
2319
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
2267
2320
  return _regeneratorRuntime().wrap(function _callee15$(_context17) {
2268
2321
  while (1) switch (_context17.prev = _context17.next) {
@@ -2303,7 +2356,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2303
2356
  normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
2304
2357
  num: getSafeProductNum(num),
2305
2358
  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
2359
+ unique_identification_number: ((_targetProduct$metada10 = targetProduct.metadata) === null || _targetProduct$metada10 === void 0 ? void 0 : _targetProduct$metada10.unique_identification_number) || unique_identification_number
2307
2360
  })
2308
2361
  }));
2309
2362
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
@@ -3242,11 +3295,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3242
3295
  _step9;
3243
3296
  try {
3244
3297
  for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
3245
- var _product$metadata6, _ref24, _ref25, _existed$origin, _rawProduct$metadata;
3298
+ var _product$metadata7, _ref24, _ref25, _existed$origin, _rawProduct$metadata;
3246
3299
  var _step9$value = _slicedToArray(_step9.value, 2),
3247
3300
  index = _step9$value[0],
3248
3301
  product = _step9$value[1];
3249
- var uid = (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.unique_identification_number;
3302
+ var uid = (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.unique_identification_number;
3250
3303
  if (!uid) continue;
3251
3304
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
3252
3305
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
@@ -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;