diff --git a/product_uom_use_type/README.rst b/product_uom_use_type/README.rst new file mode 100644 index 000000000000..66260cb5e3ce --- /dev/null +++ b/product_uom_use_type/README.rst @@ -0,0 +1,75 @@ +====================== +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-quentinDupont%2Fgrap--odoo--incubator-lightgray.png?logo=github + :target: https://github.com/quentinDupont/grap-odoo-incubator/tree/12.0-MIG_product_uom_use_type-after-rebase/product_uom_use_type + :alt: quentinDupont/grap-odoo-incubator + +|badge1| |badge2| |badge3| + +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/quentinDupont/grap-odoo-incubator/12.0-MIG_product_uom_use_type-after-rebase/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/quentinDupont/grap-odoo-incubator/12.0-MIG_product_uom_use_type-after-rebase/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 part of the `quentinDupont/grap-odoo-incubator `_ project on GitHub. + +You are welcome to contribute. diff --git a/product_uom_use_type/__init__.py b/product_uom_use_type/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /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 000000000000..2ee29d6c3f5d --- /dev/null +++ b/product_uom_use_type/__manifest__.py @@ -0,0 +1,15 @@ +# 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": "12.0.1.0.0", + "category": "Product", + "website": "https://github.com/OCA/product-attribute", + "author": "GRAP, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["product"], + "data": ["views/view_product_uom.xml"], + "demo": ["demo/product_uom.xml", "demo/product_template.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 000000000000..00372fe1375d --- /dev/null +++ b/product_uom_use_type/demo/product_template.xml @@ -0,0 +1,16 @@ + + + + + + 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 000000000000..7d1ae1054d85 --- /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 000000000000..fcd56e2fb195 --- /dev/null +++ b/product_uom_use_type/demo/res_groups.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/product_uom_use_type/i18n/fr.po b/product_uom_use_type/i18n/fr.po new file mode 100644 index 000000000000..32a94b67c5e7 --- /dev/null +++ b/product_uom_use_type/i18n/fr.po @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_uom_use_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-10-16 12:06+0000\n" +"PO-Revision-Date: 2017-10-16 12:06+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:product.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.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 Template" +msgstr "Modèle d'article" + +#. module: product_uom_use_type +#: model:ir.model,name:product_uom_use_type.model_product_uom +msgid "Product Unit of Measure" +msgstr "Unité de mesure d'article" + +#. module: product_uom_use_type +#: selection:product.uom,use_type:0 +msgid "Unit available for purchases" +msgstr "Achat uniquement" + +#. module: product_uom_use_type +#: selection:product.uom,use_type:0 +msgid "Unit available for sales" +msgstr "Vente uniquement" + +#. module: product_uom_use_type +#: selection:product.uom,use_type:0 +msgid "Unit available for sales and purchases" +msgstr "Achat et vente" + +#. module: product_uom_use_type +#: field:product.uom,use_type:0 +msgid "Use type" +msgstr "Type d'usage" + diff --git a/product_uom_use_type/models/__init__.py b/product_uom_use_type/models/__init__.py new file mode 100644 index 000000000000..c820c3e41883 --- /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 000000000000..5067e8537375 --- /dev/null +++ b/product_uom_use_type/models/product_product.py @@ -0,0 +1,14 @@ +# 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", "uom_po_id") + def _onchange_uom(self): + if self.uom_id.use_type != "sale": + super(ProductProduct, self)._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 000000000000..3042af829321 --- /dev/null +++ b/product_uom_use_type/models/product_template.py @@ -0,0 +1,20 @@ +# 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 + + +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 self.uom_id.use_type != "sale": + super(ProductTemplate, self)._onchange_uom_id() 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 000000000000..f63b4da0dee3 --- /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 000000000000..0803b1aa1c07 --- /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 000000000000..7b482cb226a5 --- /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 000000000000..0c372b00d496 --- /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 000000000000..a058ae007aa8 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 000000000000..17facafabc57 --- /dev/null +++ b/product_uom_use_type/static/description/index.html @@ -0,0 +1,434 @@ + + + + + + +Product UoM - Use Type + + + +
+

Product UoM - Use Type

+ + +

Beta License: AGPL-3 quentinDupont/grap-odoo-incubator

+

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/quentinDupont/grap-odoo-incubator/12.0-MIG_product_uom_use_type-after-rebase/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/quentinDupont/grap-odoo-incubator/12.0-MIG_product_uom_use_type-after-rebase/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 part of the quentinDupont/grap-odoo-incubator project on GitHub.

+

You are welcome to 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 000000000000..c5780ff1465f 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 000000000000..415fc88e08af 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 000000000000..fc263c20e9d1 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 000000000000..d9b96c4fa5a5 --- /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 000000000000..a4bde299fb1c --- /dev/null +++ b/product_uom_use_type/tests/test_module.py @@ -0,0 +1,40 @@ +# 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.tests.common import TransactionCase + + +class TestModule(TransactionCase): + def setUp(self): + super(TestModule, self).setUp() + self.template_obj = self.env["product.template"] + self.both_unit = self.env.ref("uom.product_uom_litre") + self.sale_unit = self.env.ref("product_uom_use_type.product_uom_pint") + self.product_template = self.env.ref( + "product_uom_use_type.product_bier_faucheuse" + ) + + # Test Section + def test_01_onchange_template(self): + + self.product_template.uom_id = self.both_unit + self.product_template._onchange_uom_id() + self.assertEqual( + self.product_template.uom_po_id.use_type, + self.both_unit.use_type, + "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 + uom_po_id_before = self.product_template.uom_po_id + self.product_template.uom_id = self.sale_unit + self.product_template._onchange_uom_id() + self.assertEqual( + self.product_template.uom_po_id, + uom_po_id_before, + "Setting a 'sale' unit as main UoM should not change the purchase" + " UoM", + ) 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 000000000000..db150e4b8a77 --- /dev/null +++ b/product_uom_use_type/views/view_product_uom.xml @@ -0,0 +1,29 @@ + + + + + + uom.uom + + + + + + + + + + uom.uom + + + + + + + + +