From b0ab2169d7422254887a71d13a633ae9bfa53593 Mon Sep 17 00:00:00 2001 From: Quentin Dupont Date: Tue, 4 Mar 2025 15:37:24 +0100 Subject: [PATCH] [16.0][IMP] fermente_mrp compute product stock rule --- fermente_mrp/__init__.py | 1 + fermente_mrp/__manifest__.py | 1 + fermente_mrp/data/stock_route.xml | 13 +++++++ fermente_mrp/models/__init__.py | 1 + fermente_mrp/models/product_template.py | 24 ++++++++++++ fermente_mrp/readme/CONTRIBUTORS.rst | 1 + fermente_mrp/readme/DESCRIPTION.rst | 8 ++++ fermente_mrp/tests/__init__.py | 1 + fermente_mrp/tests/test_product_template.py | 43 +++++++++++++++++++++ 9 files changed, 93 insertions(+) create mode 100644 fermente_mrp/data/stock_route.xml create mode 100644 fermente_mrp/models/__init__.py create mode 100644 fermente_mrp/models/product_template.py create mode 100644 fermente_mrp/tests/__init__.py create mode 100644 fermente_mrp/tests/test_product_template.py diff --git a/fermente_mrp/__init__.py b/fermente_mrp/__init__.py index e69de29b..0650744f 100644 --- a/fermente_mrp/__init__.py +++ b/fermente_mrp/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fermente_mrp/__manifest__.py b/fermente_mrp/__manifest__.py index 562ed437..fb7bbe97 100644 --- a/fermente_mrp/__manifest__.py +++ b/fermente_mrp/__manifest__.py @@ -11,6 +11,7 @@ "license": "AGPL-3", "depends": ["mrp"], "data": [ + "data/stock_route.xml", "views/mrp_production_view.xml", "security/ir.model.access.csv", ], diff --git a/fermente_mrp/data/stock_route.xml b/fermente_mrp/data/stock_route.xml new file mode 100644 index 00000000..885b77c8 --- /dev/null +++ b/fermente_mrp/data/stock_route.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/fermente_mrp/models/__init__.py b/fermente_mrp/models/__init__.py new file mode 100644 index 00000000..e8fa8f6b --- /dev/null +++ b/fermente_mrp/models/__init__.py @@ -0,0 +1 @@ +from . import product_template diff --git a/fermente_mrp/models/product_template.py b/fermente_mrp/models/product_template.py new file mode 100644 index 00000000..2bb33c9f --- /dev/null +++ b/fermente_mrp/models/product_template.py @@ -0,0 +1,24 @@ +# Copyright (C) 2025 - 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 models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + """ + Note 1 : j'ai hesité à enlever la route si pas de BoM mais effet de bord : + Si tu coches "Manufacture" et que tu as pas de BoM encore, ça le décoche. Donc naze. + """ + + def _compute_bom_count(self): + super()._compute_bom_count() + manufacture_route = self.env.ref("mrp.route_warehouse0_manufacture").id + for product in self.filtered(lambda x: x.bom_count != 0): + product.route_ids = [ + (4, manufacture_route), + ] + return True diff --git a/fermente_mrp/readme/CONTRIBUTORS.rst b/fermente_mrp/readme/CONTRIBUTORS.rst index e1525ce0..544bbaf9 100644 --- a/fermente_mrp/readme/CONTRIBUTORS.rst +++ b/fermente_mrp/readme/CONTRIBUTORS.rst @@ -1 +1,2 @@ * Sylvain LE GAL (https://www.twitter.com/legalsylvain) +* Quentin DUPONT (quentin.dupont@grap.coop) diff --git a/fermente_mrp/readme/DESCRIPTION.rst b/fermente_mrp/readme/DESCRIPTION.rst index 0338efeb..8814028e 100644 --- a/fermente_mrp/readme/DESCRIPTION.rst +++ b/fermente_mrp/readme/DESCRIPTION.rst @@ -3,3 +3,11 @@ Customize Odoo / odoo / ``mrp`` module. **Access Rights** * Allow members of ``mrp.group_mrp_user`` to create ``mrp.bom`` and ``mrp.bom.line``. + +**MRP - Stock** + +* Set active route "Replenish on Order (MTO)" + +**Product** + +* Add onchange to facilitate stock routes manufacturing. \ No newline at end of file diff --git a/fermente_mrp/tests/__init__.py b/fermente_mrp/tests/__init__.py new file mode 100644 index 00000000..8811bb54 --- /dev/null +++ b/fermente_mrp/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_template diff --git a/fermente_mrp/tests/test_product_template.py b/fermente_mrp/tests/test_product_template.py new file mode 100644 index 00000000..cec95db7 --- /dev/null +++ b/fermente_mrp/tests/test_product_template.py @@ -0,0 +1,43 @@ +# Copyright (C) 2025 - 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 TestProductTemplate(TransactionCase): + def setUp(self): + super().setUp() + self.manufacture_route = self.env.ref("mrp.route_warehouse0_manufacture") + + self.product_test = self.env["product.template"].create( + { + "name": "Product Test", + } + ) + + self.bom = self.env["mrp.bom"].create( + { + "product_tmpl_id": self.product_test.id, + "product_qty": 1.0, + } + ) + + def test_01_compute_bom_count_with_bom(self): + self.product_test._compute_bom_count() + + self.assertIn( + self.manufacture_route, + self.product_test.route_ids, + "Manufacturing route should have been added.", + ) + + def test_02_compute_bom_count_without_bom(self): + self.bom.unlink() + self.product_test._compute_bom_count() + + self.assertNotIn( + self.manufacture_route, + self.product_test.route_ids, + "Manufacturing route should have been deleted.", + )