refactor: move _code_activated_coupon_ids property definition from PosStore to PosOrder for better state management
This commit is contained in:
parent
c1735741a0
commit
d1bfd81554
@ -52,6 +52,28 @@ patch(PosOrderline.prototype, {
|
|||||||
// ─── PosOrder patches ─────────────────────────────────────────────────────────
|
// ─── PosOrder patches ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
patch(PosOrder.prototype, {
|
patch(PosOrder.prototype, {
|
||||||
|
setup() {
|
||||||
|
super.setup(...arguments);
|
||||||
|
Object.defineProperty(this, "_code_activated_coupon_ids", {
|
||||||
|
get() {
|
||||||
|
const ids = this.raw._code_activated_coupon_ids || [];
|
||||||
|
const result = [];
|
||||||
|
for (const id of ids) {
|
||||||
|
const coupon = this.models["loyalty.card"].get(id);
|
||||||
|
if (coupon && coupon.program_id) {
|
||||||
|
result.push(coupon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
set(values) {
|
||||||
|
this.update({ _code_activated_coupon_ids: values });
|
||||||
|
},
|
||||||
|
configurable: true,
|
||||||
|
enumerable: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getLoyaltyPoints reads coupon_id.id — guard undefined coupon_id.
|
* getLoyaltyPoints reads coupon_id.id — guard undefined coupon_id.
|
||||||
*/
|
*/
|
||||||
@ -124,24 +146,6 @@ patch(OrderPaymentValidation.prototype, {
|
|||||||
// ─── PosStore patches ─────────────────────────────────────────────────────────
|
// ─── PosStore patches ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
patch(PosStore.prototype, {
|
patch(PosStore.prototype, {
|
||||||
async setup(env, deps) {
|
|
||||||
await super.setup(...arguments);
|
|
||||||
const desc = Object.getOwnPropertyDescriptor(PosOrder.prototype, "_code_activated_coupon_ids");
|
|
||||||
if (desc && desc.get) {
|
|
||||||
const originalGet = desc.get;
|
|
||||||
Object.defineProperty(PosOrder.prototype, "_code_activated_coupon_ids", {
|
|
||||||
get: function () {
|
|
||||||
const result = originalGet.call(this);
|
|
||||||
if (!result) return result;
|
|
||||||
return result.filter((coupon) => coupon && coupon.program_id);
|
|
||||||
},
|
|
||||||
set: desc.set,
|
|
||||||
configurable: true,
|
|
||||||
enumerable: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* afterProcessServerData — purge orphaned lines from ALL orders after load.
|
* afterProcessServerData — purge orphaned lines from ALL orders after load.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user