Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modular_types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
19 changes: 19 additions & 0 deletions modular_types/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
'name': 'Modular Types',
'version': '1.0',
'depends': ['base', 'sale_management', 'mrp', 'stock'],
'author': 'Aryan Donga (ardo)',
'description': 'Modular Types for BOM Components',
'application': False,
'installable': True,
'license': 'LGPL-3',
'data': [
'security/ir.model.access.csv',
'views/product_modular_type_views.xml',
'views/mrp_bom_views.xml',
'views/product_template_views.xml',
'views/mrp_production_views.xml',
'wizard/sale_order_line_wizard_views.xml',
'views/sale_order_views.xml',
],
}
9 changes: 9 additions & 0 deletions modular_types/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from . import product_modular_type
from . import product_template
from . import mrp_bom_line
from . import sale_order_line
from . import mrp_production
from . import modular_type_value
from . import mrp_bom
from . import sale_order
from . import stock_move
17 changes: 17 additions & 0 deletions modular_types/models/modular_type_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from odoo import fields, models


class ModularTypeValue(models.Model):
_name = 'modular.type.value'
_description = 'Modular Type Value for Sale Order Line'

sale_order_line_id = fields.Many2one(
'sale.order.line', string='Sale Order Line', ondelete='cascade'
)
modular_type_id = fields.Many2one(
comodel_name='product.modular.type',
string='Modular Type',
required=True,
ondelete='cascade',
)
value = fields.Float('Value', required=True)
14 changes: 14 additions & 0 deletions modular_types/models/mrp_bom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from odoo import Command, fields, models


class MrpBom(models.Model):
_inherit = 'mrp.bom'

applied_modular_types = fields.Many2many(
'product.modular.type', compute='_compute_applied_modular_types', readonly=True
)

def _compute_applied_modular_types(self):
for bom in self:
modular_types = bom.bom_line_ids.mapped('modular_type_id')
bom.applied_modular_types = [Command.set(modular_types.ids)]
27 changes: 27 additions & 0 deletions modular_types/models/mrp_bom_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from odoo import api, fields, models


class MrpBomLine(models.Model):
_inherit = 'mrp.bom.line'

modular_type_id = fields.Many2one(
'product.modular.type',
string='Modular Type',
domain="[('id', 'in', allowed_modular_type_ids)]",
)

allowed_modular_type_ids = fields.Many2many(
'product.modular.type', compute='_compute_allowed_modular_type_ids', store=False
)

@api.depends('bom_id.product_tmpl_id')
def _compute_allowed_modular_type_ids(self):
for line in self:
if line.bom_id.product_tmpl_id:
line.allowed_modular_type_ids = (
line.bom_id.product_tmpl_id.modular_type_ids
)
else:
line.allowed_modular_type_ids = self.env[
'product.modular.type'
].search([])
21 changes: 21 additions & 0 deletions modular_types/models/mrp_production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from odoo import fields, models


class MrpProduction(models.Model):
_inherit = 'mrp.production'

is_modular_bom = fields.Boolean(
readonly=True, compute='_compute_is_modular_bom', store=True
)

def _compute_is_modular_bom(self):
for production in self:
if (
production.bom_id
and production.bom_id.product_tmpl_id
and production.bom_id.product_tmpl_id.modular_type_ids
):
production.is_modular_bom = True
else:
production.is_modular_bom = False
return True
8 changes: 8 additions & 0 deletions modular_types/models/product_modular_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import fields, models


class ProductModularType(models.Model):
_name = 'product.modular.type'
_description = 'Modular Types for Products'

name = fields.Char(string='Name', required=True)
9 changes: 9 additions & 0 deletions modular_types/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = 'product.template'

modular_type_ids = fields.Many2many(
string='Module Types', comodel_name='product.modular.type'
)
29 changes: 29 additions & 0 deletions modular_types/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from odoo import models


class SaleOrder(models.Model):
_inherit = 'sale.order'

def action_confirm(self):
self.ensure_one()
res = super().action_confirm()

for manufacturing_order in self.mrp_production_ids:
# Get the sale order line matching the manufacturing order
so_reference_line = self.order_line.filtered(
lambda line: line.product_id == manufacturing_order.product_id
and line.product_uom_qty == manufacturing_order.product_qty
)

# Iterate through the move lines of the manufacturing order
for move_line in manufacturing_order.move_raw_ids.filtered(
lambda move: move.modular_type_id
):
# Find the corresponding modular type value
modular_value = so_reference_line.modular_type_value_ids.filtered(
lambda m: m.modular_type_id == move_line.modular_type_id
).value

move_line.product_uom_qty *= modular_value if modular_value else 0.0

return res
17 changes: 17 additions & 0 deletions modular_types/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from odoo import api, fields, models


class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

has_modular_type = fields.Boolean(compute='_compute_has_modular_type', store=True)
modular_type_value_ids = fields.One2many('modular.type.value', 'sale_order_line_id')

@api.depends('product_id')
def _compute_has_modular_type(self):
for line in self:
line.has_modular_type = (
bool(line.product_id.product_tmpl_id.modular_type_ids)
if line.product_id
else False
)
20 changes: 20 additions & 0 deletions modular_types/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from odoo import api, fields, models


class StockMove(models.Model):
_inherit = 'stock.move'

modular_type_id = fields.Many2one(
comodel_name='product.modular.type',
compute='_compute_modular_type_id',
store=True,
string='Modular Type',
)

@api.depends('raw_material_production_id.bom_id.bom_line_ids')
def _compute_modular_type_id(self):
for move in self:
bom_line = move.raw_material_production_id.bom_id.bom_line_ids.filtered(
lambda bl: bl.product_id == move.product_id
)
move.modular_type_id = bom_line.modular_type_id if bom_line else False
5 changes: 5 additions & 0 deletions modular_types/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
modular_types.access_product_modular_types,access_product_modular_types,model_product_modular_type,base.group_user,1,1,1,1
modular_types.access_modular_type_values, access_modular_type_values,model_modular_type_value,base.group_user,1,1,1,1
modular_types.access_sale_order_line_wizard,access_sale_order_line_wizard,model_sale_order_line_wizard,base.group_user,1,1,1,1
modular_types.access_sale_order_line_wizard_line,access_sale_order_line_wizard_line,model_sale_order_line_wizard_line,base.group_user,1,1,1,1
1 change: 1 addition & 0 deletions modular_types/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_modular_types
Loading