Skip to content

Commit

Permalink
[FIX] sale_loyalty: prevent error while remove all product quantities…
Browse files Browse the repository at this point in the history
… from cart

Currently, an error is generated when removing all product quantities from the
cart after a claiming a reward(discount).

Step to produce:

- Install a 'website_sale_loyalty' module.
- Navigate to the website / eCommerce / Loyalty / Discount & Loyalty to create
a record.
- Set the Loyalty Program name and Program Type as 'Loyalty Cards'.(Ensure it's
available on sale and the website.)
-  And add 'Rewards' and set a Reward Type as 'Discount' which is applied to
on Cheapest Product.
 - Go to the website shop add any product on a card, Open a cart increase the
 quantity of the product, and claim the discount reward.
- Again go to Loyalty Program and open Loyalty Card, Open a record and add a
Balance(greater than 200 as default reward points are 200) and copy 'Code'.
- Again go to the website shop and apply this code to claim a discount after a
claim discount.
- Now remove all product quantity from a cart.

AttributeError: 'bool' object has no attribute 'price_unit'

The issue occurs when attempting to remove all product quantities from a cart.
At this point [1], a bool value  'False' is returned, and the system attempts to
get a value of 'price_unit' from it [2].

link [1]: https://github.com/odoo/odoo/blob/499056a82db26f7d9caa86314e666e2bd49cc79c/addons/sale_loyalty/models/sale_order.py#L187-L195

link [2]: https://github.com/odoo/odoo/blob/499056a82db26f7d9caa86314e666e2bd49cc79c/addons/sale_loyalty/models/sale_order.py#L205

This commit resolve issue, If the _cheapest_line() method returns False then
also returns False from _discountable_cheapest(), To raise an error at [3].

link [3]:  https://github.com/odoo/odoo/blob/cbc40eccf576c499709f7825edad9a3b3ce7a22d/addons/sale_loyalty/models/sale_order.py#L317-L333

sentry-5119007021

closes odoo#163403

X-original-commit: dfd1aab
Signed-off-by: Meet Gandhi (mega) <mega@odoo.com>
  • Loading branch information
mega-odoo committed Apr 26, 2024
1 parent 2d2a772 commit cf16b96
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions addons/sale_loyalty/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ def _discountable_cheapest(self, reward):
assert reward.discount_applicability == 'cheapest'

cheapest_line = self._cheapest_line()
if not cheapest_line:
return False, False
discountable = cheapest_line.price_total
discountable_per_taxes = cheapest_line.price_unit * (1 - (cheapest_line.discount or 0) / 100)
taxes = cheapest_line.tax_id.filtered(lambda t: t.amount_type != 'fixed')
Expand Down

0 comments on commit cf16b96

Please sign in to comment.