Add technical helper to compute easily template fields from product variant fields
Project description
Products - Compute Technical Fields (template from Variant)
This module extends the functionality of product module, introducing a technical helper to define easily template fields that are computed from variant values.
Table of contents
Development
Replace this code:
class ProductTemplate(models.Model):
_inherit = "product.template"
net_weight = fields.Float(
compute="_compute_net_weight",
inverse="_inverse_net_weight",
store=True,
)
@api.depends("product_variant_ids", "product_variant_ids.net_weight")
def _compute_net_weight(self):
for template in self:
if template.product_variant_count == 1:
template.net_weight = template.product_variant_ids.net_weight
else:
template.net_weight = 0.0
def _inverse_net_weight(self):
for template in self:
if len(template.product_variant_ids) == 1:
template.product_variant_ids.net_weight = template.net_weight
def _get_related_fields_variant_template(self):
res = super()._get_related_fields_variant_template()
res.append("net_weight")
return res
By this code:
class ProductTemplate(models.Model):
_inherit = "product.template"
net_weight = fields.Float(
compute=lambda x: x._compute_template_field_from_variant_field("net_weight"),
inverse=lambda x: x._set_product_variant_field("net_weight"),
store=True,
)
def _get_related_fields_variant_template(self):
res = super()._get_related_fields_variant_template()
res.append("net_weight")
return res
Known issues / Roadmap
Do not port this module in version 17.0.
(the feature is native since V17.0)
Bug Tracker
Bugs are tracked on GitHub 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.
Do not contact contributors directly about support or help with technical issues.
Credits
Contributors
Sylvain LE GAL (https://www.twitter.com/legalsylvain)
Odoo SA.
The code of this module is a backport of the code of product module in Odoo Version 18.0 CE.
Maintainers
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
Current maintainer:
This module is part of the OCA/product-attribute project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file odoo_addon_product_compute_template_field_from_variant_helper-16.0.1.0.0.2-py3-none-any.whl.
File metadata
- Download URL: odoo_addon_product_compute_template_field_from_variant_helper-16.0.1.0.0.2-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
238e7cb0e4a46953a8a0f5699d0dfa2934b722fdc9d53fe719bba958980262ad
|
|
| MD5 |
8b8eada7cc278c732ff75b781f456a9b
|
|
| BLAKE2b-256 |
d100a5291a8bac750f25120e905d656d587a7e63932a30d02a9d8416e0577a0c
|