diff --git a/product_uom_use_type/README.rst b/product_uom_use_type/README.rst new file mode 100644 index 00000000000..c19ce5778f1 --- /dev/null +++ b/product_uom_use_type/README.rst @@ -0,0 +1,91 @@ +====================== +Product UoM - Use Type +====================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fproduct--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/12.0/product_uom_use_type + :alt: OCA/product-attribute +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-attribute-12-0/product-attribute-12-0-product_uom_use_type + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/135/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends unities of measure (uom) by sorting them into three +categories : + +* uom for sales only +* uom for purchases only +* uom for both sales and purchases (**default**). + +.. figure:: https://raw.githubusercontent.com/OCA/product-attribute/12.0/product_uom_use_type/static/description/use_type_list.png + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Every unities of measure's use type will be set as **both** by default. + +If you want to change that (or when you create a new unity of measure), +set use type field with sales/purchase/both. + +.. figure:: https://raw.githubusercontent.com/OCA/product-attribute/12.0/product_uom_use_type/static/description/use_type_form.png + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* GRAP + +Contributors +~~~~~~~~~~~~ + +* Quentin Dupont +* Sylvain LE GAL + +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/product-attribute `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_uom_use_type/__init__.py b/product_uom_use_type/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/product_uom_use_type/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_uom_use_type/__manifest__.py b/product_uom_use_type/__manifest__.py new file mode 100644 index 00000000000..e347d1e4fb6 --- /dev/null +++ b/product_uom_use_type/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2019, Grap +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Product UoM - Use Type", + "summary": "Define UoM for Sale and / or for Purchase purpose", + "version": "16.0.1.0.0", + "category": "Product", + "website": "https://github.com/OCA/product-attribute", + "author": "GRAP, Odoo Community Association (OCA)", + "maintainers": ["legalsylvain"], + "license": "AGPL-3", + "depends": ["product", "uom"], + "data": ["views/view_product_uom.xml"], + "demo": [ + "demo/product_uom.xml", + "demo/product_template.xml", + "demo/res_groups.xml", + ], + "installable": True, +} diff --git a/product_uom_use_type/demo/product_template.xml b/product_uom_use_type/demo/product_template.xml new file mode 100644 index 00000000000..ab51be8abd8 --- /dev/null +++ b/product_uom_use_type/demo/product_template.xml @@ -0,0 +1,20 @@ + + + + + + Bier - La Faucheuse + + + + + + diff --git a/product_uom_use_type/demo/product_uom.xml b/product_uom_use_type/demo/product_uom.xml new file mode 100644 index 00000000000..2e3148bc989 --- /dev/null +++ b/product_uom_use_type/demo/product_uom.xml @@ -0,0 +1,27 @@ + + + + + + Barrel - 159L (Unit only for purchases) + + purchase + + 0.2 + bigger + + + + Pint US - 0,55L (Unit only for sales) + + sale + + + smaller + + + diff --git a/product_uom_use_type/demo/res_groups.xml b/product_uom_use_type/demo/res_groups.xml new file mode 100644 index 00000000000..258d41499b0 --- /dev/null +++ b/product_uom_use_type/demo/res_groups.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/product_uom_use_type/i18n/ca.po b/product_uom_use_type/i18n/ca.po new file mode 100644 index 00000000000..16f357e9b67 --- /dev/null +++ b/product_uom_use_type/i18n/ca.po @@ -0,0 +1,106 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_uom_use_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-02-08 13:44+0000\n" +"Last-Translator: claudiagn \n" +"Language-Team: none\n" +"Language: ca\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: product_uom_use_type +#: model:uom.uom,name:product_uom_use_type.product_uom_barrel +msgid "Barrel - 159L (Unit only for purchases)" +msgstr "Barril - 159L (Unitat només per a compres)" + +#. module: product_uom_use_type +#: model:product.template,name:product_uom_use_type.product_bier_faucheuse +msgid "Bier - La Faucheuse" +msgstr "Cervesa: The Grim Reaper" + +#. module: product_uom_use_type +#: model:ir.model.fields,help:product_uom_use_type.field_product_product__uom_id +#: model:ir.model.fields,help:product_uom_use_type.field_product_template__uom_id +msgid "Default unit of measure used for all stock operations." +msgstr "" +"Unitat de mesura predeterminada que s’utilitza per a totes les operacions " +"d’estoc." + +#. module: product_uom_use_type +#: model:ir.model.fields,help:product_uom_use_type.field_product_product__uom_po_id +#: model:ir.model.fields,help:product_uom_use_type.field_product_template__uom_po_id +msgid "Default unit of measure used for purchase orders. It must be in the same category as the default unit of measure." +msgstr "" +"Unitat de mesura predeterminada que s’utilitza per a les comandes de compra. " +"Ha de ser de la mateixa categoria que la unitat de mesura per defecte." + +#. module: product_uom_use_type +#: model:product.template,uom_name:product_uom_use_type.product_bier_faucheuse +#: model:product.template,volume_uom_name:product_uom_use_type.product_bier_faucheuse +msgid "Liter(s)" +msgstr "Litre(s)" + +#. module: product_uom_use_type +#: model:uom.uom,name:product_uom_use_type.product_uom_pint +msgid "Pint US - 0,55L (Unit only for sales)" +msgstr "Pint US - 0,55L (Unitat només per a vendes)" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_product_product +msgid "Product" +msgstr "Producte" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_product_template +msgid "Product Template" +msgstr "Plantilla de producte" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_uom_uom +msgid "Product Unit of Measure" +msgstr "Unitat de mesura del producte" + +#. module: product_uom_use_type +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_product__uom_po_id +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_template__uom_po_id +msgid "Purchase Unit of Measure" +msgstr "Unitat de mesura de compres" + +#. module: product_uom_use_type +#: selection:uom.uom,use_type:0 +msgid "Unit available for purchases" +msgstr "Unitat disponible per compres" + +#. module: product_uom_use_type +#: selection:uom.uom,use_type:0 +msgid "Unit available for sales" +msgstr "Unitat disponible per vendes" + +#. module: product_uom_use_type +#: selection:uom.uom,use_type:0 +msgid "Unit available for sales and purchases" +msgstr "Unitat disponible per vendes i compres" + +#. module: product_uom_use_type +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_product__uom_id +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_template__uom_id +msgid "Unit of Measure" +msgstr "Unitat de mesura" + +#. module: product_uom_use_type +#: model:ir.model.fields,field_description:product_uom_use_type.field_uom_uom__use_type +msgid "Use Type" +msgstr "Tipus d'ús" + +#. module: product_uom_use_type +#: model:product.template,weight_uom_name:product_uom_use_type.product_bier_faucheuse +msgid "kg" +msgstr "kg" diff --git a/product_uom_use_type/i18n/es.po b/product_uom_use_type/i18n/es.po new file mode 100644 index 00000000000..2442d41a69b --- /dev/null +++ b/product_uom_use_type/i18n/es.po @@ -0,0 +1,106 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_uom_use_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-09-15 12:00+0000\n" +"Last-Translator: claudiagn \n" +"Language-Team: none\n" +"Language: es\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 3.10\n" + +#. module: product_uom_use_type +#: model:uom.uom,name:product_uom_use_type.product_uom_barrel +msgid "Barrel - 159L (Unit only for purchases)" +msgstr "Barril - 159L (Unidad solo para compras)" + +#. module: product_uom_use_type +#: model:product.template,name:product_uom_use_type.product_bier_faucheuse +msgid "Bier - La Faucheuse" +msgstr "Bier - La Faucheuse" + +#. module: product_uom_use_type +#: model:ir.model.fields,help:product_uom_use_type.field_product_product__uom_id +#: model:ir.model.fields,help:product_uom_use_type.field_product_template__uom_id +msgid "Default unit of measure used for all stock operations." +msgstr "" +"Unidad de medida predeterminada utilizada para todas las operaciones de " +"stock." + +#. module: product_uom_use_type +#: model:ir.model.fields,help:product_uom_use_type.field_product_product__uom_po_id +#: model:ir.model.fields,help:product_uom_use_type.field_product_template__uom_po_id +msgid "Default unit of measure used for purchase orders. It must be in the same category as the default unit of measure." +msgstr "" +"Unidad de medida predeterminada utilizada para órdenes de compra. Debe estar " +"en la misma categoría que la unidad de medida predeterminada." + +#. module: product_uom_use_type +#: model:product.template,uom_name:product_uom_use_type.product_bier_faucheuse +#: model:product.template,volume_uom_name:product_uom_use_type.product_bier_faucheuse +msgid "Liter(s)" +msgstr "Litro(s)" + +#. module: product_uom_use_type +#: model:uom.uom,name:product_uom_use_type.product_uom_pint +msgid "Pint US - 0,55L (Unit only for sales)" +msgstr "Pinta US - 0,55L (Unidad solo para venta)" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_product_product +msgid "Product" +msgstr "Producto" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_product_template +msgid "Product Template" +msgstr "Plantilla de producto" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_uom_uom +msgid "Product Unit of Measure" +msgstr "Unidad de medida del producto" + +#. module: product_uom_use_type +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_product__uom_po_id +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_template__uom_po_id +msgid "Purchase Unit of Measure" +msgstr "Unidad de medida de compra" + +#. module: product_uom_use_type +#: selection:uom.uom,use_type:0 +msgid "Unit available for purchases" +msgstr "Unidad disponible para compras" + +#. module: product_uom_use_type +#: selection:uom.uom,use_type:0 +msgid "Unit available for sales" +msgstr "Unidad disponible para ventas" + +#. module: product_uom_use_type +#: selection:uom.uom,use_type:0 +msgid "Unit available for sales and purchases" +msgstr "Unidad disponible para ventas y compras" + +#. module: product_uom_use_type +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_product__uom_id +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_template__uom_id +msgid "Unit of Measure" +msgstr "Unidad de medida" + +#. module: product_uom_use_type +#: model:ir.model.fields,field_description:product_uom_use_type.field_uom_uom__use_type +msgid "Use Type" +msgstr "Tipo de uso" + +#. module: product_uom_use_type +#: model:product.template,weight_uom_name:product_uom_use_type.product_bier_faucheuse +msgid "kg" +msgstr "kg" diff --git a/product_uom_use_type/i18n/fr.po b/product_uom_use_type/i18n/fr.po new file mode 100644 index 00000000000..e8828da5497 --- /dev/null +++ b/product_uom_use_type/i18n/fr.po @@ -0,0 +1,97 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_uom_use_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-10-16 12:06+0000\n" +"PO-Revision-Date: 2023-06-22 21:42+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + + +#. module: product_uom_use_type +#: model:uom.uom,name:product_uom_use_type.product_uom_barrel +msgid "Barrel - 159L (Unit only for purchases)" +msgstr "Fût - 159L (Unité valable seulement à l'achat)" + +#. module: product_uom_use_type +#: model:product.template,name:product_uom_use_type.product_bier_faucheuse +msgid "Bier - La Faucheuse" +msgstr "" + +#. module: product_uom_use_type +#: model:ir.model.fields,help:product_uom_use_type.field_product_product__uom_id +#: model:ir.model.fields,help:product_uom_use_type.field_product_template__uom_id +msgid "Default unit of measure used for all stock operations." +msgstr "" +"Unité de mesure par défaut utilisée pour toutes les opérations de stock" + +#. module: product_uom_use_type +#: model:ir.model.fields,help:product_uom_use_type.field_product_product__uom_po_id +#: model:ir.model.fields,help:product_uom_use_type.field_product_template__uom_po_id +msgid "" +"Default unit of measure used for purchase orders. It must be in the same " +"category as the default unit of measure." +msgstr "" +"Unité de mesure par défaut utilisée pour les bons de commande. Elle doit " +"être dans la même catégorie que l'unité de mesure par défaut." + +#. module: product_uom_use_type +#: model:uom.uom,name:product_uom_use_type.product_uom_pint +msgid "Pint US - 0,55L (Unit only for sales)" +msgstr "Pinte US - 0,55L (Unité valable seulement à la vente)" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_product_template +msgid "Product" +msgstr "Produit" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_uom_uom +msgid "Product Unit of Measure" +msgstr "Unité de mesure du produit" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_product_product +msgid "Product Variant" +msgstr "Variante de produit" + +#. module: product_uom_use_type +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_product__uom_po_id +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_template__uom_po_id +msgid "Purchase UoM" +msgstr "UdM achat" + +#. module: product_uom_use_type +#: model:ir.model.fields.selection,name:product_uom_use_type.selection__uom_uom__use_type__purchase +msgid "Unit available for purchases" +msgstr "Achat uniquement" + +#. module: product_uom_use_type +#: model:ir.model.fields.selection,name:product_uom_use_type.selection__uom_uom__use_type__sale +msgid "Unit available for sales" +msgstr "Vente uniquement" + +#. module: product_uom_use_type +#: model:ir.model.fields.selection,name:product_uom_use_type.selection__uom_uom__use_type__both +msgid "Unit available for sales and purchases" +msgstr "Achat et vente" + +#. module: product_uom_use_type +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_product__uom_id +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_template__uom_id +msgid "Unit of Measure" +msgstr "Unité de mesure d'article" + +#. module: product_uom_use_type +#: model:ir.model.fields,field_description:product_uom_use_type.field_uom_uom__use_type +msgid "Use Type" +msgstr "Type d'usage" diff --git a/product_uom_use_type/i18n/product_uom_use_type.pot b/product_uom_use_type/i18n/product_uom_use_type.pot new file mode 100644 index 00000000000..1f1b397624e --- /dev/null +++ b/product_uom_use_type/i18n/product_uom_use_type.pot @@ -0,0 +1,92 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_uom_use_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-06-22 21:41+0000\n" +"PO-Revision-Date: 2023-06-22 21:41+0000\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: product_uom_use_type +#: model:uom.uom,name:product_uom_use_type.product_uom_barrel +msgid "Barrel - 159L (Unit only for purchases)" +msgstr "" + +#. module: product_uom_use_type +#: model:product.template,name:product_uom_use_type.product_bier_faucheuse +msgid "Bier - La Faucheuse" +msgstr "" + +#. module: product_uom_use_type +#: model:ir.model.fields,help:product_uom_use_type.field_product_product__uom_id +#: model:ir.model.fields,help:product_uom_use_type.field_product_template__uom_id +msgid "Default unit of measure used for all stock operations." +msgstr "" + +#. module: product_uom_use_type +#: model:ir.model.fields,help:product_uom_use_type.field_product_product__uom_po_id +#: model:ir.model.fields,help:product_uom_use_type.field_product_template__uom_po_id +msgid "" +"Default unit of measure used for purchase orders. It must be in the same " +"category as the default unit of measure." +msgstr "" + +#. module: product_uom_use_type +#: model:uom.uom,name:product_uom_use_type.product_uom_pint +msgid "Pint US - 0,55L (Unit only for sales)" +msgstr "" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_product_template +msgid "Product" +msgstr "" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_uom_uom +msgid "Product Unit of Measure" +msgstr "" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_product_product +msgid "Product Variant" +msgstr "" + +#. module: product_uom_use_type +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_product__uom_po_id +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_template__uom_po_id +msgid "Purchase UoM" +msgstr "" + +#. module: product_uom_use_type +#: model:ir.model.fields.selection,name:product_uom_use_type.selection__uom_uom__use_type__purchase +msgid "Unit available for purchases" +msgstr "" + +#. module: product_uom_use_type +#: model:ir.model.fields.selection,name:product_uom_use_type.selection__uom_uom__use_type__sale +msgid "Unit available for sales" +msgstr "" + +#. module: product_uom_use_type +#: model:ir.model.fields.selection,name:product_uom_use_type.selection__uom_uom__use_type__both +msgid "Unit available for sales and purchases" +msgstr "" + +#. module: product_uom_use_type +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_product__uom_id +#: model:ir.model.fields,field_description:product_uom_use_type.field_product_template__uom_id +msgid "Unit of Measure" +msgstr "" + +#. module: product_uom_use_type +#: model:ir.model.fields,field_description:product_uom_use_type.field_uom_uom__use_type +msgid "Use Type" +msgstr "" \ No newline at end of file diff --git a/product_uom_use_type/models/__init__.py b/product_uom_use_type/models/__init__.py new file mode 100644 index 00000000000..c820c3e4188 --- /dev/null +++ b/product_uom_use_type/models/__init__.py @@ -0,0 +1,3 @@ +from . import product_template +from . import product_product +from . import product_uom diff --git a/product_uom_use_type/models/product_product.py b/product_uom_use_type/models/product_product.py new file mode 100644 index 00000000000..fbf6c00a588 --- /dev/null +++ b/product_uom_use_type/models/product_product.py @@ -0,0 +1,29 @@ +# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + @api.onchange("uom_id") + def _onchange_uom_id(self): + # If it's an UoM dedicated to sale, We can't set is as uom_po_id + # So prevent to call super(), but check if categories are consistent + if self.uom_id.use_type == "sale": + if self.uom_id.category_id != self.uom_po_id.category_id: + self.uom_po_id = False + return + return super()._onchange_uom_id() + + @api.onchange("uom_po_id") + def _onchange_uom(self): + # If it's an PO UoM dedicated to purchase, We can't set is as uom_sid + # So prevent to call super(), but check if categories are consistent + if self.uom_po_id.use_type == "purchase": + if self.uom_id.category_id != self.uom_po_id.category_id: + self.uom_id = False + return + return super()._onchange_uom() diff --git a/product_uom_use_type/models/product_template.py b/product_uom_use_type/models/product_template.py new file mode 100644 index 00000000000..422ffdd4288 --- /dev/null +++ b/product_uom_use_type/models/product_template.py @@ -0,0 +1,46 @@ +# Copyright (C) 2017 - Today: GRAP (http://www.grap.coop) +# @author: Quentin DUPONT +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + uom_id = fields.Many2one(domain=[("use_type", "in", ("sale", "both"))]) + + uom_po_id = fields.Many2one(domain=[("use_type", "in", ("purchase", "both"))]) + + @api.onchange("uom_id") + def _onchange_uom_id(self): + # If it's an UoM dedicated to sale, We can't set is as uom_po_id + # So prevent to call super(), but check if categories are consistent + if self.uom_id.use_type == "sale": + if self.uom_id.category_id != self.uom_po_id.category_id: + self.uom_po_id = False + return + return super()._onchange_uom_id() + + @api.onchange("uom_po_id") + def _onchange_uom(self): + # If it's an PO UoM dedicated to purchase, We can't set is as uom_sid + # So prevent to call super(), but check if categories are consistent + if self.uom_po_id.use_type == "purchase": + if self.uom_id.category_id != self.uom_po_id.category_id: + self.uom_id = False + return + return super()._onchange_uom() + + @api.constrains("uom_id", "uom_po_id") + def _check_uom(self): + if self.filtered(lambda x: x.uom_id.use_type == "purchase"): + raise ValidationError( + _("you can not set a 'Purchase' UoM as the main product UoM.") + ) + if self.filtered(lambda x: x.uom_po_id.use_type == "sale"): + raise ValidationError( + _("you can not set a 'Sale' UoM as the product Purchase UoM.") + ) + return super()._check_uom() diff --git a/product_uom_use_type/models/product_uom.py b/product_uom_use_type/models/product_uom.py new file mode 100644 index 00000000000..f63b4da0dee --- /dev/null +++ b/product_uom_use_type/models/product_uom.py @@ -0,0 +1,18 @@ +# Copyright 2019, Grap +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProductUom(models.Model): + _inherit = "uom.uom" + + use_type = fields.Selection( + [ + ("sale", "Unit available for sales"), + ("purchase", "Unit available for purchases"), + ("both", "Unit available for sales and purchases"), + ], + required=True, + default="both", + ) diff --git a/product_uom_use_type/readme/CONFIGURE.rst b/product_uom_use_type/readme/CONFIGURE.rst new file mode 100644 index 00000000000..97a7ea1e23a --- /dev/null +++ b/product_uom_use_type/readme/CONFIGURE.rst @@ -0,0 +1,6 @@ +Every unities of measure's use type will be set as **both** by default. + +If you want to change that (or when you create a new unity of measure), +set use type field with sales/purchase/both. + +.. figure:: ../static/description/use_type_form.png diff --git a/product_uom_use_type/readme/CONTRIBUTORS.rst b/product_uom_use_type/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..7b482cb226a --- /dev/null +++ b/product_uom_use_type/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Quentin Dupont +* Sylvain LE GAL diff --git a/product_uom_use_type/readme/DESCRIPTION.rst b/product_uom_use_type/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..a098599bc32 --- /dev/null +++ b/product_uom_use_type/readme/DESCRIPTION.rst @@ -0,0 +1,8 @@ +This module extends unities of measure (uom) by sorting them into three +categories : + +* uom for sales only +* uom for purchases only +* uom for both sales and purchases (**default**). + +.. figure:: ../static/description/use_type_list.png diff --git a/product_uom_use_type/static/description/icon.png b/product_uom_use_type/static/description/icon.png new file mode 100644 index 00000000000..a058ae007aa Binary files /dev/null and b/product_uom_use_type/static/description/icon.png differ diff --git a/product_uom_use_type/static/description/index.html b/product_uom_use_type/static/description/index.html new file mode 100644 index 00000000000..e06f92e3950 --- /dev/null +++ b/product_uom_use_type/static/description/index.html @@ -0,0 +1,439 @@ + + + + + + +Product UoM - Use Type + + + +
+

