From f21eed3a7be713a97a8d304555d7aa77e7504776 Mon Sep 17 00:00:00 2001 From: "VRA(OpenERP)" <> Date: Mon, 14 Dec 2009 12:48:03 +0530 Subject: [PATCH] [FIX] Account : Accounts containing moves cannot be deleted lp bug: https://launchpad.net/bugs/438690 fixed bzr revid: jvo@tinyerp.com-20091214071803-gasvptqio1ssheo6 --- addons/account/account.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 0948092a0b3..00d5072302f 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -411,15 +411,27 @@ class account_account(osv.osv): default['child_parent_ids'] = False return super(account_account, self).copy(cr, uid, id, default, context=context) + def _check_moves(self, cr, uid, ids, method, context): + line_obj = self.pool.get('account.move.line') + account_ids = self.search(cr, uid, [('id', 'child_of', ids)]) + if line_obj.search(cr, uid, [('account_id', 'in', account_ids)]): + if method == 'write': + raise osv.except_osv(_('Error !'), _('You cannot deactivate an account that contains account moves.')) + elif method == 'unlink': + raise osv.except_osv(_('Error !'), _('You cannot remove an account which has account entries!. ')) + return True + def write(self, cr, uid, ids, vals, context=None): if not context: context = {} if 'active' in vals and not vals['active']: - line_obj = self.pool.get('account.move.line') - account_ids = self.search(cr, uid, [('id', 'child_of', ids)]) - if line_obj.search(cr, uid, [('account_id', 'in', account_ids)]): - raise osv.except_osv(_('Error !'), _('You can not deactivate an account that contains account moves.')) + self._check_moves(cr, uid, ids, "write", context) return super(account_account, self).write(cr, uid, ids, vals, context=context) + + def unlink(self, cr, uid, ids, context={}): + self._check_moves(cr, uid, ids, "unlink", context) + return super(account_account, self).unlink(cr, uid, ids, context) + account_account() class account_journal_view(osv.osv):