Merge lp:~openerp-dev/openobject-addons/trunk-opw-579043-port-kbh into lp:openobject-addons

Proposed by Khushboo Bhatt(openerp)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-opw-579043-port-kbh
Merge into: lp:openobject-addons
Diff against target: 146 lines (+91/-15)
1 file modified
mrp_byproduct/mrp_byproduct.py (+91/-15)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-opw-579043-port-kbh
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+138114@code.launchpad.net

Description of the change

Hello,

[FIX] mrp_subproduct doesnt pull sub products from bill of material when we have type phantom"

Issue :
After adding a suproduct line in Bill of matirial of type=Phantom we hope to see the material asigned in sub product of phantom bill of material when confirming the production order with the parent bill of material that the mrp_subproduct fills in finished product, but it doesn't do it.

Steps:
Check this video : http://youtu.be/Fp4Vj5aNtrw

Code is forward port from 6.1

Thanks,
Khushboo.

To post a comment you must log in.

Unmerged revisions

8209. By Khushboo Bhatt(openerp)

[FIX]mrp_byproduct:description updated

8208. By Khushboo Bhatt(openerp)

[MERGE]merge with trunk

8207. By Khushboo Bhatt(openerp)

[REM]mrp_byproduct:description removed

8206. By ado

[FIX]mrp_byproduct: doesnt pull sub products from bill of material when we have type phantom

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mrp_byproduct/mrp_byproduct.py'
2--- mrp_byproduct/mrp_byproduct.py 2012-12-08 10:33:38 +0000
3+++ mrp_byproduct/mrp_byproduct.py 2012-12-10 09:10:26 +0000
4@@ -21,6 +21,8 @@
5
6 from osv import fields
7 from osv import osv
8+
9+import tools
10 import decimal_precision as dp
11 from tools.translate import _
12
13@@ -75,38 +77,106 @@
14 'sub_products':fields.one2many('mrp.subproduct', 'bom_id', 'Byproducts'),
15 }
16
17+ def _bom_explode(self, cr, uid, bom, factor, properties=[], addthis=False, level=0, routing_id=False, result_subproducts=False):
18+ """ Finds sub products and work centers for related bom lines which has several sub products defined in it.
19+ @param bom: BoM of particular product.
20+ @param factor: Factor of product UoM.
21+ @param properties: A List of properties Ids.
22+ @param addthis: If BoM found then True else False.
23+ @param level: Depth level to find BoM lines starts from 10.
24+ @return: result: List of dictionaries containing product details.
25+ result2: List of dictionaries containing Work Center details.
26+ """
27+ if result_subproducts is False:
28+ result_subproducts = []
29+ if self._columns.has_key('sub_products'):#if module mrp_subproduct is installed
30+ for sub_product in bom.sub_products:
31+ qty1 = sub_product.product_qty
32+ if sub_product.subproduct_type == 'variable':
33+ qty1 = factor*qty1/bom.product_uom.factor_inv
34+ result_subproducts.append({
35+ 'product_id': sub_product.product_id.id,
36+ 'product_qty': qty1,
37+ 'product_uom': sub_product.product_uom.id,
38+ })
39+ routing_obj = self.pool.get('mrp.routing')
40+ factor = factor / (bom.product_efficiency or 1.0)
41+ factor = rounding(factor, bom.product_rounding)
42+ if factor < bom.product_rounding:
43+ factor = bom.product_rounding
44+ result = []
45+ result2 = []
46+ phantom = False
47+ if bom.type == 'phantom' and not bom.bom_lines:
48+ newbom = self._bom_find(cr, uid, bom.product_id.id, bom.product_uom.id, properties)
49+
50+ if newbom:
51+ newbom_pool = self.browse(cr, uid, newbom)
52+ res = self._bom_explode(cr, uid, self.browse(cr, uid, [newbom])[0], factor*bom.product_qty/(newbom_pool.product_qty*newbom_pool.product_uom.factor_inv), properties, addthis=True, level=level+10, result_subproducts=result_subproducts)
53+ result = result + res[0]
54+ result2 = result2 + res[1]
55+ phantom = True
56+ else:
57+ phantom = False
58+ if not phantom:
59+ if addthis and not bom.bom_lines:
60+ result.append(
61+ {
62+ 'name': bom.product_id.name,
63+ 'product_id': bom.product_id.id,
64+ 'product_qty': bom.product_qty * factor,
65+ 'product_uom': bom.product_uom.id,
66+ 'product_uos_qty': bom.product_uos and bom.product_uos_qty * factor or False,
67+ 'product_uos': bom.product_uos and bom.product_uos.id or False,
68+ })
69+ routing = (routing_id and routing_obj.browse(cr, uid, routing_id)) or bom.routing_id or False
70+ if routing:
71+ for wc_use in routing.workcenter_lines:
72+ wc = wc_use.workcenter_id
73+ d, m = divmod(factor, wc_use.workcenter_id.capacity_per_cycle)
74+ mult = (d + (m and 1.0 or 0.0))
75+ cycle = mult * wc_use.cycle_nbr
76+ result2.append({
77+ 'name': tools.ustr(wc_use.name) + ' - ' + tools.ustr(bom.product_id.name),
78+ 'workcenter_id': wc.id,
79+ 'sequence': level+(wc_use.sequence or 0),
80+ 'cycle': cycle,
81+ 'hour': float(wc_use.hour_nbr*mult + ((wc.time_start or 0.0)+(wc.time_stop or 0.0)+cycle*(wc.time_cycle or 0.0)) * (wc.time_efficiency or 1.0)),
82+ })
83+ for bom2 in bom.bom_lines:
84+ res = self._bom_explode(cr, uid, bom2, factor, properties, addthis=True, level=level+10, result_subproducts=result_subproducts)
85+ result = result + res[0]
86+ result2 = result2 + res[1]
87+ return result, result2
88+
89 mrp_bom()
90
91 class mrp_production(osv.osv):
92 _description = 'Production'
93 _inherit= 'mrp.production'
94
95-
96 def action_confirm(self, cr, uid, ids):
97 """ Confirms production order and calculates quantity based on subproduct_type.
98 @return: Newly generated picking Id.
99 """
100+ bom_obj = self.pool.get('mrp.bom')
101+ uom_obj = self.pool.get('product.uom')
102 picking_id = super(mrp_production,self).action_confirm(cr, uid, ids)
103 for production in self.browse(cr, uid, ids):
104 source = production.product_id.product_tmpl_id.property_stock_production.id
105- if not production.bom_id:
106+ bom_id = production.bom_id
107+ if not bom_id:
108 continue
109- for sub_product in production.bom_id.sub_products:
110- qty1 = sub_product.product_qty
111- qty2 = production.product_uos and production.product_uos_qty or False
112- if sub_product.subproduct_type == 'variable':
113- if production.product_qty:
114- qty1 *= production.product_qty / (production.bom_id.product_qty or 1.0)
115- if production.product_uos_qty:
116- qty2 *= production.product_uos_qty / (production.bom_id.product_uos_qty or 1.0)
117+ factor = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, bom_id.product_uom.id)
118+ result_subproducts =[]
119+ res = bom_obj._bom_explode(cr, uid, bom_id, factor / bom_id.product_qty, properties=False, routing_id=False, result_subproducts=result_subproducts)
120+ for sub_product in result_subproducts:
121 data = {
122 'name': 'PROD:'+production.name,
123 'date': production.date_planned,
124- 'product_id': sub_product.product_id.id,
125- 'product_qty': qty1,
126- 'product_uom': sub_product.product_uom.id,
127- 'product_uos_qty': qty2,
128- 'product_uos': production.product_uos and production.product_uos.id or False,
129+ 'product_id': sub_product['product_id'],
130+ 'product_qty': sub_product['product_qty'],
131+ 'product_uom': sub_product['product_uom'],
132 'location_id': source,
133 'location_dest_id': production.location_dest_id.id,
134 'move_dest_id': production.move_prod_id.id,
135@@ -140,6 +210,12 @@
136
137 mrp_production()
138
139+def rounding(f, r):
140+ import math
141+ if not r:
142+ return f
143+ return math.ceil(f / r) * r
144+
145 class change_production_qty(osv.osv_memory):
146 _inherit = 'change.production.qty'
147

Subscribers

People subscribed via source and target branches

to all changes: