From 0e430028c1a63c3d8df7bb648dbc540ff0202d3f Mon Sep 17 00:00:00 2001 From: "Rucha (Open ERP)" Date: Thu, 24 Mar 2011 18:53:58 +0530 Subject: [PATCH] [FIX]: stock: Fixed scraping move having production lot lp bug: https://launchpad.net/bugs/739181 fixed bzr revid: rpa@tinyerp.com-20110324132358-yn5gwkj68pnun0qs --- addons/mrp/stock.py | 1 - addons/stock/stock.py | 24 ++++++++++++++++++++++-- addons/stock/wizard/stock_move.py | 4 ++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 0c1454edf98..7e1be541d65 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -137,7 +137,6 @@ class StockMove(osv.osv): wf_service = netsvc.LocalService("workflow") for move in self.browse(cr, uid, ids, context=context): new_moves = super(StockMove, self).action_scrap(cr, uid, [move.id], product_qty, location_id, context=context) - self.write(cr, uid, [move.id], {'prodlot_id': False, 'tracking_id': False}) production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])]) for prod_id in production_ids: wf_service.trg_validate(uid, 'mrp.production', prod_id, 'button_produce', cr) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index db5b3f677d3..aba85619216 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2236,6 +2236,7 @@ class stock_move(osv.osv): if quantity <= 0: raise osv.except_osv(_('Warning!'), _('Please provide a positive quantity to scrap!')) res = [] + to_done = [] for move in self.browse(cr, uid, ids, context=context): move_qty = move.product_qty uos_qty = quantity / move_qty * move.product_uos_qty @@ -2251,13 +2252,32 @@ class stock_move(osv.osv): if move.location_id.usage <> 'internal': default_val.update({'location_id': move.location_dest_id.id}) new_move = self.copy(cr, uid, move.id, default_val) + res.append(new_move) + to_done.append(new_move) + + if move.prodlot_id: + # Create a new move with the qty of scrapped move without prodlot + default_val = { + 'product_qty': quantity, + 'product_uos_qty': uos_qty, + 'tracking_id': move.tracking_id.id, + 'prodlot_id': False + } + newmove = self.copy(cr, uid, move.id, default_val) + res.append(new_move) + # Reduce amount of original move by qty of scrapped move + if move.product_qty - quantity > 0: + move.write({ + 'product_qty': move.product_qty - quantity, + 'product_uos_qty': move.product_uos_qty - uos_qty, + }) + - res += [new_move] product_obj = self.pool.get('product.product') for (id, name) in product_obj.name_get(cr, uid, [move.product_id.id]): self.log(cr, uid, move.id, "%s x %s %s" % (move.product_qty, name, _("were scrapped"))) - self.action_done(cr, uid, res) + self.action_done(cr, uid, to_done, context=context) return res def action_split(self, cr, uid, ids, quantity, split_by_qty=1, prefix=False, with_lot=True, context=None): diff --git a/addons/stock/wizard/stock_move.py b/addons/stock/wizard/stock_move.py index abcf193bb35..427f6bdc295 100644 --- a/addons/stock/wizard/stock_move.py +++ b/addons/stock/wizard/stock_move.py @@ -161,9 +161,9 @@ class stock_move_scrap(osv.osv_memory): context = {} move_obj = self.pool.get('stock.move') move_ids = context['active_ids'] - for data in self.read(cr, uid, ids): + for data in self.browse(cr, uid, ids): move_obj.action_scrap(cr, uid, move_ids, - data['product_qty'], data['location_id'], + data.product_qty, data.location_id.id, context=context) return {'type': 'ir.actions.act_window_close'}