Skip to content

Commit aaf74ba

Browse files
hieulucky111huynh-ch
authored andcommitted
[MIG] mrp_bom_attribute_match: Migration to 19.0
1 parent 12eba12 commit aaf74ba

File tree

9 files changed

+67
-58
lines changed

9 files changed

+67
-58
lines changed

mrp_bom_attribute_match/README.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ BOM Attribute Match
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github
24-
:target: https://github.com/OCA/manufacture/tree/18.0/mrp_bom_attribute_match
24+
:target: https://github.com/OCA/manufacture/tree/19.0/mrp_bom_attribute_match
2525
:alt: OCA/manufacture
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/manufacture-18-0/manufacture-18-0-mrp_bom_attribute_match
27+
:target: https://translation.odoo-community.org/projects/manufacture-19-0/manufacture-19-0-mrp_bom_attribute_match
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -131,7 +131,7 @@ Bug Tracker
131131
Bugs are tracked on `GitHub Issues <https://github.com/OCA/manufacture/issues>`_.
132132
In case of trouble, please check there if your issue has already been reported.
133133
If you spotted it first, help us to smash it by providing a detailed and welcomed
134-
`feedback <https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_bom_attribute_match%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
134+
`feedback <https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_bom_attribute_match%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
135135

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

@@ -159,6 +159,10 @@ Contributors
159159

160160
- Eugenio Micó <eugenio@studio73.es>
161161

162+
- `Komit <https://komit-consulting.com>`__
163+
164+
- Hieu Vo Minh Bao <hieu.vmb@komit-consulting.com>
165+
162166
Maintainers
163167
-----------
164168

@@ -172,6 +176,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
172176
mission is to support the collaborative development of Odoo features and
173177
promote its widespread use.
174178

175-
This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/18.0/mrp_bom_attribute_match>`_ project on GitHub.
179+
This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/19.0/mrp_bom_attribute_match>`_ project on GitHub.
176180

177181
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

mrp_bom_attribute_match/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "BOM Attribute Match",
3-
"version": "18.0.1.0.2",
3+
"version": "19.0.1.0.0",
44
"category": "Manufacturing",
55
"author": "Ilyas, Ooops, Odoo Community Association (OCA)",
66
"summary": "Dynamic BOM component based on product attribute",

mrp_bom_attribute_match/models/mrp_bom.py

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
from odoo import _, api, fields, models
3+
from odoo import api, fields, models
44
from odoo.exceptions import UserError, ValidationError
55
from odoo.tools import float_round
66

@@ -23,12 +23,6 @@ class MrpBomLine(models.Model):
2323
compute="_compute_match_on_attribute_ids",
2424
store=True,
2525
)
26-
product_uom_category_id = fields.Many2one(
27-
"uom.category",
28-
related=None,
29-
compute="_compute_product_uom_category_id",
30-
compute_sudo=True,
31-
)
3226

3327
@api.model_create_multi
3428
def create(self, vals_list):
@@ -46,49 +40,19 @@ def create(self, vals_list):
4640
)
4741
return super().create(vals_list)
4842

49-
@api.depends("product_id", "component_template_id")
50-
def _compute_product_uom_category_id(self):
51-
"""Compute the product_uom_category_id field.
52-
53-
This is the product category that will be allowed to use on the product_uom_id
54-
field, already covered by core module:
55-
https://github.com/odoo/odoo/blob/331b9435c/addons/mrp/models/mrp_bom.py#L372
56-
57-
In core, though, this field is related to "product_id.uom_id.category_id".
58-
Here we make it computed to choose between component_template_id and
59-
product_id, depending on which one is set
60-
"""
61-
# pylint: disable=missing-return
62-
# NOTE: To play nice with other modules trying to do the same:
63-
# 1) Set the field value as if it were a related field (core behaviour)
64-
# 2) Call super (if it's there)
65-
# 3) Update only the records we want
66-
for rec in self:
67-
rec.product_uom_category_id = rec.product_id.uom_id.category_id
68-
if hasattr(super(), "_compute_product_uom_category_id"):
69-
super()._compute_product_uom_category_id()
70-
for rec in self:
71-
if rec.component_template_id:
72-
rec.product_uom_category_id = (
73-
rec.component_template_id.uom_id.category_id
74-
)
75-
7643
@api.onchange("component_template_id")
7744
def _onchange_component_template_id(self):
7845
if self.component_template_id:
7946
if self.product_id:
8047
self.product_backup_id = self.product_id
8148
self.product_id = False
82-
if (
83-
self.product_uom_id.category_id
84-
!= self.component_template_id.uom_id.category_id
85-
):
49+
if not self.product_uom_id:
8650
self.product_uom_id = self.component_template_id.uom_id
8751
else:
8852
if self.product_backup_id:
8953
self.product_id = self.product_backup_id
9054
self.product_backup_id = False
91-
if self.product_uom_id.category_id != self.product_id.uom_id.category_id:
55+
if not self.product_uom_id:
9256
self.product_uom_id = self.product_id.uom_id
9357

9458
@api.depends("component_template_id")
@@ -114,15 +78,15 @@ def _check_component_attributes(self):
11478
prod_attrs = bom_prod.valid_product_template_attribute_line_ids.attribute_id
11579
if not comp_attrs:
11680
raise ValidationError(
117-
_(
81+
self.env._(
11882
"No match on attribute has been detected for Component "
11983
"(Product Template) %s",
12084
cmp_tmpl.display_name,
12185
)
12286
)
12387
if not all(attr in prod_attrs for attr in comp_attrs):
12488
raise ValidationError(
125-
_(
89+
self.env._(
12690
"Some attributes of the dynamic component are not included into"
12791
" production product attributes."
12892
)
@@ -141,7 +105,7 @@ def _check_variants_validity(self):
141105
same_attrs = self.env["product.attribute"].browse(same_attr_ids)
142106
if same_attrs:
143107
raise ValidationError(
144-
_(
108+
self.env._(
145109
"You cannot use an attribute value for attribute(s) "
146110
"%(attributes)s in the field “Apply on Variants” as it's the "
147111
"same attribute used in the field “Match on Attribute” related "
@@ -281,7 +245,7 @@ def update_product_boms():
281245
graph,
282246
):
283247
raise UserError(
284-
_(
248+
self.env._(
285249
"Recursion error! A product with a Bill of Material "
286250
"should not have itself in its BoM or child BoMs!"
287251
)

mrp_bom_attribute_match/models/product.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from odoo import _, api, models
1+
from odoo import Command, api, models
22
from odoo.exceptions import UserError
33

44

@@ -20,7 +20,7 @@ def _check_product_with_component_change_allowed(self):
2020
diff = rec.env["product.attribute"].browse(diff_ids)
2121
if diff:
2222
raise UserError(
23-
_(
23+
self.env._(
2424
"The attributes you're trying to remove are used in "
2525
"the BoM as a match with Component (Product Template). "
2626
"To remove these attributes, first remove the BOM line "
@@ -47,7 +47,7 @@ def _check_component_change_allowed(self):
4747
if len(diff) > 0:
4848
attr_recs = self.env["product.attribute"].browse(diff)
4949
raise UserError(
50-
_(
50+
self.env._(
5151
"This product template is used as a component in the "
5252
"BOMs for %(bom)s and attribute(s) %(attributes)s is "
5353
"not present in all such product(s), and this would "
@@ -65,3 +65,33 @@ def _get_component_boms(self):
6565
if bom_lines:
6666
return bom_lines.mapped("bom_id")
6767
return False
68+
69+
70+
class ProductProduct(models.Model):
71+
_inherit = "product.product"
72+
73+
def _compute_bom_price(self, bom, boms_to_recompute=False, byproduct_bom=False):
74+
self.ensure_one()
75+
# OVERRIDE to fill in the `line.product_id` if a component template is used.
76+
# To avoid a complete override, we HACK the bom by replacing it with a virtual
77+
# record, and modifying it's lines on-the-fly.
78+
has_template_lines = any(
79+
line.component_template_id for line in bom.bom_line_ids
80+
)
81+
if has_template_lines:
82+
bom = bom.new(origin=bom)
83+
to_ignore_line_ids = []
84+
for line in bom.bom_line_ids:
85+
if line._skip_bom_line(self) or not line.component_template_id:
86+
continue
87+
line_product = bom._get_component_template_product(
88+
line, self, line.product_id
89+
)
90+
if not line_product:
91+
to_ignore_line_ids.append(line.id)
92+
continue
93+
else:
94+
line.product_id = line_product
95+
if to_ignore_line_ids:
96+
bom.bom_line_ids = [Command.unlink(id) for id in to_ignore_line_ids]
97+
return super()._compute_bom_price(bom, boms_to_recompute, byproduct_bom)

mrp_bom_attribute_match/readme/CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
- Iván Todorovich \<<ivan.todorovich@camptocamp.com>\>
55
- [Studio73](https://www.studio73.es)
66
- Eugenio Micó \<<eugenio@studio73.es>\>
7+
- [Komit](https://komit-consulting.com)
8+
- Hieu Vo Minh Bao \<<hieu.vmb@komit-consulting.com>\>

mrp_bom_attribute_match/reports/mrp_report_bom_structure.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
44

55
from odoo import Command, api, models
6+
from odoo.api import NewId
67

78

89
class ReportBomStructure(models.AbstractModel):
@@ -65,6 +66,6 @@ def _get_bom_data(
6566
if has_template_lines:
6667
for component in data.get("components", []):
6768
for key, value in component.items():
68-
if isinstance(value, models.NewId):
69+
if isinstance(value, NewId):
6970
component[key] = value.origin
7071
return data

mrp_bom_attribute_match/static/description/index.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>BOM Attribute Match</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:54f862e1aa9155a9900716afa6f3fd1d7f5249d1f04fd88dcf228eb4427018b6
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<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/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/manufacture/tree/18.0/mrp_bom_attribute_match"><img alt="OCA/manufacture" src="https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/manufacture-18-0/manufacture-18-0-mrp_bom_attribute_match"><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/manufacture&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<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/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/manufacture/tree/19.0/mrp_bom_attribute_match"><img alt="OCA/manufacture" src="https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/manufacture-19-0/manufacture-19-0-mrp_bom_attribute_match"><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/manufacture&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>This module addresses the BoM case where the product to manufacture has
379379
one attribute with tens or hundreds of values (usually attribute
380380
“color”, eg: “Configurable Desk” can be produced in 900 different
@@ -476,7 +476,7 @@ <h2><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h2>
476476
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/manufacture/issues">GitHub Issues</a>.
477477
In case of trouble, please check there if your issue has already been reported.
478478
If you spotted it first, help us to smash it by providing a detailed and welcomed
479-
<a class="reference external" href="https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_bom_attribute_match%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
479+
<a class="reference external" href="https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_bom_attribute_match%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
480480
<p>Do not contact contributors directly about support or help with technical issues.</p>
481481
</div>
482482
<div class="section" id="credits">
@@ -503,6 +503,10 @@ <h3><a class="toc-backref" href="#toc-entry-5">Contributors</a></h3>
503503
<li>Eugenio Micó &lt;<a class="reference external" href="mailto:eugenio&#64;studio73.es">eugenio&#64;studio73.es</a>&gt;</li>
504504
</ul>
505505
</li>
506+
<li><a class="reference external" href="https://komit-consulting.com">Komit</a><ul>
507+
<li>Hieu Vo Minh Bao &lt;<a class="reference external" href="mailto:hieu.vmb&#64;komit-consulting.com">hieu.vmb&#64;komit-consulting.com</a>&gt;</li>
508+
</ul>
509+
</li>
506510
</ul>
507511
</div>
508512
<div class="section" id="maintainers">
@@ -514,7 +518,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
514518
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
515519
mission is to support the collaborative development of Odoo features and
516520
promote its widespread use.</p>
517-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/manufacture/tree/18.0/mrp_bom_attribute_match">OCA/manufacture</a> project on GitHub.</p>
521+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/manufacture/tree/19.0/mrp_bom_attribute_match">OCA/manufacture</a> project on GitHub.</p>
518522
<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>
519523
</div>
520524
</div>

mrp_bom_attribute_match/tests/common.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ def setUpClass(cls):
9191
"value_ids": [Command.set(cls.product_attribute.value_ids.ids)],
9292
}
9393
)
94-
cls.env.ref("uom.group_uom").write({"users": [(Command.link(cls.env.user.id))]})
94+
cls.env.ref("uom.group_uom").write(
95+
{"user_ids": [(Command.link(cls.env.user.id))]}
96+
)
97+
cls.env.ref("product.group_product_variant").write(
98+
{"user_ids": [(Command.link(cls.env.user.id))]}
99+
)
95100
# Create boms
96101
cls.bom_id = cls._create_bom(
97102
cls.product_sword,

mrp_bom_attribute_match/tests/test_mrp_bom_line.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def setUpClass(cls):
1313
cls.product_plastic.write(
1414
{
1515
"uom_id": cls.uom_dozen.id,
16-
"uom_po_id": cls.uom_dozen.id,
1716
}
1817
)
1918

0 commit comments

Comments
 (0)