[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
This commit is contained in:
Joseph Caburnay
2021-10-06 10:27:04 +00:00
committed by Pierre Masereel
parent 44b9f7d343
commit 9c19cadef7
+12 -2
View File
@@ -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);