[FIX] website_sale_loyalty: fix dictionary updating
After recent refactoring [1], sentry caught [2] `KeyError` on adding a record to `res[coupon]` in `_get_claimable_and_showable_rewards` method. Dictionary `res` may not have `coupon` and hence it leads to the error https://github.com/odoo/odoo/blob/31b8151736b3382cca5601cd652b1d5482790af9/addons/website_sale_loyalty/models/sale_order.py#L198-L205 https://github.com/odoo/odoo/blob/31b8151736b3382cca5601cd652b1d5482790af9/addons/sale_loyalty/models/sale_order.py#L595 Fix it by checking `coupon in res` first. [1]: https://github.com/odoo/odoo/commit/6525d5fba40c77ef9ed4445b8b9573550a1e2442 [2]: https://online.sentry.io/issues/4235487414 closes odoo/odoo#124616 X-original-commit: 57a00cae57116869f33e7267ad5ee84bd7600593 Signed-off-by: Ivan Elizaryev (iel) <iel@odoo.com>
This commit is contained in:
@@ -215,5 +215,8 @@ class SaleOrder(models.Model):
|
||||
if coupon.expiration_date and coupon.expiration_date < fields.Date.today():
|
||||
continue
|
||||
if points >= reward.required_points:
|
||||
res[coupon] |= reward
|
||||
if coupon in res:
|
||||
res[coupon] |= reward
|
||||
else:
|
||||
res[coupon] = reward
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user