@pisell/pisellos 2.2.194 → 2.2.196

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
@@ -150,6 +150,8 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
150
150
  private formatSummaryMetadataMoney;
151
151
  private syncSummaryProductMetadata;
152
152
  private calculateSummaryAmountGap;
153
+ private getSummaryRefundAmount;
154
+ private calculatePaymentTargetAmount;
153
155
  private getPaymentTargetAmount;
154
156
  ensureTempOrder(): OrderTempOrder;
155
157
  restoreOrder(): OrderTempOrder;
@@ -265,7 +267,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
265
267
  private logSubmitBackendRejected;
266
268
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
267
269
  createOrder(params: CommitOrderParams['query']): {
268
- type: "appointment_booking" | "virtual";
270
+ type: "virtual" | "appointment_booking";
269
271
  platform: string;
270
272
  sales_channel: string;
271
273
  order_sales_channel: string;
@@ -56,6 +56,12 @@ function isSameDiscountList(left, right) {
56
56
  if (!Array.isArray(left) || !Array.isArray(right)) return false;
57
57
  return JSON.stringify(normalizeDiscountListSignature(left)) === JSON.stringify(normalizeDiscountListSignature(right));
58
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
+ }
59
65
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
60
66
  _inherits(OrderModule, _BaseModule);
61
67
  var _super = _createSuper(OrderModule);
@@ -97,8 +103,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
97
103
  key: "applyProductDiscountPrices",
98
104
  value: function applyProductDiscountPrices(products) {
99
105
  return (products || []).map(function (product) {
100
- var _product$metadata, _product$metadata$sou, _product$metadata2, _product$metadata3, _product$original_pri;
101
- 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;
102
108
  var discountItems = Array.isArray(product.discount_list) ? product.discount_list : [];
103
109
  var hasOnlyPersistedDiscountSnapshots = product.order_detail_id !== undefined && product.order_detail_id !== null && discountItems.length > 0 && discountItems.every(function (discount) {
104
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;
@@ -108,7 +114,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
108
114
  }
109
115
  var totalPerUnitDiscount = resolveEffectivePerUnitDiscount(product);
110
116
  var optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
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';
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';
112
118
  var newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
113
119
  var newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
114
120
  if (product.metadata) {
@@ -448,6 +454,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
448
454
  var _ref2;
449
455
  var uid = getOrderProductLineUid(product);
450
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
+ }
451
460
  var mergedProduct = previous ? mergeOrderProductDisplayFields(previous, product) : product;
452
461
  return _objectSpread(_objectSpread({}, mergedProduct), {}, {
453
462
  discount_list: normalizeOrderProductDiscountList(syncManualProductDiscountProductNum(mergedProduct.discount_list, mergedProduct.num))
@@ -984,27 +993,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
984
993
  }
985
994
  }, {
986
995
  key: "updateTempOrderPaymentStatus",
987
- value: function updateTempOrderPaymentStatus(tempOrder) {
988
- if (this.shouldKeepPaymentStatusAfterAmountRecalc(tempOrder.payment_status)) {
996
+ value: function updateTempOrderPaymentStatus(tempOrder, options) {
997
+ var summary = (options === null || options === void 0 ? void 0 : options.summary) || this.store.summary || createEmptySummary();
998
+ var paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
999
+ var refundAmount = this.getSummaryRefundAmount(summary);
1000
+ var netPaymentTotal = Decimal.max(paymentTotal.minus(refundAmount), 0);
1001
+ var targetAmount = this.calculatePaymentTargetAmount(tempOrder, summary);
1002
+ if (this.shouldKeepPaymentStatusAfterAmountRecalc(tempOrder.payment_status, {
1003
+ netPaymentTotal: netPaymentTotal,
1004
+ paymentTotal: paymentTotal,
1005
+ refundAmount: refundAmount,
1006
+ targetAmount: targetAmount,
1007
+ previousSummary: options === null || options === void 0 ? void 0 : options.previousSummary,
1008
+ tempOrder: tempOrder
1009
+ })) {
989
1010
  return;
990
1011
  }
991
- var paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
992
- var targetAmount = this.getPaymentTargetAmount();
993
1012
  if (targetAmount.lte(0)) {
994
1013
  tempOrder.payment_status = 'paid';
995
1014
  return;
996
1015
  }
997
- if (paymentTotal.lte(0)) {
1016
+ if (netPaymentTotal.lte(0)) {
998
1017
  tempOrder.payment_status = 'payment_processing';
999
1018
  return;
1000
1019
  }
1001
- tempOrder.payment_status = paymentTotal.gte(targetAmount) ? 'paid' : 'partially_paid';
1020
+ tempOrder.payment_status = netPaymentTotal.gte(targetAmount) ? 'paid' : 'partially_paid';
1002
1021
  }
1003
1022
  }, {
1004
1023
  key: "shouldKeepPaymentStatusAfterAmountRecalc",
1005
- value: function shouldKeepPaymentStatusAfterAmountRecalc(paymentStatus) {
1024
+ value: function shouldKeepPaymentStatusAfterAmountRecalc(paymentStatus, params) {
1006
1025
  var normalizedStatus = String(paymentStatus || '').trim().toLowerCase();
1007
- return normalizedStatus === 'refunded' || normalizedStatus === 'partially_refunded';
1026
+ if (normalizedStatus !== 'refunded' && normalizedStatus !== 'partially_refunded') {
1027
+ return false;
1028
+ }
1029
+ if (params.refundAmount.lte(0)) return false;
1030
+ if (params.previousSummary) {
1031
+ var previousTargetAmount = this.calculatePaymentTargetAmount(params.tempOrder, params.previousSummary);
1032
+ if (!previousTargetAmount.eq(params.targetAmount)) return false;
1033
+ }
1034
+ if (normalizedStatus === 'refunded') {
1035
+ return params.refundAmount.gte(params.paymentTotal);
1036
+ }
1037
+ return params.netPaymentTotal.gte(params.targetAmount);
1008
1038
  }
1009
1039
  }, {
1010
1040
  key: "resolveWalletPassUseValue",
@@ -1165,20 +1195,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1165
1195
  var tempOrder = params.tempOrder,
1166
1196
  summary = params.summary,
1167
1197
  orderPaidAmount = params.orderPaidAmount;
1198
+ var refundAmount = this.getSummaryRefundAmount(summary);
1199
+ var netOrderPaidAmount = Decimal.max(orderPaidAmount.minus(refundAmount), 0);
1200
+ var targetAmount = this.calculatePaymentTargetAmount(tempOrder, summary);
1201
+ return targetAmount.minus(netOrderPaidAmount).toFixed(2);
1202
+ }
1203
+ }, {
1204
+ key: "getSummaryRefundAmount",
1205
+ value: function getSummaryRefundAmount(summary) {
1206
+ return Decimal.max(new Decimal((summary === null || summary === void 0 ? void 0 : summary.total_refund_amount) || 0), 0);
1207
+ }
1208
+ }, {
1209
+ key: "calculatePaymentTargetAmount",
1210
+ value: function calculatePaymentTargetAmount(tempOrder, summary) {
1168
1211
  var depositAmount = summary.deposit_amount || tempOrder.deposit_amount || '0.00';
1169
1212
  var isDeposit = tempOrder.is_deposit === 1 || new Decimal(depositAmount || 0).gt(0);
1170
- var targetAmount = isDeposit ? new Decimal(depositAmount || 0) : new Decimal(summary.total_amount || summary.expect_amount || 0);
1171
- return targetAmount.minus(orderPaidAmount).toFixed(2);
1213
+ return isDeposit ? new Decimal(depositAmount || 0) : new Decimal(summary.total_amount || summary.expect_amount || 0);
1172
1214
  }
1173
1215
  }, {
1174
1216
  key: "getPaymentTargetAmount",
1175
1217
  value: function getPaymentTargetAmount() {
1176
1218
  var tempOrder = this.ensureTempOrder();
1177
1219
  var summary = this.store.summary || createEmptySummary();
1178
- if (tempOrder.is_deposit === 1) {
1179
- return new Decimal(tempOrder.deposit_amount || summary.deposit_amount || 0);
1180
- }
1181
- return new Decimal(summary.total_amount || summary.expect_amount || 0);
1220
+ return this.calculatePaymentTargetAmount(tempOrder, summary);
1182
1221
  }
1183
1222
  }, {
1184
1223
  key: "ensureTempOrder",
@@ -1302,9 +1341,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1302
1341
  if (!tempOrder) return null;
1303
1342
  var summary = this.store.summary || createEmptySummary();
1304
1343
  var depositAmount = tempOrder.deposit_amount || summary.deposit_amount || '0.00';
1305
- var targetAmount = tempOrder.is_deposit === 1 ? new Decimal(depositAmount || 0) : new Decimal(summary.total_amount || summary.expect_amount || 0);
1306
- var paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
1307
- var amountGap = targetAmount.minus(paymentTotal).toFixed(2);
1344
+ var paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
1345
+ var amountGap = this.calculateSummaryAmountGap({
1346
+ tempOrder: tempOrder,
1347
+ summary: summary,
1348
+ orderPaidAmount: paidPaymentSummary.gapPaidAmount
1349
+ });
1308
1350
  return {
1309
1351
  isDeposit: tempOrder.is_deposit === 1 || depositAmount !== '0.00',
1310
1352
  depositAmount: depositAmount,
@@ -1481,11 +1523,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1481
1523
  }, {
1482
1524
  key: "removeLinkedBookingsForProduct",
1483
1525
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
1484
- var _product$metadata4,
1485
- _product$metadata5,
1526
+ var _product$metadata5,
1527
+ _product$metadata6,
1486
1528
  _this7 = this;
1487
- 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);
1488
- 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);
1529
+ 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);
1530
+ 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);
1489
1531
  if (!productUid && !bookingUid) return;
1490
1532
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
1491
1533
  var currentBookingUid = _this7.getBookingUniqueIdentificationNumber(booking);
@@ -1506,7 +1548,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1506
1548
  key: "recalculateSummary",
1507
1549
  value: function () {
1508
1550
  var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(options) {
1509
- var tempOrder, salesSummary, existedSummary, paidPaymentSummary, emptySummary, salesSummaryResult, summary;
1551
+ var tempOrder, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummary, salesSummaryResult, summaryForGap, summary;
1510
1552
  return _regeneratorRuntime().wrap(function _callee9$(_context11) {
1511
1553
  while (1) switch (_context11.prev = _context11.next) {
1512
1554
  case 0:
@@ -1520,43 +1562,52 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1520
1562
  this.sanitizeTempOrderProducts(tempOrder);
1521
1563
  salesSummary = this.getSalesSummary();
1522
1564
  existedSummary = this.store.summary || createEmptySummary();
1565
+ totalRefundAmount = existedSummary.total_refund_amount || '0.00';
1523
1566
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
1524
1567
  if (salesSummary) {
1525
- _context11.next = 13;
1568
+ _context11.next = 15;
1526
1569
  break;
1527
1570
  }
1528
- emptySummary = _objectSpread(_objectSpread({}, createEmptySummary()), {}, {
1529
- total_refund_amount: existedSummary.total_refund_amount || '0.00',
1571
+ emptyBaseSummary = _objectSpread(_objectSpread({}, createEmptySummary()), {}, {
1572
+ total_refund_amount: totalRefundAmount
1573
+ });
1574
+ emptySummary = _objectSpread(_objectSpread({}, emptyBaseSummary), {}, {
1530
1575
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
1531
1576
  order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
1532
1577
  amount_gap: this.calculateSummaryAmountGap({
1533
1578
  tempOrder: tempOrder,
1534
- summary: createEmptySummary(),
1579
+ summary: emptyBaseSummary,
1535
1580
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
1536
1581
  }),
1537
1582
  pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
1538
1583
  });
1539
1584
  tempOrder.surcharge_fee = emptySummary.surcharge_fee;
1540
- this.updateTempOrderPaymentStatus(tempOrder);
1541
1585
  this.store.summary = emptySummary;
1586
+ this.updateTempOrderPaymentStatus(tempOrder, {
1587
+ previousSummary: existedSummary,
1588
+ summary: emptySummary
1589
+ });
1542
1590
  return _context11.abrupt("return", this.store.summary);
1543
- case 13:
1544
- _context11.next = 15;
1591
+ case 15:
1592
+ _context11.next = 17;
1545
1593
  return salesSummary.getSummary({
1546
1594
  products: tempOrder.products,
1547
1595
  isPriceIncludeTax: tempOrder.is_price_include_tax,
1548
1596
  shopDiscount: tempOrder.shop_discount
1549
1597
  });
1550
- case 15:
1598
+ case 17:
1551
1599
  salesSummaryResult = _context11.sent;
1552
1600
  this.syncSummaryProductMetadata(tempOrder.products || []);
1601
+ summaryForGap = _objectSpread(_objectSpread({}, salesSummaryResult), {}, {
1602
+ total_refund_amount: totalRefundAmount
1603
+ });
1553
1604
  summary = _objectSpread(_objectSpread({}, salesSummaryResult), {}, {
1554
- total_refund_amount: existedSummary.total_refund_amount || '0.00',
1605
+ total_refund_amount: totalRefundAmount,
1555
1606
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
1556
1607
  order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
1557
1608
  amount_gap: this.calculateSummaryAmountGap({
1558
1609
  tempOrder: tempOrder,
1559
- summary: salesSummaryResult,
1610
+ summary: summaryForGap,
1560
1611
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
1561
1612
  }),
1562
1613
  pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
@@ -1572,9 +1623,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1572
1623
  tempOrder.surcharges = summary.surcharges || [];
1573
1624
  tempOrder.deposit_amount = summary.deposit_amount || '0.00';
1574
1625
  tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
1575
- this.updateTempOrderPaymentStatus(tempOrder);
1626
+ this.updateTempOrderPaymentStatus(tempOrder, {
1627
+ previousSummary: existedSummary,
1628
+ summary: summary
1629
+ });
1576
1630
  return _context11.abrupt("return", this.store.summary);
1577
- case 27:
1631
+ case 30:
1578
1632
  case "end":
1579
1633
  return _context11.stop();
1580
1634
  }
@@ -2020,7 +2074,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2020
2074
  value: function () {
2021
2075
  var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(product, booking) {
2022
2076
  var _this10 = this;
2023
- var tempOrder, linked, productToAdd, incomingFingerprint, normalizedIncoming, hasIncomingGoodPass, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct;
2077
+ var tempOrder, linked, productToAdd, incomingFingerprint, normalizedIncoming, hasIncomingGoodPass, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
2024
2078
  return _regeneratorRuntime().wrap(function _callee13$(_context15) {
2025
2079
  while (1) switch (_context15.prev = _context15.next) {
2026
2080
  case 0:
@@ -2085,7 +2139,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2085
2139
  })
2086
2140
  })));
2087
2141
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
2088
- tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
2142
+ nextNum = getSafeProductNum(targetProduct.num + normalizedProduct.num);
2143
+ targetIsManualProductDiscount = isManualProductDiscountProduct(targetProduct);
2144
+ nextDiscountList = targetIsManualProductDiscount ? normalizeOrderProductDiscountList(syncManualProductDiscountProductNum(targetProduct.discount_list, nextNum)) : normalizedProduct.discount_list;
2145
+ tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
2146
+ discount_list: nextDiscountList,
2089
2147
  metadata: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.metadata || {}), normalizedProduct.metadata || {}), {}, {
2090
2148
  unique_identification_number: targetUid
2091
2149
  }),
@@ -2095,10 +2153,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2095
2153
  option: []
2096
2154
  }), {}, {
2097
2155
  option: getProductSkuOptions(normalizedProduct)
2098
- }),
2156
+ })
2157
+ }, targetIsManualProductDiscount ? {
2158
+ selling_price: targetProduct.selling_price,
2159
+ original_price: targetProduct.original_price,
2160
+ payment_price: targetProduct.payment_price,
2161
+ metadata: _objectSpread(_objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), targetProduct.metadata || {}), {}, {
2162
+ unique_identification_number: targetUid
2163
+ })
2164
+ } : {}), {}, {
2099
2165
  note: targetProduct.note,
2100
2166
  order_detail_id: targetProduct.order_detail_id,
2101
- num: getSafeProductNum(targetProduct.num + normalizedProduct.num)
2167
+ num: nextNum
2102
2168
  });
2103
2169
  this.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
2104
2170
  }
@@ -3274,11 +3340,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3274
3340
  _step9;
3275
3341
  try {
3276
3342
  for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
3277
- var _product$metadata6, _ref24, _ref25, _existed$origin, _rawProduct$metadata;
3343
+ var _product$metadata7, _ref24, _ref25, _existed$origin, _rawProduct$metadata;
3278
3344
  var _step9$value = _slicedToArray(_step9.value, 2),
3279
3345
  index = _step9$value[0],
3280
3346
  product = _step9$value[1];
3281
- var uid = (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.unique_identification_number;
3347
+ var uid = (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.unique_identification_number;
3282
3348
  if (!uid) continue;
3283
3349
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
3284
3350
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
@@ -37,6 +37,31 @@ export * from "./types";
37
37
  import { QuotationModule } from "../../modules/Quotation";
38
38
  import { transformBaseProductToOrderProduct as _transformBaseProductToOrderProduct } from "./utils/transformBaseProductToOrderProduct";
39
39
  import { calculateBaseSalesProductBookingPrice } from "./utils/quotationPrice";
40
+ function isBaseSalesManualProductDiscountProduct(product) {
41
+ var _product$metadata, _product$metadata2;
42
+ 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) {
43
+ return (item === null || item === void 0 ? void 0 : item.type) === 'product';
44
+ });
45
+ }
46
+ function getBaseSalesProductUid(product) {
47
+ var _product$metadata3;
48
+ var uid = (product === null || product === void 0 || (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
49
+ if (uid === undefined || uid === null || uid === '') return null;
50
+ return String(uid);
51
+ }
52
+ function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
53
+ var previousByUid = new Map();
54
+ (previousProducts || []).forEach(function (product, index) {
55
+ var uid = getBaseSalesProductUid(product);
56
+ if (uid) previousByUid.set(uid, product);
57
+ previousByUid.set("__index__:".concat(index), product);
58
+ });
59
+ return (nextProducts || []).map(function (product, index) {
60
+ var uid = getBaseSalesProductUid(product);
61
+ var previous = (uid ? previousByUid.get(uid) : undefined) || previousByUid.get("__index__:".concat(index));
62
+ return previous && isBaseSalesManualProductDiscountProduct(previous) ? previous : product;
63
+ });
64
+ }
40
65
  export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
41
66
  _inherits(BaseSalesImpl, _BaseModule);
42
67
  var _super = _createSuper(BaseSalesImpl);
@@ -342,7 +367,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
342
367
  _product$num,
343
368
  _ref8,
344
369
  _product$quantity,
345
- _product$metadata;
370
+ _product$metadata4;
346
371
  if (!authoritativeProduct) return product;
347
372
  var selectedBundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
348
373
  var authoritativeBundles = this.getAuthoritativeBundleItems(authoritativeProduct);
@@ -373,7 +398,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
373
398
  });
374
399
  }(),
375
400
  product_bundle: productBundle,
376
- metadata: (_product$metadata = product.metadata) !== null && _product$metadata !== void 0 ? _product$metadata : authoritativeProduct.metadata
401
+ metadata: (_product$metadata4 = product.metadata) !== null && _product$metadata4 !== void 0 ? _product$metadata4 : authoritativeProduct.metadata
377
402
  });
378
403
  }
379
404
  }, {
@@ -1180,7 +1205,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1180
1205
  value: function () {
1181
1206
  var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
1182
1207
  var _this$getOrderIdentit, _tempOrder$customer, _tempOrder$_extend, _tempOrder$_extend2, _discountModule$getDi, _discountModule$getOr, _discountModule$getDi2;
1183
- var tempOrder, orderStore, discountModule, rulesModule, orderId, customerId, currentDiscountList, originalDiscountList, hasManualDiscountSelection, discountAction, discountConfigCacheKey, preparedDiscountList, _discountModule$setOr, nextDiscountList, shouldSkipAutoApplyFetchedDiscounts, _summary, _tempOrder$holder, _tempOrder$holder2, _orderStore$summary, holders, result, _iterator, _step, _product$metadata2, _tempOrder$_extend3, _product$metadata3, _product$metadata$sou, _product$metadata4, _product$metadata5, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice, summary;
1208
+ var tempOrder, orderStore, discountModule, rulesModule, orderId, customerId, currentDiscountList, originalDiscountList, hasManualDiscountSelection, discountAction, discountConfigCacheKey, preparedDiscountList, _discountModule$setOr, nextDiscountList, shouldSkipAutoApplyFetchedDiscounts, _summary, _tempOrder$holder, _tempOrder$holder2, _orderStore$summary, holders, result, _iterator, _step, _product$metadata5, _tempOrder$_extend3, _product$metadata$sou, _product$metadata6, _product$metadata7, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice, summary;
1184
1209
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1185
1210
  while (1) switch (_context12.prev = _context12.next) {
1186
1211
  case 0:
@@ -1291,7 +1316,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1291
1316
  discountList: nextDiscountList
1292
1317
  };
1293
1318
  if (result.productList) {
1294
- tempOrder.products = result.productList;
1319
+ tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1295
1320
  }
1296
1321
  _iterator = _createForOfIteratorHelper(tempOrder.products || []);
1297
1322
  _context12.prev = 45;
@@ -1302,9 +1327,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1302
1327
  break;
1303
1328
  }
1304
1329
  product = _step.value;
1305
- productUid = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.unique_identification_number;
1330
+ productUid = (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number;
1306
1331
  runtimeOrigin = productUid ? (_tempOrder$_extend3 = tempOrder._extend) === null || _tempOrder$_extend3 === void 0 || (_tempOrder$_extend3 = _tempOrder$_extend3.productsByUid) === null || _tempOrder$_extend3 === void 0 || (_tempOrder$_extend3 = _tempOrder$_extend3[productUid]) === null || _tempOrder$_extend3 === void 0 ? void 0 : _tempOrder$_extend3.origin : undefined;
1307
- if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || (_product$metadata3 = product.metadata) !== null && _product$metadata3 !== void 0 && _product$metadata3.is_manual_discount)) {
1332
+ if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || isBaseSalesManualProductDiscountProduct(product))) {
1308
1333
  _context12.next = 53;
1309
1334
  break;
1310
1335
  }
