diff --git a/mrp_bom_attribute_match/README.rst b/mrp_bom_attribute_match/README.rst new file mode 100644 index 0000000000..35e16b86e3 --- /dev/null +++ b/mrp_bom_attribute_match/README.rst @@ -0,0 +1,144 @@ +=================== +BOM Attribute Match +=================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f598ece9b32319e94b8b593ab4fedb6065d0965d3725a767a2ba630893da7d4d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.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-16-0/manufacture-16-0-mrp_bom_attribute_match + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=16.0 + :alt: Try me on Runboat + +|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 `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Ilyas +* Ooops + +Contributors +~~~~~~~~~~~~ + +* Ooops404 + + * Ilyas + +* `Camptocamp `_ + + * Iván Todorovich + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_bom_attribute_match/__init__.py b/mrp_bom_attribute_match/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/mrp_bom_attribute_match/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_bom_attribute_match/__manifest__.py b/mrp_bom_attribute_match/__manifest__.py new file mode 100644 index 0000000000..b2c75b66e9 --- /dev/null +++ b/mrp_bom_attribute_match/__manifest__.py @@ -0,0 +1,13 @@ +{ + "name": "BOM Attribute Match", + "version": "16.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", + ], +} diff --git a/mrp_bom_attribute_match/i18n/hr.po b/mrp_bom_attribute_match/i18n/hr.po new file mode 100644 index 0000000000..6c49fa541f --- /dev/null +++ b/mrp_bom_attribute_match/i18n/hr.po @@ -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 \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 "" diff --git a/mrp_bom_attribute_match/i18n/it.po b/mrp_bom_attribute_match/i18n/it.po new file mode 100644 index 0000000000..a8cea03c10 --- /dev/null +++ b/mrp_bom_attribute_match/i18n/it.po @@ -0,0 +1,193 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_bom_attribute_match +# +# Francesco @ Ooops , 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: 2023-01-01 13:45+0000\n" +"Last-Translator: mymage \n" +"Language-Team: Italian \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.14.1\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 "" +"Nessuna corrispondenza trovata nell'attributo per il componente (modello " +"prodotto) %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 "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 "Dominio ID UdM prodotto" + +#. 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 "" +"L'attributo che si sta cercando di eliminare è utilizzato nelle DiBa come " +"corrispondenza con un componente (modello prodotto). Per rimuovere questo " +"attributo, prima rimuovere la riga di DiBa con il componente corrispondente." +"\n" +"Attributo: %s\n" +"DiBa: %s" + +#. 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" diff --git a/mrp_bom_attribute_match/i18n/mrp_bom_attribute_match.pot b/mrp_bom_attribute_match/i18n/mrp_bom_attribute_match.pot new file mode 100644 index 0000000000..6bb00e48f3 --- /dev/null +++ b/mrp_bom_attribute_match/i18n/mrp_bom_attribute_match.pot @@ -0,0 +1,114 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_bom_attribute_match +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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_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_category_id +msgid "Product Uom Category" +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 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\n" +"BoM: %(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 %(bom)s and " +"attribute(s) %(attributes)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) %(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." +msgstr "" diff --git a/mrp_bom_attribute_match/models/__init__.py b/mrp_bom_attribute_match/models/__init__.py new file mode 100644 index 0000000000..8485117d59 --- /dev/null +++ b/mrp_bom_attribute_match/models/__init__.py @@ -0,0 +1,3 @@ +from . import mrp_bom +from . import mrp_production +from . import product diff --git a/mrp_bom_attribute_match/models/mrp_bom.py b/mrp_bom_attribute_match/models/mrp_bom.py new file mode 100644 index 0000000000..ccb7f41604 --- /dev/null +++ b/mrp_bom_attribute_match/models/mrp_bom.py @@ -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() diff --git a/mrp_bom_attribute_match/models/mrp_production.py b/mrp_bom_attribute_match/models/mrp_production.py new file mode 100644 index 0000000000..076604e1b7 --- /dev/null +++ b/mrp_bom_attribute_match/models/mrp_production.py @@ -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() diff --git a/mrp_bom_attribute_match/models/product.py b/mrp_bom_attribute_match/models/product.py new file mode 100644 index 0000000000..7c9088c09f --- /dev/null +++ b/mrp_bom_attribute_match/models/product.py @@ -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 diff --git a/mrp_bom_attribute_match/readme/CONTRIBUTORS.rst b/mrp_bom_attribute_match/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..1a74944ba7 --- /dev/null +++ b/mrp_bom_attribute_match/readme/CONTRIBUTORS.rst @@ -0,0 +1,7 @@ +* Ooops404 + + * Ilyas + +* `Camptocamp `_ + + * Iván Todorovich diff --git a/mrp_bom_attribute_match/readme/DESCRIPTION.rst b/mrp_bom_attribute_match/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..e079f5673e --- /dev/null +++ b/mrp_bom_attribute_match/readme/DESCRIPTION.rst @@ -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. diff --git a/mrp_bom_attribute_match/readme/USAGE.rst b/mrp_bom_attribute_match/readme/USAGE.rst new file mode 100644 index 0000000000..b0bb99b71e --- /dev/null +++ b/mrp_bom_attribute_match/readme/USAGE.rst @@ -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. diff --git a/mrp_bom_attribute_match/static/description/icon.png b/mrp_bom_attribute_match/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/mrp_bom_attribute_match/static/description/icon.png differ diff --git a/mrp_bom_attribute_match/static/description/index.html b/mrp_bom_attribute_match/static/description/index.html new file mode 100644 index 0000000000..acbe97a2d6 --- /dev/null +++ b/mrp_bom_attribute_match/static/description/index.html @@ -0,0 +1,482 @@ + + + + + + +BOM Attribute Match + + + +
+

BOM Attribute Match

+ + +

Beta License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runboat

+

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

+ +
+

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

+
+
    +
  1. Create a product to produce e.g. Desk.
  2. +
  3. Set 1 attribute (e.g. Color). And select possible values for it.
  4. +
  5. Create a component product (material) e.g. Plastic.
  6. +
  7. Set 1 attribute (Color). And select possible values for it.
  8. +
  9. Create a BOM.
  10. +
  11. Select a manufacturing product Desk.
  12. +
  13. Add a BOM line. Select Component (product template) Plastic.
  14. +
  15. You will see Color attribute appeared in the Apply On Attribute field.
  16. +
  17. Save the BOM.
  18. +
  19. Create Manufacturing Order. Select Desk with e.g. Red color to produce and BOM you created.
  20. +
  21. You will see in the component list Plastic added with corresponding (red) color.
  22. +
+
+

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. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Ilyas
  • +
  • Ooops
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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 project on GitHub.

+

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

+
+
+
+ + diff --git a/mrp_bom_attribute_match/tests/__init__.py b/mrp_bom_attribute_match/tests/__init__.py new file mode 100644 index 0000000000..9b6b0f0740 --- /dev/null +++ b/mrp_bom_attribute_match/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_bom_attribute_match diff --git a/mrp_bom_attribute_match/tests/common.py b/mrp_bom_attribute_match/tests/common.py new file mode 100644 index 0000000000..98e4960716 --- /dev/null +++ b/mrp_bom_attribute_match/tests/common.py @@ -0,0 +1,155 @@ +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.p4 = self.env["product.template"].create( + { + "name": "P4", + "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"]) + + category = self.env["uom.category"].search([])[0] + + self.env["uom.uom"].create( + { + "name": "Bigger UoM of my category", + "factor_inv": 42, + "uom_type": "bigger", + "rounding": 0.5, + "category_id": category.id, + } + ) + mrp_bom_form.bom_line_ids.product_uom_id = self.env["uom.uom"].search([])[0].id + 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 + mrp_bom_form._values["product_uom_id"] = self.env["uom.uom"].search([])[0] + 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.p4.product_variant_ids[0] + line_form.product_qty = 1 + self.p3_bom_id = mrp_bom_form.save() diff --git a/mrp_bom_attribute_match/tests/test_mrp_bom_attribute_match.py b/mrp_bom_attribute_match/tests/test_mrp_bom_attribute_match.py new file mode 100644 index 0000000000..addd7420dc --- /dev/null +++ b/mrp_bom_attribute_match/tests/test_mrp_bom_attribute_match.py @@ -0,0 +1,179 @@ +from odoo.exceptions import UserError, ValidationError +from odoo.tests import Form + +from .common import TestMrpAttachmentMgmtBase + + +class TestMrpAttachmentMgmt(TestMrpAttachmentMgmtBase): + @classmethod + def setUpClass(cls): + cls.product_id = 1 + 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.name == "Plastic Sword" + )[0] + 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" + ) + 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] + # added to have product_uom_id.roundig > 0 + product_uom_id = self.env["uom.uom"].search([])[0].id + for bom_line in self.bom_id.bom_line_ids: + bom_line.product_uom_id = product_uom_id + # 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) diff --git a/mrp_bom_attribute_match/views/mrp_bom_views.xml b/mrp_bom_attribute_match/views/mrp_bom_views.xml new file mode 100644 index 0000000000..d647e178d5 --- /dev/null +++ b/mrp_bom_attribute_match/views/mrp_bom_views.xml @@ -0,0 +1,34 @@ + + + + mrp.bom + + + + + + + + + + + + {'readonly': [('component_template_id', '!=', False)]} + + "1" + + + + + + + diff --git a/setup/mrp_bom_attribute_match/odoo/addons/mrp_bom_attribute_match b/setup/mrp_bom_attribute_match/odoo/addons/mrp_bom_attribute_match new file mode 120000 index 0000000000..c9961e5316 --- /dev/null +++ b/setup/mrp_bom_attribute_match/odoo/addons/mrp_bom_attribute_match @@ -0,0 +1 @@ +../../../../mrp_bom_attribute_match \ No newline at end of file diff --git a/setup/mrp_bom_attribute_match/setup.py b/setup/mrp_bom_attribute_match/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/mrp_bom_attribute_match/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)