Merge lp:~vauxoo/openobject-addons/6.1-bug-1051367-moylop260_vauxoo into lp:openobject-addons/6.1

Proposed by Moisés López - http://www.vauxoo.com
Status: Needs review
Proposed branch: lp:~vauxoo/openobject-addons/6.1-bug-1051367-moylop260_vauxoo
Merge into: lp:openobject-addons/6.1
Diff against target: 97 lines (+28/-19)
2 files modified
mrp/mrp.py (+17/-5)
mrp_subproduct/mrp_subproduct.py (+11/-14)
To merge this branch: bzr merge lp:~vauxoo/openobject-addons/6.1-bug-1051367-moylop260_vauxoo
Reviewer Review Type Date Requested Status
Nhomar - Vauxoo (community) Needs Information
OpenERP Core Team Pending
Review via email: mp+124590@code.launchpad.net

Description of the change

Fix bom explode qty

To post a comment you must log in.
6993. By Moisés López - http://www.vauxoo.com

[FIX] [mrp_subproduct] Fix name variable

6994. By Moisés López - http://www.vauxoo.com

[FIX] [mrp] Fix mrp subproducts validation zero & fix calc

Revision history for this message
Nhomar - Vauxoo (nhomar) wrote :

Moy.

To avoid misunderstood, can we prepare a use-case for this MP or link the videos related to the bug please.

Just for information to openerp team.

all explanation is really here:

bug #1047680

If we can prepare some test yaml it can be great Moy,
Regards.

review: Needs Information

Unmerged revisions

6994. By Moisés López - http://www.vauxoo.com

[FIX] [mrp] Fix mrp subproducts validation zero & fix calc

6993. By Moisés López - http://www.vauxoo.com

[FIX] [mrp_subproduct] Fix name variable

6992. By Moisés López - http://www.vauxoo.com

[REF] [mrp & mrp_subproducts] BoM explode qty refactory

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mrp/mrp.py'
2--- mrp/mrp.py 2012-07-23 08:44:52 +0000
3+++ mrp/mrp.py 2012-09-17 17:14:20 +0000
4@@ -292,8 +292,8 @@
5 result = bom.id
6 max_prop = prop
7 return result
8-
9- def _bom_explode(self, cr, uid, bom, factor, properties=[], addthis=False, level=0, routing_id=False):
10+
11+ def _bom_explode(self, cr, uid, bom, factor, properties=[], addthis=False, level=0, routing_id=False, result_subproducts=False):
12 """ Finds Products and Work Centers for related BoM for manufacturing order.
13 @param bom: BoM of particular product.
14 @param factor: Factor of product UoM.
15@@ -303,6 +303,18 @@
16 @return: result: List of dictionaries containing product details.
17 result2: List of dictionaries containing Work Center details.
18 """
19+ if result_subproducts is False:
20+ result_subproducts = []
21+ if self._columns.has_key('sub_products'):#if module mrp_subproduct is installed
22+ for sub_product in bom.sub_products:
23+ qty1 = sub_product.product_qty
24+ if sub_product.subproduct_type == 'variable':
25+ qty1 = factor*qty1/bom.product_uom.factor_inv
26+ result_subproducts.append({
27+ 'product_id': sub_product.product_id.id,
28+ 'product_qty': qty1,
29+ 'product_uom': sub_product.product_uom.id,
30+ })
31 routing_obj = self.pool.get('mrp.routing')
32 factor = factor / (bom.product_efficiency or 1.0)
33 factor = rounding(factor, bom.product_rounding)
34@@ -313,9 +325,9 @@
35 phantom = False
36 if bom.type == 'phantom' and not bom.bom_lines:
37 newbom = self._bom_find(cr, uid, bom.product_id.id, bom.product_uom.id, properties)
38-
39 if newbom:
40- res = self._bom_explode(cr, uid, self.browse(cr, uid, [newbom])[0], factor*bom.product_qty, properties, addthis=True, level=level+10)
41+ newbom_pool = self.browse(cr, uid, newbom)
42+ 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)
43 result = result + res[0]
44 result2 = result2 + res[1]
45 phantom = True
46@@ -347,7 +359,7 @@
47 '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)),
48 })
49 for bom2 in bom.bom_lines:
50- res = self._bom_explode(cr, uid, bom2, factor, properties, addthis=True, level=level+10)
51+ res = self._bom_explode(cr, uid, bom2, factor, properties, addthis=True, level=level+10, result_subproducts=result_subproducts)
52 result = result + res[0]
53 result2 = result2 + res[1]
54 return result, result2
55
56=== modified file 'mrp_subproduct/mrp_subproduct.py'
57--- mrp_subproduct/mrp_subproduct.py 2012-02-14 15:57:46 +0000
58+++ mrp_subproduct/mrp_subproduct.py 2012-09-17 17:14:20 +0000
59@@ -73,27 +73,24 @@
60 """ Confirms production order and calculates quantity based on subproduct_type.
61 @return: Newly generated picking Id.
62 """
63+ bom_obj = self.pool.get('mrp.bom')
64+ uom_obj = self.pool.get('product.uom')
65 picking_id = super(mrp_production,self).action_confirm(cr, uid, ids)
66 for production in self.browse(cr, uid, ids):
67 source = production.product_id.product_tmpl_id.property_stock_production.id
68- if not production.bom_id:
69+ bom_id = production.bom_id
70+ if not bom_id:
71 continue
72- for sub_product in production.bom_id.sub_products:
73- qty1 = sub_product.product_qty
74- qty2 = production.product_uos and production.product_uos_qty or False
75- if sub_product.subproduct_type == 'variable':
76- if production.product_qty:
77- qty1 *= production.product_qty / (production.bom_id.product_qty or 1.0)
78- if production.product_uos_qty:
79- qty2 *= production.product_uos_qty / (production.bom_id.product_uos_qty or 1.0)
80+ factor = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, bom_id.product_uom.id)
81+ result_subproducts =[]
82+ res = bom_obj._bom_explode(cr, uid, bom_id, factor / bom_id.product_qty, properties=False, routing_id=False, result_subproducts=result_subproducts)
83+ for sub_product in result_subproducts:
84 data = {
85 'name': 'PROD:'+production.name,
86 'date': production.date_planned,
87- 'product_id': sub_product.product_id.id,
88- 'product_qty': qty1,
89- 'product_uom': sub_product.product_uom.id,
90- 'product_uos_qty': qty2,
91- 'product_uos': production.product_uos and production.product_uos.id or False,
92+ 'product_id': sub_product['product_id'],
93+ 'product_qty': sub_product['product_qty'],
94+ 'product_uom': sub_product['product_uom'],
95 'location_id': source,
96 'location_dest_id': production.location_dest_id.id,
97 'move_dest_id': production.move_prod_id.id,