Skip to content

Commit 4635364

Browse files
author
kuay-odoo
committed
[ADD] bom_modular_extension: add modular type in BOM, Product, Sale, Manufacture
- Introduced 'modular.type' model to define modular categories. - Linked modular types to product templates via many2many field. - Added modular_type_id in BOM lines with dynamic filtering per product. - Added security access rules for new models and wizards. - Extended views for BOM, manufacturing orders, sale orders, and product templates. - Created 'sale.order.line.modular.type' model to hold modular values for sale order lines. - Displayed modular types via wizard in sale order lines. - Updated stock moves to inherit modular type from BOM line. - Adjusted MRP component quantity using modular value during order confirmation.
1 parent 64ab48c commit 4635364

19 files changed

+294
-0
lines changed

bom_modular_extension/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from . import wizard

bom_modular_extension/__manifest__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "BOM Modular Extension",
3+
"description": "Add modular types and multiplies MO line quantity by SO values",
4+
"version": "1.0",
5+
"depends": ["sale_management", "mrp", "product"],
6+
"category": "Manufacturing",
7+
"data": [
8+
"security/ir.model.access.csv",
9+
"views/product_template.xml",
10+
"views/mrp_bom_line.xml",
11+
"wizard/sale_order_line_wizard.xml",
12+
"views/sale_order_button.xml",
13+
"views/mrp_production.xml",
14+
],
15+
"application": False,
16+
"auto_install": False,
17+
"license": "LGPL-3",
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from . import modular_type
2+
from . import product_template
3+
from . import mrp_bom_line
4+
from . import sale_order_line
5+
from . import sale_order_line_modular_type
6+
from . import sale_order
7+
from . import stock_move
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from odoo import fields, models
2+
3+
4+
class modularType(models.Model):
5+
_name = "modular.type"
6+
_description = "Help to give modular type to product"
7+
8+
name = fields.Char(string="Name", required=True)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from odoo import fields, models, api
2+
3+
4+
class MrpBomLine(models.Model):
5+
_inherit = "mrp.bom.line"
6+
7+
modular_type_id = fields.Many2one(
8+
"modular.type",
9+
string="Modular Type",
10+
domain="[('id', 'in', filter_modular_type_ids)]",
11+
help="Specify which modular type this BOM line belongs to",
12+
)
13+
14+
filter_modular_type_ids = fields.Many2many(
15+
"modular.type",
16+
compute="_compute_available_modular_types",
17+
string="Available Modular Types",
18+
)
19+
20+
@api.depends("bom_id.product_tmpl_id")
21+
def _compute_available_modular_types(self):
22+
for line in self:
23+
product_tmpl = line.bom_id.product_tmpl_id
24+
line.filter_modular_type_ids = (
25+
product_tmpl.modular_type_ids if product_tmpl else False
26+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from odoo import fields, models
2+
3+
4+
class productTemplate(models.Model):
5+
_inherit = "product.template"
6+
7+
modular_type_ids = fields.Many2many(
8+
"modular.type", help="Help to give modular type to product"
9+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from odoo import models
2+
3+
4+
class SaleOrder(models.Model):
5+
_inherit = "sale.order"
6+
7+
def action_confirm(self):
8+
res = super().action_confirm()
9+
10+
for production in self.mrp_production_ids:
11+
selected_order_line = self.order_line.filtered(
12+
lambda line: line.product_id == production.product_id
13+
and line.product_uom_qty == production.product_qty
14+
)
15+
16+
for stock_line in production.move_raw_ids.filtered(
17+
lambda move: move.modular_type_id
18+
):
19+
modular_value = (
20+
selected_order_line.mapped("modular_type_value_ids")
21+
.filtered(lambda m: m.modular_type_id == stock_line.modular_type_id)
22+
.value
23+
)
24+
25+
stock_line.product_uom_qty *= modular_value or 0.0
26+
27+
return res
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from odoo import api, fields, models
2+
3+
4+
class saleOrderLine(models.Model):
5+
_inherit = "sale.order.line"
6+
7+
modular_type_value_ids = fields.One2many(
8+
"sale.order.line.modular.type", "order_line_id", string="Modular Type Value"
9+
)
10+
11+
is_modular_types = fields.Boolean(
12+
string="Has modular type", compute="_compute_has_modular_types"
13+
)
14+
15+
@api.depends("product_template_id")
16+
def _compute_has_modular_types(self):
17+
for record in self:
18+
record.is_modular_types = bool(record.product_template_id.modular_type_ids)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from odoo import fields, models
2+
3+
4+
class saleOrderLineModularType(models.Model):
5+
_name = "sale.order.line.modular.type"
6+
_description = "Modular Type Value for Sale Order Line"
7+
8+
order_line_id = fields.Many2one("sale.order.line", string="Order Line")
9+
modular_type_id = fields.Many2one("modular.type", string="Modular Type")
10+
value = fields.Float(string="Value", required=True)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from odoo import api, fields, models
2+
3+
4+
class StockMove(models.Model):
5+
_inherit = "stock.move"
6+
7+
modular_type_id = fields.Many2one(
8+
comodel_name="modular.type",
9+
compute="_compute_modular_type_id",
10+
store=True,
11+
string="Modular Type",
12+
)
13+
14+
@api.depends("raw_material_production_id.bom_id.bom_line_ids")
15+
def _compute_modular_type_id(self):
16+
for move in self:
17+
bom_line = move.raw_material_production_id.bom_id.bom_line_ids.filtered(
18+
lambda bl: bl.product_id == move.product_id
19+
)
20+
move.modular_type_id = bom_line.modular_type_id if bom_line else False

0 commit comments

Comments
 (0)