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
=== modified file 'mrp_byproduct/mrp_byproduct.py'
--- mrp_byproduct/mrp_byproduct.py 2012-12-08 10:33:38 +0000
+++ mrp_byproduct/mrp_byproduct.py 2012-12-10 09:10:26 +0000
@@ -21,6 +21,8 @@
2121
22from osv import fields22from osv import fields
23from osv import osv23from osv import osv
24
25import tools
24import decimal_precision as dp26import decimal_precision as dp
25from tools.translate import _27from tools.translate import _
2628
@@ -75,38 +77,106 @@
75 'sub_products':fields.one2many('mrp.subproduct', 'bom_id', 'Byproducts'),77 'sub_products':fields.one2many('mrp.subproduct', 'bom_id', 'Byproducts'),
76 }78 }
7779
80 def _bom_explode(self, cr, uid, bom, factor, properties=[], addthis=False, level=0, routing_id=False, result_subproducts=False):
81 """ Finds sub products and work centers for related bom lines which has several sub products defined in it.
82 @param bom: BoM of particular product.
83 @param factor: Factor of product UoM.
84 @param properties: A List of properties Ids.
85 @param addthis: If BoM found then True else False.
86 @param level: Depth level to find BoM lines starts from 10.
87 @return: result: List of dictionaries containing product details.
88 result2: List of dictionaries containing Work Center details.
89 """
90 if result_subproducts is False:
91 result_subproducts = []
92 if self._columns.has_key('sub_products'):#if module mrp_subproduct is installed
93 for sub_product in bom.sub_products:
94 qty1 = sub_product.product_qty
95 if sub_product.subproduct_type == 'variable':
96 qty1 = factor*qty1/bom.product_uom.factor_inv
97 result_subproducts.append({
98 'product_id': sub_product.product_id.id,
99 'product_qty': qty1,
100 'product_uom': sub_product.product_uom.id,
101 })
102 routing_obj = self.pool.get('mrp.routing')
103 factor = factor / (bom.product_efficiency or 1.0)
104 factor = rounding(factor, bom.product_rounding)
105 if factor < bom.product_rounding:
106 factor = bom.product_rounding
107 result = []
108 result2 = []
109 phantom = False
110 if bom.type == 'phantom' and not bom.bom_lines:
111 newbom = self._bom_find(cr, uid, bom.product_id.id, bom.product_uom.id, properties)
112
113 if newbom:
114 newbom_pool = self.browse(cr, uid, newbom)
115 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)
116 result = result + res[0]
117 result2 = result2 + res[1]
118 phantom = True
119 else:
120 phantom = False
121 if not phantom:
122 if addthis and not bom.bom_lines:
123 result.append(
124 {
125 'name': bom.product_id.name,
126 'product_id': bom.product_id.id,
127 'product_qty': bom.product_qty * factor,
128 'product_uom': bom.product_uom.id,
129 'product_uos_qty': bom.product_uos and bom.product_uos_qty * factor or False,
130 'product_uos': bom.product_uos and bom.product_uos.id or False,
131 })
132 routing = (routing_id and routing_obj.browse(cr, uid, routing_id)) or bom.routing_id or False
133 if routing:
134 for wc_use in routing.workcenter_lines:
135 wc = wc_use.workcenter_id
136 d, m = divmod(factor, wc_use.workcenter_id.capacity_per_cycle)
137 mult = (d + (m and 1.0 or 0.0))
138 cycle = mult * wc_use.cycle_nbr
139 result2.append({
140 'name': tools.ustr(wc_use.name) + ' - ' + tools.ustr(bom.product_id.name),
141 'workcenter_id': wc.id,
142 'sequence': level+(wc_use.sequence or 0),
143 'cycle': cycle,
144 '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)),
145 })
146 for bom2 in bom.bom_lines:
147 res = self._bom_explode(cr, uid, bom2, factor, properties, addthis=True, level=level+10, result_subproducts=result_subproducts)
148 result = result + res[0]
149 result2 = result2 + res[1]
150 return result, result2
151
78mrp_bom()152mrp_bom()
79153
80class mrp_production(osv.osv):154class mrp_production(osv.osv):
81 _description = 'Production'155 _description = 'Production'
82 _inherit= 'mrp.production'156 _inherit= 'mrp.production'
83157
84
85 def action_confirm(self, cr, uid, ids):158 def action_confirm(self, cr, uid, ids):
86 """ Confirms production order and calculates quantity based on subproduct_type.159 """ Confirms production order and calculates quantity based on subproduct_type.
87 @return: Newly generated picking Id.160 @return: Newly generated picking Id.
88 """161 """
162 bom_obj = self.pool.get('mrp.bom')
163 uom_obj = self.pool.get('product.uom')
89 picking_id = super(mrp_production,self).action_confirm(cr, uid, ids)164 picking_id = super(mrp_production,self).action_confirm(cr, uid, ids)
90 for production in self.browse(cr, uid, ids):165 for production in self.browse(cr, uid, ids):
91 source = production.product_id.product_tmpl_id.property_stock_production.id166 source = production.product_id.product_tmpl_id.property_stock_production.id
92 if not production.bom_id:167 bom_id = production.bom_id
168 if not bom_id:
93 continue169 continue
94 for sub_product in production.bom_id.sub_products:170 factor = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, bom_id.product_uom.id)
95 qty1 = sub_product.product_qty171 result_subproducts =[]
96 qty2 = production.product_uos and production.product_uos_qty or False172 res = bom_obj._bom_explode(cr, uid, bom_id, factor / bom_id.product_qty, properties=False, routing_id=False, result_subproducts=result_subproducts)
97 if sub_product.subproduct_type == 'variable':173 for sub_product in result_subproducts:
98 if production.product_qty:
99 qty1 *= production.product_qty / (production.bom_id.product_qty or 1.0)
100 if production.product_uos_qty:
101 qty2 *= production.product_uos_qty / (production.bom_id.product_uos_qty or 1.0)
102 data = {174 data = {
103 'name': 'PROD:'+production.name,175 'name': 'PROD:'+production.name,
104 'date': production.date_planned,176 'date': production.date_planned,
105 'product_id': sub_product.product_id.id,177 'product_id': sub_product['product_id'],
106 'product_qty': qty1,178 'product_qty': sub_product['product_qty'],
107 'product_uom': sub_product.product_uom.id,179 'product_uom': sub_product['product_uom'],
108 'product_uos_qty': qty2,
109 'product_uos': production.product_uos and production.product_uos.id or False,
110 'location_id': source,180 'location_id': source,
111 'location_dest_id': production.location_dest_id.id,181 'location_dest_id': production.location_dest_id.id,
112 'move_dest_id': production.move_prod_id.id,182 'move_dest_id': production.move_prod_id.id,
@@ -140,6 +210,12 @@
140210
141mrp_production()211mrp_production()
142212
213def rounding(f, r):
214 import math
215 if not r:
216 return f
217 return math.ceil(f / r) * r
218
143class change_production_qty(osv.osv_memory):219class change_production_qty(osv.osv_memory):
144 _inherit = 'change.production.qty'220 _inherit = 'change.production.qty'
145221

Subscribers

People subscribed via source and target branches

to all changes: