@pisell/pisellos 2.2.197 → 2.2.199

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.
Files changed (45) hide show
  1. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +7 -3
  2. package/dist/modules/Cart/utils/cartProduct.js +11 -1
  3. package/dist/modules/Cart/utils/changePrice.js +11 -11
  4. package/dist/modules/Order/index.d.ts +16 -0
  5. package/dist/modules/Order/index.js +1232 -568
  6. package/dist/modules/Order/types.d.ts +1 -0
  7. package/dist/modules/Order/utils.d.ts +33 -2
  8. package/dist/modules/Order/utils.js +112 -55
  9. package/dist/modules/Payment/walletpass.js +14 -7
  10. package/dist/modules/SalesSummary/utils.js +394 -149
  11. package/dist/server/index.d.ts +3 -0
  12. package/dist/server/index.js +294 -190
  13. package/dist/server/modules/order/index.d.ts +8 -0
  14. package/dist/server/modules/order/index.js +536 -317
  15. package/dist/server/modules/order/types.d.ts +2 -0
  16. package/dist/solution/BaseSales/index.js +2 -1
  17. package/dist/solution/BaseSales/types.d.ts +1 -0
  18. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +19 -4
  19. package/dist/solution/BookingByStep/index.d.ts +1 -1
  20. package/dist/solution/ScanOrder/types.d.ts +1 -0
  21. package/dist/solution/ScanOrder/utils.js +26 -9
  22. package/dist/solution/VenueBooking/index.js +2 -1
  23. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +4 -1
  24. package/lib/modules/Cart/utils/cartProduct.js +11 -1
  25. package/lib/modules/Cart/utils/changePrice.js +12 -20
  26. package/lib/modules/Order/index.d.ts +16 -0
  27. package/lib/modules/Order/index.js +525 -18
  28. package/lib/modules/Order/types.d.ts +1 -0
  29. package/lib/modules/Order/utils.d.ts +33 -2
  30. package/lib/modules/Order/utils.js +44 -9
  31. package/lib/modules/Payment/walletpass.js +7 -3
  32. package/lib/modules/SalesSummary/utils.js +256 -46
  33. package/lib/server/index.d.ts +3 -0
  34. package/lib/server/index.js +82 -3
  35. package/lib/server/modules/order/index.d.ts +8 -0
  36. package/lib/server/modules/order/index.js +106 -4
  37. package/lib/server/modules/order/types.d.ts +2 -0
  38. package/lib/solution/BaseSales/index.js +2 -1
  39. package/lib/solution/BaseSales/types.d.ts +1 -0
  40. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +15 -1
  41. package/lib/solution/BookingByStep/index.d.ts +1 -1
  42. package/lib/solution/ScanOrder/types.d.ts +1 -0
  43. package/lib/solution/ScanOrder/utils.js +28 -10
  44. package/lib/solution/VenueBooking/index.js +2 -1
  45. package/package.json +1 -1
@@ -86,6 +86,80 @@ var OrderModule = class extends import_BaseModule.BaseModule {
86
86
  */
87
87
  this.draftPersistEnabled = true;
88
88
  }
