From d1bfd81554efeb60074c8cd51fd06f86fbb2b394 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Fri, 29 May 2026 17:14:56 +0700 Subject: [PATCH] refactor: move _code_activated_coupon_ids property definition from PosStore to PosOrder for better state management --- .../src/app/pos_loyalty_safe_coupon_patch.js | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/static/src/app/pos_loyalty_safe_coupon_patch.js b/static/src/app/pos_loyalty_safe_coupon_patch.js index 2a60236..398fb75 100644 --- a/static/src/app/pos_loyalty_safe_coupon_patch.js +++ b/static/src/app/pos_loyalty_safe_coupon_patch.js @@ -52,6 +52,28 @@ patch(PosOrderline.prototype, { // ─── PosOrder patches ───────────────────────────────────────────────────────── 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. */ @@ -124,24 +146,6 @@ patch(OrderPaymentValidation.prototype, { // ─── PosStore patches ───────────────────────────────────────────────────────── 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. */