add product_configurator_website_fix
This commit is contained in:
parent
29ef56b800
commit
83146e83ff
4 changed files with 46 additions and 0 deletions
1
product_configurator_website_fix/__init__.py
Normal file
1
product_configurator_website_fix/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
from . import models
|
||||||
9
product_configurator_website_fix/__manifest__.py
Normal file
9
product_configurator_website_fix/__manifest__.py
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "Product Configurator Website Fix",
|
||||||
|
"version": "17.0.1.0.0",
|
||||||
|
"summary": "Avoid cartesian product explosion on /shop for configurable products",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"category": "website",
|
||||||
|
"depends": ["website_sale", "product_configurator"],
|
||||||
|
"installable": True,
|
||||||
|
}
|
||||||
1
product_configurator_website_fix/models/__init__.py
Normal file
1
product_configurator_website_fix/models/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
from . import product_template
|
||||||
35
product_configurator_website_fix/models/product_template.py
Normal file
35
product_configurator_website_fix/models/product_template.py
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
from odoo import models
|
||||||
|
|
||||||
|
|
||||||
|
class ProductTemplate(models.Model):
|
||||||
|
_inherit = "product.template"
|
||||||
|
|
||||||
|
def _get_possible_combinations(self, parent_combination=None, necessary_values=None):
|
||||||
|
"""Configurable templates keep no variants on purpose (see
|
||||||
|
``product_configurator._create_variant_ids``). For a non-dynamic
|
||||||
|
template core treats a combination without an existing variant as
|
||||||
|
impossible, so the generator walks the *whole* cartesian product
|
||||||
|
without ever yielding. Short-circuit it.
|
||||||
|
"""
|
||||||
|
self.ensure_one()
|
||||||
|
if self.config_ok:
|
||||||
|
return iter(())
|
||||||
|
return super()._get_possible_combinations(parent_combination, necessary_values)
|
||||||
|
|
||||||
|
def _get_first_possible_combination(
|
||||||
|
self, parent_combination=None, necessary_values=None
|
||||||
|
):
|
||||||
|
self.ensure_one()
|
||||||
|
if self.config_ok:
|
||||||
|
return self.env["product.template.attribute.value"]
|
||||||
|
return super()._get_first_possible_combination(
|
||||||
|
parent_combination, necessary_values
|
||||||
|
)
|
||||||
|
|
||||||
|
def _is_add_to_cart_possible(self, parent_combination=None):
|
||||||
|
"""A configurable product is always addable: the variant is created
|
||||||
|
when the configuration session is validated."""
|
||||||
|
self.ensure_one()
|
||||||
|
if self.config_ok:
|
||||||
|
return self.active and self._can_be_added_to_cart()
|
||||||
|
return super()._is_add_to_cart_possible(parent_combination)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue