Skip to content

Commit 385627f

Browse files
committed
[FIX] pos_loyalty: compute point rewarded when discount reward updates
Currently loyalty points rewarded are not correctly computed when there is a discount reward that updates its prices. Steps to reproduce: ------------------- * Create a loyalty program 1 point per $ spent * Create a promo program, 10% on order, minimum 1 product on the order * Create a product to sell in the pos, price 1$ * Open pos shop * Select any customer * Select the created product once > Observation: To pay 0.9$, points remarded 0.9 OK * Select the created product once again > Observation: To pay 1.8$, points remarded 1.9 NOT OK Why the fix: ------------ https://github.com/odoo/odoo/blob/b87c896969cc576a799ac63f03501be1e87b0e84/addons/pos_loyalty/static/src/overrides/models/loyalty.js#L362-L384 As the promo program giving the discoutn has already been triggered once, it is not considered claimable again thus `changed` will never be set to true. Thus we never call `_updateLoyaltyPrograms()`. The recomputation of the price value for the promo discount is done by `_updateRewardLines()`, the points need to be computed afterward . opw-4804205 closes odoo#217925 Signed-off-by: Adrien Guilliams (adgu) <adgu@odoo.com>
1 parent 3e1ac28 commit 385627f

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

addons/pos_loyalty/static/src/overrides/models/loyalty.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ patch(Order.prototype, {
363363
return this._updateLoyaltyPrograms().then(async () => {
364364
// Try auto claiming rewards
365365
const claimableRewards = this.getClaimableRewards(false, false, true);
366-
let changed = false;
367366
for (const { coupon_id, reward } of claimableRewards) {
368367
if (
369368
reward.program_id.rewards.length === 1 &&
@@ -372,14 +371,10 @@ patch(Order.prototype, {
372371
(reward.reward_type == "product" && !reward.multi_product))
373372
) {
374373
this._applyReward(reward, coupon_id);
375-
changed = true;
376374
}
377375
}
378-
// Rewards may impact the number of points gained
379-
if (changed) {
380-
await this._updateLoyaltyPrograms();
381-
}
382376
this._updateRewardLines();
377+
await this._updateLoyaltyPrograms();
383378
});
384379
});
385380
},

addons/pos_loyalty/static/tests/tours/PosLoyaltyTour.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,11 @@ registry.category("web_tour.tours").add("PosLoyaltyPointsGlobalDiscountProgramNo
467467
ProductScreen.clickCustomer("AAAA"),
468468
ProductScreen.addOrderline("product_a", "1"),
469469
PosLoyalty.hasRewardLine("10% on your order", "-10.00"),
470-
PosLoyalty.orderTotalIs("90"),
471-
PosLoyalty.pointsAwardedAre("90"),
472-
PosLoyalty.finalizeOrder("Cash", "90"),
470+
ProductScreen.clickDisplayedProduct("product_a"),
471+
PosLoyalty.hasRewardLine("10% on your order", "-20.00"),
472+
PosLoyalty.orderTotalIs("180"),
473+
PosLoyalty.pointsAwardedAre("180"),
474+
PosLoyalty.finalizeOrder("Cash", "180"),
473475
].flat(),
474476
});
475477

addons/pos_loyalty/tests/test_frontend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ def test_points_awarded_global_discount_code_no_domain_program(self):
18551855
"PosLoyaltyPointsGlobalDiscountProgramNoDomain",
18561856
login="pos_user",
18571857
)
1858-
self.assertEqual(loyalty_card.points, 90)
1858+
self.assertEqual(loyalty_card.points, 180)
18591859

18601860
def test_points_awarded_discount_code_no_domain_program(self):
18611861
"""

0 commit comments

Comments
 (0)