From 34b923a19e795afa4f5cb74c4047c40dd463d268 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Tue, 28 Jan 2014 16:41:25 +0100 Subject: [PATCH] [IMP] change split signature and take into account for action_consume bzr revid: jco@openerp.com-20140128154125-3j1rpc4w6maywcmt --- addons/mrp/mrp.py | 6 ++---- addons/mrp/stock.py | 7 ++++--- addons/stock/stock.py | 13 ++++++------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index eadda8c69f9..4da68d522c2 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -920,14 +920,12 @@ class mrp_production(osv.osv): if corresponding_move: corresponding_move = corresponding_move[0] default_values = {} - if main_production_move: - default_values = {'consumed_for': main_production_move} if corresponding_move.product_qty > consume['product_qty']: stock_mov_obj.action_consume(cr, uid, [corresponding_move.id], consume['product_qty'], corresponding_move.location_id.id, - restrict_lot_id = consume['lot_id'], default_values = default_values, context=context) + restrict_lot_id = consume['lot_id'], consumed_for = main_production_move, context=context) else: stock_mov_obj.action_consume(cr, uid, [corresponding_move.id], corresponding_move.product_qty, corresponding_move.location_id.id, - restrict_lot_id = consume['lot_id'], default_values = default_values, context=context) + restrict_lot_id = consume['lot_id'], consumed_for = main_production_move, context=context) self.message_post(cr, uid, production_id, body=_("%s produced") % self._description, context=context) self.signal_button_produce_done(cr, uid, [production_id]) diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index efe5a1a1c42..294a315a72e 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -130,9 +130,10 @@ class StockMove(osv.osv): ctx = context.copy() if location_id: ctx['source_location_id'] = location_id - res.append(self.split(cr, uid, move, move_qty - quantity_rest, restrict_lot_id=restrict_lot_id, - restrict_partner_id=restrict_partner_id, context=ctx)) - #TODO need to add consumed_for here + new_mov = self.split(cr, uid, move, move_qty - quantity_rest, restrict_lot_id=restrict_lot_id, + restrict_partner_id=restrict_partner_id, context=ctx) + self.write(cr, uid, new_mov, {'consumed_for': consumed_for},context=context) + res.append(new_mov) else: res.append(move.id) if location_id: diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 3ccbf3bca50..4510815a090 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1900,14 +1900,12 @@ class stock_move(osv.osv): return res - def split(self, cr, uid, move, qty, restrict_lot_id=False, default_values = None, context=None): + def split(self, cr, uid, move, qty, restrict_lot_id=False, restrict_partner_id=False, context=None): """ Splits qty from move move into a new move :param move: browse record :param qty: float. quantity to split (given in product UoM) :param context: dictionay. can contains the special key 'source_location_id' in order to force the source location when copying the move """ - if default_values is None: - default_values = {} if move.product_qty <= qty or qty == 0: return move.id @@ -1920,9 +1918,7 @@ class stock_move(osv.osv): if move.state in ('done', 'cancel'): raise osv.except_osv(_('Error'), _('You cannot split a move done')) - - defaults = default_values.copy() - defaults.update({ + defaults = { 'product_uom_qty': uom_qty, 'product_uos_qty': uos_qty, 'state': move.state, @@ -1930,7 +1926,8 @@ class stock_move(osv.osv): 'move_dest_id': False, 'reserved_quant_ids': [], 'restrict_lot_id': restrict_lot_id, - }) + 'restrict_partner_id': restrict_partner_id + } if context.get('source_location_id'): defaults['location_id'] = context['source_location_id'] new_move = self.copy(cr, uid, move.id, defaults) @@ -1950,6 +1947,8 @@ class stock_move(osv.osv): self.action_confirm(cr, uid, [new_move], context=context) return new_move + + class stock_inventory(osv.osv): _name = "stock.inventory" _description = "Inventory"