Skip to content

Commit 980ab7b

Browse files
committed
[ADD] mrp_llc: fix mrp calculation by use of low level code
1 parent b76091c commit 980ab7b

6 files changed

Lines changed: 263 additions & 0 deletions

File tree

mrp_llc/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import mrp
4+
import procurement
5+
import product
6+
import stock

mrp_llc/__openerp__.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP Module
5+
#
6+
# Copyright (C) 2014 Asphalt Zipper, Inc.
7+
# Author scosist
8+
#
9+
# This program is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU Affero General Public License as
11+
# published by the Free Software Foundation, either version 3 of the
12+
# License, or (at your option) any later version.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU Affero General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU Affero General Public License
20+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
#
22+
##############################################################################
23+
24+
{
25+
"name": "MRP LLC",
26+
"version": "0.1",
27+
"summary": "MRP Low Level Code",
28+
"category": "Manufacturing",
29+
"author": "scosist",
30+
"website": "http://www.github.com/asphaltzipper/azi-odoo-modules",
31+
'description': """
32+
MRP Calculation by low level code.
33+
""",
34+
"depends": ["mrp"],
35+
"data" : [],
36+
"demo": [],
37+
"test":[],
38+
"js":[],
39+
"css":[],
40+
"installable": True,
41+
"auto_install": False,
42+
}

mrp_llc/mrp.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP Module
5+
#
6+
# Copyright (C) 2014 Asphalt Zipper, Inc.
7+
# Author scosist
8+
#
9+
# This program is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU Affero General Public License as
11+
# published by the Free Software Foundation, either version 3 of the
12+
# License, or (at your option) any later version.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU Affero General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU Affero General Public License
20+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
#
22+
#############################################################################
23+
24+
import time
25+
from openerp import models, fields, api
26+
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
27+
from openerp.exceptions import ValidationError
28+
from openerp.tools.translate import _
29+
30+
class mrp_bom(models.Model):
31+
_inherit = ['mrp.bom']
32+
33+
@api.model
34+
def _bom_explode_llc(self, bom, product, result=None, properties=None, llc=1, previous_products=None, master_bom=None):
35+
master_bom = master_bom or bom
36+
result = result or {}
37+
38+
for bom_line_id in bom.bom_line_ids:
39+
if bom_line_id.date_start and bom_line_id.date_start > time.strftime(DEFAULT_SERVER_DATETIME_FORMAT) or \
40+
bom_line_id.date_stop and bom_line_id.date_stop < time.strftime(DEFAULT_SERVER_DATETIME_FORMAT):
41+
continue
42+
# all bom_line_id variant values must be in the product
43+
if bom_line_id.attribute_value_ids:
44+
if not product or (set(map(int,bom_line_id.attribute_value_ids or [])) - set(map(int,product.attribute_value_ids))):
45+
continue
46+
47+
if previous_products and bom_line_id.product_id.product_tmpl_id.id in previous_products:
48+
raise ValidationError(_('Invalid Action!'), _('Bom "%s" contains a BoM line with a product recursion: "%s".') % (master_bom.name,bom_line_id.product_id.name_get()[0][1]))
49+
50+
bom_id = self._bom_find(product_id=bom_line_id.product_id.id, properties=properties)
51+
52+
if bom_id:
53+
all_prod = [bom.product_tmpl_id.id] + (previous_products or [])
54+
bom2 = self.browse(bom_id)
55+
if bom_line_id.type != "phantom" and bom2.type != "phantom":
56+
if result[bom_line_id.product_id.id] < llc:
57+
result[bom_line_id.product_id.id] = llc
58+
res = self._bom_explode_llc(bom2, bom_line_id.product_id, result, properties, llc + 1, all_prod, master_bom)
59+
result.update(res)
60+
else:
61+
res = self._bom_explode_llc(bom2, bom_line_id.product_id, result, properties, llc, all_prod, master_bom)
62+
result.update(res)
63+
elif bom_line_id.type != "phantom":
64+
if result[bom_line_id.product_id.id] < llc:
65+
result[bom_line_id.product_id.id] = llc
66+
else:
67+
raise ValidationError(_('Invalid Action!'), _('BoM "%s" contains a phantom BoM line but the product "%s" does not have any BoM defined.') % (master_bom.name,bom_line_id.product_id.name_get()[0][1]))
68+
return result
69+
70+
@api.model
71+
def _top_level_boms(self):
72+
bom_line_product_ids = []
73+
top_level_boms = set()
74+
bom_ids = self.search([])
75+
bom_line_obj = self.env['mrp.bom.line']
76+
bom_line_ids = bom_line_obj.search([])
77+
for bom_line in bom_line_ids:
78+
bom_line_product_ids.append(bom_line.product_id.id)
79+
for bom in bom_ids:
80+
bom_product_ids = []
81+
if bom.product_id:
82+
bom_product_ids.append(bom.product_id.id)
83+
else:
84+
for variant in bom.product_tmpl_id.product_variant_ids:
85+
bom_product_ids.append(variant.id)
86+
#if any variants are in bom_line, do not add bom
87+
if not set(bom_product_ids).intersection(bom_line_product_ids):
88+
top_level_boms.add(bom.id)
89+
return top_level_boms
90+
91+
@api.model
92+
def compute_llc(self, properties=None):
93+
llc_updates = {}
94+
# reset low level code first, then compute
95+
product_obj = self.env['product.product']
96+
product_ids = product_obj.search([])
97+
for product in product_ids:
98+
llc_updates[product.id] = 0
99+
top_level_boms = self._top_level_boms()
100+
for bom_point in self.browse(top_level_boms):
101+
res = self._bom_explode_llc(bom_point, bom_point.product_id, llc_updates, properties)
102+
for (k,v) in res.items():
103+
if v > llc_updates[k]:
104+
llc_updates[k] = v
105+
for (k,v) in llc_updates.items():
106+
product_obj.browse([k]).write({'low_level_code': v})
107+
108+
109+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

