diff --git a/product_logistics_uom/README.rst b/product_logistics_uom/README.rst
index 1532ffaa929d..33d06a326815 100644
--- a/product_logistics_uom/README.rst
+++ b/product_logistics_uom/README.rst
@@ -17,13 +17,13 @@ Product logistics UoM
: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--attribute-lightgray.png?logo=github
- :target: https://github.com/OCA/product-attribute/tree/17.0/product_logistics_uom
+ :target: https://github.com/OCA/product-attribute/tree/18.0/product_logistics_uom
:alt: OCA/product-attribute
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/product-attribute-17-0/product-attribute-17-0-product_logistics_uom
+ :target: https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_logistics_uom
: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-attribute&target_branch=17.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=18.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -96,7 +96,7 @@ 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 `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -112,17 +112,18 @@ Authors
Contributors
------------
-- Raphaël Reverdy
-- Fernando La Chica
-- Laurent Mignon
+- Raphaël Reverdy
+- Fernando La Chica
+- Laurent Mignon
+- Nhan Tran
Other credits
-------------
The development of this module has been financially supported by:
-- Akretion
-- La Base
+- Akretion
+- La Base
Maintainers
-----------
@@ -145,6 +146,6 @@ Current `maintainer `__:
|maintainer-hparfr|
-This module is part of the `OCA/product-attribute `_ project on GitHub.
+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.
diff --git a/product_logistics_uom/__manifest__.py b/product_logistics_uom/__manifest__.py
index 4da525cc361e..e905b4de233a 100644
--- a/product_logistics_uom/__manifest__.py
+++ b/product_logistics_uom/__manifest__.py
@@ -3,7 +3,7 @@
{
"name": "Product logistics UoM",
"summary": "Configure product weights and volume UoM",
- "version": "17.0.1.0.0",
+ "version": "18.0.1.0.0",
"development_status": "Beta",
"category": "Product",
"website": "https://github.com/OCA/product-attribute",
diff --git a/product_logistics_uom/hooks.py b/product_logistics_uom/hooks.py
index 1e769f9044da..246d40fdf989 100644
--- a/product_logistics_uom/hooks.py
+++ b/product_logistics_uom/hooks.py
@@ -3,7 +3,7 @@
import logging
-from odoo.tools import sql
+from odoo.tools import SQL, sql
_logger = logging.getLogger(__name__)
@@ -16,26 +16,29 @@ def pre_init_hook(env): # pragma: nocover
_logger.info("Recompute volume on product.product")
# get default m3 uom
env.cr.execute(
- """
+ SQL("""
SELECT res_id
FROM ir_model_data
WHERE module = 'uom' AND name = 'product_uom_cubic_meter'
- """
+ """)
)
m3_uom_id = env.cr.fetchone()[0]
# get uom factor
env.cr.execute(
- """
+ SQL(
+ """
SELECT factor
FROM uom_uom
WHERE id = %s
""",
- (m3_uom_id,),
+ m3_uom_id,
+ )
)
m3_uom_factor = env.cr.fetchone()[0]
# update volume where volume_uom_id is not null and not m3
env.cr.execute(
- """
+ SQL(
+ """
UPDATE product_product
SET volume = product_product.volume / product_uom.factor * %s
FROM uom_uom product_uom,
@@ -44,12 +47,15 @@ def pre_init_hook(env): # pragma: nocover
AND pt.id = product_product.product_tmpl_id
AND volume_uom_id IS NOT NULL AND pt.volume_uom_id != %s
""",
- (m3_uom_factor, m3_uom_id),
+ m3_uom_factor,
+ m3_uom_id,
+ )
)
_logger.info(f"{env.cr.rowcount} product_product rows updated")
# update product_template with 1 product_product
env.cr.execute(
- """
+ SQL(
+ """
UPDATE product_template
SET Volume = unique_product.volume
FROM (
@@ -62,33 +68,37 @@ def pre_init_hook(env): # pragma: nocover
WHERE product_template.id = unique_product.product_tmpl_id
AND product_template.volume_uom_id != %s
""",
- (m3_uom_id,),
+ m3_uom_id,
+ )
)
_logger.info(f"{env.cr.rowcount} product_template rows updated")
if sql.column_exists(env.cr, "product_template", "weight_uom_id"):
_logger.info("Recompute weight on product.product")
# get default kg uom
env.cr.execute(
- """
+ SQL("""
SELECT res_id
FROM ir_model_data
WHERE module = 'uom' AND name = 'product_uom_kgm'
- """
+ """)
)
kg_uom_id = env.cr.fetchone()[0]
# get uom factor
env.cr.execute(
- """
+ SQL(
+ """
SELECT factor
FROM uom_uom
WHERE id = %s
""",
- (kg_uom_id,),
+ kg_uom_id,
+ )
)
kg_uom_factor = env.cr.fetchone()[0]
# update weight where weight_uom_id is not null and not kg
env.cr.execute(
- """
+ SQL(
+ """
UPDATE product_product
SET weight = product_product.weight / product_uom.factor * %s
FROM uom_uom product_uom, product_template pt
@@ -96,12 +106,15 @@ def pre_init_hook(env): # pragma: nocover
AND pt.id = product_product.product_tmpl_id
AND weight_uom_id IS NOT NULL AND pt.weight_uom_id != %s
""",
- (kg_uom_factor, kg_uom_id),
+ kg_uom_factor,
+ kg_uom_id,
+ )
)
_logger.info(f"{env.cr.rowcount} product_product rows updated")
# update product_template with 1 product_product
env.cr.execute(
- """
+ SQL(
+ """
UPDATE product_template
SET weight = unique_product.weight
FROM (
@@ -114,6 +127,7 @@ def pre_init_hook(env): # pragma: nocover
WHERE product_template.id = unique_product.product_tmpl_id
AND product_template.weight_uom_id != %s
""",
- (kg_uom_id,),
+ kg_uom_id,
+ )
)
_logger.info(f"{env.cr.rowcount} product_template rows updated")
diff --git a/product_logistics_uom/models/product_template.py b/product_logistics_uom/models/product_template.py
index 24b8cd4b2596..64287ca5509d 100644
--- a/product_logistics_uom/models/product_template.py
+++ b/product_logistics_uom/models/product_template.py
@@ -41,7 +41,6 @@ class ProductTemplate(models.Model):
volume_uom_name = fields.Char(
string="Volume unit of measure label",
related="volume_uom_id.name",
- readonly=True,
)
weight_uom_id = fields.Many2one(
@@ -50,14 +49,12 @@ class ProductTemplate(models.Model):
domain=lambda self: [
("category_id", "=", self.env.ref("uom.product_uom_categ_kgm").id)
],
- compute=False,
default=lambda self: self._get_weight_uom_id_from_ir_config_parameter(),
)
weight_uom_name = fields.Char(
string="Weight unit of measure label",
related="weight_uom_id.name",
- readonly=True,
)
show_volume_uom_warning = fields.Boolean(
@@ -108,54 +105,46 @@ def _get_length_uom_id_from_ir_config_parameter(self):
"volume_uom_id",
)
def _compute_product_volume(self):
- unique_variants = self.filtered(
- lambda template: len(template.product_variant_ids) == 1
- )
- for template in unique_variants:
- template.product_volume = template.product_variant_ids.product_volume
- for template in self - unique_variants:
- template.product_volume = 0.0
+ for template in self:
+ template.product_volume = (
+ template.product_variant_ids.product_volume
+ if template.product_variant_count == 1
+ else 0.0
+ )
def _inverse_product_volume(self):
for template in self:
- if len(template.product_variant_ids) == 1:
+ if template.product_variant_count == 1:
template.product_variant_ids.product_volume = template.product_volume
@api.depends("weight", "weight_uom_id")
def _compute_product_weight(self):
- unique_variants = self.filtered(
- lambda template: len(template.product_variant_ids) == 1
- )
- for template in unique_variants:
- template.product_weight = template.product_variant_ids.product_weight
- for template in self - unique_variants:
- template.product_weight = 0.0
+ for template in self:
+ template.product_weight = (
+ template.product_variant_ids.product_weight
+ if template.product_variant_count == 1
+ else 0.0
+ )
def _inverse_product_weight(self):
for template in self:
- if len(template.product_variant_ids) == 1:
+ if template.product_variant_count == 1:
template.product_variant_ids.product_weight = template.product_weight
@api.depends("volume", "volume_uom_id")
def _compute_show_volume_uom_warning(self):
- unique_variants = self.filtered(
- lambda template: len(template.product_variant_ids) == 1
- )
- for template in unique_variants:
+ for template in self:
template.show_volume_uom_warning = (
template.product_variant_ids.show_volume_uom_warning
+ if template.product_variant_count == 1
+ else False
)
- for template in self - unique_variants:
- template.show_volume_uom_warning = False
@api.depends("weight", "weight_uom_id")
def _compute_show_weight_uom_warning(self):
- unique_variants = self.filtered(
- lambda template: len(template.product_variant_ids) == 1
- )
- for template in unique_variants:
+ for template in self:
template.show_weight_uom_warning = (
template.product_variant_ids.show_weight_uom_warning
+ if template.product_variant_count == 1
+ else False
)
- for template in self - unique_variants:
- template.show_weight_uom_warning = False
diff --git a/product_logistics_uom/readme/CONTRIBUTORS.md b/product_logistics_uom/readme/CONTRIBUTORS.md
index 2777045382a9..2d16ddf81b9e 100644
--- a/product_logistics_uom/readme/CONTRIBUTORS.md
+++ b/product_logistics_uom/readme/CONTRIBUTORS.md
@@ -1,3 +1,4 @@
- Raphaël Reverdy \<\>
- Fernando La Chica \<\>
- Laurent Mignon \<\>
+- Nhan Tran \<\>
diff --git a/product_logistics_uom/static/description/index.html b/product_logistics_uom/static/description/index.html
index acda9dc63485..efd658eedacf 100644
--- a/product_logistics_uom/static/description/index.html
+++ b/product_logistics_uom/static/description/index.html
@@ -369,7 +369,7 @@ Product logistics UoM
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:42ad3cfeaf195979b68830ec0c2c4708612bea09d87622384a694f131561772a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
This module allows to choose an Unit Of Measure (UoM) for products
weight and volume. It can be set product per product for users in
group_uom.
@@ -439,7 +439,7 @@
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.
+feedback.
Do not contact contributors directly about support or help with technical issues.