From 0ab9cf3fa0af7ea164031aa97725c03752628f87 Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Fri, 28 Jan 2022 14:49:02 +0000 Subject: [PATCH] [FIX] pos_coupon: Coupons code disappear when switching table Current behavior: When adding a coupon with a code in a PoS (restaurant/bar) if you switch table and come back to the first table the coupon code is disappearing Steps to reproduce: - Activate promo code for a PoS (restaurant/bar) - Go on table A, add some product and enter a code for the order - Leave table, and come back to table A - The promo code has dissapeared note: A better fix could be done on master adding bookedCouponCode on order field to save it between the table switching. opw-2733081 closes odoo/odoo#85524 X-original-commit: bdc4895226374932a92a543ff25ea1a41d5a4ce8 Signed-off-by: Grazioso Andrea (agr) Signed-off-by: Engels Robin (roen) --- addons/pos_coupon/models/pos_order.py | 6 +++++- addons/pos_coupon/static/src/js/coupon.js | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/addons/pos_coupon/models/pos_order.py b/addons/pos_coupon/models/pos_order.py index 5e8edf7b55f..07ec797b186 100644 --- a/addons/pos_coupon/models/pos_order.py +++ b/addons/pos_coupon/models/pos_order.py @@ -64,7 +64,11 @@ class PosOrder(models.Model): def _get_fields_for_order_line(self): fields = super(PosOrder, self)._get_fields_for_order_line() - fields.append('is_program_reward') + fields.extend({ + 'is_program_reward', + 'coupon_id', + 'program_id', + }) return fields class PosOrderLine(models.Model): diff --git a/addons/pos_coupon/static/src/js/coupon.js b/addons/pos_coupon/static/src/js/coupon.js index d5db2791744..0ccebf51487 100644 --- a/addons/pos_coupon/static/src/js/coupon.js +++ b/addons/pos_coupon/static/src/js/coupon.js @@ -238,9 +238,9 @@ odoo.define('pos_coupon.pos', function (require) { this._initializePrograms(); } init_from_JSON(json) { + this.bookedCouponCodes = this.bookedCouponCodes ? this.order.bookedCouponCodes : {}; + this.activePromoProgramIds = this.activePromoProgramIds ? this.order.activePromoProgramIds : []; super.init_from_JSON(...arguments); - this.bookedCouponCodes = json.bookedCouponCodes; - this.activePromoProgramIds = json.activePromoProgramIds; } export_as_JSON() { let json = super.export_as_JSON(...arguments); @@ -1022,6 +1022,11 @@ odoo.define('pos_coupon.pos', function (require) { this.is_program_reward = json.is_program_reward; this.program_id = json.program_id; this.coupon_id = json.coupon_id; + if (this.coupon_id && this.coupon_id[1]) { + this.order.bookedCouponCodes[this.coupon_id[1]] = new CouponCode(this.coupon_id[1], this.coupon_id[0], this.program_id[0]); + } else if (json.program_id && json.program_id[0]) { + this.order.activePromoProgramIds.push(json.program_id[0]); + } } super.init_from_JSON(...arguments); }