From b430f760ae82b5aee42522a4560d9558d87a0715 Mon Sep 17 00:00:00 2001 From: "aag (OpenERP)" Date: Mon, 3 Jan 2011 16:19:33 +0530 Subject: [PATCH 1/2] [FIX] stock:Cancelling periodic inventory is now cancel account move lp bug: https://launchpad.net/bugs/458901 fixed bzr revid: aag@tinyerp.co.in-20110103104933-qip7fqkxbl5gyaar --- addons/stock/stock.py | 13 ++++++++++++- addons/stock/stock_view.xml | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 88924105c16..42eeb615f84 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2573,8 +2573,19 @@ class stock_inventory(osv.osv): """ Cancels the stock move and change inventory state to draft. @return: True """ + move_obj = self.pool.get('stock.move') + account_move_obj = self.pool.get('account.move') for inv in self.browse(cr, uid, ids, context=context): - self.pool.get('stock.move').action_cancel(cr, uid, [x.id for x in inv.move_ids], context) + move_obj.action_cancel(cr, uid, [x.id for x in inv.move_ids], context) + for move in inv.move_ids: + account_move_ids = account_move_obj.search(cr, uid, [('name','=',move.name)]) + if account_move_ids: + account_move_data_l = account_move_obj.read(cr, uid, account_move_ids, ['state']) + for account_move in account_move_data_l: + if account_move['state'] == 'posted': + raise osv.except_osv(_('UserError'), + _('You can not cancel inventory which has any account move with posted state.')) + account_move_obj.unlink(cr, uid, [account_move['id']]) self.write(cr, uid, [inv.id], {'state': 'draft'}) return True diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index 86135e8f13d..95e97161e5e 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -170,8 +170,8 @@ - -