From 8001a5f2b921281f9cedc82b44abc036508bf5b3 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Wed, 17 Aug 2011 14:48:26 +0530 Subject: [PATCH 01/10] [FIX] mrp,mrp_subproduct:sub_products qty is True when Product type is Variable lp bug: https://launchpad.net/bugs/794431 fixed bzr revid: aag@tinyerp.com-20110817091826-fkg4y3b6pbbh220e --- addons/mrp/mrp.py | 11 ++++++++--- addons/mrp/wizard/mrp_product_produce.py | 5 +++-- addons/mrp_subproduct/mrp_subproduct.py | 10 ++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index ec429488914..5c36579281e 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -680,6 +680,11 @@ class mrp_production(osv.osv): if production.move_created_ids: res = False return res + + def rest_qty_compute(self, cr, uid, obj, move_obj=None, context=None): + qty = obj.product_qty * sub_qty + res = {'product_qty': qty, 'sub_qty': 1} + return res def action_produce(self, cr, uid, production_id, production_qty, production_mode, context=None): """ To produce final product based on production mode (consume/consume&produce). @@ -694,7 +699,6 @@ class mrp_production(osv.osv): stock_mov_obj = self.pool.get('stock.move') production = self.browse(cr, uid, production_id, context=context) - produced_qty = 0 if production_mode == 'consume_produce': produced_qty = production_qty @@ -749,11 +753,12 @@ class mrp_production(osv.osv): for produce_product in production.move_created_ids: produced_qty = produced_products.get(produce_product.product_id.id, 0) - rest_qty = production.product_qty - produced_qty + get_qty = self.rest_qty_compute(cr, uid, production, produce_product) + rest_qty = get_qty['product_qty'] - produced_qty if rest_qty <= production_qty: production_qty = rest_qty if rest_qty > 0 : - stock_mov_obj.action_consume(cr, uid, [produce_product.id], production_qty, context=context) + stock_mov_obj.action_consume(cr, uid, [produce_product.id], production_qty * get_qty['sub_qty'], context=context) for raw_product in production.move_lines2: new_parent_ids = [] diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py index 69fc3a9dd7d..dc9a235ff63 100644 --- a/addons/mrp/wizard/mrp_product_produce.py +++ b/addons/mrp/wizard/mrp_product_produce.py @@ -49,8 +49,9 @@ class mrp_product_produce(osv.osv_memory): context['active_id'], context=context) done = 0.0 for move in prod.move_created_ids2: - if not move.scrapped: - done += move.product_qty + if move.product_id == prod.product_id: + if not move.scrapped: + done += move.product_qty return (prod.product_qty - done) or prod.product_qty _defaults = { diff --git a/addons/mrp_subproduct/mrp_subproduct.py b/addons/mrp_subproduct/mrp_subproduct.py index 130411987c1..1e43078955c 100644 --- a/addons/mrp_subproduct/mrp_subproduct.py +++ b/addons/mrp_subproduct/mrp_subproduct.py @@ -97,5 +97,15 @@ class mrp_production(osv.osv): self.pool.get('stock.move').create(cr, uid, data) return picking_id + def rest_qty_compute(self, cr, uid, obj, move_obj=None, context=None): + sub_obj = self.pool.get('mrp.subproduct') + sub_qty = 1 + sub_id = sub_obj.search(cr, uid,[('product_id', '=', move_obj.product_id.id)] ) + if sub_id: + sub_qty = sub_obj.browse(cr ,uid, sub_id[0]).product_qty + qty = obj.product_qty * sub_qty + res = {'product_qty': qty, 'sub_qty': sub_qty} + return res + mrp_production() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 306da071e79c3373a29e7e747f15598b5fb473d7 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Wed, 17 Aug 2011 15:06:20 +0530 Subject: [PATCH 02/10] [IMP]mrp: Optimize code bzr revid: aag@tinyerp.com-20110817093620-c3bmophuut6n2to6 --- addons/mrp/mrp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 5c36579281e..8e917d8cac5 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -682,7 +682,7 @@ class mrp_production(osv.osv): return res def rest_qty_compute(self, cr, uid, obj, move_obj=None, context=None): - qty = obj.product_qty * sub_qty + qty = obj.product_qty res = {'product_qty': qty, 'sub_qty': 1} return res From f8db8e64b0b94fd07bd8d317469bb4138eb76fb5 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Wed, 17 Aug 2011 15:22:49 +0530 Subject: [PATCH 03/10] [IMP]mrp,mrp_subproducts: Optimize code bzr revid: aag@tinyerp.com-20110817095249-ujrm0onvzng60pad --- addons/mrp/mrp.py | 3 +-- addons/mrp_subproduct/mrp_subproduct.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 8e917d8cac5..88b0433e3f4 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -682,8 +682,7 @@ class mrp_production(osv.osv): return res def rest_qty_compute(self, cr, uid, obj, move_obj=None, context=None): - qty = obj.product_qty - res = {'product_qty': qty, 'sub_qty': 1} + res = {'product_qty': obj.product_qty, 'sub_qty': 1} return res def action_produce(self, cr, uid, production_id, production_qty, production_mode, context=None): diff --git a/addons/mrp_subproduct/mrp_subproduct.py b/addons/mrp_subproduct/mrp_subproduct.py index 1e43078955c..499d941a1b8 100644 --- a/addons/mrp_subproduct/mrp_subproduct.py +++ b/addons/mrp_subproduct/mrp_subproduct.py @@ -103,8 +103,7 @@ class mrp_production(osv.osv): sub_id = sub_obj.search(cr, uid,[('product_id', '=', move_obj.product_id.id)] ) if sub_id: sub_qty = sub_obj.browse(cr ,uid, sub_id[0]).product_qty - qty = obj.product_qty * sub_qty - res = {'product_qty': qty, 'sub_qty': sub_qty} + res = {'product_qty': obj.product_qty * sub_qty, 'sub_qty': sub_qty} return res mrp_production() From a648fdaccbd28812634cbccb0a0d1e1ae1819b95 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Wed, 17 Aug 2011 15:38:31 +0530 Subject: [PATCH 04/10] [IMP]mrp,mrp_subproducts: Optimize code - remove dic res bzr revid: aag@tinyerp.com-20110817100831-hrtypdvv921sz5o8 --- addons/mrp/mrp.py | 3 +-- addons/mrp_subproduct/mrp_subproduct.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 88b0433e3f4..5f8ac32c7d5 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -682,8 +682,7 @@ class mrp_production(osv.osv): return res def rest_qty_compute(self, cr, uid, obj, move_obj=None, context=None): - res = {'product_qty': obj.product_qty, 'sub_qty': 1} - return res + return {'product_qty': obj.product_qty, 'sub_qty': 1} def action_produce(self, cr, uid, production_id, production_qty, production_mode, context=None): """ To produce final product based on production mode (consume/consume&produce). diff --git a/addons/mrp_subproduct/mrp_subproduct.py b/addons/mrp_subproduct/mrp_subproduct.py index 499d941a1b8..96b16bc19fb 100644 --- a/addons/mrp_subproduct/mrp_subproduct.py +++ b/addons/mrp_subproduct/mrp_subproduct.py @@ -103,8 +103,7 @@ class mrp_production(osv.osv): sub_id = sub_obj.search(cr, uid,[('product_id', '=', move_obj.product_id.id)] ) if sub_id: sub_qty = sub_obj.browse(cr ,uid, sub_id[0]).product_qty - res = {'product_qty': obj.product_qty * sub_qty, 'sub_qty': sub_qty} - return res + return {'product_qty': obj.product_qty * sub_qty, 'sub_qty': sub_qty} mrp_production() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From cb99fda783295e9b666c8cd2d3fe44ac569d0bd1 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Tue, 23 Aug 2011 15:57:08 +0530 Subject: [PATCH 05/10] [FIX] mrp,mrp_subproduct:sub_products qty is True when Product type is Variable & sub product is in more than one BOM lp bug: https://launchpad.net/bugs/794431 fixed bzr revid: aag@tinyerp.com-20110823102708-itcfkm74hlhj6m3t --- addons/mrp/mrp.py | 8 +++++--- addons/mrp_subproduct/mrp_subproduct.py | 10 +++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 5f8ac32c7d5..fcea97a4960 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -681,8 +681,10 @@ class mrp_production(osv.osv): res = False return res - def rest_qty_compute(self, cr, uid, obj, move_obj=None, context=None): - return {'product_qty': obj.product_qty, 'sub_qty': 1} + def rest_qty_compute(self, cr, uid, production_id, move_id=None, context=None): + production_obj = self.pool.get('mrp.production') + production_browse = prod_obj.browse(cr, uid, production_id, context) + return {'product_qty': production_browse.product_qty, 'sub_qty': 1} def action_produce(self, cr, uid, production_id, production_qty, production_mode, context=None): """ To produce final product based on production mode (consume/consume&produce). @@ -751,7 +753,7 @@ class mrp_production(osv.osv): for produce_product in production.move_created_ids: produced_qty = produced_products.get(produce_product.product_id.id, 0) - get_qty = self.rest_qty_compute(cr, uid, production, produce_product) + get_qty = self.rest_qty_compute(cr, uid, production.id, produce_product.id) rest_qty = get_qty['product_qty'] - produced_qty if rest_qty <= production_qty: production_qty = rest_qty diff --git a/addons/mrp_subproduct/mrp_subproduct.py b/addons/mrp_subproduct/mrp_subproduct.py index 96b16bc19fb..0b2672652c9 100644 --- a/addons/mrp_subproduct/mrp_subproduct.py +++ b/addons/mrp_subproduct/mrp_subproduct.py @@ -97,13 +97,17 @@ class mrp_production(osv.osv): self.pool.get('stock.move').create(cr, uid, data) return picking_id - def rest_qty_compute(self, cr, uid, obj, move_obj=None, context=None): + def rest_qty_compute(self, cr, uid, production_id, move_id=None, context=None): sub_obj = self.pool.get('mrp.subproduct') + move_obj = self.pool.get('stock.move') + production_obj = self.pool.get('mrp.production') + production_browse = production_obj.browse(cr, uid, production_id, context) + move_browse = move_obj.browse(cr, uid, move_id, context) sub_qty = 1 - sub_id = sub_obj.search(cr, uid,[('product_id', '=', move_obj.product_id.id)] ) + sub_id = sub_obj.search(cr, uid,[('product_id', '=', move_browse.product_id.id),('bom_id', '=', production_browse.bom_id.id)] ) if sub_id: sub_qty = sub_obj.browse(cr ,uid, sub_id[0]).product_qty - return {'product_qty': obj.product_qty * sub_qty, 'sub_qty': sub_qty} + return {'product_qty': production_browse.product_qty * sub_qty, 'sub_qty': sub_qty} mrp_production() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From e1d67534c6a44c949025bf4d2315c5c2e24465e4 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Wed, 9 Nov 2011 15:31:06 +0530 Subject: [PATCH 06/10] [Fix] mrp,mrp_subproduct:Add function _get_quantity_to_produce to calculate production qty and sub product qty lp bug: https://launchpad.net/bugs/794431 fixed bzr revid: aag@tinyerp.com-20111109100106-7vjyuxi55iq2k52k --- addons/mrp/mrp.py | 28 ++++++++++++++++++++----- addons/mrp_subproduct/mrp_subproduct.py | 16 +++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 4bf6fe99584..17e6e2273a7 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -679,11 +679,29 @@ class mrp_production(osv.osv): if production.move_created_ids: res = False return res - - def rest_qty_compute(self, cr, uid, production_id, move_id=None, context=None): + + def _get_quantity_to_produce(self, cr, uid, production_id, move_id=None, context=None): + + """ Compute Production Qty of product.This method will be overwritten by mrp_subproduct. + @return: Dictionary of values. + """ + if context is None: + context = {} + production_obj = self.pool.get('mrp.production') - production_browse = prod_obj.browse(cr, uid, production_id, context) - return {'product_qty': production_browse.product_qty, 'sub_qty': 1} + production_browse = production_obj.browse(cr, uid, production_id, context) + if context.get('product_qty',False): + product_qty = context['product_qty'] + sub_qty = context['sub_qty'] + else: + product_qty = production_browse.product_qty + sub_qty = 1 + res = {'product_qty': product_qty, 'sub_qty': sub_qty} + return res + + + + def action_produce(self, cr, uid, production_id, production_qty, production_mode, context=None): """ To produce final product based on production mode (consume/consume&produce). @@ -752,7 +770,7 @@ class mrp_production(osv.osv): for produce_product in production.move_created_ids: produced_qty = produced_products.get(produce_product.product_id.id, 0) - get_qty = self.rest_qty_compute(cr, uid, production.id, produce_product.id) + get_qty = self._get_quantity_to_produce(cr, uid, production.id, produce_product.id, context) rest_qty = get_qty['product_qty'] - produced_qty if rest_qty <= production_qty: production_qty = rest_qty diff --git a/addons/mrp_subproduct/mrp_subproduct.py b/addons/mrp_subproduct/mrp_subproduct.py index 0b2672652c9..1ae67a38f94 100644 --- a/addons/mrp_subproduct/mrp_subproduct.py +++ b/addons/mrp_subproduct/mrp_subproduct.py @@ -97,7 +97,14 @@ class mrp_production(osv.osv): self.pool.get('stock.move').create(cr, uid, data) return picking_id - def rest_qty_compute(self, cr, uid, production_id, move_id=None, context=None): + def _get_quantity_to_produce(self, cr, uid, production_id, move_id=None, context=None): + + """ Compute Production Qty of product.This method is overwrite of mrp_production. + @return: Dictionary of values. + """ + if context is None: + context = {} + sub_obj = self.pool.get('mrp.subproduct') move_obj = self.pool.get('stock.move') production_obj = self.pool.get('mrp.production') @@ -106,8 +113,11 @@ class mrp_production(osv.osv): sub_qty = 1 sub_id = sub_obj.search(cr, uid,[('product_id', '=', move_browse.product_id.id),('bom_id', '=', production_browse.bom_id.id)] ) if sub_id: - sub_qty = sub_obj.browse(cr ,uid, sub_id[0]).product_qty - return {'product_qty': production_browse.product_qty * sub_qty, 'sub_qty': sub_qty} + sub_qty = sub_obj.browse(cr ,uid, sub_id[0], context).product_qty + context ['product_qty'] = production_browse.product_qty * sub_qty + context ['sub_qty'] = sub_qty + return super(mrp_production, self)._get_quantity_to_produce(cr, uid, production_id, move_id, context=context) + mrp_production() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 2a0b2f3cc5a39751ee822b52017ea151f3d229a3 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Wed, 9 Nov 2011 16:04:52 +0530 Subject: [PATCH 07/10] [Fix] mrp,mrp_subproduct:Add Context in method bzr revid: aag@tinyerp.com-20111109103452-zk1kg7tppzdw90nh --- addons/mrp/mrp.py | 4 ++-- addons/mrp_subproduct/mrp_subproduct.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 17e6e2273a7..0fdfd66d7e6 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -689,7 +689,7 @@ class mrp_production(osv.osv): context = {} production_obj = self.pool.get('mrp.production') - production_browse = production_obj.browse(cr, uid, production_id, context) + production_browse = production_obj.browse(cr, uid, production_id, context=context) if context.get('product_qty',False): product_qty = context['product_qty'] sub_qty = context['sub_qty'] @@ -770,7 +770,7 @@ class mrp_production(osv.osv): for produce_product in production.move_created_ids: produced_qty = produced_products.get(produce_product.product_id.id, 0) - get_qty = self._get_quantity_to_produce(cr, uid, production.id, produce_product.id, context) + get_qty = self._get_quantity_to_produce(cr, uid, production.id, produce_product.id, context=context) rest_qty = get_qty['product_qty'] - produced_qty if rest_qty <= production_qty: production_qty = rest_qty diff --git a/addons/mrp_subproduct/mrp_subproduct.py b/addons/mrp_subproduct/mrp_subproduct.py index 1ae67a38f94..427297f0a1c 100644 --- a/addons/mrp_subproduct/mrp_subproduct.py +++ b/addons/mrp_subproduct/mrp_subproduct.py @@ -111,9 +111,9 @@ class mrp_production(osv.osv): production_browse = production_obj.browse(cr, uid, production_id, context) move_browse = move_obj.browse(cr, uid, move_id, context) sub_qty = 1 - sub_id = sub_obj.search(cr, uid,[('product_id', '=', move_browse.product_id.id),('bom_id', '=', production_browse.bom_id.id)] ) + sub_id = sub_obj.search(cr, uid,[('product_id', '=', move_browse.product_id.id),('bom_id', '=', production_browse.bom_id.id)], context=context ) if sub_id: - sub_qty = sub_obj.browse(cr ,uid, sub_id[0], context).product_qty + sub_qty = sub_obj.browse(cr ,uid, sub_id[0], context=context).product_qty context ['product_qty'] = production_browse.product_qty * sub_qty context ['sub_qty'] = sub_qty return super(mrp_production, self)._get_quantity_to_produce(cr, uid, production_id, move_id, context=context) From 7431974eafaeeab0cb2a1a139096397ad4e4ff70 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Wed, 9 Nov 2011 16:06:04 +0530 Subject: [PATCH 08/10] [IMP]: remove blank space bzr revid: aag@tinyerp.com-20111109103604-mrnu9od0a3fniuhf --- addons/mrp/mrp.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 0fdfd66d7e6..7be913cbbe4 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -698,10 +698,6 @@ class mrp_production(osv.osv): sub_qty = 1 res = {'product_qty': product_qty, 'sub_qty': sub_qty} return res - - - - def action_produce(self, cr, uid, production_id, production_qty, production_mode, context=None): """ To produce final product based on production mode (consume/consume&produce). From d8dfd2b13d7e48cd1e841358c3298c4b91d3b7ff Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Wed, 9 Nov 2011 16:23:21 +0530 Subject: [PATCH 09/10] [IMP] mrp_subproduct:set variable as a default for subproduct_type and add tooltip bzr revid: aag@tinyerp.com-20111109105321-r55u6gtfbnjm0a8w --- addons/mrp_subproduct/mrp_subproduct.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mrp_subproduct/mrp_subproduct.py b/addons/mrp_subproduct/mrp_subproduct.py index 427297f0a1c..ffd7433d0ba 100644 --- a/addons/mrp_subproduct/mrp_subproduct.py +++ b/addons/mrp_subproduct/mrp_subproduct.py @@ -29,11 +29,11 @@ class mrp_subproduct(osv.osv): 'product_id': fields.many2one('product.product', 'Product', required=True), 'product_qty': fields.float('Product Qty', required=True), 'product_uom': fields.many2one('product.uom', 'Product UOM', required=True), - 'subproduct_type': fields.selection([('fixed','Fixed'),('variable','Variable')], 'Quantity Type', required=True), + 'subproduct_type': fields.selection([('fixed','Fixed'),('variable','Variable')], 'Quantity Type', required=True, help="Production Type of Product"), 'bom_id': fields.many2one('mrp.bom', 'BoM'), } _defaults={ - 'subproduct_type': lambda *args: 'fixed' + 'subproduct_type': lambda *args: 'variable' } def onchange_product_id(self, cr, uid, ids, product_id, context=None): From cbaf08b7dbad57452f4ec5a3d0fdac870ab0f424 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 9 Nov 2011 16:10:38 +0100 Subject: [PATCH 10/10] [IMP] mrp, mrp_subproduct: cleaner implementation of the fix for lp:794431 proposed by aag lp bug: https://launchpad.net/bugs/794431 fixed bzr revid: qdp-launchpad@openerp.com-20111109151038-oqo76jgzbd87t7v9 --- addons/mrp/mrp.py | 32 ++++++++------------ addons/mrp_subproduct/mrp_subproduct.py | 39 +++++++++++++------------ 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 7be913cbbe4..aeacf4a71a2 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -680,24 +680,16 @@ class mrp_production(osv.osv): res = False return res - def _get_quantity_to_produce(self, cr, uid, production_id, move_id=None, context=None): - - """ Compute Production Qty of product.This method will be overwritten by mrp_subproduct. - @return: Dictionary of values. + def _get_subproduct_factor(self, cr, uid, production_id, move_id=None, context=None): + """ Compute the factor to compute the qty of procucts to produce for the given production_id. By default, + it's always equal to the quantity encoded in the production order or the production wizard, but if the + module mrp_subproduct is installed, then we must use the move_id to identify the product to produce + and its quantity. + :param production_id: ID of the mrp.order + :param move_id: ID of the stock move that needs to be produced. Will be used in mrp_subproduct. + :return: The factor to apply to the quantity that we should produce for the given production order. """ - if context is None: - context = {} - - production_obj = self.pool.get('mrp.production') - production_browse = production_obj.browse(cr, uid, production_id, context=context) - if context.get('product_qty',False): - product_qty = context['product_qty'] - sub_qty = context['sub_qty'] - else: - product_qty = production_browse.product_qty - sub_qty = 1 - res = {'product_qty': product_qty, 'sub_qty': sub_qty} - return res + return 1 def action_produce(self, cr, uid, production_id, production_qty, production_mode, context=None): """ To produce final product based on production mode (consume/consume&produce). @@ -766,12 +758,12 @@ class mrp_production(osv.osv): for produce_product in production.move_created_ids: produced_qty = produced_products.get(produce_product.product_id.id, 0) - get_qty = self._get_quantity_to_produce(cr, uid, production.id, produce_product.id, context=context) - rest_qty = get_qty['product_qty'] - produced_qty + subproduct_factor = self._get_subproduct_factor(cr, uid, production.id, produce_product.id, context=context) + rest_qty = (subproduct_factor * production.product_qty) - produced_qty if rest_qty <= production_qty: production_qty = rest_qty if rest_qty > 0 : - stock_mov_obj.action_consume(cr, uid, [produce_product.id], production_qty * get_qty['sub_qty'], context=context) + stock_mov_obj.action_consume(cr, uid, [produce_product.id], (subproduct_factor * production_qty), context=context) for raw_product in production.move_lines2: new_parent_ids = [] diff --git a/addons/mrp_subproduct/mrp_subproduct.py b/addons/mrp_subproduct/mrp_subproduct.py index ffd7433d0ba..bb3b6789574 100644 --- a/addons/mrp_subproduct/mrp_subproduct.py +++ b/addons/mrp_subproduct/mrp_subproduct.py @@ -29,11 +29,14 @@ class mrp_subproduct(osv.osv): 'product_id': fields.many2one('product.product', 'Product', required=True), 'product_qty': fields.float('Product Qty', required=True), 'product_uom': fields.many2one('product.uom', 'Product UOM', required=True), - 'subproduct_type': fields.selection([('fixed','Fixed'),('variable','Variable')], 'Quantity Type', required=True, help="Production Type of Product"), + 'subproduct_type': fields.selection([('fixed','Fixed'),('variable','Variable')], 'Quantity Type', required=True, help="Define how the quantity of subproducts will be set on the production orders using this BoM.\ + 'Fixed' depicts a situation where the quantity of created subproduct is always equal to the quantity set on the BoM, regardless of how many are created in the production order.\ + By opposition, 'Variable' means that the quantity will be computed as\ + '(quantity of subproduct set on the BoM / quantity of manufactured product set on the BoM * quantity of manufactured product in the production order.)'"), 'bom_id': fields.many2one('mrp.bom', 'BoM'), } _defaults={ - 'subproduct_type': lambda *args: 'variable' + 'subproduct_type': 'variable', } def onchange_product_id(self, cr, uid, ids, product_id, context=None): @@ -97,27 +100,27 @@ class mrp_production(osv.osv): self.pool.get('stock.move').create(cr, uid, data) return picking_id - def _get_quantity_to_produce(self, cr, uid, production_id, move_id=None, context=None): - - """ Compute Production Qty of product.This method is overwrite of mrp_production. - @return: Dictionary of values. + def _get_subproduct_factor(self, cr, uid, production_id, move_id=None, context=None): + """Compute the factor to compute the qty of procucts to produce for the given production_id. By default, + it's always equal to the quantity encoded in the production order or the production wizard, but with + the module mrp_subproduct installed it can differ for subproducts having type 'variable'. + :param production_id: ID of the mrp.order + :param move_id: ID of the stock move that needs to be produced. Identify the product to produce. + :return: The factor to apply to the quantity that we should produce for the given production order and stock move. """ - if context is None: - context = {} - sub_obj = self.pool.get('mrp.subproduct') move_obj = self.pool.get('stock.move') production_obj = self.pool.get('mrp.production') - production_browse = production_obj.browse(cr, uid, production_id, context) - move_browse = move_obj.browse(cr, uid, move_id, context) - sub_qty = 1 - sub_id = sub_obj.search(cr, uid,[('product_id', '=', move_browse.product_id.id),('bom_id', '=', production_browse.bom_id.id)], context=context ) + production_browse = production_obj.browse(cr, uid, production_id, context=context) + move_browse = move_obj.browse(cr, uid, move_id, context=context) + subproduct_factor = 1 + sub_id = sub_obj.search(cr, uid,[('product_id', '=', move_browse.product_id.id),('bom_id', '=', production_browse.bom_id.id), ('subproduct_type', '=', 'variable')], context=context) if sub_id: - sub_qty = sub_obj.browse(cr ,uid, sub_id[0], context=context).product_qty - context ['product_qty'] = production_browse.product_qty * sub_qty - context ['sub_qty'] = sub_qty - return super(mrp_production, self)._get_quantity_to_produce(cr, uid, production_id, move_id, context=context) - + subproduct_record = sub_obj.browse(cr ,uid, sub_id[0], context=context) + if subproduct_record.bom_id.product_qty: + subproduct_factor = subproduct_record.product_qty / subproduct_record.bom_id.product_qty + return subproduct_factor + return super(mrp_production, self)._get_subproduct_factor(cr, uid, production_id, move_id, context=context) mrp_production() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: