From 4e162188480767513845f9b47e298770570d6a75 Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Wed, 1 Sep 2021 08:59:52 +0000 Subject: [PATCH] [FIX] pos_coupon: remove the reward lines before recomputation of rewards Task-id: 2631220 Part-of: odoo/odoo#77903 --- addons/pos_coupon/static/src/js/coupon.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/pos_coupon/static/src/js/coupon.js b/addons/pos_coupon/static/src/js/coupon.js index c7156704d20..f86e9297004 100644 --- a/addons/pos_coupon/static/src/js/coupon.js +++ b/addons/pos_coupon/static/src/js/coupon.js @@ -22,6 +22,7 @@ odoo.define('pos_coupon.pos', function (require) { const session = require('web.session'); const concurrency = require('web.concurrency'); const { Gui } = require('point_of_sale.Gui'); + const { float_is_zero } = require('web.utils'); const dp = new concurrency.DropPrevious(); @@ -258,7 +259,6 @@ odoo.define('pos_coupon.pos', function (require) { () => { if (!this.pos.config.use_coupon_programs) return; dp.add(this._getNewRewardLines()).then(([newRewardLines, rewardsContainer]) => { - this.orderlines.remove(this._getRewardLines()); this.orderlines.add(newRewardLines); // We need this for the rendering of ActivePrograms component. this.rewardsContainer = rewardsContainer; @@ -427,6 +427,8 @@ odoo.define('pos_coupon.pos', function (require) { * @returns {[models.Orderline[], RewardsContainer]} */ _getNewRewardLines: async function () { + // Remove the reward lines before recalculation of rewards. + this.orderlines.remove(this._getRewardLines()); const rewardsContainer = await this._calculateRewards(); // We set the programs that will generate coupons after validation of this order. // See `_postPushOrderResolve` in the `PaymentScreen`. @@ -770,7 +772,12 @@ odoo.define('pos_coupon.pos', function (require) { ? this.get_total_with_tax() : this.get_total_without_tax(); // TODO jcb rule_minimum_amount has to be converted. - if (!(amountToCheck >= program.rule_minimum_amount)) { + if ( + !( + amountToCheck > program.rule_minimum_amount || + float_is_zero(amountToCheck - program.rule_minimum_amount, this.pos.currency.decimals) + ) + ) { return { successful: false, reason: 'Minimum amount for this program is not satisfied.',