diff --git a/mrp_bom_line_net_qty/README.rst b/mrp_bom_line_net_qty/README.rst new file mode 100644 index 000000000..28a2d7183 --- /dev/null +++ b/mrp_bom_line_net_qty/README.rst @@ -0,0 +1,89 @@ +=================================== +MRP BoM Line Net and Gross Quantity +=================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:db30c1cf56c778d61a123afdde23cac7a1c569f218185c5a32334fa74d7e51a9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_line_net_qty + :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_line_net_qty + :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| + +Handle gross and net quantity on BoM lines thanks to loss percentage +Fill quantity (original one is 'gross quantity') : it set automatically 'net quantity' +Fill loss percentage, Odoo will show two buttons to calculate net or 'gross quantity' +You can also set 'net quantity' and calculate 'gross quantity' with loss percentage + +.. figure:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_net_qty/static/description/mrp_bom_line_net_qty.gif + +Here are the added fields + +.. figure:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_net_qty/static/description/change_net_qty_before.png + +.. figure:: https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_net_qty/static/description/change_net_qty_after.png + +/!\ Line with difference with theorical values are set in yellow + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* GRAP + +Contributors +~~~~~~~~~~~~ + +* Quentin Dupont (quentin.dupont@grap.coop) + +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_line_net_qty/__init__.py b/mrp_bom_line_net_qty/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mrp_bom_line_net_qty/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_bom_line_net_qty/__manifest__.py b/mrp_bom_line_net_qty/__manifest__.py new file mode 100644 index 000000000..36096af08 --- /dev/null +++ b/mrp_bom_line_net_qty/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright (C) 2023-Today: GRAP (http://www.grap.coop) +# @author: Quentin Dupont +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "MRP BoM Line Net and Gross Quantity", + "version": "16.0.1.0.0", + "category": "Manufacturing", + "author": "GRAP, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "license": "AGPL-3", + "depends": [ + "mrp", + ], + "data": [ + "views/view_mrp_bom.xml", + ], + "installable": True, +} diff --git a/mrp_bom_line_net_qty/i18n/fr.po b/mrp_bom_line_net_qty/i18n/fr.po new file mode 100644 index 000000000..19bdce88f --- /dev/null +++ b/mrp_bom_line_net_qty/i18n/fr.po @@ -0,0 +1,80 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_bom_line_net_qty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-02-26 16:45+0000\n" +"PO-Revision-Date: 2024-02-26 16:45+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: mrp_bom_line_net_qty +#: model_terms:ir.ui.view,arch_db:mrp_bom_line_net_qty.view_mrp_bom_form +msgid ">" +msgstr "" + +#. module: mrp_bom_line_net_qty +#: model:ir.model,name:mrp_bom_line_net_qty.model_mrp_bom_line +msgid "Bill of Material Line" +msgstr "Ligne de nomenclature" + +#. module: mrp_bom_line_net_qty +#: model:ir.model.fields,field_description:mrp_bom_line_net_qty.field_mrp_bom_line__diff_product_qty_gross_net +msgid "Diff Product Qty Gross Net" +msgstr "" + +#. module: mrp_bom_line_net_qty +#: model:ir.model.fields,field_description:mrp_bom_line_net_qty.field_mrp_bom_line__loss_percentage +msgid "Loss %" +msgstr "Perte %" + +#. module: mrp_bom_line_net_qty +#: model:ir.model.fields,field_description:mrp_bom_line_net_qty.field_mrp_bom_line__product_qty_net +msgid "Net quantity" +msgstr "Qté nette" + +#. module: mrp_bom_line_net_qty +#: model:ir.model.fields,help:mrp_bom_line_net_qty.field_mrp_bom_line__loss_percentage +msgid "Percentage loss, for example, when grating carrots" +msgstr "Pourcentage de perte, après avoir râper des carottes par exemple." + +#. module: mrp_bom_line_net_qty +#. odoo-python +#: code:addons/mrp_bom_line_net_qty/models/mrp_bom_line.py:0 +#, python-format +msgid "" +"Setting gross quantity with 100% loss makes no sense.\n" +"Change this value." +msgstr "" +"Définir une quantité brute avec 100% de perte n'a pas de sens.\n" +"Changer cette valeur de pourcentage." + +#. module: mrp_bom_line_net_qty +#: model_terms:ir.ui.view,arch_db:mrp_bom_line_net_qty.view_mrp_bom_form +msgid "" +"This will set product gross quantity with net quantity and loss percentage" +msgstr "" +"Cela définira la quantité brut de produits grâce à la quantité net et le " +"pourcentage de perte." + +#. module: mrp_bom_line_net_qty +#: model_terms:ir.ui.view,arch_db:mrp_bom_line_net_qty.view_mrp_bom_form +msgid "" +"This will set product net quantity with gross quantity and loss percentage" +msgstr "" +"Cela définira la quantité net de produits grâce à la quantité brute et le " +"pourcentage de perte." + +#. module: mrp_bom_line_net_qty +#: model:ir.model.fields,help:mrp_bom_line_net_qty.field_mrp_bom_line__product_qty_net +msgid "" +"Weight after any preparation, e.g. weight of carrots after they are grated." +msgstr "" +"Poids net après une préparation, après avoir râper des carottes par exemple." diff --git a/mrp_bom_line_net_qty/models/__init__.py b/mrp_bom_line_net_qty/models/__init__.py new file mode 100644 index 000000000..35aa482ff --- /dev/null +++ b/mrp_bom_line_net_qty/models/__init__.py @@ -0,0 +1 @@ +from . import mrp_bom_line diff --git a/mrp_bom_line_net_qty/models/mrp_bom_line.py b/mrp_bom_line_net_qty/models/mrp_bom_line.py new file mode 100644 index 000000000..2a9f08b0d --- /dev/null +++ b/mrp_bom_line_net_qty/models/mrp_bom_line.py @@ -0,0 +1,67 @@ +# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop) +# @author: Quentin DUPONT (quentin.dupont@grap.coop) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class MrpBomLine(models.Model): + _inherit = "mrp.bom.line" + + product_qty_net = fields.Float( + string="Net quantity", + help="Weight after any preparation, e.g. weight of carrots after they are grated.", + digits="Product Unit of Measure", + ) + loss_percentage = fields.Float( + string="Loss %", + help="Percentage loss, for example, when grating carrots", + digits=(16, 2), + ) + diff_product_qty_gross_net = fields.Float( + digits="Product Price", + compute="_compute_diff_product_qty_gross_net", + ) + + # Functions to change product fields + def calculate_qty_net_theoretical(self, product_qty_gross, loss_percentage): + return (1 - loss_percentage / 100) * product_qty_gross + + @api.depends("product_qty", "product_qty_net", "loss_percentage") + def _compute_diff_product_qty_gross_net(self): + for bom_line in self: + _bomline_qty_net_theorical = self.calculate_qty_net_theoretical( + bom_line.product_qty, bom_line.loss_percentage + ) + _diff_product_qty_gross_net = round( + (bom_line.product_qty_net - _bomline_qty_net_theorical), 2 + ) + bom_line.diff_product_qty_gross_net = _diff_product_qty_gross_net + + # Two buttons to handle two cases : you base your price on net qty or gross qty + def set_product_qty_net(self): + for bom_line in self.filtered(lambda x: x.product_qty): + bom_line.product_qty_net = self.calculate_qty_net_theoretical( + bom_line.product_qty, bom_line.loss_percentage + ) + + def set_product_qty_gross(self): + for bom_line in self.filtered(lambda x: x.product_qty_net): + if bom_line.loss_percentage == 100: + raise UserError( + _( + "Setting gross quantity with 100% loss makes no sense.\n" + "Change this value." + ) + ) + else: + bom_line.product_qty = bom_line.product_qty_net / ( + 1 - bom_line.loss_percentage / 100 + ) + + # If you change mandatory field product_qty (gross qty), the net quantity adapts + @api.onchange("product_qty") + def _onchange_product_qty(self): + for bom_line in self: + bom_line.product_qty_net = bom_line.product_qty diff --git a/mrp_bom_line_net_qty/readme/CONTRIBUTORS.rst b/mrp_bom_line_net_qty/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..9ed470628 --- /dev/null +++ b/mrp_bom_line_net_qty/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Quentin Dupont (quentin.dupont@grap.coop) diff --git a/mrp_bom_line_net_qty/readme/DESCRIPTION.rst b/mrp_bom_line_net_qty/readme/DESCRIPTION.rst new file mode 100644 index 000000000..2e4220ab9 --- /dev/null +++ b/mrp_bom_line_net_qty/readme/DESCRIPTION.rst @@ -0,0 +1,14 @@ +Handle gross and net quantity on BoM lines thanks to loss percentage +Fill quantity (original one is 'gross quantity') : it set automatically 'net quantity' +Fill loss percentage, Odoo will show two buttons to calculate net or 'gross quantity' +You can also set 'net quantity' and calculate 'gross quantity' with loss percentage + +.. figure:: ../static/description/mrp_bom_line_net_qty.gif + +Here are the added fields + +.. figure:: ../static/description/change_net_qty_before.png + +.. figure:: ../static/description/change_net_qty_after.png + +/!\ Line with difference with theorical values are set in yellow diff --git a/mrp_bom_line_net_qty/static/description/change_net_qty_after.png b/mrp_bom_line_net_qty/static/description/change_net_qty_after.png new file mode 100644 index 000000000..385f669fc Binary files /dev/null and b/mrp_bom_line_net_qty/static/description/change_net_qty_after.png differ diff --git a/mrp_bom_line_net_qty/static/description/change_net_qty_before.png b/mrp_bom_line_net_qty/static/description/change_net_qty_before.png new file mode 100644 index 000000000..caf00e9b5 Binary files /dev/null and b/mrp_bom_line_net_qty/static/description/change_net_qty_before.png differ diff --git a/mrp_bom_line_net_qty/static/description/index.html b/mrp_bom_line_net_qty/static/description/index.html new file mode 100644 index 000000000..b11724cdc --- /dev/null +++ b/mrp_bom_line_net_qty/static/description/index.html @@ -0,0 +1,435 @@ + + + + + + +MRP BoM Line Net and Gross Quantity + + + +
+

MRP BoM Line Net and Gross Quantity

+ + +

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

+

Handle gross and net quantity on BoM lines thanks to loss percentage +Fill quantity (original one is ‘gross quantity’) : it set automatically ‘net quantity’ +Fill loss percentage, Odoo will show two buttons to calculate net or ‘gross quantity’ +You can also set ‘net quantity’ and calculate ‘gross quantity’ with loss percentage

+
+https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_net_qty/static/description/mrp_bom_line_net_qty.gif +
+

Here are the added fields

+
+https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_net_qty/static/description/change_net_qty_before.png +
+
+https://raw.githubusercontent.com/OCA/manufacture/16.0/mrp_bom_line_net_qty/static/description/change_net_qty_after.png +
+

/!Line with difference with theorical values are set in yellow

+

Table of contents

+ +
+

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

+
    +
  • 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/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_line_net_qty/static/description/mrp_bom_line_net_qty.gif b/mrp_bom_line_net_qty/static/description/mrp_bom_line_net_qty.gif new file mode 100644 index 000000000..896ea88c9 Binary files /dev/null and b/mrp_bom_line_net_qty/static/description/mrp_bom_line_net_qty.gif differ diff --git a/mrp_bom_line_net_qty/tests/__init__.py b/mrp_bom_line_net_qty/tests/__init__.py new file mode 100644 index 000000000..278eebc0d --- /dev/null +++ b/mrp_bom_line_net_qty/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_bom_line_net_qty diff --git a/mrp_bom_line_net_qty/tests/test_mrp_bom_line_net_qty.py b/mrp_bom_line_net_qty/tests/test_mrp_bom_line_net_qty.py new file mode 100644 index 000000000..95c18cc05 --- /dev/null +++ b/mrp_bom_line_net_qty/tests/test_mrp_bom_line_net_qty.py @@ -0,0 +1,53 @@ +# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop) +# @author: Quentin DUPONT (quentin.dupont@grap.coop) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestMrpBomLineNetQty(TransactionCase): + def setUp(self): + super(TestMrpBomLineNetQty, self).setUp() + self.bom_desk_combination = self.env.ref("mrp.mrp_bom_manufacture") + + def test_01_calculate_qty_net(self): + bom_line_0 = self.bom_desk_combination.bom_line_ids[0] + self.assertNotEqual(bom_line_0.product_qty, bom_line_0.product_qty_net) + # Trigger onchange to get produt_qty_net + bom_line_0._onchange_product_qty() + self.assertEqual(bom_line_0.product_qty, bom_line_0.product_qty_net) + + def test_02_change_gross_qty_onchange_net(self): + bom_line_0 = self.bom_desk_combination.bom_line_ids[0] + bom_line_0.product_qty = 10 + # Trigger onchange to get produt_qty_net + bom_line_0._onchange_product_qty() + self.assertEqual(bom_line_0.product_qty, bom_line_0.product_qty_net) + + def test_03_change_qty_check_diff(self): + bom_line_0 = self.bom_desk_combination.bom_line_ids[0] + # Trigger onchange to get produt_qty_net + bom_line_0._onchange_product_qty() + self.assertEqual(bom_line_0.diff_product_qty_gross_net, 0) + bom_line_0.product_qty_net = bom_line_0.product_qty + 10 + self.assertNotEqual(bom_line_0.diff_product_qty_gross_net, 0) + + def test_04_change_loss_check_button_calculate_net(self): + bom_line_0 = self.bom_desk_combination.bom_line_ids[0] + bom_line_0.product_qty = 100 + bom_line_0.loss_percentage = 10 + # Trigger onchange to get produt_qty_net + bom_line_0._onchange_product_qty() + self.assertNotEqual(90, bom_line_0.product_qty_net) + # Trigger button to set produt_qty_net + bom_line_0.set_product_qty_net() + self.assertEqual(90, bom_line_0.product_qty_net) + + def test_05_change_loss_check_button_calculate_gross(self): + bom_line_0 = self.bom_desk_combination.bom_line_ids[0] + bom_line_0.product_qty_net = 90 + bom_line_0.loss_percentage = 10 + self.assertNotEqual(100, bom_line_0.product_qty) + # Trigger button to set produt_qty_net + bom_line_0.set_product_qty_gross() + self.assertEqual(100, bom_line_0.product_qty) diff --git a/mrp_bom_line_net_qty/views/view_mrp_bom.xml b/mrp_bom_line_net_qty/views/view_mrp_bom.xml new file mode 100644 index 000000000..857a08b76 --- /dev/null +++ b/mrp_bom_line_net_qty/views/view_mrp_bom.xml @@ -0,0 +1,52 @@ + + + + + + + + + + mrp.bom + + + + + +