[FIX] website_sale: prevent adding archived products to cart

Prevents adding archived products to the cart.

TaskId-2925397

closes odoo/odoo#96483

X-original-commit: 623014802e643e19eb61966c5f639e2b04ff9e81
Signed-off-by: William Braeckman (wbr) <wbr@odoo.com>
This commit is contained in:
William Braeckman
2022-07-21 01:53:41 +02:00
parent 42f0dd02ae
commit 11938424c3
2 changed files with 13 additions and 1 deletions
@@ -93,7 +93,7 @@ class Product(models.Model):
def _is_add_to_cart_allowed(self):
self.ensure_one()
return self.user_has_groups('base.group_system') or (self.sale_ok and self.website_published)
return self.user_has_groups('base.group_system') or (self.active and self.sale_ok and self.website_published)
def _get_contextual_price_tax_selection(self):
self.ensure_one()
@@ -47,3 +47,15 @@ class WebsiteSaleCart(TransactionCase):
with self.assertRaises(UserError):
with MockRequest(product.with_user(self.public_user).env, website=self.website.with_user(self.public_user)):
self.WebsiteSaleController.cart_update_json(product_id=product.id, add_qty=1)
def test_add_cart_archived_product(self):
# Try to add an archived product
product = self.env['product.product'].create({
'name': 'Test Product',
'sale_ok': True,
})
product.active = False
with self.assertRaises(UserError):
with MockRequest(product.with_user(self.public_user).env, website=self.website.with_user(self.public_user)):
self.WebsiteSaleController.cart_update_json(product_id=product.id, add_qty=1)