mrp_llc/procurement.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP Module
5+
#
6+
# Copyright (C) 2014 Asphalt Zipper, Inc.
7+
# Author scosist
8+
#
9+
# This program is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU Affero General Public License as
11+
# published by the Free Software Foundation, either version 3 of the
12+
# License, or (at your option) any later version.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU Affero General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU Affero General Public License
20+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
#
22+
#############################################################################
23+
24+
from openerp import models, fields, api
25+
from openerp.tools.translate import _
26+
27+
class procurement_order(models.Model):
28+
_inherit = 'procurement.order'
29+
30+
@api.model
31+
def _procure_orderpoint_confirm(self, use_new_cursor=False, company_id = False):
32+
bom_obj = self.env['mrp.bom']
33+
bom_obj.compute_llc()
34+
if use_new_cursor:
35+
self._cr.commit()
36+
return super(procurement_order, self)._procure_orderpoint_confirm(use_new_cursor, company_id)
37+
38+
39+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

mrp_llc/product.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP Module
5+
#
6+
# Copyright (C) 2014 Asphalt Zipper, Inc.
7+
# Author scosist
8+
#
9+
# This program is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU Affero General Public License as
11+
# published by the Free Software Foundation, either version 3 of the
12+
# License, or (at your option) any later version.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU Affero General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU Affero General Public License
20+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
#
22+
#############################################################################
23+
24+
from openerp import models, fields, api
25+
from openerp.tools.translate import _
26+
27+
class product_product(models.Model):
28+
_inherit = "product.product"
29+
30+
low_level_code = fields.Integer('LLC', required=True, default=0)
31+
32+
33+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

mrp_llc/stock.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP Module
5+
#
6+
# Copyright (C) 2014 Asphalt Zipper, Inc.
7+
# Author scosist
8+
#
9+
# This program is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU Affero General Public License as
11+
# published by the Free Software Foundation, either version 3 of the
12+
# License, or (at your option) any later version.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU Affero General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU Affero General Public License
20+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
#
22+
#############################################################################
23+
24+
from openerp import models, fields, api
25+
from openerp.tools.translate import _
26+
27+
class stock_warehouse_orderpoint(models.Model):
28+
_inherit = 'stock.warehouse.orderpoint'
29+
_order = 'product_llc'
30+
31+
product_llc = fields.Integer(string='Product LLC', store=True, related='product_id.low_level_code', readonly=True)
32+
33+
34+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

0 commit comments

Comments
 (0)