From d7849d322d05e992cf0ca3fe2d5ca6a07ea3b940 Mon Sep 17 00:00:00 2001 From: "Jay (OpenERP)" Date: Tue, 31 Aug 2010 15:50:45 +0530 Subject: [PATCH] [FIX] MRP : Cancellation of procurement allowed if it has no moves attached lp bug: https://launchpad.net/bugs/626695 fixed bzr revid: jvo@tinyerp.com-20100831102045-p9r88j380x515k25 --- addons/procurement/procurement.py | 8 ++++---- addons/stock/stock.py | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/addons/procurement/procurement.py b/addons/procurement/procurement.py index dc072cc520a..298d9b05449 100644 --- a/addons/procurement/procurement.py +++ b/addons/procurement/procurement.py @@ -179,7 +179,7 @@ class procurement_order(osv.osv): @param proc: Current procurement. @return: Quantity or False. """ - if proc.product_id.type == 'product': + if proc.product_id.type == 'product' and proc.move_id: if proc.move_id.product_uos: return proc.move_id.product_uos_qty return False @@ -189,7 +189,7 @@ class procurement_order(osv.osv): @param proc: Current procurement. @return: UoS or False. """ - if proc.product_id.type == 'product': + if proc.product_id.type == 'product' and proc.move_id: if proc.move_id.product_uos: return proc.move_id.product_uos.id return False @@ -405,7 +405,7 @@ class procurement_order(osv.osv): todo2 = [] move_obj = self.pool.get('stock.move') for proc in self.browse(cr, uid, ids): - if proc.close_move: + if proc.close_move and proc.move_id: if proc.move_id.state not in ('done', 'cancel'): todo2.append(proc.move_id.id) else: @@ -430,7 +430,7 @@ class procurement_order(osv.osv): """ ok = False for procurement in self.browse(cr, uid, ids): - if procurement.move_id.state == 'assigned' or procurement.move_id.state == 'done': + if procurement.move_id and procurement.move_id.state == 'assigned' or procurement.move_id.state == 'done': self.action_done(cr, uid, [procurement.id]) ok = True return ok diff --git a/addons/stock/stock.py b/addons/stock/stock.py index aac1ac869ed..e19e36b641f 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1003,7 +1003,7 @@ class stock_picking(osv.osv): def unlink(self, cr, uid, ids, context=None): move_obj = self.pool.get('stock.move') - if not context: + if context is None: context = {} for pick in self.browse(cr, uid, ids, context=context): if pick.state in ['done','cancel']: @@ -1886,12 +1886,13 @@ class stock_move(osv.osv): def unlink(self, cr, uid, ids, context=None): if context is None: context = {} + ctx = context.copy() for move in self.browse(cr, uid, ids, context=context): - if move.state != 'draft': + if move.state != 'draft' and not ctx.get('call_unlink',False): raise osv.except_osv(_('UserError'), _('You can only delete draft moves.')) return super(stock_move, self).unlink( - cr, uid, ids, context=context) + cr, uid, ids, context=ctx) def _create_lot(self, cr, uid, ids, product_id, prefix=False): """ Creates production lot