Skip to content

Commit

Permalink
[MIG] product_variant_configurator: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelregidor committed Jun 18, 2024
1 parent 5d83b27 commit 516d71a
Show file tree
Hide file tree
Showing 20 changed files with 95 additions and 72 deletions.
17 changes: 10 additions & 7 deletions product_variant_configurator/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ Configuration

To configure the creation of the variants behaviour, you need to:

1. Go to ``Sales > Configuration > Settings``, and select "Attributes
and Variants (Set product attributes (e.g. color, size) to sell
variants)" on "Product Catalog" section.
2. Go to ``Sales > Catalog > Products``, and select a product.
3. On the Variants tab edit the value of the field ``Variant Creation``.
1. Go to ``Sales > Configuration > Settings``, and select "Variants
(Sell variants of a product using attributes (size, color, etc.))" on
"Product Catalog" section.
2. Go to ``Sales > Products > Products``, and select a product.
3. On the Attributes & Variants tab edit the value of the field
``Variant Creation``.
4. If you want to stop the automatic creation of the variant, and have
the same behaviour for all the products in the same category, go to
``Inventory > Configuration > Product Categories``, select the
Expand All @@ -66,8 +67,8 @@ Usage

(after installing sale_management application)

1. Go to ``Sales > Catalog > Product Variants``.
2. Click on "Create" button for creating a new one.
1. Go to ``Sales > Products > Product Variants``.
2. Click on "New" button for creating a new one.
3. On the field "Product Template", select a product template that has
several attributes.
4. A table with the attributes of the template will appear below.
Expand Down Expand Up @@ -127,6 +128,8 @@ Contributors
- Simone Versienti <s.versienti@apuliasoftware.it>
- Adria Gil Sorribes <adria.gil@forgeflow.com>
- Héctor Villarreal Ortega <hector.villarreal@forgeflow.com>
- Manuel Regidor <manuel.regidor@sygel.es>
- Valentín Vinagre <valentin.vinagre@sygel.es>

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion product_variant_configurator/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"name": "Product Variant Configurator",
"summary": "Provides an abstract model for product variant configuration.",
"version": "16.0.1.0.5",
"version": "17.0.1.0.0",
"category": "Product Variant",
"development_status": "Production/Stable",
"license": "AGPL-3",
Expand Down
3 changes: 2 additions & 1 deletion product_variant_configurator/models/ir_ui_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def _postprocess_tag_groupby(self, node, name_manager, node_info):
field of a many2one model, and that model also has the same field name.
In this example, the stock.valuation.layer.tree view contains a groupby
product_id, and the product.product model already has a product_id field,
relating to the same model. Without this code we would reach a recursion error."""
relating to the same model. Without this code we would reach a recursion
error."""
name = node.get("name")
if name_manager.model._name == "product.product" and name == "product_id":
return
Expand Down
31 changes: 23 additions & 8 deletions product_variant_configurator/models/pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@
class ProductPricelist(models.Model):
_inherit = "product.pricelist"