Product UoM - Use Type

+ + +

Beta License: AGPL-3 OCA/product-attribute Translate me on Weblate Try me on Runbot

+

This module extends unities of measure (uom) by sorting them into three +categories :

+
    +
  • uom for sales only
  • +
  • uom for purchases only
  • +
  • uom for both sales and purchases (default).
  • +
+
+https://raw.githubusercontent.com/OCA/product-attribute/12.0/product_uom_use_type/static/description/use_type_list.png +
+

Table of contents

+ +
+

Configuration

+

Every unities of measure’s use type will be set as both by default.

+

If you want to change that (or when you create a new unity of measure), +set use type field with sales/purchase/both.

+
+https://raw.githubusercontent.com/OCA/product-attribute/12.0/product_uom_use_type/static/description/use_type_form.png +
+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • GRAP
  • +
+
+
+

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

+

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

+
+
+
+ + diff --git a/product_uom_use_type/static/description/use_type_form.png b/product_uom_use_type/static/description/use_type_form.png new file mode 100644 index 00000000000..c5780ff1465 Binary files /dev/null and b/product_uom_use_type/static/description/use_type_form.png differ diff --git a/product_uom_use_type/static/description/use_type_list.png b/product_uom_use_type/static/description/use_type_list.png new file mode 100644 index 00000000000..415fc88e08a Binary files /dev/null and b/product_uom_use_type/static/description/use_type_list.png differ diff --git a/product_uom_use_type/static/src/img/demo/bier_faucheuse.png b/product_uom_use_type/static/src/img/demo/bier_faucheuse.png new file mode 100644 index 00000000000..fc263c20e9d Binary files /dev/null and b/product_uom_use_type/static/src/img/demo/bier_faucheuse.png differ diff --git a/product_uom_use_type/tests/__init__.py b/product_uom_use_type/tests/__init__.py new file mode 100644 index 00000000000..d9b96c4fa5a --- /dev/null +++ b/product_uom_use_type/tests/__init__.py @@ -0,0 +1 @@ +from . import test_module diff --git a/product_uom_use_type/tests/test_module.py b/product_uom_use_type/tests/test_module.py new file mode 100644 index 00000000000..2a95106308b --- /dev/null +++ b/product_uom_use_type/tests/test_module.py @@ -0,0 +1,89 @@ +# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.exceptions import ValidationError +from odoo.tests.common import Form, TransactionCase + + +class TestModule(TransactionCase): + def setUp(self): + super().setUp() + self.ProductTemplate = self.env["product.template"] + self.env.ref("base.user_root").write( + { + "groups_id": [ + (4, self.env.ref("uom.group_uom").id), + ] + } + ) + self.volume_both_unit = self.env.ref("uom.product_uom_litre") + self.volume_sale_unit = self.env.ref("product_uom_use_type.product_uom_pint") + self.volume_purchase_unit = self.env.ref( + "product_uom_use_type.product_uom_barrel" + ) + self.weight_both_unit = self.env.ref("uom.product_uom_kgm") + + def _test_onchange(self, model_name): + product_form = Form(self.env[model_name]) + product_form.name = "Demo Product" + product_form.uom_id = self.volume_both_unit + self.assertEqual( + product_form.uom_po_id, + product_form.uom_id, + "Setting a 'both' unit as main UoM should set the same as Purchase UoM", + ) + + # Change unit to sale unit + # Should NOT change po_uom_id to the same + product_form.uom_id = self.volume_sale_unit + self.assertEqual( + product_form.uom_po_id, + self.volume_both_unit, + "Setting a 'sale' unit as main UoM should not change the purchase UoM", + ) + + # Change unit to sale unit + inconsistent categories + # Should set uom_po_id to False + product_form.uom_id = self.weight_both_unit + product_form.uom_po_id = self.weight_both_unit + product_form.uom_id = self.volume_sale_unit + self.assertEqual( + product_form.uom_po_id.id, + False, + "Setting a 'sale' unit as main UoM should set to False the Purchase UoM" + " if categories doesn't match", + ) + + def test_01_onchange_template(self): + self._test_onchange("product.template") + + def test_02_onchange_product(self): + self._test_onchange("product.product") + + def test_03_constrains(self): + self.ProductTemplate.create( + { + "name": "Demo Template OK", + "uom_id": self.volume_both_unit.id, + "uom_po_id": self.volume_both_unit.id, + } + ) + + with self.assertRaises(ValidationError): + self.ProductTemplate.create( + { + "name": "Demo Template uom_id KO", + "uom_id": self.volume_purchase_unit.id, + "uom_po_id": self.volume_both_unit.id, + } + ) + + with self.assertRaises(ValidationError): + self.ProductTemplate.create( + { + "name": "Demo Template uom_po_id KO", + "uom_id": self.volume_both_unit.id, + "uom_po_id": self.volume_sale_unit.id, + } + ) diff --git a/product_uom_use_type/views/view_product_uom.xml b/product_uom_use_type/views/view_product_uom.xml new file mode 100644 index 00000000000..fd20581e99f --- /dev/null +++ b/product_uom_use_type/views/view_product_uom.xml @@ -0,0 +1,29 @@ + + + + + + uom.uom + + + + + + + + + + uom.uom + + + + + + + + + diff --git a/setup/product_uom_use_type/odoo/addons/product_uom_use_type b/setup/product_uom_use_type/odoo/addons/product_uom_use_type new file mode 120000 index 00000000000..8955fe3d0bb --- /dev/null +++ b/setup/product_uom_use_type/odoo/addons/product_uom_use_type @@ -0,0 +1 @@ +../../../../product_uom_use_type \ No newline at end of file diff --git a/setup/product_uom_use_type/setup.py b/setup/product_uom_use_type/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/product_uom_use_type/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)