89
+ collectHydratedEditDiscounts(products) {
90
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
91
+ const discountMap = /* @__PURE__ */ new Map();
92
+ for (const product of products || []) {
93
+ for (const item of (product == null ? void 0 : product.discount_list) || []) {
94
+ const type = (item == null ? void 0 : item.type) ?? (item == null ? void 0 : item.tag);
95
+ if (!type || type === "product")
96
+ continue;
97
+ const resourceId = ((_a = item == null ? void 0 : item.discount) == null ? void 0 : _a.resource_id) ?? (item == null ? void 0 : item.resource_id) ?? (item == null ? void 0 : item.discount_id) ?? (item == null ? void 0 : item.order_discount_id);
98
+ if (resourceId === void 0 || resourceId === null || resourceId === "")
99
+ continue;
100
+ const id = Number(resourceId);
101
+ const key = Number.isFinite(id) ? id : String(resourceId);
102
+ const title = ((_b = item == null ? void 0 : item.discount) == null ? void 0 : _b.title) ?? {};
103
+ const amount = Number((item == null ? void 0 : item.amount) || 0);
104
+ const detail = {
105
+ amount: String((item == null ? void 0 : item.amount) ?? "0"),
106
+ type,
107
+ resource_id: key,
108
+ title,
109
+ original_amount: String(((_c = item == null ? void 0 : item.discount) == null ? void 0 : _c.original_amount) ?? (item == null ? void 0 : item.amount) ?? "0"),
110
+ num: Number(((_d = item == null ? void 0 : item.metadata) == null ? void 0 : _d.num) ?? (product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity) ?? 1) || 1,
111
+ metadata: item == null ? void 0 : item.metadata,
112
+ discount: item == null ? void 0 : item.discount,
113
+ _num: Number(((_e = item == null ? void 0 : item.metadata) == null ? void 0 : _e.num) ?? (product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity) ?? 1) || 1
114
+ };
115
+ discountMap.set(key, {
116
+ id: key,
117
+ product_name: "",
118
+ encoded: "",
119
+ code: "",
120
+ tag: type,
121
+ product_id: ((_f = item == null ? void 0 : item.discount) == null ? void 0 : _f.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
122
+ relation_type: "",
123
+ par_value: String(((_g = item == null ? void 0 : item.discount) == null ? void 0 : _g.original_amount) ?? (item == null ? void 0 : item.amount) ?? "0"),
124
+ used_par_value: String((item == null ? void 0 : item.amount) ?? "0"),
125
+ limit_status: "enable",
126
+ limited_relation_product_data: {
127
+ id: 0,
128
+ type: "products",
129
+ product_ids: [product == null ? void 0 : product.product_id].filter((value) => value !== void 0 && value !== null),
130
+ product_collection_id: [],
131
+ filter: 0,
132
+ exclude_product_ids: []
133
+ },
134
+ balance: String((item == null ? void 0 : item.amount) ?? "0"),
135
+ format_title: title,
136
+ product: {
137
+ id: (product == null ? void 0 : product.product_id) ?? 0,
138
+ title: "",
139
+ is_charge_tax: (product == null ? void 0 : product.is_charge_tax) ?? 0,
140
+ base_price: String((product == null ? void 0 : product.original_price) ?? (product == null ? void 0 : product.selling_price) ?? "0")
141
+ },
142
+ type,
143
+ resource_id: key,
144
+ isEditMode: true,
145
+ isSelected: true,
146
+ isAvailable: true,
147
+ isUsed: true,
148
+ isDisabled: true,
149
+ amount,
150
+ discount: {
151
+ ...(item == null ? void 0 : item.discount) || {},
152
+ resource_id: key,
153
+ discount_product_id: ((_h = item == null ? void 0 : item.discount) == null ? void 0 : _h.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
154
+ discount_calculation_mode: ((_i = item == null ? void 0 : item.discount) == null ? void 0 : _i.discount_calculation_mode) ?? "item_level"
155
+ },
156
+ applicableProductDetails: [detail],
157
+ appliedProductDetails: [detail]
158
+ });
159
+ }
160
+ }
161
+ return Array.from(discountMap.values());
162
+ }
89
163
  /**
90
164
  * Populate `savedAmount` on each discount based on product-level discount details.
91
165
  * Only selected discounts get a non-zero value.
@@ -244,7 +318,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
244
318
  }
245
319
  // ─── Discount: 公共 API ───
246
320
  async loadDiscountConfig(params) {
247
- var _a, _b, _c, _d, _e, _f;
321
+ var _a, _b, _c, _d, _e, _f, _g;
248
322
  const orderId = params.orderId || ((_a = this.store.tempOrder) == null ? void 0 : _a.order_id) || void 0;
249
323
  const discountList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
250
324
  customer_id: params.customerId,
@@ -256,10 +330,18 @@ var OrderModule = class extends import_BaseModule.BaseModule {
256
330
  ...orderId ? { order_id: orderId } : {}
257
331
  }));
258
332
  if (discountList) {
259
- await ((_c = this.store.discount) == null ? void 0 : _c.setOriginalDiscountList(discountList));
260
- await ((_d = this.store.discount) == null ? void 0 : _d.setDiscountList(discountList));
261
- }
262
- if (params.apply !== false && ((_f = (_e = this.store.tempOrder) == null ? void 0 : _e.products) == null ? void 0 : _f.length)) {
333
+ const currentEditDiscounts = (((_c = this.store.discount) == null ? void 0 : _c.getDiscountList()) || []).filter((discount) => discount == null ? void 0 : discount.isEditMode);
334
+ const currentEditDiscountIds = new Set(
335
+ currentEditDiscounts.map((discount) => discount == null ? void 0 : discount.id)
336
+ );
337
+ const mergedDiscountList = [
338
+ ...currentEditDiscounts,
339
+ ...discountList.filter((discount) => !currentEditDiscountIds.has(discount == null ? void 0 : discount.id))
340
+ ];
341
+ await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(mergedDiscountList));
342
+ await ((_e = this.store.discount) == null ? void 0 : _e.setDiscountList(mergedDiscountList));
343
+ }
344
+ if (params.apply !== false && ((_g = (_f = this.store.tempOrder) == null ? void 0 : _f.products) == null ? void 0 : _g.length)) {
263
345
  this.applyDiscount();
264
346
  }
265
347
  return this.getDiscountList();
@@ -268,6 +350,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
268
350
  var _a;
269
351
  return ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
270
352
  }
353
+ async ensureEditDiscountConfigForProductChange(tempOrder) {
354
+ var _a, _b, _c, _d, _e, _f;
355
+ const orderId = tempOrder.order_id;
356
+ const customerId = Number(
357
+ tempOrder.customer_id || ((_a = tempOrder.customer) == null ? void 0 : _a.id) || ((_c = (_b = tempOrder._extend) == null ? void 0 : _b.customerSnapshot) == null ? void 0 : _c.id) || ((_e = (_d = tempOrder._extend) == null ? void 0 : _d.customerSnapshot) == null ? void 0 : _e.customer_id) || 0
358
+ );
359
+ if (!orderId || !customerId || customerId === 1)
360
+ return;
361
+ const currentDiscountList = ((_f = this.store.discount) == null ? void 0 : _f.getDiscountList()) || [];
362
+ const hasRuntimeDiscounts = currentDiscountList.some((discount) => !(discount == null ? void 0 : discount.isEditMode));
363
+ if (hasRuntimeDiscounts)
364
+ return;
365
+ await this.loadDiscountConfig({
366
+ customerId,
367
+ action: "edit",
368
+ orderId: Number(orderId),
369
+ apply: false
370
+ });
371
+ }
271
372
  async scanCode(code, customerId) {
272
373
  var _a, _b, _c, _d, _e;
273
374
  const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || { discountList: [], unavailableReasonKey: null };
@@ -741,14 +842,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
741
842
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
742
843
  orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
743
844
  gapPaidAmount: summary.gapPaidAmount.plus(this.calculatePaymentGapAmount(paymentRecord)),
744
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(this.calculatePaymentServiceFee(paymentRecord))
845
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(this.calculatePaymentServiceFee(paymentRecord)),
846
+ roundingAmount: summary.roundingAmount.plus(this.calculatePaymentRoundingAmount(paymentRecord))
745
847
  };
746
848
  },
747
849
  {
748
850
  customerPaidAmount: new import_decimal.default(0),
749
851
  orderPaidAmount: new import_decimal.default(0),
750
852
  gapPaidAmount: new import_decimal.default(0),
751
- payServiceChargeAmount: new import_decimal.default(0)
853
+ payServiceChargeAmount: new import_decimal.default(0),
854
+ roundingAmount: new import_decimal.default(0)
752
855
  }
753
856
  );
754
857
  }
@@ -768,6 +871,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
768
871
  const rounding = new import_decimal.default(payment.rounding_amount || 0);
769
872
  return new import_decimal.default(payment.origin_amount || 0).minus(rounding);
770
873
  }
874
+ calculatePaymentRoundingAmount(payment) {
875
+ if (payment.rounding_amount === void 0 || payment.rounding_amount === null || payment.rounding_amount === "") {
876
+ return new import_decimal.default(0);
877
+ }
878
+ return new import_decimal.default(payment.rounding_amount || 0);
879
+ }
771
880
  formatSummaryMetadataMoney(value) {
772
881
  if (value === void 0 || value === null || value === "")
773
882
  return void 0;
@@ -782,6 +891,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
782
891
  "surcharge_rounding_remainder",
783
892
  "tax_fee_rounding_remainder"
784
893
  ];
894
+ const metadataMoneyKeys = [
895
+ "main_product_attached_bundle_selling_price",
896
+ "main_product_attached_bundle_payment_price"
897
+ ];
785
898
  for (const product of products || []) {
786
899
  const productRecord = product;
787
900
  const metadata = productRecord.metadata && typeof productRecord.metadata === "object" ? { ...productRecord.metadata } : {};
@@ -793,10 +906,26 @@ var OrderModule = class extends import_BaseModule.BaseModule {
793
906
  metadata[key] = value;
794
907
  hasMetadataPatch = true;
795
908
  }
909
+ for (const key of metadataMoneyKeys) {
910
+ const value = this.formatSummaryMetadataMoney(metadata[key]);
911
+ if (value === void 0)
912
+ continue;
913
+ metadata[key] = value;
914
+ hasMetadataPatch = true;
915
+ }
916
+ if (metadata.average_discount_amount_rate !== void 0) {
917
+ hasMetadataPatch = true;
918
+ }
796
919
  if (Array.isArray(productRecord.relation_surcharge_ids)) {
797
920
  metadata.relation_surcharge_ids = productRecord.relation_surcharge_ids;
798
921
  hasMetadataPatch = true;
799
922
  }
923
+ const productPaymentPrice = this.formatSummaryMetadataMoney(
924
+ productRecord.payment_price
925
+ );
926
+ if (productPaymentPrice !== void 0) {
927
+ productRecord.payment_price = productPaymentPrice;
928
+ }
800
929
  if (hasMetadataPatch)
801
930
  productRecord.metadata = metadata;
802
931
  if (!Array.isArray(productRecord.product_bundle))
@@ -812,6 +941,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
812
941
  bundleMetadata.surcharge_fee = bundleSurchargeFee;
813
942
  hasBundleMetadataPatch = true;
814
943
  }
944
+ const bundlePaymentPrice = this.formatSummaryMetadataMoney(
945
+ bundleRecord.bundle_payment_price
946
+ );
947
+ if (bundlePaymentPrice !== void 0) {
948
+ bundleRecord.bundle_payment_price = bundlePaymentPrice;
949
+ }
815
950
  if (Array.isArray(bundleRecord.relation_surcharge_ids)) {
816
951
  bundleMetadata.relation_surcharge_ids = bundleRecord.relation_surcharge_ids;
817
952
  hasBundleMetadataPatch = true;
@@ -834,7 +969,219 @@ var OrderModule = class extends import_BaseModule.BaseModule {
834
969
  calculatePaymentTargetAmount(tempOrder, summary) {
835
970
  const depositAmount = summary.deposit_amount || tempOrder.deposit_amount || "0.00";
836
971
  const isDeposit = tempOrder.is_deposit === 1 || new import_decimal.default(depositAmount || 0).gt(0);
837
- return isDeposit ? new import_decimal.default(depositAmount || 0) : new import_decimal.default(summary.total_amount || summary.expect_amount || 0);
972
+ return isDeposit ? new import_decimal.default(depositAmount || 0) : new import_decimal.default(summary.expect_amount || summary.total_amount || 0);
973
+ }
974
+ normalizeFingerprintMoney(value) {
975
+ if (value === void 0 || value === null || value === "")
976
+ return "";
977
+ try {
978
+ const parsed = new import_decimal.default(String(value || 0));
979
+ return parsed.toFixed(4);
980
+ } catch {
981
+ return String(value);
982
+ }
983
+ }
984
+ normalizeFingerprintValue(value) {
985
+ if (Array.isArray(value)) {
986
+ return value.map((item) => this.normalizeFingerprintValue(item));
987
+ }
988
+ if (!value || typeof value !== "object")
989
+ return value ?? "";
990
+ return Object.keys(value).sort().reduce((result, key) => {
991
+ result[key] = this.normalizeFingerprintValue(value[key]);
992
+ return result;
993
+ }, {});
994
+ }
995
+ buildProductFingerprintItem(product) {
996
+ const sku = (product == null ? void 0 : product.product_sku) || {};
997
+ const metadata = (product == null ? void 0 : product.metadata) || {};
998
+ const discountTypes = ((product == null ? void 0 : product.discount_list) || []).map((discount) => (discount == null ? void 0 : discount.type) ?? (discount == null ? void 0 : discount.tag));
999
+ const extensionType = (product == null ? void 0 : product.extension_type) || (discountTypes.includes("good_pass") ? "good_pass" : "normal");
1000
+ return {
1001
+ product_id: (product == null ? void 0 : product.product_id) ?? null,
1002
+ product_variant_id: (product == null ? void 0 : product.product_variant_id) ?? null,
1003
+ extension_type: extensionType,
1004
+ num: (0, import_utils3.getSafeProductNum)((product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity)),
1005
+ selling_price: this.normalizeFingerprintMoney(product == null ? void 0 : product.selling_price),
1006
+ original_price: this.normalizeFingerprintMoney(product == null ? void 0 : product.original_price),
1007
+ payment_price: this.normalizeFingerprintMoney((product == null ? void 0 : product.payment_price) ?? (product == null ? void 0 : product.selling_price)),
1008
+ metadata: {
1009
+ source_product_price: this.normalizeFingerprintMoney(metadata.source_product_price),
1010
+ main_product_selling_price: this.normalizeFingerprintMoney(metadata.main_product_selling_price),
1011
+ main_product_original_price: this.normalizeFingerprintMoney(metadata.main_product_original_price),
1012
+ product_discount_difference: this.normalizeFingerprintMoney(metadata.product_discount_difference)
1013
+ },
1014
+ product_sku: this.normalizeFingerprintValue({
1015
+ code: sku.code ?? "",
1016
+ barcode: sku.barcode ?? "",
1017
+ variant_id: sku.variant_id ?? (product == null ? void 0 : product.product_variant_id) ?? 0,
1018
+ variant: sku.variant || [],
1019
+ option: (0, import_utils.getProductSkuOptions)(product || {}).map((option) => ({
1020
+ id: (option == null ? void 0 : option.id) ?? (option == null ? void 0 : option.option_group_item_id) ?? null,
1021
+ option_group_id: (option == null ? void 0 : option.option_group_id) ?? null,
1022
+ option_group_item_id: (option == null ? void 0 : option.option_group_item_id) ?? (option == null ? void 0 : option.id) ?? null,
1023
+ num: Number((option == null ? void 0 : option.num) ?? 1) || 1,
1024
+ add_price: this.normalizeFingerprintMoney((option == null ? void 0 : option.add_price) ?? (option == null ? void 0 : option.price))
1025
+ }))
1026
+ }),
1027
+ product_bundle: this.normalizeFingerprintValue(((product == null ? void 0 : product.product_bundle) || []).map((bundle) => ({
1028
+ bundle_product_id: (bundle == null ? void 0 : bundle.bundle_product_id) ?? (bundle == null ? void 0 : bundle._bundle_product_id) ?? (bundle == null ? void 0 : bundle.product_id) ?? null,
1029
+ bundle_variant_id: (bundle == null ? void 0 : bundle.bundle_variant_id) ?? (bundle == null ? void 0 : bundle.product_variant_id) ?? 0,
1030
+ num: (0, import_utils3.getSafeProductNum)((bundle == null ? void 0 : bundle.num) ?? (bundle == null ? void 0 : bundle.quantity)),
1031
+ price: this.normalizeFingerprintMoney(bundle == null ? void 0 : bundle.price),
1032
+ bundle_selling_price: this.normalizeFingerprintMoney(bundle == null ? void 0 : bundle.bundle_selling_price),
1033
+ price_type: (bundle == null ? void 0 : bundle.price_type) ?? "",
1034
+ price_type_ext: (bundle == null ? void 0 : bundle.price_type_ext) ?? ""
1035
+ }))),
1036
+ discount_list: this.normalizeFingerprintValue(((product == null ? void 0 : product.discount_list) || []).map((discount) => {
1037
+ var _a;
1038
+ return {
1039
+ type: (discount == null ? void 0 : discount.type) ?? (discount == null ? void 0 : discount.tag) ?? "",
1040
+ discount_id: (discount == null ? void 0 : discount.discount_id) ?? (discount == null ? void 0 : discount.order_discount_id) ?? ((_a = discount == null ? void 0 : discount.discount) == null ? void 0 : _a.resource_id) ?? null,
1041
+ amount: this.normalizeFingerprintMoney(discount == null ? void 0 : discount.amount)
1042
+ };
1043
+ }))
1044
+ };
1045
+ }
1046
+ buildOrderProductsFingerprint(products) {
1047
+ const items = (products || []).map((product) => this.buildProductFingerprintItem(product));
1048
+ items.sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
1049
+ return JSON.stringify(items);
1050
+ }
1051
+ buildProductStructuralFingerprintItem(product) {
1052
+ const sku = (product == null ? void 0 : product.product_sku) || {};
1053
+ const metadata = (product == null ? void 0 : product.metadata) || {};
1054
+ const discountTypes = ((product == null ? void 0 : product.discount_list) || []).map((discount) => (discount == null ? void 0 : discount.type) ?? (discount == null ? void 0 : discount.tag));
1055
+ const extensionType = (product == null ? void 0 : product.extension_type) || (discountTypes.includes("good_pass") ? "good_pass" : "normal");
1056
+ return {
1057
+ product_id: (product == null ? void 0 : product.product_id) ?? null,
1058
+ product_variant_id: (product == null ? void 0 : product.product_variant_id) ?? null,
1059
+ extension_type: extensionType,
1060
+ num: (0, import_utils3.getSafeProductNum)((product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity)),
1061
+ metadata: {
1062
+ unique_identification_number: metadata.unique_identification_number ?? (product == null ? void 0 : product.unique_identification_number) ?? "",
1063
+ price_override: metadata.price_override ?? "",
1064
+ is_manual_discount: metadata.is_manual_discount ?? "",
1065
+ product_discount_reason: metadata.product_discount_reason ?? ""
1066
+ },
1067
+ product_sku: this.normalizeFingerprintValue({
1068
+ code: sku.code ?? "",
1069
+ barcode: sku.barcode ?? "",
1070
+ variant_id: sku.variant_id ?? (product == null ? void 0 : product.product_variant_id) ?? 0,
1071
+ variant: sku.variant || [],
1072
+ option: (0, import_utils.getProductSkuOptions)(product || {}).map((option) => ({
1073
+ id: (option == null ? void 0 : option.id) ?? (option == null ? void 0 : option.option_group_item_id) ?? null,
1074
+ option_group_id: (option == null ? void 0 : option.option_group_id) ?? null,
1075
+ option_group_item_id: (option == null ? void 0 : option.option_group_item_id) ?? (option == null ? void 0 : option.id) ?? null,
1076
+ num: Number((option == null ? void 0 : option.num) ?? 1) || 1,
1077
+ add_price: this.normalizeFingerprintMoney((option == null ? void 0 : option.add_price) ?? (option == null ? void 0 : option.price))
1078
+ }))
1079
+ }),
1080
+ product_bundle: this.normalizeFingerprintValue(((product == null ? void 0 : product.product_bundle) || []).map((bundle) => ({
1081
+ bundle_id: (bundle == null ? void 0 : bundle.bundle_id) ?? (bundle == null ? void 0 : bundle.id) ?? null,
1082
+ bundle_group_id: (bundle == null ? void 0 : bundle.bundle_group_id) ?? (bundle == null ? void 0 : bundle.group_id) ?? null,
1083
+ bundle_product_id: (bundle == null ? void 0 : bundle.bundle_product_id) ?? (bundle == null ? void 0 : bundle._bundle_product_id) ?? (bundle == null ? void 0 : bundle.product_id) ?? null,
1084
+ bundle_variant_id: (bundle == null ? void 0 : bundle.bundle_variant_id) ?? (bundle == null ? void 0 : bundle.product_variant_id) ?? 0,
1085
+ num: (0, import_utils3.getSafeProductNum)((bundle == null ? void 0 : bundle.num) ?? (bundle == null ? void 0 : bundle.quantity)),
1086
+ price_type: (bundle == null ? void 0 : bundle.price_type) ?? "",
1087
+ price_type_ext: (bundle == null ? void 0 : bundle.price_type_ext) ?? "",
1088
+ option: this.normalizeFingerprintValue(((bundle == null ? void 0 : bundle.option) || []).map((option) => ({
1089
+ id: (option == null ? void 0 : option.id) ?? (option == null ? void 0 : option.option_group_item_id) ?? null,
1090
+ option_group_id: (option == null ? void 0 : option.option_group_id) ?? null,
1091
+ option_group_item_id: (option == null ? void 0 : option.option_group_item_id) ?? (option == null ? void 0 : option.id) ?? null,
1092
+ num: Number((option == null ? void 0 : option.num) ?? 1) || 1,
1093
+ add_price: this.normalizeFingerprintMoney((option == null ? void 0 : option.add_price) ?? (option == null ? void 0 : option.price))
1094
+ })))
1095
+ }))),
1096
+ discount_list: this.normalizeFingerprintValue(((product == null ? void 0 : product.discount_list) || []).map((discount) => {
1097
+ var _a;
1098
+ return {
1099
+ type: (discount == null ? void 0 : discount.type) ?? (discount == null ? void 0 : discount.tag) ?? "",
1100
+ discount_id: (discount == null ? void 0 : discount.discount_id) ?? (discount == null ? void 0 : discount.order_discount_id) ?? ((_a = discount == null ? void 0 : discount.discount) == null ? void 0 : _a.resource_id) ?? null,
1101
+ amount: this.normalizeFingerprintMoney(discount == null ? void 0 : discount.amount)
1102
+ };
1103
+ }))
1104
+ };
1105
+ }
1106
+ buildOrderProductsStructuralFingerprint(products) {
1107
+ const items = (products || []).map((product) => this.buildProductStructuralFingerprintItem(product));
1108
+ items.sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
1109
+ return JSON.stringify(items);
1110
+ }
1111
+ getOriginalSalesSnapshot(tempOrder) {
1112
+ var _a;
1113
+ const snapshot = (_a = tempOrder._extend) == null ? void 0 : _a.originalSalesSnapshot;
1114
+ if (!snapshot || typeof snapshot !== "object")
1115
+ return null;
1116
+ if (typeof snapshot.productFingerprint !== "string")
1117
+ return null;
1118
+ return snapshot;
1119
+ }
1120
+ restoreOriginalSnapshotIfProductsUnchanged(tempOrder) {
1121
+ const snapshot = this.getOriginalSalesSnapshot(tempOrder);
1122
+ if (!snapshot)
1123
+ return null;
1124
+ const currentFingerprint = this.buildOrderProductsFingerprint(tempOrder.products);
1125
+ if (currentFingerprint !== snapshot.productFingerprint) {
1126
+ const currentStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(tempOrder.products);
1127
+ const snapshotStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(
1128
+ Array.isArray(snapshot.products) ? snapshot.products : []
1129
+ );
1130
+ if (currentStructuralFingerprint !== snapshotStructuralFingerprint)
1131
+ return null;
1132
+ }
1133
+ const summary = {
1134
+ ...(0, import_utils.createEmptySummary)(),
1135
+ ...(0, import_lodash_es.cloneDeep)(snapshot.summary || {})
1136
+ };
1137
+ if (Array.isArray(snapshot.products)) {
1138
+ tempOrder.products = (0, import_lodash_es.cloneDeep)(snapshot.products);
1139
+ }
1140
+ if (Array.isArray(snapshot.surcharges)) {
1141
+ tempOrder.surcharges = (0, import_lodash_es.cloneDeep)(snapshot.surcharges);
1142
+ }
1143
+ tempOrder.surcharge_fee = summary.surcharge_fee || tempOrder.surcharge_fee;
1144
+ tempOrder.deposit_amount = summary.deposit_amount || "0.00";
1145
+ tempOrder.is_deposit = summary.deposit_amount !== "0.00" ? 1 : 0;
1146
+ this.store.summary = summary;
1147
+ return summary;
1148
+ }
1149
+ clearPersistedAmountFieldsForFullRecalc(products) {
1150
+ const moneyKeys = [
1151
+ "surcharge_fee",
1152
+ "main_product_attached_bundle_surcharge_fee",
1153
+ "surcharge_rounding_remainder",
1154
+ "main_product_attached_bundle_tax_fee",
1155
+ "tax_fee",
1156
+ "original_tax_fee",
1157
+ "tax_fee_rounding_remainder",
1158
+ "original_tax_fee_rounding_remainder"
1159
+ ];
1160
+ const metadataMoneyKeys = [
1161
+ "main_product_attached_bundle_surcharge_fee",
1162
+ "surcharge_rounding_remainder",
1163
+ "main_product_attached_bundle_tax_fee",
1164
+ "tax_fee_rounding_remainder"
1165
+ ];
1166
+ for (const product of products || []) {
1167
+ const record = product;
1168
+ for (const key of moneyKeys)
1169
+ delete record[key];
1170
+ if (record.metadata && typeof record.metadata === "object") {
1171
+ record.metadata = { ...record.metadata };
1172
+ for (const key of metadataMoneyKeys)
1173
+ delete record.metadata[key];
1174
+ }
1175
+ for (const bundle of record.product_bundle || []) {
1176
+ for (const key of moneyKeys)
1177
+ delete bundle[key];
1178
+ if (bundle.metadata && typeof bundle.metadata === "object") {
1179
+ bundle.metadata = { ...bundle.metadata };
1180
+ for (const key of metadataMoneyKeys)
1181
+ delete bundle.metadata[key];
1182
+ }
1183
+ }
1184
+ }
838
1185
  }
839
1186
  getPaymentTargetAmount() {
840
1187
  const tempOrder = this.ensureTempOrder();
@@ -1092,6 +1439,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1092
1439
  if (!tempOrder)
1093
1440
  return null;
1094
1441
  this.sanitizeTempOrderProducts(tempOrder);
1442
+ const snapshotSummary = this.restoreOriginalSnapshotIfProductsUnchanged(tempOrder);
1443
+ if (snapshotSummary)
1444
+ return snapshotSummary;
1445
+ const shouldFullRecalculateFromSnapshot = Boolean(this.getOriginalSalesSnapshot(tempOrder));
1446
+ const summaryProducts = shouldFullRecalculateFromSnapshot ? (0, import_lodash_es.cloneDeep)(tempOrder.products || []) : tempOrder.products;
1447
+ if (shouldFullRecalculateFromSnapshot) {
1448
+ this.clearPersistedAmountFieldsForFullRecalc(summaryProducts || []);
1449
+ }
1095
1450
  const salesSummary = this.getSalesSummary();
1096
1451
  const existedSummary = this.store.summary || (0, import_utils.createEmptySummary)();
1097
1452
  const totalRefundAmount = existedSummary.total_refund_amount || "0.00";
@@ -1112,7 +1467,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1112
1467
  summary: emptyBaseSummary,
1113
1468
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
1114
1469
  }),
1115
- pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
1470
+ pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2),
1471
+ rounding_amount: paidPaymentSummary.roundingAmount.toFixed(2)
1116
1472
  };
1117
1473
  tempOrder.surcharge_fee = emptySummary.surcharge_fee;
1118
1474
  this.store.summary = emptySummary;
@@ -1123,26 +1479,47 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1123
1479
  return this.store.summary;
1124
1480
  }
1125
1481
  const salesSummaryResult = await salesSummary.getSummary({
1126
- products: tempOrder.products,
1482
+ products: summaryProducts,
1127
1483
  isPriceIncludeTax: tempOrder.is_price_include_tax,
1128
1484
  shopDiscount: tempOrder.shop_discount
1129
1485
  });
1486
+ if (shouldFullRecalculateFromSnapshot) {
1487
+ tempOrder.products = summaryProducts;
1488
+ }
1130
1489
  this.syncSummaryProductMetadata(tempOrder.products || []);
1490
+ const roundingAmount = paidPaymentSummary.roundingAmount;
1491
+ const payServiceChargeAmount = paidPaymentSummary.payServiceChargeAmount;
1492
+ const hasSalesSummaryAmount = salesSummaryResult.expect_amount !== void 0 || salesSummaryResult.total_amount !== void 0;
1493
+ const expectAmount = hasSalesSummaryAmount ? new import_decimal.default(salesSummaryResult.expect_amount ?? salesSummaryResult.total_amount ?? 0) : null;
1494
+ const amountPaymentPatch = hasSalesSummaryAmount || !roundingAmount.eq(0) || !payServiceChargeAmount.eq(0) ? {
1495
+ rounding_amount: roundingAmount.toFixed(2),
1496
+ ...expectAmount ? {
1497
+ total_amount: import_decimal.default.max(
1498
+ 0,
1499
+ expectAmount.plus(roundingAmount).plus(payServiceChargeAmount)
1500
+ ).toFixed(2)
1501
+ } : {}
1502
+ } : {};
1503
+ const normalizedExpectAmountPatch = expectAmount && salesSummaryResult.expect_amount === void 0 ? { expect_amount: expectAmount.toFixed(2) } : {};
1131
1504
  const summaryForGap = {
1132
1505
  ...salesSummaryResult,
1133
- total_refund_amount: totalRefundAmount
1506
+ total_refund_amount: totalRefundAmount,
1507
+ ...amountPaymentPatch,
1508
+ ...normalizedExpectAmountPatch
1134
1509
  };
1135
1510
  const summary = {
1136
1511
  ...salesSummaryResult,
1137
1512
  total_refund_amount: totalRefundAmount,
1138
1513
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
1139
1514
  order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
1515
+ ...amountPaymentPatch,
1516
+ ...normalizedExpectAmountPatch,
1140
1517
  amount_gap: this.calculateSummaryAmountGap({
1141
1518
  tempOrder,
1142
1519
  summary: summaryForGap,
1143
1520
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
1144
1521
  }),
1145
- pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
1522
+ pay_service_charge_amount: payServiceChargeAmount.toFixed(2)
1146
1523
  };
1147
1524
  this.store.summary = summary;
1148
1525
  if (summary.is_price_include_tax !== void 0) {
@@ -1226,6 +1603,49 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1226
1603
  email: String(source.email ?? params.email)
1227
1604
  };
1228
1605
  }
1606
+ isCustomerBoundDiscount(discount) {
1607
+ const type = (discount == null ? void 0 : discount.type) ?? (discount == null ? void 0 : discount.tag);
1608
+ return type === "good_pass" || type === "discount_card" || type === "product_discount_card";
1609
+ }
1610
+ clearCustomerBoundDiscounts(tempOrder) {
1611
+ var _a, _b, _c, _d;
1612
+ const filterDiscountList = (discountList) => {
1613
+ if (!Array.isArray(discountList))
1614
+ return [];
1615
+ return discountList.filter((discount) => !this.isCustomerBoundDiscount(discount));
1616
+ };
1617
+ tempOrder.products = (tempOrder.products || []).map((product) => {
1618
+ const nextProduct = {
1619
+ ...product,
1620
+ discount_list: filterDiscountList(product.discount_list)
1621
+ };
1622
+ if (Array.isArray(nextProduct.product_bundle)) {
1623
+ nextProduct.product_bundle = nextProduct.product_bundle.map((bundle) => ({
1624
+ ...bundle,
1625
+ discount_list: filterDiscountList(bundle.discount_list)
1626
+ }));
1627
+ }
1628
+ return nextProduct;
1629
+ });
1630
+ delete tempOrder.discount_list;
1631
+ const discountModule = this.store.discount;
1632
+ if (!discountModule)
1633
+ return;
1634
+ const currentDiscounts = ((_a = discountModule.getDiscountList) == null ? void 0 : _a.call(discountModule)) || [];
1635
+ const currentOriginalDiscounts = ((_b = discountModule.getOriginalDiscountList) == null ? void 0 : _b.call(discountModule)) || [];
1636
+ const nextDiscounts = currentDiscounts.filter((discount) => {
1637
+ if (discount == null ? void 0 : discount.isEditMode)
1638
+ return true;
1639
+ return !this.isCustomerBoundDiscount(discount);
1640
+ });
1641
+ const nextOriginalDiscounts = currentOriginalDiscounts.filter((discount) => {
1642
+ if (discount == null ? void 0 : discount.isEditMode)
1643
+ return true;
1644
+ return !this.isCustomerBoundDiscount(discount);
1645
+ });
1646
+ void ((_c = discountModule.setDiscountList) == null ? void 0 : _c.call(discountModule, nextDiscounts));
1647
+ void ((_d = discountModule.setOriginalDiscountList) == null ? void 0 : _d.call(discountModule, nextOriginalDiscounts));
1648
+ }
1229
1649
  /**
1230
1650
  * 更新当前 tempOrder 的客户协议字段。
1231
1651
  *
@@ -1234,6 +1654,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1234
1654
  */
1235
1655
  updateTempOrderCustomer(customer) {
1236
1656
  const tempOrder = this.ensureTempOrder();
1657
+ const previousCustomerId = tempOrder.customer_id ?? null;
1237
1658
  const customerId = customer.customer_id ?? customer.customerId ?? customer.id ?? null;
1238
1659
  const customerName = customer.customer_name ?? customer.customerName ?? customer.display_name ?? customer.name ?? "";
1239
1660
  tempOrder.customer_id = customerId === null || customerId === void 0 || customerId === "" ? null : Number(customerId);
@@ -1251,6 +1672,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1251
1672
  phone: tempOrder.phone,
1252
1673
  email: tempOrder.email
1253
1674
  });
1675
+ const nextCustomerId = tempOrder.customer_id ?? null;
1254
1676
  this.persistTempOrder();
1255
1677
  return {
1256
1678
  customerId: tempOrder.customer_id,
@@ -1289,6 +1711,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1289
1711
  const nextCustomerId = tempOrder.customer_id ?? null;
1290
1712
  if (String(previousCustomerId ?? "") !== String(nextCustomerId ?? "")) {
1291
1713
  (0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
1714
+ this.clearCustomerBoundDiscounts(tempOrder);
1292
1715
  }
1293
1716
  this.persistTempOrder();
1294
1717
  this.saveDraftInBackground();
@@ -1325,6 +1748,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1325
1748
  tempOrder.customer = null;
1326
1749
  if (tempOrder._extend)
1327
1750
  delete tempOrder._extend.customerSnapshot;
1751
+ this.clearCustomerBoundDiscounts(tempOrder);
1328
1752
  this.persistTempOrder();
1329
1753
  this.saveDraftInBackground();
1330
1754
  this.core.effects.emit(import_types.OrderHooks.OnOrderCustomerChange, null);
@@ -1445,21 +1869,41 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1445
1869
  */
1446
1870
  updateVoucherOrderPayments(payments) {
1447
1871
  const tempOrder = this.ensureTempOrder();
1872
+ const isVoucherPayment = (payment) => {
1873
+ return payment.voucher_id !== void 0 && Number(payment.voucher_id) !== 0;
1874
+ };
1875
+ const hasSyncedOrderPayment = (payment) => {
1876
+ return payment.order_payment_id !== void 0 && payment.order_payment_id !== null;
1877
+ };
1448
1878
  const mappedVouchers = (0, import_utils.mapPaymentItemsToOrderPayments)(
1449
1879
  payments.map(
1450
1880
  (payment) => this.normalizePaymentSource(payment, { defaultPaid: true })
1451
1881
  )
1452
1882
  ).filter((payment) => {
1453
- return payment.voucher_id !== void 0 && Number(payment.voucher_id) !== 0;
1883
+ return isVoucherPayment(payment);
1454
1884
  });
1455
1885
  const nonVoucherPayments = (tempOrder.payments || []).filter((payment) => {
1456
- return payment.voucher_id === void 0 || Number(payment.voucher_id) === 0;
1886
+ return !isVoucherPayment(payment);
1887
+ });
1888
+ const syncedVoucherPayments = (tempOrder.payments || []).filter((payment) => {
1889
+ return isVoucherPayment(payment) && hasSyncedOrderPayment(payment);
1890
+ });
1891
+ const syncedVoucherPaymentIds = new Set(
1892
+ syncedVoucherPayments.map((payment) => String(payment.order_payment_id))
1893
+ );
1894
+ const replaceableVouchers = mappedVouchers.filter((payment) => {
1895
+ if (!hasSyncedOrderPayment(payment))
1896
+ return true;
1897
+ return !syncedVoucherPaymentIds.has(String(payment.order_payment_id));
1457
1898
  });
1458
1899
  const cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
1459
- vouchers: mappedVouchers,
1460
- nonVoucherPayments
1900
+ vouchers: replaceableVouchers,
1901
+ nonVoucherPayments: [
1902
+ ...nonVoucherPayments,
1903
+ ...syncedVoucherPayments
1904
+ ]
1461
1905
  });
1462
- tempOrder.payments = [...nonVoucherPayments, ...cappedVouchers];
1906
+ tempOrder.payments = [...nonVoucherPayments, ...syncedVoucherPayments, ...cappedVouchers];
1463
1907
  this.updateTempOrderPaymentStatus(tempOrder);
1464
1908
  this.persistTempOrder();
1465
1909
  void this.recalculateSummary({ createIfMissing: true }).catch((error) => {
@@ -1610,6 +2054,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1610
2054
  if (linked) {
1611
2055
  tempOrder.bookings = [...tempOrder.bookings || [], linked.booking];
1612
2056
  }
2057
+ await this.ensureEditDiscountConfigForProductChange(tempOrder);
1613
2058
  await this.applyPromotion();
1614
2059
  this.applyDiscount();
1615
2060
  this.sanitizeTempOrderProducts(tempOrder);
@@ -1635,6 +2080,44 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1635
2080
  (item) => (item == null ? void 0 : item.type) === "good_pass" || (item == null ? void 0 : item.tag) === "good_pass"
1636
2081
  );
1637
2082
  }
2083
+ getBundleRuntimeIdentity(bundle) {
2084
+ if (!bundle || typeof bundle !== "object")
2085
+ return "";
2086
+ return [
2087
+ bundle.bundle_id ?? bundle.id ?? "",
2088
+ bundle.bundle_group_id ?? bundle.group_id ?? "",
2089
+ bundle.bundle_product_id ?? bundle._bundle_product_id ?? bundle.product_id ?? "",
2090
+ bundle.bundle_variant_id ?? bundle.product_variant_id ?? 0
2091
+ ].join("|");
2092
+ }
2093
+ preservePersistedBundlePriceFields(previousBundles, nextBundles) {
2094
+ if (!Array.isArray(nextBundles))
2095
+ return nextBundles;
2096
+ if (!Array.isArray(previousBundles) || previousBundles.length === 0)
2097
+ return nextBundles;
2098
+ const previousByIdentity = /* @__PURE__ */ new Map();
2099
+ previousBundles.forEach((bundle) => {
2100
+ const identity = this.getBundleRuntimeIdentity(bundle);
2101
+ if (identity)
2102
+ previousByIdentity.set(identity, bundle);
2103
+ });
2104
+ return nextBundles.map((bundle, index) => {
2105
+ if (!bundle || typeof bundle !== "object")
2106
+ return bundle;
2107
+ const previous = previousByIdentity.get(this.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
2108
+ if (!previous || typeof previous !== "object")
2109
+ return bundle;
2110
+ return {
2111
+ ...bundle,
2112
+ price: previous.price,
2113
+ custom_price: previous.custom_price,
2114
+ bundle_payment_price: previous.bundle_payment_price,
2115
+ bundle_selling_price: previous.bundle_selling_price,
2116
+ original_price: previous.original_price,
2117
+ product_price: previous.product_price
2118
+ };
2119
+ });
2120
+ }
1638
2121
  async updateOrderProduct(params) {
1639
2122
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1640
2123
  const {
@@ -1715,6 +2198,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1715
2198
  main_product_original_price: (_k = targetProduct.metadata) == null ? void 0 : _k.main_product_original_price,
1716
2199
  price_schema_version: ((_l = targetProduct.metadata) == null ? void 0 : _l.price_schema_version) ?? 2
1717
2200
  };
2201
+ nextProduct.product_bundle = this.preservePersistedBundlePriceFields(
2202
+ targetProduct.product_bundle,
2203
+ nextProduct.product_bundle
2204
+ );
1718
2205
  } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
1719
2206
  const existedMeta = nextProduct.metadata || {};
1720
2207
  nextProduct.metadata = { ...existedMeta };
@@ -2380,11 +2867,31 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2380
2867
  * 例如数组字段、商品行唯一值、价格 metadata、summary 派生状态和 _extend。
2381
2868
  */
2382
2869
  async hydrateTempOrderFromRecord(record, options) {
2870
+ var _a, _b;
2383
2871
  const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
2384
2872
  const nextTempOrder = this.normalizeTempOrderForRuntime(raw);
2873
+ const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
2874
+ const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map((s) => ({ ...s || {} })) : (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []);
2385
2875
  this.store.tempOrder = nextTempOrder;
2386
- this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
2876
+ this.store.summary = {
2877
+ ...(0, import_utils.createEmptySummary)(),
2878
+ ...rawSummary,
2879
+ surcharges: summarySurcharges
2880
+ };
2881
+ nextTempOrder._extend = {
2882
+ ...nextTempOrder._extend || {},
2883
+ originalSalesSnapshot: {
2884
+ summary: (0, import_lodash_es.cloneDeep)(this.store.summary),
2885
+ products: (0, import_lodash_es.cloneDeep)(nextTempOrder.products || []),
2886
+ payments: (0, import_lodash_es.cloneDeep)(nextTempOrder.payments || []),
2887
+ surcharges: (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []),
2888
+ productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
2889
+ }
2890
+ };
2387
2891
  this.store.lastOrderInfo = raw.lastOrderInfo || raw;
2892
+ const hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
2893
+ await ((_a = this.store.discount) == null ? void 0 : _a.setOriginalDiscountList(hydratedEditDiscounts));
2894
+ await ((_b = this.store.discount) == null ? void 0 : _b.setDiscountList(hydratedEditDiscounts));
2388
2895
  if (options == null ? void 0 : options.recalcOnHydrate) {
2389
2896
  await this.recalculateSummary({ createIfMissing: false });
2390
2897
  }