refactor: move _code_activated_coupon_ids filter logic from PosOrder to a dynamic property wrapper in PosStore setup
This commit is contained in:
parent
d308497945
commit
c1735741a0
@ -52,22 +52,6 @@ patch(PosOrderline.prototype, {
|
|||||||
// ─── PosOrder patches ─────────────────────────────────────────────────────────
|
// ─── PosOrder patches ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
patch(PosOrder.prototype, {
|
patch(PosOrder.prototype, {
|
||||||
get _code_activated_coupon_ids() {
|
|
||||||
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 _code_activated_coupon_ids(values) {
|
|
||||||
this.update({ _code_activated_coupon_ids: values });
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getLoyaltyPoints reads coupon_id.id — guard undefined coupon_id.
|
* getLoyaltyPoints reads coupon_id.id — guard undefined coupon_id.
|
||||||
*/
|
*/
|
||||||
@ -140,6 +124,24 @@ 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