[FIX] Stock :Picking removal should remove moves too

bzr revid: gpa@tinyerp.com-20100511091705-7uqknh1fkk12w5uz
This commit is contained in:
gpa 2010-05-11 14:47:05 +05:30
parent 123cb46c6c
commit 9f31cb419c
1 changed files with 13 additions and 5 deletions

View File

@ -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={}):