Skip to content

Commit b787cfe

Browse files
committed
[FIX] sale_loyalty: use reward description as SOL name for free product
Currently, the reward's product name is used as the SOL name for the free product, which can be confusing. To reproduce this issue: 1) Install the sale_loyalty module. 2) Create a loyalty program that grants a free product. 3) Manually update the reward's description. 4) Create an SO with a SOL containing that product 5) Apply the reward and observe the behavior. Issue / Cause: The free product’s description is taken from the reward product’s name, not the manually updated description. At the point of sale, the name is retrieved from discount_line_product_id rather than reward_product_ids https://github.com/odoo/odoo/blob/0abdcd9ef6ad3fc932dc0eb46d8aa973b00c34c2/addons/pos_loyalty/static/src/overrides/models/pos_order.js#L1162 Solution: To resolve this inconsistent behavior, the free product name in the sale order line will now be taken from the reward description. opw-4982774 closes odoo#229370 X-original-commit: 27d9d9d Signed-off-by: anko-odoo <[email protected]> Signed-off-by: Altaf Shaik (alsh) <[email protected]>
1 parent 6d74cdc commit b787cfe

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

addons/sale_loyalty/models/sale_order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def _get_reward_values_product(self, reward, coupon, product=None, **kwargs):
265265
claimable_count = float_round(points / reward.required_points, precision_rounding=1, rounding_method='DOWN') if not reward.clear_wallet else 1
266266
cost = points if reward.clear_wallet else claimable_count * reward.required_points
267267
return [{
268-
'name': _("Free Product - %(product)s", product=product.with_context(display_default_code=False).display_name),
268+
'name': reward.description,
269269
'product_id': product.id,
270270
'discount': 100,
271271
'product_uom_qty': reward.reward_product_qty * claimable_count,

addons/sale_loyalty/tests/test_loyalty.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,3 +1155,31 @@ def test_domain_on_cheapest_reward(self):
11551155
self._apply_promo_code(order, '10discount')
11561156
msg = "Discount should be applied to the line with the cheapest valid product."
11571157
self.assertEqual(order.order_line[3].price_total, -5.0, msg)
1158+
1159+
def test_sol_free_product_description_equals_reward_description(self):
1160+
"""
1161+
Ensure that if a "Free Product" reward is added to a sale order,
1162+
its line description matches the reward description.
1163+
"""
1164+
loyalty_program = self.env['loyalty.program'].create(
1165+
self.env['loyalty.program']._get_template_values()['buy_x_get_y']
1166+
)
1167+
reward = loyalty_program.reward_ids[0]
1168+
updated_description = f"{reward.description} Adding manual description"
1169+
reward.description = updated_description
1170+
1171+
order = self.empty_order
1172+
order.write({
1173+
'order_line': [
1174+
Command.create({
1175+
'product_id': reward.reward_product_id.id,
1176+
'name': '1 Product',
1177+
'product_uom_qty': 4.0,
1178+
}),
1179+
]
1180+
})
1181+
order._update_programs_and_rewards()
1182+
self._claim_reward(order, loyalty_program)
1183+
1184+
self.assertEqual(len(order.order_line.ids), 2)
1185+
self.assertEqual(order.order_line[1].name, updated_description)

0 commit comments

Comments
 (0)