Skip to content

Commit

Permalink
[MIG] partner_logistics_uom: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasTran380381 authored and Lukas Tran committed Oct 25, 2024
1 parent cb79ff1 commit 5eb0636
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 62 deletions.
21 changes: 11 additions & 10 deletions product_logistics_uom/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -96,7 +96,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/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-attribute/issues/new?body=module:%20product_logistics_uom%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_logistics_uom%0Aversion:%2018.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.

Expand All @@ -112,17 +112,18 @@ Authors
Contributors
------------

- Raphaël Reverdy <raphael.reverdy@akretion.com>
- Fernando La Chica <fernandolachica@gmail.com>
- Laurent Mignon <laurent.mignon@acsone.eu>
- Raphaël Reverdy <raphael.reverdy@akretion.com>
- Fernando La Chica <fernandolachica@gmail.com>
- Laurent Mignon <laurent.mignon@acsone.eu>
- Nhan Tran <nhant@trobz.com>

Other credits
-------------

The development of this module has been financially supported by:

- Akretion <https://akretion.com>
- La Base <https://labase.coop>
- Akretion <https://akretion.com>
- La Base <https://labase.coop>

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

|maintainer-hparfr|

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion product_logistics_uom/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
48 changes: 31 additions & 17 deletions product_logistics_uom/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import logging

from odoo.tools import sql
from odoo.tools import SQL, sql

_logger = logging.getLogger(__name__)

Expand All @@ -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,
Expand All @@ -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 (
Expand All @@ -62,46 +68,53 @@ 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
WHERE product_uom.id = weight_uom_id
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 (
Expand All @@ -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")
51 changes: 20 additions & 31 deletions product_logistics_uom/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions product_logistics_uom/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Raphaël Reverdy \<<raphael.reverdy@akretion.com>\>
- Fernando La Chica \<<fernandolachica@gmail.com>\>
- Laurent Mignon \<<laurent.mignon@acsone.eu>\>
- Nhan Tran \<<nhant@trobz.com>\>
7 changes: 4 additions & 3 deletions product_logistics_uom/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Product logistics UoM</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:42ad3cfeaf195979b68830ec0c2c4708612bea09d87622384a694f131561772a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-attribute/tree/17.0/product_logistics_uom"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-17-0/product-attribute-17-0-product_logistics_uom"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-attribute/tree/18.0/product_logistics_uom"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_logistics_uom"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>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.</p>
Expand Down Expand Up @@ -439,7 +439,7 @@ <h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/product-attribute/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/product-attribute/issues/new?body=module:%20product_logistics_uom%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/product-attribute/issues/new?body=module:%20product_logistics_uom%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -457,6 +457,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<li>Raphaël Reverdy &lt;<a class="reference external" href="mailto:raphael.reverdy&#64;akretion.com">raphael.reverdy&#64;akretion.com</a>&gt;</li>
<li>Fernando La Chica &lt;<a class="reference external" href="mailto:fernandolachica&#64;gmail.com">fernandolachica&#64;gmail.com</a>&gt;</li>
<li>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt;</li>
<li>Nhan Tran &lt;<a class="reference external" href="mailto:nhant&#64;trobz.com">nhant&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand All @@ -478,7 +479,7 @@ <h2><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/hparfr"><img alt="hparfr" src="https://github.com/hparfr.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-attribute/tree/17.0/product_logistics_uom">OCA/product-attribute</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-attribute/tree/18.0/product_logistics_uom">OCA/product-attribute</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down

0 comments on commit 5eb0636

Please sign in to comment.