def _compute_price_rule(self, products, qty, uom=None, date=False, **kwargs):
def _compute_price_rule(
self,
products,
quantity,
currency=None,
uom=None,
date=False,
compute_price=True,
**kwargs,
):
"""Overwrite for covering the case where templates are passed and a
different uom is used."""
if products[0]._name != "product.template":
# Standard use case - Nothing to do
return super(ProductPricelist, self)._compute_price_rule(
return super()._compute_price_rule(
products,
qty,
date=date,
uom=uom,
quantity,
currency,
uom,
date,
compute_price,
**kwargs,
)
# Isolate object
pricelist_obj = self
Expand All @@ -31,9 +43,12 @@ def _compute_price_rule(self, products, qty, uom=None, date=False, **kwargs):

return super(ProductPricelist, pricelist_obj)._compute_price_rule(
products,
qty,
date=date,
uom=False,
quantity,
currency,
uom,
date,
compute_price,
**kwargs,
)

def template_price_get(self, prod_id, qty, partner=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def create(self, vals_list):
This happens when quick-creating values from the product configurator.
"""
attr_values = super(ProductAttributeValue, self).create(vals_list)
attr_values = super().create(vals_list)
if "template_for_attribute_value" in self.env.context:
template = self.env["product.template"].browse(
self.env.context["template_for_attribute_value"]
)
for attr in attr_values:
line = template.attribute_line_ids.filtered(
lambda x: x.attribute_id == attr.attribute_id
lambda x, attr=attr: x.attribute_id == attr.attribute_id
)
line.value_ids = [(4, attr.id)]
return attr_values
2 changes: 1 addition & 1 deletion product_variant_configurator/models/product_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def onchange_no_create_variants(self):
}

def write(self, values):
res = super(ProductCategory, self).write(values)
res = super().write(values)
if "no_create_variants" in values and not values.get("no_create_variants"):
self.env["product.template"].search(
[("categ_id", "=", self.id), ("no_create_variants", "=", "empty")]
Expand Down
17 changes: 9 additions & 8 deletions product_variant_configurator/models/product_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def _order_attributes(self, template, product_attribute_values):
res2 = []
for val in res:
value = product_attribute_values.filtered(
lambda x: x.attribute_id.id == val["attribute_id"]
lambda x, val=val: x.attribute_id.id == val["attribute_id"]
)
if value:
val["value_id"] = value
Expand Down Expand Up @@ -252,7 +252,7 @@ def create(self, vals_list):
def unlink(self):
"""Mimic `ondelete="cascade"`."""
attributes = self.mapped("product_attribute_ids")
result = super(ProductConfigurator, self).unlink()
result = super().unlink()
if result:
attributes.unlink()
return result
Expand Down Expand Up @@ -281,14 +281,15 @@ def create_variant_if_needed(self):
product_attribute = product_attribute_value.attribute_id
existing_attribute_line = (
self.product_tmpl_id.attribute_line_ids.filtered( # noqa
lambda l: l.attribute_id == product_attribute
lambda line,
product_attribute=product_attribute: line.attribute_id
== product_attribute
)
)
product_template_attribute_values |= (
existing_attribute_line.product_template_value_ids.filtered( # noqa
lambda v: v.product_attribute_value_id
== product_attribute_value
)
product_template_attribute_values |= existing_attribute_line.product_template_value_ids.filtered( # noqa
lambda v,
prod_attr_val=product_attribute_value: v.product_attribute_value_id
== prod_attr_val
)
product = product_obj.create(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _compute_possible_value_ids(self):
for record in self:
# This should be unique due to the new constraint added
attribute = record.product_tmpl_id.attribute_line_ids.filtered(
lambda x: x.attribute_id == record.attribute_id
lambda x, record=record: x.attribute_id == record.attribute_id
)
record.possible_value_ids = attribute.value_ids.sorted()

Expand Down
4 changes: 2 additions & 2 deletions product_variant_configurator/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _get_product_attributes_values_dict(self):
res = self.product_tmpl_id._get_product_attributes_dict()
for val in res:
value = self.product_template_attribute_value_ids.filtered(
lambda x: x.attribute_id.id == val["attribute_id"]
lambda x, val=val: x.attribute_id.id == val["attribute_id"]
)
val["value_id"] = value.product_attribute_value_id.id
return res
Expand Down Expand Up @@ -171,4 +171,4 @@ def create(self, vals_list):
)
vals.pop("product_attribute_ids")
vals["product_template_attribute_value_ids"] = [(4, x) for x in ptav]
return super(ProductProduct, self).create(vals_list)
return super().create(vals_list)
6 changes: 3 additions & 3 deletions product_variant_configurator/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def create(self, vals_list):
for vals in vals_list:
# Needed because ORM removes this value from the dictionary
vals["name"] = self.env.context["product_name"]
return super(ProductTemplate, self).create(vals_list)
return super().create(vals_list)

def write(self, values):
res = super(ProductTemplate, self).write(values)
res = super().write(values)
if "no_create_variants" in values:
self._create_variant_ids()
return res
Expand Down Expand Up @@ -86,7 +86,7 @@ def name_search(self, name="", args=None, operator="ilike", limit=100):
name=name, args=args, operator=operator, limit=limit
)
# Make the other search
temp += super(ProductTemplate, self).name_search(
temp += super().name_search(
name=name, args=args, operator=operator, limit=limit
)
# Merge both results
Expand Down
11 changes: 6 additions & 5 deletions product_variant_configurator/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

To configure the creation of the variants behaviour, you need to:

1. Go to `Sales > Configuration > Settings`, and select "Attributes and
Variants (Set product attributes (e.g. color, size) to sell
variants)" on "Product Catalog" section.
2. Go to `Sales > Catalog > Products`, and select a product.
3. On the Variants tab edit the value of the field `Variant Creation`.
1. Go to `Sales > Configuration > Settings`, and select "Variants (Sell
variants of a product using attributes (size, color, etc.))" on
"Product Catalog" section.
2. Go to `Sales > Products > Products`, and select a product.
3. On the Attributes & Variants tab edit the value of the field
`Variant Creation`.
4. If you want to stop the automatic creation of the variant, and have
the same behaviour for all the products in the same category, go to
`Inventory > Configuration > Product Categories`, select the
Expand Down
2 changes: 2 additions & 0 deletions product_variant_configurator/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
- Simone Versienti \<<s.versienti@apuliasoftware.it>\>
- Adria Gil Sorribes \<<adria.gil@forgeflow.com>\>
- Héctor Villarreal Ortega \<<hector.villarreal@forgeflow.com>\>
- Manuel Regidor \<<manuel.regidor@sygel.es>\>
- Valentín Vinagre \<<valentin.vinagre@sygel.es>\>
4 changes: 2 additions & 2 deletions product_variant_configurator/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(after installing sale_management application)

1. Go to `Sales > Catalog > Product Variants`.
2. Click on "Create" button for creating a new one.
1. Go to `Sales > Products > Product Variants`.
2. Click on "New" button for creating a new one.
3. On the field "Product Template", select a product template that has
several attributes.
4. A table with the attributes of the template will appear below.
Expand Down
17 changes: 10 additions & 7 deletions product_variant_configurator/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,12 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>(after installing sale_management application)</p>
<p>To configure the creation of the variants behaviour, you need to:</p>
<ol class="arabic simple">
<li>Go to <tt class="docutils literal">Sales &gt; Configuration &gt; Settings</tt>, and select “Attributes
and Variants (Set product attributes (e.g. color, size) to sell
variants)” on “Product Catalog” section.</li>
<li>Go to <tt class="docutils literal">Sales &gt; Catalog &gt; Products</tt>, and select a product.</li>
<li>On the Variants tab edit the value of the field <tt class="docutils literal">Variant Creation</tt>.</li>
<li>Go to <tt class="docutils literal">Sales &gt; Configuration &gt; Settings</tt>, and select “Variants
(Sell variants of a product using attributes (size, color, etc.))” on
“Product Catalog” section.</li>
<li>Go to <tt class="docutils literal">Sales &gt; Products &gt; Products</tt>, and select a product.</li>
<li>On the Attributes &amp; Variants tab edit the value of the field
<tt class="docutils literal">Variant Creation</tt>.</li>
<li>If you want to stop the automatic creation of the variant, and have
the same behaviour for all the products in the same category, go to
<tt class="docutils literal">Inventory &gt; Configuration &gt; Product Categories</tt>, select the
Expand All @@ -412,8 +413,8 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>(after installing sale_management application)</p>
<ol class="arabic simple">
<li>Go to <tt class="docutils literal">Sales &gt; Catalog &gt; Product Variants</tt>.</li>
<li>Click on “Create” button for creating a new one.</li>
<li>Go to <tt class="docutils literal">Sales &gt; Products &gt; Product Variants</tt>.</li>
<li>Click on “New” button for creating a new one.</li>
<li>On the field “Product Template”, select a product template that has
several attributes.</li>
<li>A table with the attributes of the template will appear below.</li>
Expand Down Expand Up @@ -468,6 +469,8 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Simone Versienti &lt;<a class="reference external" href="mailto:s.versienti&#64;apuliasoftware.it">s.versienti&#64;apuliasoftware.it</a>&gt;</li>
<li>Adria Gil Sorribes &lt;<a class="reference external" href="mailto:adria.gil&#64;forgeflow.com">adria.gil&#64;forgeflow.com</a>&gt;</li>
<li>Héctor Villarreal Ortega &lt;<a class="reference external" href="mailto:hector.villarreal&#64;forgeflow.com">hector.villarreal&#64;forgeflow.com</a>&gt;</li>
<li>Manuel Regidor &lt;<a class="reference external" href="mailto:manuel.regidor&#64;sygel.es">manuel.regidor&#64;sygel.es</a>&gt;</li>
<li>Valentín Vinagre &lt;<a class="reference external" href="mailto:valentin.vinagre&#64;sygel.es">valentin.vinagre&#64;sygel.es</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class TestProductConfiguratorAttribute(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestProductConfiguratorAttribute, cls).setUpClass()
super().setUpClass()
# ENVIRONMENTS
cls.product_attribute = cls.env["product.attribute"]
cls.product_attribute_value = cls.env["product.attribute.value"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class TestProductPriceList(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestProductPriceList, cls).setUpClass()
super().setUpClass()

# ENVIRONMENTS
cls.product_template = cls.env["product.template"].with_context(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class TestProductVariantConfigurator(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestProductVariantConfigurator, cls).setUpClass()
super().setUpClass()

# ENVIRONMENTS
cls.product_attribute = cls.env["product.attribute"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class TestProductVariant(TransactionCase):
def setUp(self):
super(TestProductVariant, self).setUp()
super().setUp()
self.tmpl_model = self.env["product.template"].with_context(
check_variant_creation=True
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<field name="name" position="attributes">
<attribute
name="attrs"
>{'invisible': ['|', ('id', '!=', False), ('product_tmpl_id', '!=', False)], 'readonly': [('product_tmpl_id', '!=', False)]}</attribute>
<attribute name="invisible">id or product_tmpl_id</attribute>
<attribute name="readonly">product_tmpl_id</attribute>
</field>
<field name="product_tmpl_id" position="attributes">
<attribute name="placeholder">Product Template</attribute>
<attribute name="invisible">0</attribute>
<attribute name="readonly">0</attribute>
<attribute
name="attrs"
>{'readonly': [('id', '!=', False)], 'required': [('id', '!=', False)]}</attribute>
<attribute name="readonly">id</attribute>
<attribute name="required">id</attribute>
</field>
<xpath expr="//field[@name='product_tmpl_id']/.." position="after">
<p class="oe_grey" attrs="{'invisible':[('id','!=',False)]}">
<p class="oe_grey" invisible="id">
Select a template for a variant. Keep empty for a new full product.
</p>
</xpath>
Expand All @@ -39,26 +36,26 @@
name="product_attribute_ids"
nolabel="1"
colspan="2"
attrs="{'invisible': ['|', ('id','!=',False), '|', ('product_tmpl_id','=',False), ('product_attribute_ids', '=', [])]}"
invisible="id or not product_tmpl_id or not product_attribute_ids"
context="{'default_product_template_id': product_tmpl_id, 'default_owner_model': 'product.product', 'show_price_extra': True, 'show_attribute': False}"
>
<tree create="0" delete="0" editable="1">
<field name="owner_model" invisible="1" />
<field name="owner_id" invisible="1" />
<field name="owner_model" column_invisible="1" />
<field name="owner_id" column_invisible="1" />
<field name="attribute_id" />
<field
name="possible_value_ids"
widget="many2many_tags"
invisible="1"
column_invisible="1"
/>
<field name="product_tmpl_id" invisible="1" />
<field name="product_tmpl_id" column_invisible="1" />
<field
name="value_id"
context="{'show_attribute': False, 'default_attribute_id': attribute_id, 'template_for_attribute_value': product_tmpl_id}"
/>
<field
name="price_extra"
invisible="not context.get('show_price_extra', False)"
column_invisible="not context.get('show_price_extra', False)"
/>
</tree>
</field>
Expand All @@ -67,7 +64,7 @@
for="product_id"
string="This product already exists."
style="color: red;"
attrs="{'invisible': [('product_id', '=', False)]}"
invisible="not product_id"
/>
</group>
</xpath>
Expand Down
Loading

0 comments on commit 516d71a

Please sign in to comment.