From 9c19cadef7df7e90bf89457c9145f263824425ba Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Mon, 6 Sep 2021 14:29:52 +0000 Subject: [PATCH] [FIX] pos_coupon: do not count refund orderlines when computing rewards 1. Sell Product A with discount because of Automatic Promo on specific product. 2. Refund Product A with its discount. 3. Add Product A in the refund order. [BUG] No discount for the added Product A because the total count of Product A in the order is 0 (or less because of the discount line). In this fix, we don't count the refund orderlines, this way, when a product is added which qualifies the automatic promo, that new line will be properly discounted. Part-of: odoo/odoo#77903 --- addons/pos_coupon/static/src/js/coupon.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/addons/pos_coupon/static/src/js/coupon.js b/addons/pos_coupon/static/src/js/coupon.js index a70e3fcd259..c7156704d20 100644 --- a/addons/pos_coupon/static/src/js/coupon.js +++ b/addons/pos_coupon/static/src/js/coupon.js @@ -297,11 +297,21 @@ odoo.define('pos_coupon.pos', function (require) { * rendered at the bottom of the orderlines list. */ get_orderlines: function () { - return [...this._getRegularOrderlines(), ...this._getRewardLines()]; + const orderlines = _order_super.get_orderlines.apply(this, arguments); + const rewardLines = []; + const nonRewardLines = []; + for (const line of orderlines) { + if (line.is_program_reward) { + rewardLines.push(line); + } else { + nonRewardLines.push(line); + } + } + return [...nonRewardLines, ...rewardLines]; }, _getRegularOrderlines: function () { const orderlines = _order_super.get_orderlines.apply(this, arguments); - return orderlines.filter((line) => !line.is_program_reward); + return orderlines.filter((line) => !line.is_program_reward && !line.refunded_orderline_id); }, _getRewardLines: function () { const orderlines = _order_super.get_orderlines.apply(this, arguments);