Skip to content

Commit

Permalink
[ADD] product_configurator: Migrated to v17
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikul-OSI committed Feb 15, 2024
1 parent 6a10823 commit ac945b4
Show file tree
Hide file tree
Showing 31 changed files with 717 additions and 601 deletions.
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ repos:
- id: check-xml
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/OCA/pylint-odoo
rev: v8.0.19
hooks:
Expand Down
Binary file added pandoc-3.1.11.1-1-amd64.deb
Binary file not shown.
24 changes: 15 additions & 9 deletions product_configurator/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ Product Configurator
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--configurator-lightgray.png?logo=github
:target: https://github.com/OCA/product-configurator/tree/16.0/product_configurator
:target: https://github.com/OCA/product-configurator/tree/17.0/product_configurator
:alt: OCA/product-configurator
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-configurator-16-0/product-configurator-16-0-product_configurator
:target: https://translation.odoo-community.org/projects/product-configurator-17-0/product-configurator-17-0-product_configurator
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-configurator&target_branch=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-configurator&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module has all the mechanics to support product configuration. It serves as a base
dependency for configuration interfaces.
This module has all the mechanics to support product configuration. It
serves as a base dependency for configuration interfaces.

**Table of contents**

Expand All @@ -42,20 +42,26 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-configurator/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/product-configurator/issues/new?body=module:%20product_configurator%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/product-configurator/issues/new?body=module:%20product_configurator%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~
-------

* Pledra

Contributors
------------

- Nikul Chaudhary <nchaudhary@opensourceintegrators.com>
- Murtaza Mithaiwala <mmithaiwala@opensourceintegrators.com>

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -75,6 +81,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-PCatinean|

This module is part of the `OCA/product-configurator <https://github.com/OCA/product-configurator/tree/16.0/product_configurator>`_ project on GitHub.
This module is part of the `OCA/product-configurator <https://github.com/OCA/product-configurator/tree/17.0/product_configurator>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
8 changes: 4 additions & 4 deletions product_configurator/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Product Configurator",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "Generic Modules/Base",
"summary": "Base for product configuration interface modules",
"author": "Pledra, Odoo Community Association (OCA)",
Expand Down Expand Up @@ -28,10 +28,10 @@
"assets": {
"web.assets_backend": [
"/product_configurator/static/src/scss/form_widget.scss",
"/product_configurator/static/src/js/form_widgets.js",
"/product_configurator/static/src/js/form_widgets.esm.js",
"/product_configurator/static/src/js/boolean_button_widget.esm.js",
"/product_configurator/static/src/js/boolean_button_widget.xml",
"/product_configurator/static/src/js/relational_fields.js",
"/product_configurator/static/src/js/relational_fields.esm.js",
]
},
"demo": [
Expand All @@ -44,7 +44,7 @@
],
"images": ["static/description/cover.png"],
"post_init_hook": "post_init_hook",
"qweb": ["static/xml/create_button.xml"],
# "qweb": ["static/xml/create_button.xml"],
"development_status": "Beta",
"maintainers": ["PCatinean"],
"installable": True,
Expand Down
4 changes: 2 additions & 2 deletions product_configurator/init_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
logger = logging.getLogger(__name__)


def post_init_hook(cr, registry):
def post_init_hook(env):
"""Transfer existing weight values to weight_dummy after installation
since now the weight field is computed
"""
cr.execute("UPDATE product_product SET weight_dummy = weight")
env.cr.execute("UPDATE product_product SET weight_dummy = weight")
3 changes: 1 addition & 2 deletions product_configurator/models/ir_ui_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ def _validate_tag_button(self, node, name_manager, node_info):
special = node.get("special")
if special and special == "no_save":
return

Check warning on line 10 in product_configurator/models/ir_ui_view.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/ir_ui_view.py#L10

Added line #L10 was not covered by tests
else:
return super()._validate_tag_button(node, name_manager, node_info)
return super()._validate_tag_button(node, name_manager, node_info)
43 changes: 26 additions & 17 deletions product_configurator/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _compute_product_variant_count(self):
1 as many views and methods trigger only when a template has at least
one variant attached. Since we create them from the template we should
have access to them always"""
result = super(ProductTemplate, self)._compute_product_variant_count()
result = super()._compute_product_variant_count()
for product_tmpl in self:
config_ok = product_tmpl.config_ok
variant_count = product_tmpl.product_variant_count
Expand Down Expand Up @@ -148,7 +148,7 @@ def _search_weight(self, operator, value):

def _check_default_values(self):
default_val_ids = (
self.attribute_line_ids.filtered(lambda l: l.default_val)
self.attribute_line_ids.filtered(lambda line: line.default_val)
.mapped("default_val")
.ids
)
Expand All @@ -159,7 +159,7 @@ def _check_default_values(self):
value_ids=default_val_ids, product_tmpl_id=self.id, final=False
)
except ValidationError as exc:
raise exc
raise ValidationError(exc.args[0]) from exc
except Exception as exc:

Check warning on line 163 in product_configurator/models/product.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product.py#L163

Added line #L163 was not covered by tests
raise ValidationError(
_("Default values provided generate an invalid configuration")
Expand All @@ -177,7 +177,7 @@ def _check_default_value_domains(self):
"generate an invalid configuration.\
\n%s"
)
% (exc.args[0])
% (exc.name)
) from exc

def toggle_config(self):
Expand Down Expand Up @@ -205,7 +205,7 @@ def unlink(self):
)
if variant_unlink:
self -= config_template
res = super(ProductTemplate, self).unlink()
res = super().unlink()
return res

def copy(self, default=None):
Expand All @@ -214,7 +214,7 @@ def copy(self, default=None):
if not default:
default = {}
self = self.with_context(check_constraint=False)
res = super(ProductTemplate, self).copy(default=default)
res = super().copy(default=default)

# Attribute lines
attribute_line_dict = {}
Expand Down Expand Up @@ -325,7 +325,7 @@ def create(self, vals_list):
config_ok = vals.get("config_ok", False)
if config_ok:
self.check_config_user_access()
return super(ProductTemplate, self).create(vals_list)
return super().create(vals_list)

def write(self, vals):
"""Patch for check access rights of user(configurable products)"""
Expand All @@ -334,7 +334,7 @@ def write(self, vals):
if change_config_ok or configurable_templates:
self[:1].check_config_user_access()

return super(ProductTemplate, self).write(vals)
return super().write(vals)

@api.constrains("config_line_ids")
def _check_config_line_domain(self):
Expand All @@ -347,35 +347,44 @@ def _check_config_line_domain(self):
domain_value_ids = domain_id.domain_line_ids.mapped("value_ids")
invalid_value_ids = domain_value_ids - tmpl_value_ids
invalid_attribute_ids = domain_attr_ids - tmpl_attribute_ids
if not invalid_attribute_ids and not invalid_value_ids:
if not invalid_value_ids and not invalid_value_ids:
continue

Check warning on line 351 in product_configurator/models/product.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product.py#L351

Added line #L351 was not covered by tests
if not error_message:
error_message = _(
"Following Attribute/Value from restriction "
"are not present in template attributes/values. "
"Please make sure you are adding right restriction"
)
error_message += _("\nRestriction: %s", domain_id.name)
error_message += _("\nRestriction: %s") % (domain_id.name)
error_message += (
invalid_attribute_ids
and _(
"\nAttribute/s: %s", ", ".join(invalid_attribute_ids.mapped("name"))
)
and _("\nAttribute/s: %s")
% (", ".join(invalid_attribute_ids.mapped("name")))
or ""
)
error_message += (
invalid_value_ids
and _("\nValue/s: %s\n", ", ".join(invalid_value_ids.mapped("name")))
and _("\nValue/s: %s\n") % (", ".join(invalid_value_ids.mapped("name")))
or ""
)
if error_message:
raise ValidationError(error_message)

@api.model
def _name_search(self, name, domain=None, operator="ilike", limit=None, order=None):
domain = domain or []
domain += ["|", ("name", operator, name), ("default_code", operator, name)]
return self._search(domain, limit=limit, order=order)

Check warning on line 377 in product_configurator/models/product.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product.py#L375-L377

Added lines #L375 - L377 were not covered by tests


class ProductProduct(models.Model):
_inherit = "product.product"
_rec_name = "config_name"

def _get_conversions_dict(self):
conversions = {"float": float, "integer": int}
return conversions

@api.constrains("product_template_attribute_value_ids")
def _check_duplicate_product(self):
"""Check for prducts with same attribute values/custom values"""
Expand Down Expand Up @@ -537,7 +546,7 @@ def unlink(self):
self.env["product.product"].check_config_user_access(mode="delete")
ctx = dict(self.env.context, unlink_from_variant=True)
self.env.context = ctx
return super(ProductProduct, self).unlink()
return super().unlink()

@api.model_create_multi
def create(self, vals_list):
Expand All @@ -546,7 +555,7 @@ def create(self, vals_list):
config_ok = vals.get("config_ok", False)
if config_ok:
self.check_config_user_access(mode="create")

Check warning on line 557 in product_configurator/models/product.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product.py#L557

Added line #L557 was not covered by tests
return super(ProductProduct, self).create(vals_list)
return super().create(vals_list)

def write(self, vals):
"""Patch for check access rights of user(configurable products)"""
Expand All @@ -555,7 +564,7 @@ def write(self, vals):
if change_config_ok or configurable_products:
self[:1].check_config_user_access(mode="write")

return super(ProductProduct, self).write(vals)
return super().write(vals)

def _compute_product_price_extra(self):
standard_products = self.filtered(lambda product: not product.config_ok)
Expand Down
Loading

0 comments on commit ac945b4

Please sign in to comment.