[FIX] pos_loyalty: apply rewards for coupon programs without rules

For loyalty programs of type 'coupons' with no rules defined,
the points were not being calculated correctly in the PoS.

The pointsForPrograms function was returning an empty list [] when
no rules exist. This caused _getRealCouponPoints to skip calculation.

This commit checks the program type and returns the points
if it is 'coupons'.

opw-3457550

closes odoo/odoo#133445

X-original-commit: 25ff280dfbec7e6d6f1c0a345e1902a2ab5c0774
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
This commit is contained in:
Pedram (PEBR)
2023-08-30 07:04:00 +00:00
parent 7736259e6c
commit 6e57324aff
3 changed files with 60 additions and 1 deletions
@@ -869,7 +869,7 @@ patch(Order.prototype, {
}
}
}
const res = points ? [{ points }] : [];
const res = (points || program.program_type === 'coupons') ? [{ points }] : [];
if (splitPoints.length) {
res.push(...splitPoints);
}
@@ -263,3 +263,20 @@ registry
return getSteps();
}
});
registry
.category("web_tour.tours")
.add("PosLoyaltyTour7", {
test: true,
url: "/pos/web",
steps: () => {
ProductScreen.do.confirmOpeningPopup();
ProductScreen.do.clickHomeCategory();
ProductScreen.exec.addOrderline('Test Product', '1');
PosLoyalty.check.orderTotalIs('100');
PosLoyalty.do.enterCode('abcda');
PosLoyalty.check.orderTotalIs('90');
return getSteps();
}
});
+42
View File
@@ -1080,3 +1080,45 @@ class TestUi(TestPointOfSaleHttpCommon):
"PosLoyaltyTour6",
login="pos_user",
)
def test_coupon_program_without_rules(self):
self.env['loyalty.program'].search([]).write({'active': False})
self.env["product.product"].create(
{
"name": "Test Product",
"type": "product",
"list_price": 100,
"available_in_pos": True,
"taxes_id": False,
}
)
# creating a coupon program without any rule
loyalty_program = self.env['loyalty.program'].create({
'name': 'Coupon Program without rules',
'program_type': 'coupons',
'trigger': 'with_code',
'applies_on': 'current',
'pos_ok': True,
'rule_ids': [],
'reward_ids': [(0, 0, {
'reward_type': 'discount',
'discount': 10,
'discount_mode': 'percent',
'discount_applicability': 'order',
})],
})
self.env["loyalty.generate.wizard"].with_context(
{"active_id": loyalty_program.id}
).create({"coupon_qty": 1, 'points_granted': 1}).generate_coupons()
self.coupon1 = loyalty_program.coupon_ids
self.coupon1.write({"code": "abcda"})
self.main_pos_config.open_ui()
self.start_tour(
"/pos/web?config_id=%d" % self.main_pos_config.id,
"PosLoyaltyTour7",
login="pos_user",
)