Skip to content

Commit

Permalink
[FIX] sale: split method _is_add_to_cart_possible for override
Browse files Browse the repository at this point in the history
This commit has as purpose to split the method `_is_add_to_cart_possible`
and put only the first part in another method so it can be overridden.

Issue:

The first part of the method _is_add_to_cart_possible check that the
product is active and can be sold.
The second part check if a combination is possible.

In sale_renting module, only the first part must be overridden since
second part is a common check to all product regardless if it
can or can't be sold or rent

opw-2879711

closes odoo#94169

X-original-commit: e5fb470
Related: odoo/enterprise#28680
Signed-off-by: Nasreddin Boulif (bon) <bon@odoo.com>
  • Loading branch information
nboulif committed Jun 21, 2022
1 parent 69b4060 commit c8f5981
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion addons/sale/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ def _get_combination_info(self, combination=False, product_id=False, add_qty=1,
'has_discounted_price': has_discounted_price,
}

def _can_be_added_to_cart(self):
"""
Pre-check to `_is_add_to_cart_possible` to know if product can be sold.
"""
return self.sale_ok

def _is_add_to_cart_possible(self, parent_combination=None):
"""
It's possible to add to cart (potentially after configuration) if
Expand All @@ -291,7 +297,7 @@ def _is_add_to_cart_possible(self, parent_combination=None):
:rtype: bool
"""
self.ensure_one()
if not self.active or not self.sale_ok:
if not self.active or not self._can_be_added_to_cart():
# for performance: avoid calling `_get_possible_combinations`
return False
return next(self._get_possible_combinations(parent_combination), False) is not False
Expand Down

0 comments on commit c8f5981

Please sign in to comment.