@@ -1314,7 +1339,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1314
1339
  return sum + Number(pd.amount || 0);
1315
1340
  }, 0);
1316
1341
  optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
1317
- sourcePrice = (_product$metadata$sou = (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.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';
1342
+ sourcePrice = (_product$metadata$sou = (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.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';
1318
1343
  newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
1319
1344
  newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
1320
1345
  if (product.metadata) {
@@ -1427,7 +1452,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1427
1452
  orderTotalAmount: Number(((_orderStore$summary2 = orderStore.summary) === null || _orderStore$summary2 === void 0 ? void 0 : _orderStore$summary2.total_amount) || 0)
1428
1453
  }) || result;
1429
1454
  if (result.productList) {
1430
- tempOrder.products = result.productList;
1455
+ tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1431
1456
  }
1432
1457
  if (!result.discountList) {
1433
1458
  _context13.next = 23;
@@ -1525,7 +1550,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1525
1550
  key: "setDiscountSelected",
1526
1551
  value: function () {
1527
1552
  var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1528
- var _tempOrder$holder5, list, updated, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder6, result, beforeSelectedIds, _iterator2, _step2, d, selectedResourceIds, _iterator3, _step3, _product$metadata6, _tempOrder$_extend4, _product$metadata7, _product$metadata$sou2, _product$metadata8, _product$metadata9, _product$original_pri2, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
1553
+ var _tempOrder$holder5, list, updated, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder6, result, beforeSelectedIds, _iterator2, _step2, d, selectedResourceIds, _iterator3, _step3, _product$metadata8, _tempOrder$_extend4, _product$metadata$sou2, _product$metadata9, _product$metadata10, _product$original_pri2, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
1529
1554
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1530
1555
  while (1) switch (_context15.prev = _context15.next) {
1531
1556
  case 0:
@@ -1569,7 +1594,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1569
1594
  discountList: updated
1570
1595
  };
1571
1596
  if (result !== null && result !== void 0 && result.productList) {
1572
- tempOrder.products = result.productList;
1597
+ tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1573
1598
  }
1574
1599
  if (result !== null && result !== void 0 && result.discountList) {
1575
1600
  nextDiscountList = result.discountList;
@@ -1610,9 +1635,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1610
1635
  break;
1611
1636
  }
1612
1637
  product = _step3.value;
1613
- productUid = (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.unique_identification_number;
1638
+ productUid = (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.unique_identification_number;
1614
1639
  runtimeOrigin = productUid ? (_tempOrder$_extend4 = tempOrder._extend) === null || _tempOrder$_extend4 === void 0 || (_tempOrder$_extend4 = _tempOrder$_extend4.productsByUid) === null || _tempOrder$_extend4 === void 0 || (_tempOrder$_extend4 = _tempOrder$_extend4[productUid]) === null || _tempOrder$_extend4 === void 0 ? void 0 : _tempOrder$_extend4.origin : undefined;
1615
- if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || (_product$metadata7 = product.metadata) !== null && _product$metadata7 !== void 0 && _product$metadata7.is_manual_discount)) {
1640
+ if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || isBaseSalesManualProductDiscountProduct(product))) {
1616
1641
  _context15.next = 25;
1617
1642
  break;
1618
1643
  }
@@ -1630,7 +1655,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1630
1655
  return sum + (pd.amount || 0);
1631
1656
  }, 0); // TODO 这块逻辑需要拿掉
1632
1657
  optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
1633
- sourcePrice = (_product$metadata$sou2 = (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.source_product_price) !== null && _product$metadata$sou2 !== void 0 ? _product$metadata$sou2 : ((_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : '0';
1658
+ sourcePrice = (_product$metadata$sou2 = (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.source_product_price) !== null && _product$metadata$sou2 !== void 0 ? _product$metadata$sou2 : ((_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : '0';
1634
1659
  newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
1635
1660
  newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
1636
1661
  if (product.metadata) {
@@ -1717,7 +1742,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1717
1742
  orderStore = this.store.order.store || {};
1718
1743
  discountModule = orderStore.discount;
1719
1744
  if (result.productList) {
1720
- tempOrder.products = result.productList;
1745
+ tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1721
1746
  }
1722
1747
  if (!result.discountList) {
1723
1748
  _context16.next = 14;
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 2 | 1 | 5 | 3 | 4 | 6;
314
+ weekNum: 0 | 2 | 1 | 6 | 3 | 5 | 4;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -0,0 +1,49 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/model/strategy/adapter/promotion/index.ts
30
+ var promotion_exports = {};
31
+ __export(promotion_exports, {
32
+ BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
+ PromotionAdapter: () => import_adapter.PromotionAdapter,
34
+ PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
+ X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
+ default: () => import_adapter2.default
37
+ });
38
+ module.exports = __toCommonJS(promotion_exports);
39
+ var import_evaluator = require("./evaluator");
40
+ var import_adapter = require("./adapter");
41
+ var import_adapter2 = __toESM(require("./adapter"));
42
+ var import_examples = require("./examples");
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ BUY_X_GET_Y_FREE_STRATEGY,
46
+ PromotionAdapter,
47
+ PromotionEvaluator,
48
+ X_ITEMS_FOR_Y_PRICE_STRATEGY
49
+ });
@@ -88,6 +88,7 @@ function buildNormalProductCacheItemFromOrderLine(input) {
88
88
  );
89
89
  const originExtend = (_c = (_b = product.metadata) == null ? void 0 : _b.origin) == null ? void 0 : _c._extend;
90
90
  const productOptionString = (0, import_orderLineDisplay.buildProductOptionStringFromOrderLine)(product);
91
+ const discountList = product.discount_list || [];
91
92
  const other = {
92
93
  product_id: resolvedId,
93
94
  product_variant_id: product.product_variant_id ?? 0,
@@ -135,6 +136,7 @@ function buildNormalProductCacheItemFromOrderLine(input) {
135
136
  ...productOptionString ? { product_option_string: productOptionString } : {},
136
137
  note: product.note,
137
138
  order_detail_id: product.order_detail_id ?? null,
139
+ discount_list: discountList,
138
140
  new: 0,
139
141
  autoClose: true,
140
142
  _extend: extend
@@ -150,6 +150,8 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
150
150
  private formatSummaryMetadataMoney;
151
151
  private syncSummaryProductMetadata;
152
152
  private calculateSummaryAmountGap;
153
+ private getSummaryRefundAmount;
154
+ private calculatePaymentTargetAmount;
153
155
  private getPaymentTargetAmount;
154
156
  ensureTempOrder(): OrderTempOrder;
155
157
  restoreOrder(): OrderTempOrder;
@@ -265,7 +267,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
265
267
  private logSubmitBackendRejected;
266
268
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
267
269
  createOrder(params: CommitOrderParams['query']): {
268
- type: "appointment_booking" | "virtual";
270
+ type: "virtual" | "appointment_booking";
269
271
  platform: string;
270
272
  sales_channel: string;
271
273
  order_sales_channel: string;
@@ -60,6 +60,10 @@ function isSameDiscountList(left, right) {
60
60
  normalizeDiscountListSignature(right)
61
61
  );
62
62
  }
63
+ function isManualProductDiscountProduct(product) {
64
+ var _a, _b;
65
+ return ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.is_manual_discount) === true || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.is_manual_discount) === 1 || ((product == null ? void 0 : product.discount_list) || []).some((item) => (item == null ? void 0 : item.type) === "product");
66
+ }
63
67
  var OrderModule = class extends import_BaseModule.BaseModule {
64
68
  constructor(name, version) {
65
69
  super(name || "order", version);
@@ -119,8 +123,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
119
123
  }
120
124
  applyProductDiscountPrices(products) {
121
125
  return (products || []).map((product) => {
122
- var _a, _b, _c;
123
- if ((_a = product.metadata) == null ? void 0 : _a.is_manual_discount)
126
+ var _a, _b;
127
+ if (isManualProductDiscountProduct(product))
124
128
  return product;
125
129
  const discountItems = Array.isArray(product.discount_list) ? product.discount_list : [];
126
130
  const hasOnlyPersistedDiscountSnapshots = product.order_detail_id !== void 0 && product.order_detail_id !== null && discountItems.length > 0 && discountItems.every((discount) => (discount == null ? void 0 : discount.order_discount_id) !== void 0 && (discount == null ? void 0 : discount.order_discount_id) !== null);
@@ -129,7 +133,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
129
133
  }
130
134
  const totalPerUnitDiscount = (0, import_utils.resolveEffectivePerUnitDiscount)(product);
131
135
  const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
132
- const sourcePrice = ((_b = product.metadata) == null ? void 0 : _b.source_product_price) ?? (((_c = product.metadata) == null ? void 0 : _c.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
136
+ const sourcePrice = ((_a = product.metadata) == null ? void 0 : _a.source_product_price) ?? (((_b = product.metadata) == null ? void 0 : _b.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
133
137
  const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
134
138
  const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
135
139
  if (product.metadata) {
@@ -346,6 +350,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
346
350
  (result.productList || []).map((product, index) => {
347
351
  const uid = (0, import_utils.getOrderProductLineUid)(product);
348
352
  const previous = (uid ? previousProductsByUid.get(uid) : void 0) ?? previousProductsByUid.get(`__index__:${index}`);
353
+ if (isManualProductDiscountProduct(previous)) {
354
+ return previous;
355
+ }
349
356
  const mergedProduct = previous ? (0, import_utils.mergeOrderProductDisplayFields)(previous, product) : product;
350
357
  return {
351
358
  ...mergedProduct,
@@ -637,25 +644,51 @@ var OrderModule = class extends import_BaseModule.BaseModule {
637
644
  }
638
645
  return normalized;
639
646
  }
640
- updateTempOrderPaymentStatus(tempOrder) {
641
- if (this.shouldKeepPaymentStatusAfterAmountRecalc(tempOrder.payment_status)) {
647
+ updateTempOrderPaymentStatus(tempOrder, options) {
648
+ const summary = (options == null ? void 0 : options.summary) || this.store.summary || (0, import_utils.createEmptySummary)();
649
+ const paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
650
+ const refundAmount = this.getSummaryRefundAmount(summary);
651
+ const netPaymentTotal = import_decimal.default.max(paymentTotal.minus(refundAmount), 0);
652
+ const targetAmount = this.calculatePaymentTargetAmount(tempOrder, summary);
653
+ if (this.shouldKeepPaymentStatusAfterAmountRecalc(tempOrder.payment_status, {
654
+ netPaymentTotal,
655
+ paymentTotal,
656
+ refundAmount,
657
+ targetAmount,
658
+ previousSummary: options == null ? void 0 : options.previousSummary,
659
+ tempOrder
660
+ })) {
642
661
  return;
643
662
  }
644
- const paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
645
- const targetAmount = this.getPaymentTargetAmount();
646
663
  if (targetAmount.lte(0)) {
647
664
  tempOrder.payment_status = "paid";
648
665
  return;
649
666
  }
650
- if (paymentTotal.lte(0)) {
667
+ if (netPaymentTotal.lte(0)) {
651
668
  tempOrder.payment_status = "payment_processing";
652
669
  return;
653
670
  }
654
- tempOrder.payment_status = paymentTotal.gte(targetAmount) ? "paid" : "partially_paid";
671
+ tempOrder.payment_status = netPaymentTotal.gte(targetAmount) ? "paid" : "partially_paid";
655
672
  }
656
- shouldKeepPaymentStatusAfterAmountRecalc(paymentStatus) {
673
+ shouldKeepPaymentStatusAfterAmountRecalc(paymentStatus, params) {
657
674
  const normalizedStatus = String(paymentStatus || "").trim().toLowerCase();
658
- return normalizedStatus === "refunded" || normalizedStatus === "partially_refunded";
675
+ if (normalizedStatus !== "refunded" && normalizedStatus !== "partially_refunded") {
676
+ return false;
677
+ }
678
+ if (params.refundAmount.lte(0))
679
+ return false;
680
+ if (params.previousSummary) {
681
+ const previousTargetAmount = this.calculatePaymentTargetAmount(
682
+ params.tempOrder,
683
+ params.previousSummary
684
+ );
685
+ if (!previousTargetAmount.eq(params.targetAmount))
686
+ return false;
687
+ }
688
+ if (normalizedStatus === "refunded") {
689
+ return params.refundAmount.gte(params.paymentTotal);
690
+ }
691
+ return params.netPaymentTotal.gte(params.targetAmount);
659
692
  }
660
693
  resolveWalletPassUseValue(payment, amount) {
661
694
  const usageUnit = payment.wallet_pass_usage_unit && typeof payment.wallet_pass_usage_unit === "object" ? payment.wallet_pass_usage_unit : null;
@@ -790,20 +823,23 @@ var OrderModule = class extends import_BaseModule.BaseModule {
790
823
  }
791
824
  calculateSummaryAmountGap(params) {
792
825
  const { tempOrder, summary, orderPaidAmount } = params;
826
+ const refundAmount = this.getSummaryRefundAmount(summary);
827
+ const netOrderPaidAmount = import_decimal.default.max(orderPaidAmount.minus(refundAmount), 0);
828
+ const targetAmount = this.calculatePaymentTargetAmount(tempOrder, summary);
829
+ return targetAmount.minus(netOrderPaidAmount).toFixed(2);
830
+ }
831
+ getSummaryRefundAmount(summary) {
832
+ return import_decimal.default.max(new import_decimal.default((summary == null ? void 0 : summary.total_refund_amount) || 0), 0);
833
+ }
834
+ calculatePaymentTargetAmount(tempOrder, summary) {
793
835
  const depositAmount = summary.deposit_amount || tempOrder.deposit_amount || "0.00";
794
836
  const isDeposit = tempOrder.is_deposit === 1 || new import_decimal.default(depositAmount || 0).gt(0);
795
- const targetAmount = isDeposit ? new import_decimal.default(depositAmount || 0) : new import_decimal.default(summary.total_amount || summary.expect_amount || 0);
796
- return targetAmount.minus(orderPaidAmount).toFixed(2);
837
+ return isDeposit ? new import_decimal.default(depositAmount || 0) : new import_decimal.default(summary.total_amount || summary.expect_amount || 0);
797
838
  }
798
839
  getPaymentTargetAmount() {
799
840
  const tempOrder = this.ensureTempOrder();
800
841
  const summary = this.store.summary || (0, import_utils.createEmptySummary)();
801
- if (tempOrder.is_deposit === 1) {
802
- return new import_decimal.default(
803
- tempOrder.deposit_amount || summary.deposit_amount || 0
804
- );
805
- }
806
- return new import_decimal.default(summary.total_amount || summary.expect_amount || 0);
842
+ return this.calculatePaymentTargetAmount(tempOrder, summary);
807
843
  }
808
844
  ensureTempOrder() {
809
845
  if (this.store.tempOrder) {
@@ -889,9 +925,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
889
925
  return null;
890
926
  const summary = this.store.summary || (0, import_utils.createEmptySummary)();
891
927
  const depositAmount = tempOrder.deposit_amount || summary.deposit_amount || "0.00";
892
- const targetAmount = tempOrder.is_deposit === 1 ? new import_decimal.default(depositAmount || 0) : new import_decimal.default(summary.total_amount || summary.expect_amount || 0);
893
- const paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
894
- const amountGap = targetAmount.minus(paymentTotal).toFixed(2);
928
+ const paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
929
+ const amountGap = this.calculateSummaryAmountGap({
930
+ tempOrder,
931
+ summary,
932
+ orderPaidAmount: paidPaymentSummary.gapPaidAmount
933
+ });
895
934
  return {
896
935
  isDeposit: tempOrder.is_deposit === 1 || depositAmount !== "0.00",
897
936
  depositAmount,
@@ -1055,25 +1094,32 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1055
1094
  this.sanitizeTempOrderProducts(tempOrder);
1056
1095
  const salesSummary = this.getSalesSummary();
1057
1096
  const existedSummary = this.store.summary || (0, import_utils.createEmptySummary)();
1097
+ const totalRefundAmount = existedSummary.total_refund_amount || "0.00";
1058
1098
  const paidPaymentSummary = this.calculatePaidPaymentSummary(
1059
1099
  tempOrder.payments || []
1060
1100
  );
1061
1101
  if (!salesSummary) {
1062
- const emptySummary = {
1102
+ const emptyBaseSummary = {
1063
1103
  ...(0, import_utils.createEmptySummary)(),
1064
- total_refund_amount: existedSummary.total_refund_amount || "0.00",
1104
+ total_refund_amount: totalRefundAmount
1105
+ };
1106
+ const emptySummary = {
1107
+ ...emptyBaseSummary,
1065
1108
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
1066
1109
  order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
1067
1110
  amount_gap: this.calculateSummaryAmountGap({
1068
1111
  tempOrder,
1069
- summary: (0, import_utils.createEmptySummary)(),
1112
+ summary: emptyBaseSummary,
1070
1113
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
1071
1114
  }),
1072
1115
  pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
1073
1116
  };
1074
1117
  tempOrder.surcharge_fee = emptySummary.surcharge_fee;
1075
- this.updateTempOrderPaymentStatus(tempOrder);
1076
1118
  this.store.summary = emptySummary;
1119
+ this.updateTempOrderPaymentStatus(tempOrder, {
1120
+ previousSummary: existedSummary,
1121
+ summary: emptySummary
1122
+ });
1077
1123
  return this.store.summary;
1078
1124
  }
1079
1125
  const salesSummaryResult = await salesSummary.getSummary({
@@ -1082,14 +1128,18 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1082
1128
  shopDiscount: tempOrder.shop_discount
1083
1129
  });
1084
1130
  this.syncSummaryProductMetadata(tempOrder.products || []);
1131
+ const summaryForGap = {
1132
+ ...salesSummaryResult,
1133
+ total_refund_amount: totalRefundAmount
1134
+ };
1085
1135
  const summary = {
1086
1136
  ...salesSummaryResult,
1087
- total_refund_amount: existedSummary.total_refund_amount || "0.00",
1137
+ total_refund_amount: totalRefundAmount,
1088
1138
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
1089
1139
  order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
1090
1140
  amount_gap: this.calculateSummaryAmountGap({
1091
1141
  tempOrder,
1092
- summary: salesSummaryResult,
1142
+ summary: summaryForGap,
1093
1143
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
1094
1144
  }),
1095
1145
  pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
@@ -1105,7 +1155,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1105
1155
  tempOrder.surcharges = summary.surcharges || [];
1106
1156
  tempOrder.deposit_amount = summary.deposit_amount || "0.00";
1107
1157
  tempOrder.is_deposit = summary.deposit_amount !== "0.00" ? 1 : 0;
1108
- this.updateTempOrderPaymentStatus(tempOrder);
1158
+ this.updateTempOrderPaymentStatus(tempOrder, {
1159
+ previousSummary: existedSummary,
1160
+ summary
1161
+ });
1109
1162
  return this.store.summary;
1110
1163
  }
1111
1164
  async getOrderSummary() {
@@ -1511,9 +1564,18 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1511
1564
  normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
1512
1565
  normalizedProduct.discount_list
1513
1566
  );
1567
+ const nextNum = (0, import_utils3.getSafeProductNum)(targetProduct.num + normalizedProduct.num);
1568
+ const targetIsManualProductDiscount = isManualProductDiscountProduct(targetProduct);
1569
+ const nextDiscountList = targetIsManualProductDiscount ? (0, import_utils.normalizeOrderProductDiscountList)(
1570
+ (0, import_manualProductDiscount.syncManualProductDiscountProductNum)(
1571
+ targetProduct.discount_list,
1572
+ nextNum
1573
+ )
1574
+ ) : normalizedProduct.discount_list;
1514
1575
  tempOrder.products[matchedIndex] = {
1515
1576
  ...targetProduct,
1516
1577
  ...normalizedProduct,
1578
+ discount_list: nextDiscountList,
1517
1579
  metadata: {
1518
1580
  ...targetProduct.metadata || {},
1519
1581
  ...normalizedProduct.metadata || {},
@@ -1524,9 +1586,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1524
1586
  ...normalizedProduct.product_sku || { option: [] },
1525
1587
  option: (0, import_utils.getProductSkuOptions)(normalizedProduct)
1526
1588
  },
1589
+ ...targetIsManualProductDiscount ? {
1590
+ selling_price: targetProduct.selling_price,
1591
+ original_price: targetProduct.original_price,
1592
+ payment_price: targetProduct.payment_price,
1593
+ metadata: {
1594
+ ...normalizedProduct.metadata || {},
1595
+ ...targetProduct.metadata || {},
1596
+ unique_identification_number: targetUid
1597
+ }
1598
+ } : {},
1527
1599
  note: targetProduct.note,
1528
1600
  order_detail_id: targetProduct.order_detail_id,
1529
- num: (0, import_utils3.getSafeProductNum)(targetProduct.num + normalizedProduct.num)
1601
+ num: nextNum
1530
1602
  };
1531
1603
  this.captureProductRuntime(
1532
1604
  tempOrder,
@@ -44,6 +44,31 @@ __reExport(BaseSales_exports, require("./types"), module.exports);
44
44
  var import_Quotation = require("../../modules/Quotation");
45
45
  var import_transformBaseProductToOrderProduct = require("./utils/transformBaseProductToOrderProduct");
46
46
  var import_quotationPrice = require("./utils/quotationPrice");
47
+ function isBaseSalesManualProductDiscountProduct(product) {
48
+ var _a, _b;
49
+ return ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.is_manual_discount) === true || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.is_manual_discount) === 1 || ((product == null ? void 0 : product.discount_list) || []).some((item) => (item == null ? void 0 : item.type) === "product");
50
+ }
51
+ function getBaseSalesProductUid(product) {
52
+ var _a;
53
+ const uid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
54
+ if (uid === void 0 || uid === null || uid === "")
55
+ return null;
56
+ return String(uid);
57
+ }
58
+ function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
59
+ const previousByUid = /* @__PURE__ */ new Map();
60
+ (previousProducts || []).forEach((product, index) => {
61
+ const uid = getBaseSalesProductUid(product);
62
+ if (uid)
63
+ previousByUid.set(uid, product);
64
+ previousByUid.set(`__index__:${index}`, product);
65
+ });
66
+ return (nextProducts || []).map((product, index) => {
67
+ const uid = getBaseSalesProductUid(product);
68
+ const previous = (uid ? previousByUid.get(uid) : void 0) || previousByUid.get(`__index__:${index}`);
69
+ return previous && isBaseSalesManualProductDiscountProduct(previous) ? previous : product;
70
+ });
71
+ }
47
72
  var BaseSalesImpl = class extends import_BaseModule.BaseModule {
48
73
  constructor(name, version) {
49
74
  super(name, version);
@@ -772,7 +797,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
772
797
  });
773
798
  }
774
799
  async loadDiscountConfig(params) {
775
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
800
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
776
801
  if (!this.store.order)
777
802
  throw new Error("order 模块未初始化");
778
803
  const tempOrder = this.store.order.ensureTempOrder();
@@ -852,19 +877,22 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
852
877
  orderTotalAmount: Number(((_n = orderStore.summary) == null ? void 0 : _n.total_amount) || 0)
853
878
  }) || { productList: tempOrder.products, discountList: nextDiscountList };
854
879
  if (result.productList) {
855
- tempOrder.products = result.productList;
880
+ tempOrder.products = preserveManualProductDiscountProducts(
881
+ tempOrder.products,
882
+ result.productList
883
+ );
856
884
  }
857
885
  for (const product of tempOrder.products || []) {
858
886
  const productUid = (_o = product.metadata) == null ? void 0 : _o.unique_identification_number;
859
887
  const runtimeOrigin = productUid ? (_r = (_q = (_p = tempOrder._extend) == null ? void 0 : _p.productsByUid) == null ? void 0 : _q[productUid]) == null ? void 0 : _r.origin : void 0;
860
- if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || ((_s = product.metadata) == null ? void 0 : _s.is_manual_discount))
888
+ if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || isBaseSalesManualProductDiscountProduct(product))
861
889
  continue;
862
890
  const totalPerUnitDiscount = (product.discount_list || []).reduce(
863
891
  (sum, pd) => sum + Number(pd.amount || 0),
864
892
  0
865
893
  );
866
894
  const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
867
- const sourcePrice = ((_t = product.metadata) == null ? void 0 : _t.source_product_price) ?? (((_u = product.metadata) == null ? void 0 : _u.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
895
+ const sourcePrice = ((_s = product.metadata) == null ? void 0 : _s.source_product_price) ?? (((_t = product.metadata) == null ? void 0 : _t.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
868
896
  const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
869
897
  const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
870
898
  if (product.metadata) {
@@ -928,7 +956,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
928
956
  orderTotalAmount: Number(((_e = orderStore.summary) == null ? void 0 : _e.total_amount) || 0)
929
957
  }) || result;
930
958
  if (result.productList) {
931
- tempOrder.products = result.productList;
959
+ tempOrder.products = preserveManualProductDiscountProducts(
960
+ tempOrder.products,
961
+ result.productList
962
+ );
932
963
  }
933
964
  if (result.discountList) {
934
965
  nextDiscountList = this.mergeHistoricalDiscountList(
@@ -974,7 +1005,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
974
1005
  }
975
1006
  // TODO 需要优化,这段逻辑太长了,里面应该有些历史遗留问题
976
1007
  async setDiscountSelected(params) {
977
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1008
+ var _a, _b, _c, _d, _e, _f, _g, _h;
978
1009
  try {
979
1010
  if (!this.store.order)
980
1011
  throw new Error("order 模块未初始化");
@@ -1008,7 +1039,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1008
1039
  }
1009
1040
  ) || { productList: tempOrder.products, discountList: updated };
1010
1041
  if (result == null ? void 0 : result.productList) {
1011
- tempOrder.products = result.productList;
1042
+ tempOrder.products = preserveManualProductDiscountProducts(
1043
+ tempOrder.products,
1044
+ result.productList
1045
+ );
1012
1046
  }
1013
1047
  if (result == null ? void 0 : result.discountList) {
1014
1048
  nextDiscountList = result.discountList;
@@ -1031,7 +1065,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1031
1065
  for (const product of tempOrder.products) {
1032
1066
  const productUid = (_c = product.metadata) == null ? void 0 : _c.unique_identification_number;
1033
1067
  const runtimeOrigin = productUid ? (_f = (_e = (_d = tempOrder._extend) == null ? void 0 : _d.productsByUid) == null ? void 0 : _e[productUid]) == null ? void 0 : _f.origin : void 0;
1034
- if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || ((_g = product.metadata) == null ? void 0 : _g.is_manual_discount))
1068
+ if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || isBaseSalesManualProductDiscountProduct(product))
1035
1069
  continue;
1036
1070
  product.discount_list = (product.discount_list || []).filter((pd) => {
1037
1071
  var _a2;
@@ -1043,7 +1077,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1043
1077
  0
1044
1078
  );
1045
1079
  const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
1046
- const sourcePrice = ((_h = product.metadata) == null ? void 0 : _h.source_product_price) ?? (((_i = product.metadata) == null ? void 0 : _i.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
1080
+ const sourcePrice = ((_g = product.metadata) == null ? void 0 : _g.source_product_price) ?? (((_h = product.metadata) == null ? void 0 : _h.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
1047
1081
  const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
1048
1082
  const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
1049
1083
  if (product.metadata) {
@@ -1080,7 +1114,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1080
1114
  const orderStore = this.store.order.store || {};
1081
1115
  const discountModule = orderStore.discount;
1082
1116
  if (result.productList) {
1083
- tempOrder.products = result.productList;
1117
+ tempOrder.products = preserveManualProductDiscountProducts(
1118
+ tempOrder.products,
1119
+ result.productList
1120
+ );
1084
1121
  }
1085
1122
  if (result.discountList) {
1086
1123
  import_Order.OrderModule.populateSavedAmounts(
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 2 | 1 | 5 | 3 | 4 | 6;
314
+ weekNum: 0 | 2 | 1 | 6 | 3 | 5 | 4;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.194",
4
+ "version": "2.2.196",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",