[FIX] pos_loyalty: specific discountable take discount into account

Current behavior:
When computing the discountable values of an order, the discount of the
program where not taken into account if you used specific discountable
products.

Steps to reproduce:
- Create products A and B with a price of 20$
- Create a loyalty program
- Rule:
  - Minimum qty : 2
  - Apply on specific products : Product A and Product B
  - Reward : 5 points per order
- Reward:
  - 10$ per order
  - In exchange of 2 points
  - Apply on specific products : Product A and Product B
- Open PoS and add Product A and Product B to the order
- A reward should be added automatically with a value of -10$
- Click on the reward button, another reward should be added but it has
  the wrong value. It should be -10$ but it is not.

opw-3232565

closes odoo/odoo#126245

X-original-commit: f33d3b09ff49aae1fdaf3379915b7e7b5f03080c
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
Signed-off-by: Robin Engels (roen) <roen@odoo.com>
This commit is contained in:
roen-odoo
2023-06-23 18:00:13 +02:00
parent ccb41edf2b
commit 075da19e4e
3 changed files with 60 additions and 1 deletions
+1 -1
View File
@@ -1127,7 +1127,7 @@ patch(Order.prototype, "pos_loyalty.Order", {
} else if (line.reward_id) {
const lineReward = this.pos.reward_by_id[line.reward_id];
if (lineReward.id === reward.id) {
continue;
linesToDiscount.push(line);
}
if (!discountLinesPerReward[line.reward_identifier_code]) {
discountLinesPerReward[line.reward_identifier_code] = [];
@@ -150,3 +150,21 @@ PosLoyalty.check.isRewardButtonHighlighted(false);
registry
.category("web_tour.tours")
.add("PosLoyaltyFreeProductTour2", { test: true, url: "/pos/web", steps: getSteps() });
startSteps();
ProductScreen.do.confirmOpeningPopup();
ProductScreen.do.clickHomeCategory();
ProductScreen.do.clickDisplayedProduct('Test Product A');
ProductScreen.check.selectedOrderlineHas('Test Product A', '1.00', '40.00');
ProductScreen.do.clickDisplayedProduct('Test Product B');
ProductScreen.check.selectedOrderlineHas('Test Product B', '1.00', '40.00');
PosLoyalty.do.clickRewardButton();
SelectionPopup.do.clickItem("$ 10 per order on specific products");
PosLoyalty.check.hasRewardLine('$ 10 per order on specific products', '-10.00', '1.00');
PosLoyalty.check.orderTotalIs('60.00');
registry
.category("web_tour.tours")
.add("PosLoyaltySpecificDiscountTour", { test: true, url: "/pos/web", steps: getSteps() });
+41
View File
@@ -926,3 +926,44 @@ class TestUi(TestPointOfSaleHttpCommon):
"GiftCardWithRefundtTour",
login="pos_user",
)
def test_loyalty_program_specific_product(self):
#create a loyalty program with a rules of minimum 2 qty that applies on produt A and B and reward 5 points. The reward is 10$ per order in exchange of 2 points on product A and B
LoyaltyProgram = self.env['loyalty.program']
(LoyaltyProgram.search([])).write({'pos_ok': False})
self.product_a = self.env["product.product"].create({
"name": "Test Product A",
"type": "product",
"list_price": 40,
"available_in_pos": True,
"taxes_id": False,
})
self.product_b = self.env["product.product"].create({
"name": "Test Product B",
"type": "product",
"list_price": 40,
"available_in_pos": True,
"taxes_id": False,
})
self.loyalty_program = self.env['loyalty.program'].create({
'name': 'Loyalty Program Test',
'program_type': 'loyalty',
'trigger': 'auto',
'pos_ok': True,
'rule_ids': [(0, 0, {
'reward_point_mode': 'order',
'reward_point_amount': 5,
'minimum_qty': 2,
'product_ids': [(6, 0, [self.product_a.id, self.product_b.id])],
})],
'reward_ids': [(0, 0, {
'reward_type': 'discount',
'discount_mode': 'per_order',
'required_points': 2,
'discount': 10,
'discount_applicability': 'specific',
'discount_product_ids': (self.product_a | self.product_b).ids,
})],
})
self.main_pos_config.open_ui()
self.start_tour("/pos/web?config_id=%d" % self.main_pos_config.id, "PosLoyaltySpecificDiscountTour", login="pos_user")