diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 54d2035b860..d96ce2da63d 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -859,15 +859,23 @@ class stock_picking(osv.osv): return True def unlink(self, cr, uid, ids, context=None): + move_obj = self.pool.get('stock.move') + if not context: + context = {} + for pick in self.browse(cr, uid, ids, context=context): if pick.state in ['done','cancel']: raise osv.except_osv(_('Error'), _('You cannot remove the picking which is in %s state !')%(pick.state,)) - elif pick.state in ['confirmed','assigned']: + elif pick.state in ['confirmed','assigned', 'draft']: ids2 = [move.id for move in pick.move_lines] - context.update({'call_unlink':True}) - self.pool.get('stock.move').action_cancel(cr, uid, ids2, context) - else: - continue + ctx = context.copy() + ctx.update({'call_unlink':True}) + if pick.state != 'draft': + #Cancelling the move in order to affect Virtual stock of product + move_obj.action_cancel(cr, uid, ids2, ctx) + #Removing the move + move_obj.unlink(cr, uid, ids2, ctx) + return super(stock_picking, self).unlink(cr, uid, ids, context=context) def do_partial(self, cr, uid, ids, partial_datas, context={}):