diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 40fd2e46525..8629655085d 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -1385,13 +1385,32 @@ class StockMove(osv.osv): def consume_moves(self, cr, uid, ids, product_qty, location_id=False, location_dest_id=False, consume=True, context=None): res = [] production_obj = self.pool.get('mrp.production') + wf_service = netsvc.LocalService("workflow") for move in self.browse(cr, uid, ids): new_moves = super(StockMove, self).consume_moves(cr, uid, [move.id], product_qty, location_id, location_dest_id, consume, context=context) production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])]) + for prod in production_obj.browse(cr, uid, production_ids, context=context): + if prod.state == 'confirmed': + production_obj.force_production(cr, uid, [prod.id]) + wf_service.trg_validate(uid, 'mrp.production', prod.id, 'button_produce', cr) for new_move in new_moves: production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]}) res.append(new_move) - return res + return res + + def scrap_moves(self, cr, uid, ids, product_qty, location_id, context=None): + res = [] + production_obj = self.pool.get('mrp.production') + wf_service = netsvc.LocalService("workflow") + for move in self.browse(cr, uid, ids): + new_moves = super(StockMove, self).scrap_moves(cr, uid, [move.id], product_qty, location_id, context=context) + 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) + for new_move in new_moves: + production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]}) + res.append(new_move) + return {} StockMove() diff --git a/addons/stock/stock.py b/addons/stock/stock.py index f1b7e34d1d5..31ffe5b6242 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1602,7 +1602,21 @@ class stock_move(osv.osv): return res def scrap_moves(self, cr, uid, ids, quantity, location_dest_id, context=None): - return self.consume_moves(cr, uid, ids, quantity, location_id=False, location_dest_id=location_dest_id, consume=False, context=context) + if quantity <= 0: + raise osv.except_osv(_('Warning!'), _('Please provide Proper Quantity !')) + res = [] + for move in self.browse(cr, uid, ids, context=context): + move_qty = move.product_qty + uos_qty = quantity / move_qty * move.product_uos_qty + default_val = { + 'product_qty': quantity, + 'product_uos_qty': uos_qty, + 'state': move.state, + 'location_dest_id': location_dest_id + } + new_move = self.copy(cr, uid, move.id, default_val) + res += [new_move] + return res stock_move()