mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
137
mrp_bom_attribute_match/README.rst
Normal file
137
mrp_bom_attribute_match/README.rst
Normal file
@@ -0,0 +1,137 @@
|
||||
===================
|
||||
BOM Attribute Match
|
||||
===================
|
||||
|
||||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
|
||||
:target: https://odoo-community.org/page/development-status
|
||||
:alt: Beta
|
||||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github
|
||||
:target: https://github.com/OCA/manufacture/tree/14.0/mrp_bom_attribute_match
|
||||
:alt: OCA/manufacture
|
||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||
:target: https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-mrp_bom_attribute_match
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||
:target: https://runbot.odoo-community.org/runbot/129/14.0
|
||||
:alt: Try me on Runbot
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
This module addresses the BoM case where the product to manufacture has one attribute with tens or hundreds of values (usually attribute "color", eg: "Configurable Desk" can be produced in 900 different colors).
|
||||
|
||||
Creating a dynamic BoM currently requires adding one BoM line for each attribute value to match component variant with attribute value (eg: component "Desk board (Green)" to be applied to variant "Green").
|
||||
|
||||
This has 3 downsides:
|
||||
|
||||
- BoM lines proliferation (more error prone)
|
||||
|
||||
- Difficult to update in case a new attribute value (new color paint) is added
|
||||
|
||||
- Difficult to update in case base component changes.
|
||||
|
||||
|
||||
This module allows to use a product template as component in BoM lines, automatically matching component variant to use in MO line with the attribute value selected for manufacture.
|
||||
|
||||
Eg: Product template "Desk Board" is added to BoM line for product "Configurable Desk"; match is made on attribute "Color". In MO, if product to manufacture is "Configurable Desk (Steel, Pink)", MO line will have component "Desk Board (Pink)".
|
||||
|
||||
Using the same BoM, if product to manufacture is "Configurable Desk (Steel, Yellow)", MO line will have component "Desk Board (Yellow)".
|
||||
|
||||
|
||||
The flow is valid also if the Component (Product Template) has more than one attribute matching the product to manufacture; in this case, on MO line the component variant will be the one matching multiple attribute values for the product to manufacture.
|
||||
|
||||
|
||||
Various checks are in place to make sure this flow is not disrupted:
|
||||
|
||||
- user cannot add a product in field "Component (Product Template)" which:
|
||||
|
||||
does not have matching attributes with product to manufacture
|
||||
|
||||
has a different variant-generating attribute than the product to manufacture
|
||||
|
||||
- Adding a new variant-generating attribute to a product used as "Component (Product Template)" raises an error if the attribute is not included in all the products to manufacture where component is referenced.
|
||||
|
||||
- Removing an attribute used for BoM attribute matching from product to manufacture raises an error.
|
||||
|
||||
- On a BoM line with Component (Product Template) set, an attribute value of attributes referenced in "Match on attribute" field cannot be used in field "Apply to variant".
|
||||
|
||||
- If attribute value for matching attribute in manufactured product is not present in component (product template), the BoM line is skipped in MO.
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
Using this module you can have dynamic components of a BOM.
|
||||
It will allow you to have only 1 line in the BOM if you have hundreds of attribute
|
||||
values for manufacturing product and hundreds of attributes values of component (material).
|
||||
|
||||
How to use
|
||||
|
||||
#. Create a product to produce e.g. Desk.
|
||||
#. Set 1 attribute (e.g. Color). And select possible values for it.
|
||||
#. Create a component product (material) e.g. Plastic.
|
||||
#. Set 1 attribute (Color). And select possible values for it.
|
||||
#. Create a BOM.
|
||||
#. Select a manufacturing product Desk.
|
||||
#. Add a BOM line. Select Component (product template) Plastic.
|
||||
#. You will see Color attribute appeared in the Apply On Attribute field.
|
||||
#. Save the BOM.
|
||||
#. Create Manufacturing Order. Select Desk with e.g. Red color to produce and BOM you created.
|
||||
#. You will see in the component list Plastic added with corresponding (red) color.
|
||||
|
||||
Consider, that to use this feature component must have only 1 attribute.
|
||||
And a values of this attribute of a manufacturing product should be available for a component.
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/manufacture/issues>`_.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
`feedback <https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_bom_attribute_match%0Aversion:%2014.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
|
||||
~~~~~~~
|
||||
|
||||
* Ilyas
|
||||
* Ooops
|
||||
|
||||
Contributors
|
||||
~~~~~~~~~~~~
|
||||
|
||||
* Ooops404 <https://ooops404.com>
|
||||
|
||||
* Ilyas
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
.. image:: https://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: https://odoo-community.org
|
||||
|
||||
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.
|
||||
|
||||
This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/14.0/mrp_bom_attribute_match>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
1
mrp_bom_attribute_match/__init__.py
Normal file
1
mrp_bom_attribute_match/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
13
mrp_bom_attribute_match/__manifest__.py
Normal file
13
mrp_bom_attribute_match/__manifest__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "BOM Attribute Match",
|
||||
"version": "15.0.1.0.0",
|
||||
"category": "Manufacturing",
|
||||
"author": "Ilyas, Ooops, Odoo Community Association (OCA)",
|
||||
"summary": "Dynamic BOM component based on product attribute",
|
||||
"depends": ["mrp"],
|
||||
"license": "AGPL-3",
|
||||
"website": "https://github.com/OCA/manufacture",
|
||||
"data": [
|
||||
"views/mrp_bom_views.xml",
|
||||
],
|
||||
}
|
||||
148
mrp_bom_attribute_match/i18n/hr.po
Normal file
148
mrp_bom_attribute_match/i18n/hr.po
Normal file
@@ -0,0 +1,148 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * mrp_bom_attribute_match
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 14.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"PO-Revision-Date: 2022-08-22 14:07+0000\n"
|
||||
"Last-Translator: Bole <bole@dajmi5.com>\n"
|
||||
"Language-Team: none\n"
|
||||
"Language: hr\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
|
||||
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
|
||||
"X-Generator: Weblate 4.3.2\n"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model,name:mrp_bom_attribute_match.model_mrp_bom
|
||||
msgid "Bill of Material"
|
||||
msgstr "Sastavnica"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model,name:mrp_bom_attribute_match.model_mrp_bom_line
|
||||
msgid "Bill of Material Line"
|
||||
msgstr "Stavka sastavnice"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__product_id
|
||||
msgid "Component"
|
||||
msgstr "Komponenta"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__component_template_id
|
||||
msgid "Component (product template)"
|
||||
msgstr "Komponenta (predložak)"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom__display_name
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__display_name
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_production__display_name
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_product_template__display_name
|
||||
msgid "Display Name"
|
||||
msgstr "Naziv"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom__id
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__id
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_production__id
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_product_template__id
|
||||
msgid "ID"
|
||||
msgstr "ID"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom____last_update
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line____last_update
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_production____last_update
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_product_template____last_update
|
||||
msgid "Last Modified on"
|
||||
msgstr "Zadnje modificirano"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__match_on_attribute_ids
|
||||
msgid "Match on Attributes"
|
||||
msgstr "Odgovarajući atributi"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"No match on attribute has been detected for Component (Product Template) %s"
|
||||
msgstr "Nije pronađen odgovarajući atribut za Komponentu (predložak) %s"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__product_backup_id
|
||||
msgid "Product Backup"
|
||||
msgstr "Pričuvni proizvod"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model,name:mrp_bom_attribute_match.model_product_template
|
||||
msgid "Product Template"
|
||||
msgstr "Predložak proizvoda"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__product_uom_id_domain
|
||||
msgid "Product Uom Id Domain"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model,name:mrp_bom_attribute_match.model_mrp_production
|
||||
msgid "Production Order"
|
||||
msgstr "Nalog za proizvodnju"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Recursion error! A product with a Bill of Material should not have itself "
|
||||
"in its BoM or child BoMs!"
|
||||
msgstr ""
|
||||
"Greška rekurzije! Proizvodsa Sastavnicom, nesmije imati sebe u Sastavnici "
|
||||
"ili podređenim sastavnicama!"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Some attributes of the dynamic component are not included into production "
|
||||
"product attributes."
|
||||
msgstr ""
|
||||
"Neki atributi dinamičke komponente nisu uključeni u atributima glavnog "
|
||||
"proizvoda."
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,help:mrp_bom_attribute_match.field_mrp_bom_line__product_backup_id
|
||||
msgid "Technical field to store previous value of product_id"
|
||||
msgstr "Tehničko polje za pohranu prethodne vrijednosti polja product_id"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/product.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"The attributes you're trying to remove is used in BoM as a match with "
|
||||
"Component (Product Template). To remove these attributes, first remove the "
|
||||
"BOM line with the matching component.\n"
|
||||
"Attributes: %s\n"
|
||||
"BoM: %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/product.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"This product template is used as a component in the BOMs for %s and "
|
||||
"attribute(s) %s is not present in all such product(s), and this would break "
|
||||
"the BOM behavior."
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"You cannot use an attribute value for attribute %s in the field “Apply on "
|
||||
"Variants” as it’s the same attribute used in field “Match on "
|
||||
"Attribute”related to the component %s."
|
||||
msgstr ""
|
||||
185
mrp_bom_attribute_match/i18n/it.po
Normal file
185
mrp_bom_attribute_match/i18n/it.po
Normal file
@@ -0,0 +1,185 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * mrp_bom_attribute_match
|
||||
#
|
||||
# Francesco @ Ooops <francesco.foresti@ooops404.com>, 2022.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 12.0+e\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2022-01-14 17:50+0000\n"
|
||||
"PO-Revision-Date: 2022-08-22 18:07+0000\n"
|
||||
"Last-Translator: Francesco Foresti <francesco.foresti@ooops404.com>\n"
|
||||
"Language-Team: Italian <http://weblate.ops404.it/projects/ooops-mrp-14-0/"
|
||||
"mrp_bom_attribute_match/it/>\n"
|
||||
"Language: it\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: nplurals=2; plural=n != 1;\n"
|
||||
"X-Generator: Weblate 4.3.2\n"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model,name:mrp_bom_attribute_match.model_mrp_bom
|
||||
msgid "Bill of Material"
|
||||
msgstr "Distinta base"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model,name:mrp_bom_attribute_match.model_mrp_bom_line
|
||||
msgid "Bill of Material Line"
|
||||
msgstr "Riga Distinta Base"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__product_id
|
||||
msgid "Component"
|
||||
msgstr "Componente"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__component_template_id
|
||||
msgid "Component (product template)"
|
||||
msgstr "Componente (modello prodotto)"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom__display_name
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__display_name
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_production__display_name
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_product_template__display_name
|
||||
msgid "Display Name"
|
||||
msgstr "Nome visualizzato"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom__id
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__id
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_production__id
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_product_template__id
|
||||
msgid "ID"
|
||||
msgstr "ID"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom____last_update
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line____last_update
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_production____last_update
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_product_template____last_update
|
||||
msgid "Last Modified on"
|
||||
msgstr "Ultima modifica il"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__match_on_attribute_ids
|
||||
msgid "Match on Attributes"
|
||||
msgstr "Corrispondenza su attributi"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"No match on attribute has been detected for Component (Product Template) %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__product_backup_id
|
||||
msgid "Product Backup"
|
||||
msgstr "Backup componente"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model,name:mrp_bom_attribute_match.model_product_template
|
||||
msgid "Product Template"
|
||||
msgstr "Modello Prodotto"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__product_uom_id_domain
|
||||
msgid "Product Uom Id Domain"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model,name:mrp_bom_attribute_match.model_mrp_production
|
||||
msgid "Production Order"
|
||||
msgstr "Ordine di Produzione"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Recursion error! A product with a Bill of Material should not have itself "
|
||||
"in its BoM or child BoMs!"
|
||||
msgstr ""
|
||||
"Errore ricorsivo! Un prodotto con una distinta base non può essere presente "
|
||||
"nella sua DiBa o nelle DiBa figlie!"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Some attributes of the dynamic component are not included into production "
|
||||
"product attributes."
|
||||
msgstr ""
|
||||
"Alcuni attributi del componente non sono inclusi tra gli attributi del "
|
||||
"prodotto da produrre."
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,help:mrp_bom_attribute_match.field_mrp_bom_line__product_backup_id
|
||||
msgid "Technical field to store previous value of product_id"
|
||||
msgstr "Campo tecnico per preservare i valori di product_id"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/product.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"The attributes you're trying to remove is used in BoM as a match with "
|
||||
"Component (Product Template). To remove these attributes, first remove the "
|
||||
"BOM line with the matching component.\n"
|
||||
"Attributes: %s\n"
|
||||
"BoM: %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/product.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"This product template is used as a component in the BOMs for %s and "
|
||||
"attribute(s) %s is not present in all such product(s), and this would break "
|
||||
"the BOM behavior."
|
||||
msgstr ""
|
||||
"Questo modello prodotto è utilizzato come componente nella DiBa per i "
|
||||
"prodotti %s e gli attributi %s non sono presenti in tutti questi prodotti; "
|
||||
"ciò può corrompere il comportamento del BOM."
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"You cannot use an attribute value for attribute %s in the field “Apply on "
|
||||
"Variants” as it’s the same attribute used in field “Match on "
|
||||
"Attribute”related to the component %s."
|
||||
msgstr ""
|
||||
"Non puoi utilizzare un valore attributo dell'attributo %s nel campo “Applica "
|
||||
"alle varianti” dato che è lo stesso attributo utilizzato nel campo "
|
||||
"“Corrispondenza su attributo” relativo al componente %s."
|
||||
|
||||
#~ msgid "Dynamic component must have only 1 attribute"
|
||||
#~ msgstr "Il componente dinamico deve avere un solo attributo"
|
||||
|
||||
#~ msgid "Match on Attribute"
|
||||
#~ msgstr "Corrispondenza su attributo"
|
||||
|
||||
#~ msgid "Only product template with one attribute can be added to this field."
|
||||
#~ msgstr ""
|
||||
#~ "Solo i modelli prodotto con un solo attributo possono essere aggiunti a "
|
||||
#~ "questo campo."
|
||||
|
||||
#~ msgid ""
|
||||
#~ "This product included into BOMs as dynamic component. Please remove it "
|
||||
#~ "from related BOMs to be able to have multiple attributes for it. BOM ids: "
|
||||
#~ "%s"
|
||||
#~ msgstr ""
|
||||
#~ "Questo prodotto è incluso in una distinta base come componente dinamico. "
|
||||
#~ "Per aggiungere altri attributi, devi rimuoverlo dalle seguenti DiBa: %s"
|
||||
|
||||
#~ msgid "Attribute Value Backup"
|
||||
#~ msgstr "Backup Valori Attributo"
|
||||
|
||||
#~ msgid "Match On Attribute"
|
||||
#~ msgstr "Corrispondenza su attributo"
|
||||
|
||||
#~ msgid "Technical field to store previous value of attribute_value_ids"
|
||||
#~ msgstr ""
|
||||
#~ "Campo tecnico per preservare i valori precedenti di attribute_value_ids"
|
||||
138
mrp_bom_attribute_match/i18n/mrp_bom_attribute_match.pot
Normal file
138
mrp_bom_attribute_match/i18n/mrp_bom_attribute_match.pot
Normal file
@@ -0,0 +1,138 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * mrp_bom_attribute_match
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 14.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model,name:mrp_bom_attribute_match.model_mrp_bom
|
||||
msgid "Bill of Material"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model,name:mrp_bom_attribute_match.model_mrp_bom_line
|
||||
msgid "Bill of Material Line"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__product_id
|
||||
msgid "Component"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__component_template_id
|
||||
msgid "Component (product template)"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom__display_name
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__display_name
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_production__display_name
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_product_template__display_name
|
||||
msgid "Display Name"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom__id
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__id
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_production__id
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_product_template__id
|
||||
msgid "ID"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom____last_update
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line____last_update
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_production____last_update
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_product_template____last_update
|
||||
msgid "Last Modified on"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__match_on_attribute_ids
|
||||
msgid "Match on Attributes"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"No match on attribute has been detected for Component (Product Template) %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__product_backup_id
|
||||
msgid "Product Backup"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model,name:mrp_bom_attribute_match.model_product_template
|
||||
msgid "Product Template"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,field_description:mrp_bom_attribute_match.field_mrp_bom_line__product_uom_id_domain
|
||||
msgid "Product Uom Id Domain"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model,name:mrp_bom_attribute_match.model_mrp_production
|
||||
msgid "Production Order"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Recursion error! A product with a Bill of Material should not have itself "
|
||||
"in its BoM or child BoMs!"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Some attributes of the dynamic component are not included into production "
|
||||
"product attributes."
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: model:ir.model.fields,help:mrp_bom_attribute_match.field_mrp_bom_line__product_backup_id
|
||||
msgid "Technical field to store previous value of product_id"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/product.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"The attributes you're trying to remove is used in BoM as a match with Component (Product Template). To remove these attributes, first remove the BOM line with the matching component.\n"
|
||||
"Attributes: %s\n"
|
||||
"BoM: %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/product.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"This product template is used as a component in the BOMs for %s and "
|
||||
"attribute(s) %s is not present in all such product(s), and this would break "
|
||||
"the BOM behavior."
|
||||
msgstr ""
|
||||
|
||||
#. module: mrp_bom_attribute_match
|
||||
#: code:addons/mrp_bom_attribute_match/models/mrp_bom.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"You cannot use an attribute value for attribute %s in the field “Apply on "
|
||||
"Variants” as it’s the same attribute used in field “Match on "
|
||||
"Attribute”related to the component %s."
|
||||
msgstr ""
|
||||
3
mrp_bom_attribute_match/models/__init__.py
Normal file
3
mrp_bom_attribute_match/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from . import mrp_bom
|
||||
from . import mrp_production
|
||||
from . import product
|
||||
354
mrp_bom_attribute_match/models/mrp_bom.py
Normal file
354
mrp_bom_attribute_match/models/mrp_bom.py
Normal file
@@ -0,0 +1,354 @@
|
||||
import logging
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.tools import float_round
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MrpBomLine(models.Model):
|
||||
_inherit = "mrp.bom.line"
|
||||
|
||||
product_id = fields.Many2one("product.product", "Component", required=False)
|
||||
product_backup_id = fields.Many2one(
|
||||
"product.product", help="Technical field to store previous value of product_id"
|
||||
)
|
||||
component_template_id = fields.Many2one(
|
||||
"product.template", "Component (product template)"
|
||||
)
|
||||
match_on_attribute_ids = fields.Many2many(
|
||||
"product.attribute",
|
||||
string="Match on Attributes",
|
||||
compute="_compute_match_on_attribute_ids",
|
||||
store=True,
|
||||
)
|
||||
product_uom_category_id = fields.Many2one(
|
||||
"uom.category",
|
||||
related=None,
|
||||
compute="_compute_product_uom_category_id",
|
||||
)
|
||||
|
||||
@api.depends("product_id", "component_template_id")
|
||||
def _compute_product_uom_category_id(self):
|
||||
"""Compute the product_uom_category_id field.
|
||||
|
||||
This is the product category that will be allowed to use on the product_uom_id
|
||||
field, already covered by core module:
|
||||
https://github.com/odoo/odoo/blob/331b9435c/addons/mrp/models/mrp_bom.py#L372
|
||||
|
||||
In core, though, this field is related to "product_id.uom_id.category_id".
|
||||
Here we make it computed to choose between component_template_id and
|
||||
product_id, depending on which one is set
|
||||
"""
|
||||
# pylint: disable=missing-return
|
||||
# NOTE: To play nice with other modules trying to do the same:
|
||||
# 1) Set the field value as if it were a related field (core behaviour)
|
||||
# 2) Call super (if it's there)
|
||||
# 3) Update only the records we want
|
||||
for rec in self:
|
||||
rec.product_uom_category_id = rec.product_id.uom_id.category_id
|
||||
if hasattr(super(), "_compute_product_uom_category_id"):
|
||||
super()._compute_product_uom_category_id()
|
||||
for rec in self:
|
||||
if rec.component_template_id:
|
||||
rec.product_uom_category_id = (
|
||||
rec.component_template_id.uom_id.category_id
|
||||
)
|
||||
|
||||
@api.onchange("component_template_id")
|
||||
def _onchange_component_template_id(self):
|
||||
if self.component_template_id:
|
||||
if self.product_id:
|
||||
self.product_backup_id = self.product_id
|
||||
self.product_id = False
|
||||
if (
|
||||
self.product_uom_id.category_id
|
||||
!= self.component_template_id.uom_id.category_id
|
||||
):
|
||||
self.product_uom_id = self.component_template_id.uom_id
|
||||
else:
|
||||
if self.product_backup_id:
|
||||
self.product_id = self.product_backup_id
|
||||
self.product_backup_id = False
|
||||
if self.product_uom_id.category_id != self.product_id.uom_id.category_id:
|
||||
self.product_uom_id = self.product_id.uom_id
|
||||
|
||||
@api.depends("component_template_id")
|
||||
def _compute_match_on_attribute_ids(self):
|
||||
for rec in self:
|
||||
if rec.component_template_id:
|
||||
rec.match_on_attribute_ids = (
|
||||
rec.component_template_id.attribute_line_ids.attribute_id.filtered(
|
||||
lambda x: x.create_variant != "no_variant"
|
||||
)
|
||||
)
|
||||
else:
|
||||
rec.match_on_attribute_ids = False
|
||||
|
||||
@api.constrains("component_template_id")
|
||||
def _check_component_attributes(self):
|
||||
for rec in self:
|
||||
if not rec.component_template_id:
|
||||
continue
|
||||
comp_attrs = (
|
||||
rec.component_template_id.valid_product_template_attribute_line_ids.attribute_id
|
||||
)
|
||||
prod_attrs = (
|
||||
rec.bom_id.product_tmpl_id.valid_product_template_attribute_line_ids.attribute_id
|
||||
)
|
||||
if not comp_attrs:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"No match on attribute has been detected for Component "
|
||||
"(Product Template) %s",
|
||||
rec.component_template_id.display_name,
|
||||
)
|
||||
)
|
||||
if not all(attr in prod_attrs for attr in comp_attrs):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Some attributes of the dynamic component are not included into "
|
||||
"production product attributes."
|
||||
)
|
||||
)
|
||||
|
||||
@api.constrains("component_template_id", "bom_product_template_attribute_value_ids")
|
||||
def _check_variants_validity(self):
|
||||
for rec in self:
|
||||
if (
|
||||
not rec.bom_product_template_attribute_value_ids
|
||||
or not rec.component_template_id
|
||||
):
|
||||
continue
|
||||
variant_attrs = rec.bom_product_template_attribute_value_ids.attribute_id
|
||||
same_attr_ids = set(rec.match_on_attribute_ids.ids) & set(variant_attrs.ids)
|
||||
same_attrs = self.env["product.attribute"].browse(same_attr_ids)
|
||||
if same_attrs:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"You cannot use an attribute value for attribute(s) %(attributes)s "
|
||||
"in the field “Apply on Variants” as it's the same attribute used "
|
||||
"in the field “Match on Attribute” related to the component "
|
||||
"%(component)s.",
|
||||
attributes=", ".join(same_attrs.mapped("name")),
|
||||
component=rec.component_template_id.name,
|
||||
)
|
||||
)
|
||||
|
||||
@api.onchange("match_on_attribute_ids")
|
||||
def _onchange_match_on_attribute_ids_check_component_attributes(self):
|
||||
if self.match_on_attribute_ids:
|
||||
self._check_component_attributes()
|
||||
|
||||
@api.onchange("bom_product_template_attribute_value_ids")
|
||||
def _onchange_bom_product_template_attribute_value_ids_check_variants(self):
|
||||
if self.bom_product_template_attribute_value_ids:
|
||||
self._check_variants_validity()
|
||||
|
||||
|
||||
class MrpBom(models.Model):
|
||||
_inherit = "mrp.bom"
|
||||
|
||||
# flake8: noqa: C901
|
||||
def explode(self, product, quantity, picking_type=False):
|
||||
# Had to replace this method
|
||||
"""
|
||||
Explodes the BoM and creates two lists with all the information you need:
|
||||
bom_done and line_done
|
||||
Quantity describes the number of times you need the BoM: so the quantity
|
||||
divided by the number created by the BoM
|
||||
and converted into its UoM
|
||||
"""
|
||||
from collections import defaultdict
|
||||
|
||||
graph = defaultdict(list)
|
||||
V = set()
|
||||
|
||||
def check_cycle(v, visited, recStack, graph):
|
||||
visited[v] = True
|
||||
recStack[v] = True
|
||||
for neighbour in graph[v]:
|
||||
if visited[neighbour] is False:
|
||||
if check_cycle(neighbour, visited, recStack, graph) is True:
|
||||
return True
|
||||
elif recStack[neighbour] is True:
|
||||
return True
|
||||
recStack[v] = False
|
||||
return False
|
||||
|
||||
product_ids = set()
|
||||
product_boms = {}
|
||||
|
||||
def update_product_boms():
|
||||
products = self.env["product.product"].browse(product_ids)
|
||||
product_boms.update(
|
||||
self._bom_find(
|
||||
products,
|
||||
bom_type="phantom",
|
||||
picking_type=picking_type or self.picking_type_id,
|
||||
company_id=self.company_id.id,
|
||||
)
|
||||
)
|
||||
# Set missing keys to default value
|
||||
for product in products:
|
||||
product_boms.setdefault(product, self.env["mrp.bom"])
|
||||
|
||||
boms_done = [
|
||||
(
|
||||
self,
|
||||
{
|
||||
"qty": quantity,
|
||||
"product": product,
|
||||
"original_qty": quantity,
|
||||
"parent_line": False,
|
||||
},
|
||||
)
|
||||
]
|
||||
lines_done = []
|
||||
V |= {product.product_tmpl_id.id}
|
||||
|
||||
bom_lines = []
|
||||
for bom_line in self.bom_line_ids:
|
||||
product_id = bom_line.product_id
|
||||
V |= {product_id.product_tmpl_id.id}
|
||||
graph[product.product_tmpl_id.id].append(product_id.product_tmpl_id.id)
|
||||
bom_lines.append((bom_line, product, quantity, False))
|
||||
product_ids.add(product_id.id)
|
||||
update_product_boms()
|
||||
product_ids.clear()
|
||||
while bom_lines:
|
||||
current_line, current_product, current_qty, parent_line = bom_lines[0]
|
||||
bom_lines = bom_lines[1:]
|
||||
|
||||
if current_line._skip_bom_line(current_product):
|
||||
continue
|
||||
|
||||
line_quantity = current_qty * current_line.product_qty
|
||||
if current_line.product_id not in product_boms:
|
||||
update_product_boms()
|
||||
product_ids.clear()
|
||||
# upd start
|
||||
component_template_product = self._get_component_template_product(
|
||||
current_line, product, current_line.product_id
|
||||
)
|
||||
if component_template_product:
|
||||
# need to set product_id temporary
|
||||
current_line.product_id = component_template_product
|
||||
else:
|
||||
# component_template_id is set, but no attribute value match.
|
||||
continue
|
||||
# upd end
|
||||
bom = product_boms.get(current_line.product_id)
|
||||
if bom:
|
||||
converted_line_quantity = current_line.product_uom_id._compute_quantity(
|
||||
line_quantity / bom.product_qty, bom.product_uom_id
|
||||
)
|
||||
bom_lines += [
|
||||
(
|
||||
line,
|
||||
current_line.product_id,
|
||||
converted_line_quantity,
|
||||
current_line,
|
||||
)
|
||||
for line in bom.bom_line_ids
|
||||
]
|
||||
for bom_line in bom.bom_line_ids:
|
||||
graph[current_line.product_id.product_tmpl_id.id].append(
|
||||
bom_line.product_id.product_tmpl_id.id
|
||||
)
|
||||
if bom_line.product_id.product_tmpl_id.id in V and check_cycle(
|
||||
bom_line.product_id.product_tmpl_id.id,
|
||||
{key: False for key in V},
|
||||
{key: False for key in V},
|
||||
graph,
|
||||
):
|
||||
raise UserError(
|
||||
_(
|
||||
"Recursion error! A product with a Bill of Material "
|
||||
"should not have itself in its BoM or child BoMs!"
|
||||
)
|
||||
)
|
||||
V |= {bom_line.product_id.product_tmpl_id.id}
|
||||
if bom_line.product_id not in product_boms:
|
||||
product_ids.add(bom_line.product_id.id)
|
||||
boms_done.append(
|
||||
(
|
||||
bom,
|
||||
{
|
||||
"qty": converted_line_quantity,
|
||||
"product": current_product,
|
||||
"original_qty": quantity,
|
||||
"parent_line": current_line,
|
||||
},
|
||||
)
|
||||
)
|
||||
else:
|
||||
# We round up here because the user expects
|
||||
# that if he has to consume a little more, the whole UOM unit
|
||||
# should be consumed.
|
||||
rounding = current_line.product_uom_id.rounding
|
||||
line_quantity = float_round(
|
||||
line_quantity, precision_rounding=rounding, rounding_method="UP"
|
||||
)
|
||||
lines_done.append(
|
||||
(
|
||||
current_line,
|
||||
{
|
||||
"qty": line_quantity,
|
||||
"product": current_product,
|
||||
"original_qty": quantity,
|
||||
"parent_line": parent_line,
|
||||
},
|
||||
)
|
||||
)
|
||||
return boms_done, lines_done
|
||||
|
||||
def _get_component_template_product(
|
||||
self, bom_line, bom_product_id, line_product_id
|
||||
):
|
||||
if bom_line.component_template_id:
|
||||
comp = bom_line.component_template_id
|
||||
comp_attr_ids = (
|
||||
comp.valid_product_template_attribute_line_ids.attribute_id.ids
|
||||
)
|
||||
prod_attr_ids = (
|
||||
bom_product_id.valid_product_template_attribute_line_ids.attribute_id.ids
|
||||
)
|
||||
# check attributes
|
||||
if not all(item in prod_attr_ids for item in comp_attr_ids):
|
||||
_log.info(
|
||||
"Component skipped. Component attributes must be included into "
|
||||
"product attributes to use component_template_id."
|
||||
)
|
||||
return False
|
||||
# find matching combination
|
||||
combination = self.env["product.template.attribute.value"]
|
||||
for ptav in bom_product_id.product_template_attribute_value_ids:
|
||||
combination |= self.env["product.template.attribute.value"].search(
|
||||
[
|
||||
("product_tmpl_id", "=", comp.id),
|
||||
("attribute_id", "=", ptav.attribute_id.id),
|
||||
(
|
||||
"product_attribute_value_id",
|
||||
"=",
|
||||
ptav.product_attribute_value_id.id,
|
||||
),
|
||||
]
|
||||
)
|
||||
if len(combination) == 0:
|
||||
return False
|
||||
product_id = comp._get_variant_for_combination(combination)
|
||||
if product_id and product_id.active:
|
||||
return product_id
|
||||
return False
|
||||
else:
|
||||
return line_product_id
|
||||
|
||||
@api.constrains("product_tmpl_id", "product_id")
|
||||
def _check_component_attributes(self):
|
||||
return self.bom_line_ids._check_component_attributes()
|
||||
|
||||
@api.constrains("product_tmpl_id", "product_id")
|
||||
def _check_variants_validity(self):
|
||||
return self.bom_line_ids._check_variants_validity()
|
||||
17
mrp_bom_attribute_match/models/mrp_production.py
Normal file
17
mrp_bom_attribute_match/models/mrp_production.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = "mrp.production"
|
||||
|
||||
def action_confirm(self):
|
||||
res = super().action_confirm()
|
||||
for bom_line in self.bom_id.bom_line_ids:
|
||||
if bom_line.component_template_id:
|
||||
# product_id was set in mrp.bom.explode for correct flow. Need to remove it.
|
||||
bom_line.product_id = False
|
||||
return res
|
||||
|
||||
@api.constrains("bom_id")
|
||||
def _check_component_attributes(self):
|
||||
self.bom_id._check_component_attributes()
|
||||
67
mrp_bom_attribute_match/models/product.py
Normal file
67
mrp_bom_attribute_match/models/product.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from odoo import _, api, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
_inherit = "product.template"
|
||||
|
||||
@api.constrains("attribute_line_ids")
|
||||
def _check_product_with_component_change_allowed(self):
|
||||
for rec in self:
|
||||
if not rec.attribute_line_ids:
|
||||
continue
|
||||
for bom in rec.bom_ids:
|
||||
for line in bom.bom_line_ids.filtered("match_on_attribute_ids"):
|
||||
prod_attr_ids = rec.attribute_line_ids.attribute_id.filtered(
|
||||
lambda x: x.create_variant != "no_variant"
|
||||
).ids
|
||||
comp_attr_ids = line.match_on_attribute_ids.ids
|
||||
diff_ids = list(set(comp_attr_ids) - set(prod_attr_ids))
|
||||
diff = rec.env["product.attribute"].browse(diff_ids)
|
||||
if diff:
|
||||
raise UserError(
|
||||
_(
|
||||
"The attributes you're trying to remove are used in "
|
||||
"the BoM as a match with Component (Product Template). "
|
||||
"To remove these attributes, first remove the BOM line "
|
||||
"with the matching component.\n"
|
||||
"Attributes: %(attributes)s\nBoM: %(bom)s",
|
||||
attributes=", ".join(diff.mapped("name")),
|
||||
bom=bom.display_name,
|
||||
)
|
||||
)
|
||||
|
||||
@api.constrains("attribute_line_ids")
|
||||
def _check_component_change_allowed(self):
|
||||
for rec in self:
|
||||
if not rec.attribute_line_ids:
|
||||
continue
|
||||
boms = self._get_component_boms()
|
||||
if not boms:
|
||||
continue
|
||||
for bom in boms:
|
||||
vpa = bom.product_tmpl_id.valid_product_template_attribute_line_ids
|
||||
prod_attr_ids = vpa.attribute_id.ids
|
||||
comp_attr_ids = self.attribute_line_ids.attribute_id.ids
|
||||
diff = list(set(comp_attr_ids) - set(prod_attr_ids))
|
||||
if len(diff) > 0:
|
||||
attr_recs = self.env["product.attribute"].browse(diff)
|
||||
raise UserError(
|
||||
_(
|
||||
"This product template is used as a component in the "
|
||||
"BOMs for %(bom)s and attribute(s) %(attributes)s is "
|
||||
"not present in all such product(s), and this would "
|
||||
"break the BOM behavior.",
|
||||
attributes=", ".join(attr_recs.mapped("name")),
|
||||
bom=bom.display_name,
|
||||
)
|
||||
)
|
||||
|
||||
def _get_component_boms(self):
|
||||
self.ensure_one()
|
||||
bom_lines = self.env["mrp.bom.line"].search(
|
||||
[("component_template_id", "=", self._origin.id)]
|
||||
)
|
||||
if bom_lines:
|
||||
return bom_lines.mapped("bom_id")
|
||||
return False
|
||||
7
mrp_bom_attribute_match/readme/CONTRIBUTORS.rst
Normal file
7
mrp_bom_attribute_match/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1,7 @@
|
||||
* Ooops404 <https://ooops404.com>
|
||||
|
||||
* Ilyas
|
||||
|
||||
* `Camptocamp <https://www.camptocamp.com>`_
|
||||
|
||||
* Iván Todorovich <ivan.todorovich@camptocamp.com>
|
||||
38
mrp_bom_attribute_match/readme/DESCRIPTION.rst
Normal file
38
mrp_bom_attribute_match/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1,38 @@
|
||||
This module addresses the BoM case where the product to manufacture has one attribute with tens or hundreds of values (usually attribute "color", eg: "Configurable Desk" can be produced in 900 different colors).
|
||||
|
||||
Creating a dynamic BoM currently requires adding one BoM line for each attribute value to match component variant with attribute value (eg: component "Desk board (Green)" to be applied to variant "Green").
|
||||
|
||||
This has 3 downsides:
|
||||
|
||||
- BoM lines proliferation (more error prone)
|
||||
|
||||
- Difficult to update in case a new attribute value (new color paint) is added
|
||||
|
||||
- Difficult to update in case base component changes.
|
||||
|
||||
|
||||
This module allows to use a product template as component in BoM lines, automatically matching component variant to use in MO line with the attribute value selected for manufacture.
|
||||
|
||||
Eg: Product template "Desk Board" is added to BoM line for product "Configurable Desk"; match is made on attribute "Color". In MO, if product to manufacture is "Configurable Desk (Steel, Pink)", MO line will have component "Desk Board (Pink)".
|
||||
|
||||
Using the same BoM, if product to manufacture is "Configurable Desk (Steel, Yellow)", MO line will have component "Desk Board (Yellow)".
|
||||
|
||||
|
||||
The flow is valid also if the Component (Product Template) has more than one attribute matching the product to manufacture; in this case, on MO line the component variant will be the one matching multiple attribute values for the product to manufacture.
|
||||
|
||||
|
||||
Various checks are in place to make sure this flow is not disrupted:
|
||||
|
||||
- user cannot add a product in field "Component (Product Template)" which:
|
||||
|
||||
does not have matching attributes with product to manufacture
|
||||
|
||||
has a different variant-generating attribute than the product to manufacture
|
||||
|
||||
- Adding a new variant-generating attribute to a product used as "Component (Product Template)" raises an error if the attribute is not included in all the products to manufacture where component is referenced.
|
||||
|
||||
- Removing an attribute used for BoM attribute matching from product to manufacture raises an error.
|
||||
|
||||
- On a BoM line with Component (Product Template) set, an attribute value of attributes referenced in "Match on attribute" field cannot be used in field "Apply to variant".
|
||||
|
||||
- If attribute value for matching attribute in manufactured product is not present in component (product template), the BoM line is skipped in MO.
|
||||
20
mrp_bom_attribute_match/readme/USAGE.rst
Normal file
20
mrp_bom_attribute_match/readme/USAGE.rst
Normal file
@@ -0,0 +1,20 @@
|
||||
Using this module you can have dynamic components of a BOM.
|
||||
It will allow you to have only 1 line in the BOM if you have hundreds of attribute
|
||||
values for manufacturing product and hundreds of attributes values of component (material).
|
||||
|
||||
How to use
|
||||
|
||||
#. Create a product to produce e.g. Desk.
|
||||
#. Set 1 attribute (e.g. Color). And select possible values for it.
|
||||
#. Create a component product (material) e.g. Plastic.
|
||||
#. Set 1 attribute (Color). And select possible values for it.
|
||||
#. Create a BOM.
|
||||
#. Select a manufacturing product Desk.
|
||||
#. Add a BOM line. Select Component (product template) Plastic.
|
||||
#. You will see Color attribute appeared in the Apply On Attribute field.
|
||||
#. Save the BOM.
|
||||
#. Create Manufacturing Order. Select Desk with e.g. Red color to produce and BOM you created.
|
||||
#. You will see in the component list Plastic added with corresponding (red) color.
|
||||
|
||||
Consider, that to use this feature component must have only 1 attribute.
|
||||
And a values of this attribute of a manufacturing product should be available for a component.
|
||||
BIN
mrp_bom_attribute_match/static/description/icon.png
Normal file
BIN
mrp_bom_attribute_match/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
476
mrp_bom_attribute_match/static/description/index.html
Normal file
476
mrp_bom_attribute_match/static/description/index.html
Normal file
@@ -0,0 +1,476 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
|
||||
<title>BOM Attribute Match</title>
|
||||
<style type="text/css">
|
||||
|
||||
/*
|
||||
:Author: David Goodger (goodger@python.org)
|
||||
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
|
||||
:Copyright: This stylesheet has been placed in the public domain.
|
||||
|
||||
Default cascading style sheet for the HTML output of Docutils.
|
||||
|
||||
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
|
||||
customize this style sheet.
|
||||
*/
|
||||
|
||||
/* used to remove borders from tables and images */
|
||||
.borderless, table.borderless td, table.borderless th {
|
||||
border: 0 }
|
||||
|
||||
table.borderless td, table.borderless th {
|
||||
/* Override padding for "table.docutils td" with "! important".
|
||||
The right padding separates the table cells. */
|
||||
padding: 0 0.5em 0 0 ! important }
|
||||
|
||||
.first {
|
||||
/* Override more specific margin styles with "! important". */
|
||||
margin-top: 0 ! important }
|
||||
|
||||
.last, .with-subtitle {
|
||||
margin-bottom: 0 ! important }
|
||||
|
||||
.hidden {
|
||||
display: none }
|
||||
|
||||
.subscript {
|
||||
vertical-align: sub;
|
||||
font-size: smaller }
|
||||
|
||||
.superscript {
|
||||
vertical-align: super;
|
||||
font-size: smaller }
|
||||
|
||||
a.toc-backref {
|
||||
text-decoration: none ;
|
||||
color: black }
|
||||
|
||||
blockquote.epigraph {
|
||||
margin: 2em 5em ; }
|
||||
|
||||
dl.docutils dd {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Uncomment (and remove this text!) to get bold-faced definition list terms
|
||||
dl.docutils dt {
|
||||
font-weight: bold }
|
||||
*/
|
||||
|
||||
div.abstract {
|
||||
margin: 2em 5em }
|
||||
|
||||
div.abstract p.topic-title {
|
||||
font-weight: bold ;
|
||||
text-align: center }
|
||||
|
||||
div.admonition, div.attention, div.caution, div.danger, div.error,
|
||||
div.hint, div.important, div.note, div.tip, div.warning {
|
||||
margin: 2em ;
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.admonition p.admonition-title, div.hint p.admonition-title,
|
||||
div.important p.admonition-title, div.note p.admonition-title,
|
||||
div.tip p.admonition-title {
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
div.attention p.admonition-title, div.caution p.admonition-title,
|
||||
div.danger p.admonition-title, div.error p.admonition-title,
|
||||
div.warning p.admonition-title, .code .error {
|
||||
color: red ;
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
/* Uncomment (and remove this text!) to get reduced vertical space in
|
||||
compound paragraphs.
|
||||
div.compound .compound-first, div.compound .compound-middle {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
div.compound .compound-last, div.compound .compound-middle {
|
||||
margin-top: 0.5em }
|
||||
*/
|
||||
|
||||
div.dedication {
|
||||
margin: 2em 5em ;
|
||||
text-align: center ;
|
||||
font-style: italic }
|
||||
|
||||
div.dedication p.topic-title {
|
||||
font-weight: bold ;
|
||||
font-style: normal }
|
||||
|
||||
div.figure {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
div.footer, div.header {
|
||||
clear: both;
|
||||
font-size: smaller }
|
||||
|
||||
div.line-block {
|
||||
display: block ;
|
||||
margin-top: 1em ;
|
||||
margin-bottom: 1em }
|
||||
|
||||
div.line-block div.line-block {
|
||||
margin-top: 0 ;
|
||||
margin-bottom: 0 ;
|
||||
margin-left: 1.5em }
|
||||
|
||||
div.sidebar {
|
||||
margin: 0 0 0.5em 1em ;
|
||||
border: medium outset ;
|
||||
padding: 1em ;
|
||||
background-color: #ffffee ;
|
||||
width: 40% ;
|
||||
float: right ;
|
||||
clear: right }
|
||||
|
||||
div.sidebar p.rubric {
|
||||
font-family: sans-serif ;
|
||||
font-size: medium }
|
||||
|
||||
div.system-messages {
|
||||
margin: 5em }
|
||||
|
||||
div.system-messages h1 {
|
||||
color: red }
|
||||
|
||||
div.system-message {
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.system-message p.system-message-title {
|
||||
color: red ;
|
||||
font-weight: bold }
|
||||
|
||||
div.topic {
|
||||
margin: 2em }
|
||||
|
||||
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
|
||||
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
|
||||
margin-top: 0.4em }
|
||||
|
||||
h1.title {
|
||||
text-align: center }
|
||||
|
||||
h2.subtitle {
|
||||
text-align: center }
|
||||
|
||||
hr.docutils {
|
||||
width: 75% }
|
||||
|
||||
img.align-left, .figure.align-left, object.align-left, table.align-left {
|
||||
clear: left ;
|
||||
float: left ;
|
||||
margin-right: 1em }
|
||||
|
||||
img.align-right, .figure.align-right, object.align-right, table.align-right {
|
||||
clear: right ;
|
||||
float: right ;
|
||||
margin-left: 1em }
|
||||
|
||||
img.align-center, .figure.align-center, object.align-center {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
table.align-center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.align-left {
|
||||
text-align: left }
|
||||
|
||||
.align-center {
|
||||
clear: both ;
|
||||
text-align: center }
|
||||
|
||||
.align-right {
|
||||
text-align: right }
|
||||
|
||||
/* reset inner alignment in figures */
|
||||
div.align-right {
|
||||
text-align: inherit }
|
||||
|
||||
/* div.align-center * { */
|
||||
/* text-align: left } */
|
||||
|
||||
.align-top {
|
||||
vertical-align: top }
|
||||
|
||||
.align-middle {
|
||||
vertical-align: middle }
|
||||
|
||||
.align-bottom {
|
||||
vertical-align: bottom }
|
||||
|
||||
ol.simple, ul.simple {
|
||||
margin-bottom: 1em }
|
||||
|
||||
ol.arabic {
|
||||
list-style: decimal }
|
||||
|
||||
ol.loweralpha {
|
||||
list-style: lower-alpha }
|
||||
|
||||
ol.upperalpha {
|
||||
list-style: upper-alpha }
|
||||
|
||||
ol.lowerroman {
|
||||
list-style: lower-roman }
|
||||
|
||||
ol.upperroman {
|
||||
list-style: upper-roman }
|
||||
|
||||
p.attribution {
|
||||
text-align: right ;
|
||||
margin-left: 50% }
|
||||
|
||||
p.caption {
|
||||
font-style: italic }
|
||||
|
||||
p.credits {
|
||||
font-style: italic ;
|
||||
font-size: smaller }
|
||||
|
||||
p.label {
|
||||
white-space: nowrap }
|
||||
|
||||
p.rubric {
|
||||
font-weight: bold ;
|
||||
font-size: larger ;
|
||||
color: maroon ;
|
||||
text-align: center }
|
||||
|
||||
p.sidebar-title {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold ;
|
||||
font-size: larger }
|
||||
|
||||
p.sidebar-subtitle {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
p.topic-title {
|
||||
font-weight: bold }
|
||||
|
||||
pre.address {
|
||||
margin-bottom: 0 ;
|
||||
margin-top: 0 ;
|
||||
font: inherit }
|
||||
|
||||
pre.literal-block, pre.doctest-block, pre.math, pre.code {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
pre.code .ln { color: grey; } /* line numbers */
|
||||
pre.code, code { background-color: #eeeeee }
|
||||
pre.code .comment, code .comment { color: #5C6576 }
|
||||
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
|
||||
pre.code .literal.string, code .literal.string { color: #0C5404 }
|
||||
pre.code .name.builtin, code .name.builtin { color: #352B84 }
|
||||
pre.code .deleted, code .deleted { background-color: #DEB0A1}
|
||||
pre.code .inserted, code .inserted { background-color: #A3D289}
|
||||
|
||||
span.classifier {
|
||||
font-family: sans-serif ;
|
||||
font-style: oblique }
|
||||
|
||||
span.classifier-delimiter {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
span.interpreted {
|
||||
font-family: sans-serif }
|
||||
|
||||
span.option {
|
||||
white-space: nowrap }
|
||||
|
||||
span.pre {
|
||||
white-space: pre }
|
||||
|
||||
span.problematic {
|
||||
color: red }
|
||||
|
||||
span.section-subtitle {
|
||||
/* font-size relative to parent (h1..h6 element) */
|
||||
font-size: 80% }
|
||||
|
||||
table.citation {
|
||||
border-left: solid 1px gray;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docinfo {
|
||||
margin: 2em 4em }
|
||||
|
||||
table.docutils {
|
||||
margin-top: 0.5em ;
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
table.footnote {
|
||||
border-left: solid 1px black;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docutils td, table.docutils th,
|
||||
table.docinfo td, table.docinfo th {
|
||||
padding-left: 0.5em ;
|
||||
padding-right: 0.5em ;
|
||||
vertical-align: top }
|
||||
|
||||
table.docutils th.field-name, table.docinfo th.docinfo-name {
|
||||
font-weight: bold ;
|
||||
text-align: left ;
|
||||
white-space: nowrap ;
|
||||
padding-left: 0 }
|
||||
|
||||
/* "booktabs" style (no vertical lines) */
|
||||
table.docutils.booktabs {
|
||||
border: 0px;
|
||||
border-top: 2px solid;
|
||||
border-bottom: 2px solid;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table.docutils.booktabs * {
|
||||
border: 0px;
|
||||
}
|
||||
table.docutils.booktabs th {
|
||||
border-bottom: thin solid;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
|
||||
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
|
||||
font-size: 100% }
|
||||
|
||||
ul.auto-toc {
|
||||
list-style-type: none }
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document" id="bom-attribute-match">
|
||||
<h1 class="title">BOM Attribute Match</h1>
|
||||
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external" 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" 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" href="https://github.com/OCA/manufacture/tree/14.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" href="https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-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" href="https://runbot.odoo-community.org/runbot/129/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p>This module addresses the BoM case where the product to manufacture has one attribute with tens or hundreds of values (usually attribute “color”, eg: “Configurable Desk” can be produced in 900 different colors).</p>
|
||||
<p>Creating a dynamic BoM currently requires adding one BoM line for each attribute value to match component variant with attribute value (eg: component “Desk board (Green)” to be applied to variant “Green”).</p>
|
||||
<p>This has 3 downsides:</p>
|
||||
<ul class="simple">
|
||||
<li>BoM lines proliferation (more error prone)</li>
|
||||
<li>Difficult to update in case a new attribute value (new color paint) is added</li>
|
||||
<li>Difficult to update in case base component changes.</li>
|
||||
</ul>
|
||||
<p>This module allows to use a product template as component in BoM lines, automatically matching component variant to use in MO line with the attribute value selected for manufacture.</p>
|
||||
<p>Eg: Product template “Desk Board” is added to BoM line for product “Configurable Desk”; match is made on attribute “Color”. In MO, if product to manufacture is “Configurable Desk (Steel, Pink)”, MO line will have component “Desk Board (Pink)”.</p>
|
||||
<p>Using the same BoM, if product to manufacture is “Configurable Desk (Steel, Yellow)”, MO line will have component “Desk Board (Yellow)”.</p>
|
||||
<p>The flow is valid also if the Component (Product Template) has more than one attribute matching the product to manufacture; in this case, on MO line the component variant will be the one matching multiple attribute values for the product to manufacture.</p>
|
||||
<p>Various checks are in place to make sure this flow is not disrupted:</p>
|
||||
<ul>
|
||||
<li><p class="first">user cannot add a product in field “Component (Product Template)” which:</p>
|
||||
<blockquote>
|
||||
<p>does not have matching attributes with product to manufacture</p>
|
||||
<p>has a different variant-generating attribute than the product to manufacture</p>
|
||||
</blockquote>
|
||||
</li>
|
||||
<li><p class="first">Adding a new variant-generating attribute to a product used as “Component (Product Template)” raises an error if the attribute is not included in all the products to manufacture where component is referenced.</p>
|
||||
</li>
|
||||
<li><p class="first">Removing an attribute used for BoM attribute matching from product to manufacture raises an error.</p>
|
||||
</li>
|
||||
<li><p class="first">On a BoM line with Component (Product Template) set, an attribute value of attributes referenced in “Match on attribute” field cannot be used in field “Apply to variant”.</p>
|
||||
</li>
|
||||
<li><p class="first">If attribute value for matching attribute in manufactured product is not present in component (product template), the BoM line is skipped in MO.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="usage">
|
||||
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
|
||||
<p>Using this module you can have dynamic components of a BOM.
|
||||
It will allow you to have only 1 line in the BOM if you have hundreds of attribute
|
||||
values for manufacturing product and hundreds of attributes values of component (material).</p>
|
||||
<p>How to use</p>
|
||||
<blockquote>
|
||||
<ol class="arabic simple">
|
||||
<li>Create a product to produce e.g. Desk.</li>
|
||||
<li>Set 1 attribute (e.g. Color). And select possible values for it.</li>
|
||||
<li>Create a component product (material) e.g. Plastic.</li>
|
||||
<li>Set 1 attribute (Color). And select possible values for it.</li>
|
||||
<li>Create a BOM.</li>
|
||||
<li>Select a manufacturing product Desk.</li>
|
||||
<li>Add a BOM line. Select Component (product template) Plastic.</li>
|
||||
<li>You will see Color attribute appeared in the Apply On Attribute field.</li>
|
||||
<li>Save the BOM.</li>
|
||||
<li>Create Manufacturing Order. Select Desk with e.g. Red color to produce and BOM you created.</li>
|
||||
<li>You will see in the component list Plastic added with corresponding (red) color.</li>
|
||||
</ol>
|
||||
</blockquote>
|
||||
<p>Consider, that to use this feature component must have only 1 attribute.
|
||||
And a values of this attribute of a manufacturing product should be available for a component.</p>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/manufacture/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 smashing it by providing a detailed and welcomed
|
||||
<a class="reference external" href="https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_bom_attribute_match%0Aversion:%2014.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">
|
||||
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
|
||||
<div class="section" id="authors">
|
||||
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Ilyas</li>
|
||||
<li>Ooops</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="contributors">
|
||||
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Ooops404 <<a class="reference external" href="https://ooops404.com">https://ooops404.com</a>><ul>
|
||||
<li>Ilyas</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
|
||||
<p>This module is maintained by the OCA.</p>
|
||||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
|
||||
<p>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.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/manufacture/tree/14.0/mrp_bom_attribute_match">OCA/manufacture</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>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
1
mrp_bom_attribute_match/tests/__init__.py
Normal file
1
mrp_bom_attribute_match/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_mrp_bom_attribute_match
|
||||
134
mrp_bom_attribute_match/tests/common.py
Normal file
134
mrp_bom_attribute_match/tests/common.py
Normal file
@@ -0,0 +1,134 @@
|
||||
from odoo.tests import Form, TransactionCase
|
||||
|
||||
|
||||
class TestMrpAttachmentMgmtBase(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls._create_products(cls)
|
||||
cls._create_boms(cls)
|
||||
|
||||
def _create_products(self):
|
||||
self.warehouse = self.env.ref("stock.warehouse0")
|
||||
route_manufacture = self.warehouse.manufacture_pull_id.route_id.id
|
||||
self.product_sword = self.env["product.template"].create(
|
||||
{
|
||||
"name": "Plastic Sword",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
self.product_surf = self.env["product.template"].create(
|
||||
{
|
||||
"name": "Surf",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
self.product_fin = self.env["product.template"].create(
|
||||
{
|
||||
"name": "Surf Fin",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
self.product_plastic = self.env["product.template"].create(
|
||||
{
|
||||
"name": "Plastic Component",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
self.p1 = self.env["product.template"].create(
|
||||
{
|
||||
"name": "P1",
|
||||
"type": "product",
|
||||
"route_ids": [(6, 0, [route_manufacture])],
|
||||
}
|
||||
)
|
||||
self.p2 = self.env["product.template"].create(
|
||||
{
|
||||
"name": "P2",
|
||||
"type": "product",
|
||||
"route_ids": [(6, 0, [route_manufacture])],
|
||||
}
|
||||
)
|
||||
self.p3 = self.env["product.template"].create(
|
||||
{
|
||||
"name": "P3",
|
||||
"type": "product",
|
||||
"route_ids": [(6, 0, [route_manufacture])],
|
||||
}
|
||||
)
|
||||
self.product_9 = self.env["product.product"].create(
|
||||
{
|
||||
"name": "Paper",
|
||||
}
|
||||
)
|
||||
self.product_10 = self.env["product.product"].create(
|
||||
{
|
||||
"name": "Stone",
|
||||
}
|
||||
)
|
||||
self.product_attribute = self.env["product.attribute"].create(
|
||||
{"name": "Colour", "display_type": "radio", "create_variant": "always"}
|
||||
)
|
||||
self.attribute_value_ids = self.env["product.attribute.value"].create(
|
||||
[
|
||||
{"name": "Cyan", "attribute_id": self.product_attribute.id},
|
||||
{"name": "Magenta", "attribute_id": self.product_attribute.id},
|
||||
]
|
||||
)
|
||||
self.plastic_attrs = self.env["product.template.attribute.line"].create(
|
||||
{
|
||||
"attribute_id": self.product_attribute.id,
|
||||
"product_tmpl_id": self.product_plastic.id,
|
||||
"value_ids": [(6, 0, self.product_attribute.value_ids.ids)],
|
||||
}
|
||||
)
|
||||
self.sword_attrs = self.env["product.template.attribute.line"].create(
|
||||
{
|
||||
"attribute_id": self.product_attribute.id,
|
||||
"product_tmpl_id": self.product_sword.id,
|
||||
"value_ids": [(6, 0, self.product_attribute.value_ids.ids)],
|
||||
}
|
||||
)
|
||||
|
||||
def _create_boms(self):
|
||||
mrp_bom_form = Form(self.env["mrp.bom"])
|
||||
mrp_bom_form.product_tmpl_id = self.product_sword
|
||||
with mrp_bom_form.bom_line_ids.new() as line_form:
|
||||
line_form.component_template_id = self.product_plastic
|
||||
line_form.product_qty = 1
|
||||
self.bom_id = mrp_bom_form.save()
|
||||
|
||||
mrp_bom_form = Form(self.env["mrp.bom"])
|
||||
mrp_bom_form.product_tmpl_id = self.product_fin
|
||||
with mrp_bom_form.bom_line_ids.new() as line_form:
|
||||
line_form.product_id = self.product_plastic.product_variant_ids[0]
|
||||
line_form.product_qty = 1
|
||||
self.fin_bom_id = mrp_bom_form.save()
|
||||
|
||||
mrp_bom_form = Form(self.env["mrp.bom"])
|
||||
mrp_bom_form.product_tmpl_id = self.product_surf
|
||||
with mrp_bom_form.bom_line_ids.new() as line_form:
|
||||
line_form.product_id = self.product_fin.product_variant_ids[0]
|
||||
line_form.product_qty = 1
|
||||
self.surf_bom_id = mrp_bom_form.save()
|
||||
|
||||
mrp_bom_form = Form(self.env["mrp.bom"])
|
||||
mrp_bom_form.product_tmpl_id = self.p1
|
||||
with mrp_bom_form.bom_line_ids.new() as line_form:
|
||||
line_form.product_id = self.p2.product_variant_ids[0]
|
||||
line_form.product_qty = 1
|
||||
self.p1_bom_id = mrp_bom_form.save()
|
||||
|
||||
mrp_bom_form = Form(self.env["mrp.bom"])
|
||||
mrp_bom_form.product_tmpl_id = self.p2
|
||||
with mrp_bom_form.bom_line_ids.new() as line_form:
|
||||
line_form.product_id = self.p3.product_variant_ids[0]
|
||||
line_form.product_qty = 1
|
||||
self.p2_bom_id = mrp_bom_form.save()
|
||||
|
||||
mrp_bom_form = Form(self.env["mrp.bom"])
|
||||
mrp_bom_form.product_tmpl_id = self.p3
|
||||
with mrp_bom_form.bom_line_ids.new() as line_form:
|
||||
line_form.product_id = self.p1.product_variant_ids[0]
|
||||
line_form.product_qty = 1
|
||||
self.p3_bom_id = mrp_bom_form.save()
|
||||
174
mrp_bom_attribute_match/tests/test_mrp_bom_attribute_match.py
Normal file
174
mrp_bom_attribute_match/tests/test_mrp_bom_attribute_match.py
Normal file
@@ -0,0 +1,174 @@
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.tests import Form
|
||||
|
||||
from .common import TestMrpAttachmentMgmtBase
|
||||
|
||||
|
||||
class TestMrpAttachmentMgmt(TestMrpAttachmentMgmtBase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
def test_bom_1(self):
|
||||
mrp_bom_form = Form(self.env["mrp.bom"])
|
||||
mrp_bom_form.product_tmpl_id = self.product_sword
|
||||
with mrp_bom_form.bom_line_ids.new() as line_form:
|
||||
line_form.product_id = self.product_plastic.product_variant_ids[0]
|
||||
line_form.component_template_id = self.product_plastic
|
||||
self.assertEqual(line_form.product_id.id, False)
|
||||
line_form.component_template_id = self.env["product.template"]
|
||||
self.assertEqual(
|
||||
line_form.product_id, self.product_plastic.product_variant_ids[0]
|
||||
)
|
||||
line_form.component_template_id = self.product_plastic
|
||||
line_form.product_qty = 1
|
||||
sword_cyan = self.sword_attrs.product_template_value_ids[0]
|
||||
with self.assertRaisesRegex(
|
||||
ValidationError,
|
||||
r"You cannot use an attribute value for attribute\(s\) .* in the "
|
||||
r"field “Apply on Variants” as it's the same attribute used in the "
|
||||
r"field “Match on Attribute” related to the component .*",
|
||||
):
|
||||
line_form.bom_product_template_attribute_value_ids.add(sword_cyan)
|
||||
|
||||
def test_bom_2(self):
|
||||
smell_attribute = self.env["product.attribute"].create(
|
||||
{"name": "Smell", "display_type": "radio", "create_variant": "always"}
|
||||
)
|
||||
orchid_attribute_value_id = self.env["product.attribute.value"].create(
|
||||
[
|
||||
{"name": "Orchid", "attribute_id": smell_attribute.id},
|
||||
]
|
||||
)
|
||||
plastic_smells_like_orchid = self.env["product.template.attribute.line"].create(
|
||||
{
|
||||
"attribute_id": smell_attribute.id,
|
||||
"product_tmpl_id": self.product_plastic.id,
|
||||
"value_ids": [(4, orchid_attribute_value_id.id)],
|
||||
}
|
||||
)
|
||||
with self.assertRaisesRegex(
|
||||
UserError,
|
||||
r"This product template is used as a component in the BOMs for .* and "
|
||||
r"attribute\(s\) .* is not present in all such product\(s\), and this "
|
||||
r"would break the BOM behavior\.",
|
||||
):
|
||||
vals = {
|
||||
"attribute_id": smell_attribute.id,
|
||||
"product_tmpl_id": self.product_plastic.id,
|
||||
"value_ids": [(4, orchid_attribute_value_id.id)],
|
||||
}
|
||||
self.product_plastic.write({"attribute_line_ids": [(0, 0, vals)]})
|
||||
mrp_bom_form = Form(self.env["mrp.bom"])
|
||||
mrp_bom_form.product_tmpl_id = self.product_sword
|
||||
with mrp_bom_form.bom_line_ids.new() as line_form:
|
||||
with self.assertRaisesRegex(
|
||||
UserError,
|
||||
r"Some attributes of the dynamic component are not included into "
|
||||
r"production product attributes\.",
|
||||
):
|
||||
line_form.component_template_id = self.product_plastic
|
||||
plastic_smells_like_orchid.unlink()
|
||||
|
||||
def test_manufacturing_order_1(self):
|
||||
mo_form = Form(self.env["mrp.production"])
|
||||
mo_form.product_id = self.product_sword.product_variant_ids.filtered(
|
||||
lambda x: x.display_name == "Plastic Sword (Cyan)"
|
||||
)
|
||||
mo_form.bom_id = self.bom_id
|
||||
mo_form.product_qty = 1
|
||||
self.mo_sword = mo_form.save()
|
||||
self.mo_sword.action_confirm()
|
||||
# Assert correct component variant was selected automatically
|
||||
self.assertEqual(
|
||||
self.mo_sword.move_raw_ids.product_id.display_name,
|
||||
"Plastic Component (Cyan)",
|
||||
)
|
||||
|
||||
def test_manufacturing_order_2(self):
|
||||
# Delete Cyan value from plastic
|
||||
self.plastic_attrs.value_ids = [(3, self.plastic_attrs.value_ids[0].id, 0)]
|
||||
mo_form = Form(self.env["mrp.production"])
|
||||
mo_form.product_id = self.product_sword.product_variant_ids.filtered(
|
||||
lambda x: x.display_name == "Plastic Sword (Cyan)"
|
||||
)
|
||||
mo_form.bom_id = self.bom_id
|
||||
mo_form.product_qty = 1
|
||||
self.mo_sword = mo_form.save()
|
||||
self.mo_sword.action_confirm()
|
||||
|
||||
def test_manufacturing_order_3(self):
|
||||
# Delete attribute from sword
|
||||
self.product_sword.attribute_line_ids = [(5, 0, 0)]
|
||||
mo_form = Form(self.env["mrp.production"])
|
||||
mo_form.product_id = self.product_sword.product_variant_ids[0]
|
||||
# Component skipped
|
||||
mo_form.bom_id = self.bom_id
|
||||
mo_form.product_qty = 1
|
||||
with self.assertRaisesRegex(
|
||||
ValidationError,
|
||||
r"Some attributes of the dynamic component are not included into .+",
|
||||
):
|
||||
self.mo_sword = mo_form.save()
|
||||
|
||||
def test_manufacturing_order_4(self):
|
||||
mo_form = Form(self.env["mrp.production"])
|
||||
mo_form.product_id = self.product_surf.product_variant_ids[0]
|
||||
mo_form.bom_id = self.surf_bom_id
|
||||
mo_form.product_qty = 1
|
||||
self.mo_sword = mo_form.save()
|
||||
self.mo_sword.action_confirm()
|
||||
|
||||
# def test_manufacturing_order_5(self):
|
||||
# mo_form = Form(self.env["mrp.production"])
|
||||
# mo_form.product_id = self.product_surf.product_variant_ids[0]
|
||||
# mo_form.bom_id = self.surf_wrong_bom_id
|
||||
# mo_form.product_qty = 1
|
||||
# self.mo_sword = mo_form.save()
|
||||
# self.mo_sword.action_confirm()
|
||||
|
||||
# def test_manufacturing_order_6(self):
|
||||
# mo_form = Form(self.env["mrp.production"])
|
||||
# mo_form.product_id = self.p1.product_variant_ids[0]
|
||||
# mo_form.bom_id = self.p1_bom_id
|
||||
# mo_form.product_qty = 1
|
||||
# self.mo_sword = mo_form.save()
|
||||
# self.mo_sword.action_confirm()
|
||||
|
||||
def test_bom_recursion(self):
|
||||
test_bom_3 = self.env["mrp.bom"].create(
|
||||
{
|
||||
"product_id": self.product_9.id,
|
||||
"product_tmpl_id": self.product_9.product_tmpl_id.id,
|
||||
"product_uom_id": self.product_9.uom_id.id,
|
||||
"product_qty": 1.0,
|
||||
"consumption": "flexible",
|
||||
"type": "normal",
|
||||
}
|
||||
)
|
||||
test_bom_4 = self.env["mrp.bom"].create(
|
||||
{
|
||||
"product_id": self.product_10.id,
|
||||
"product_tmpl_id": self.product_10.product_tmpl_id.id,
|
||||
"product_uom_id": self.product_10.uom_id.id,
|
||||
"product_qty": 1.0,
|
||||
"consumption": "flexible",
|
||||
"type": "phantom",
|
||||
}
|
||||
)
|
||||
self.env["mrp.bom.line"].create(
|
||||
{
|
||||
"bom_id": test_bom_3.id,
|
||||
"product_id": self.product_10.id,
|
||||
"product_qty": 1.0,
|
||||
}
|
||||
)
|
||||
self.env["mrp.bom.line"].create(
|
||||
{
|
||||
"bom_id": test_bom_4.id,
|
||||
"product_id": self.product_9.id,
|
||||
"product_qty": 1.0,
|
||||
}
|
||||
)
|
||||
with self.assertRaisesRegex(UserError, r"Recursion error! .+"):
|
||||
test_bom_3.explode(self.product_9, 1)
|
||||
28
mrp_bom_attribute_match/views/mrp_bom_views.xml
Normal file
28
mrp_bom_attribute_match/views/mrp_bom_views.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="mrp_bom_form_view" model="ir.ui.view">
|
||||
<field name="model">mrp.bom</field>
|
||||
<field name="inherit_id" ref="mrp.mrp_bom_form_view" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="bom_product_template_attribute_value_ids" position="before">
|
||||
<field name="match_on_attribute_ids" widget="many2many_tags" />
|
||||
<field name="product_backup_id" invisible="1" />
|
||||
</field>
|
||||
<xpath
|
||||
expr="//field[@name='bom_line_ids']//field[@name='product_id']"
|
||||
position="after"
|
||||
>
|
||||
<field name="component_template_id" />
|
||||
</xpath>
|
||||
<xpath
|
||||
expr="//field[@name='bom_line_ids']//field[@name='product_id']"
|
||||
position="attributes"
|
||||
>
|
||||
<attribute name="attrs">
|
||||
{'readonly': [('component_template_id', '!=', False)]}
|
||||
</attribute>
|
||||
<attribute name="force_save">"1"</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -0,0 +1 @@
|
||||
../../../../mrp_bom_attribute_match
|
||||
6
setup/mrp_bom_attribute_match/setup.py
Normal file
6
setup/mrp_bom_attribute_match/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
Reference in New Issue
Block a user