Skip to content

Commit

Permalink
[16.0][IMP] fermente_mrp compute product stock rule
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinDupont committed Mar 4, 2025
1 parent bd27075 commit b0ab216
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions fermente_mrp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
1 change: 1 addition & 0 deletions fermente_mrp/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "AGPL-3",
"depends": ["mrp"],
"data": [
"data/stock_route.xml",
"views/mrp_production_view.xml",
"security/ir.model.access.csv",
],
Expand Down
13 changes: 13 additions & 0 deletions fermente_mrp/data/stock_route.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2025 - Today: GRAP (http://www.grap.coop)
@author: Quentin DUPONT ([email protected])
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo noupdate="1">

<record id="stock.route_warehouse0_mto" model="stock.route">
<field name="active" eval="True" />
</record>

</odoo>
1 change: 1 addition & 0 deletions fermente_mrp/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_template
24 changes: 24 additions & 0 deletions fermente_mrp/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) 2025 - Today: GRAP (http://www.grap.coop)
# @author: Quentin DUPONT ([email protected])
# 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
1 change: 1 addition & 0 deletions fermente_mrp/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Sylvain LE GAL (https://www.twitter.com/legalsylvain)
* Quentin DUPONT ([email protected])
8 changes: 8 additions & 0 deletions fermente_mrp/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions fermente_mrp/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_product_template
43 changes: 43 additions & 0 deletions fermente_mrp/tests/test_product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (C) 2025 - Today: GRAP (http://www.grap.coop)
# @author: Quentin DUPONT ([email protected])
# 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.",
)

0 comments on commit b0ab216

Please sign in to comment.