[FIX] pos_loyalty: Consider reward divided by tax as 1 reward
Current behavior: When a reward is applied on an order containing different product with different taxes, the rewarded is divided in multiple lines (one per tax) This cause issue when calling, the `_updateRewardLines` method. Because it will consider each line as a full reward, and therefore will apply the reward multiple times even though the reward is only applied once. Steps to reproduce: - Create a reward with a discount of 5$ in exchange of 100 points - The reward should give 1 point per 1$ spent - Create a product with a price of 100$ and a tax of 10% - Create a product with a price of 100$ and no tax - Open the POS and add the 2 products to the order - Select a customer, and click the reward button - The reward will be applied 2 times (4 reward lines are created) opw-3583174 closes odoo/odoo#145759 X-original-commit: 8214322a0f06d74005c46d2623972f6eb393cc08 Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com> Signed-off-by: Robin Engels (roen) <roen@odoo.com>
This commit is contained in:
@@ -432,6 +432,7 @@ patch(Order.prototype, {
|
||||
args: {
|
||||
product: line.reward_product_id,
|
||||
},
|
||||
reward_identifier_code: line.reward_identifier_code,
|
||||
};
|
||||
if (
|
||||
claimedReward.reward.program_id.program_type === "gift_card" ||
|
||||
@@ -440,7 +441,7 @@ patch(Order.prototype, {
|
||||
paymentRewards.push(claimedReward);
|
||||
} else if (claimedReward.reward.reward_type === "product") {
|
||||
productRewards.push(claimedReward);
|
||||
} else {
|
||||
} else if (!otherRewards.some(reward => reward.reward_identifier_code === claimedReward.reward_identifier_code)) {
|
||||
otherRewards.push(claimedReward);
|
||||
}
|
||||
this.orderlines.remove(line);
|
||||
|
||||
@@ -269,7 +269,6 @@ registry.category("web_tour.tours").add('PosLoyaltyTour8', {
|
||||
].flat(),
|
||||
});
|
||||
|
||||
|
||||
registry
|
||||
.category("web_tour.tours")
|
||||
.add("PosLoyaltySpecificDiscountCategoryTour", {
|
||||
@@ -288,3 +287,24 @@ registry
|
||||
PosLoyalty.orderTotalIs('40.00'),
|
||||
].flat(),
|
||||
});
|
||||
|
||||
registry.category("web_tour.tours").add('PosLoyaltyTour9', {
|
||||
test: true,
|
||||
url: '/pos/web',
|
||||
steps: () =>
|
||||
[
|
||||
ProductScreen.clickHomeCategory(),
|
||||
ProductScreen.confirmOpeningPopup(),
|
||||
|
||||
ProductScreen.clickPartnerButton(),
|
||||
ProductScreen.clickCustomer('AAA Partner'),
|
||||
ProductScreen.clickDisplayedProduct('Product B'),
|
||||
ProductScreen.clickDisplayedProduct('Product A'),
|
||||
PosLoyalty.clickRewardButton(),
|
||||
SelectionPopup.clickItem("$ 5"),
|
||||
ProductScreen.totalAmountIs('205.00'),
|
||||
PosLoyalty.clickRewardButton(),
|
||||
SelectionPopup.clickItem("$ 5"),
|
||||
ProductScreen.totalAmountIs('200.00'),
|
||||
].flat(),
|
||||
});
|
||||
|
||||
@@ -1380,3 +1380,51 @@ class TestUi(TestPointOfSaleHttpCommon):
|
||||
"PosLoyaltySpecificDiscountCategoryTour",
|
||||
login="pos_user",
|
||||
)
|
||||
|
||||
def test_promo_with_different_taxes(self):
|
||||
self.env['loyalty.program'].search([]).write({'active': False})
|
||||
self.tax01 = self.env["account.tax"].create({
|
||||
"name": "C01 Tax",
|
||||
"amount": "10.00",
|
||||
})
|
||||
self.product_a = self.env["product.product"].create(
|
||||
{
|
||||
"name": "Product A",
|
||||
"type": "product",
|
||||
"list_price": 100,
|
||||
"available_in_pos": True,
|
||||
"taxes_id": [(6, 0, self.tax01.ids)],
|
||||
}
|
||||
)
|
||||
self.product_b = self.env["product.product"].create(
|
||||
{
|
||||
"name": "Product B",
|
||||
"type": "product",
|
||||
"list_price": 100,
|
||||
"available_in_pos": True,
|
||||
"taxes_id": False,
|
||||
}
|
||||
)
|
||||
self.free_product = self.env['loyalty.program'].create({
|
||||
'name': 'Free Product A',
|
||||
'program_type': 'loyalty',
|
||||
'trigger': 'auto',
|
||||
'applies_on': 'both',
|
||||
'rule_ids': [(0, 0, {
|
||||
'reward_point_mode': 'money',
|
||||
'reward_point_amount': 1,
|
||||
})],
|
||||
'reward_ids': [(0, 0, {
|
||||
'reward_type': 'discount',
|
||||
'required_points': 5,
|
||||
'discount_mode': 'per_order',
|
||||
'discount': 5,
|
||||
})],
|
||||
})
|
||||
self.env['res.partner'].create({'name': 'AAA Partner'})
|
||||
self.main_pos_config.open_ui()
|
||||
self.start_tour(
|
||||
"/pos/web?config_id=%d" % self.main_pos_config.id,
|
||||
"PosLoyaltyTour9",
|
||||
login="pos_user",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user