From 659c467b376f6c2529e612e32a897ea2a2b7a2fd Mon Sep 17 00:00:00 2001 From: ced <> Date: Thu, 26 Jul 2007 08:31:22 +0000 Subject: [PATCH] account: add constraint on account inactive - can not deactivate an account that have entry lines - can not create/update an entry on account deactivate bzr revid: ced-e3301b0dd80ea8042732771f549c51531d4726b3 --- addons/account/account.py | 9 +++++++++ addons/account/account_move_line.py | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 79ac233049b..7068693b970 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -312,6 +312,15 @@ class account_account(osv.osv): else: default['child_id'] = False return super(account_account, self).copy(cr, uid, id, default, context=context) + + 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') + if line_obj.search(cr, uid, [('account_id', 'in', ids)]): + raise osv.except_osv('Error!', 'You can not deactivate a account with entry lines!') + super(account_account, self).write(cr, uid, ids, vals, context=context) account_account() class account_journal_view(osv.osv): diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index cf075e81237..694978e9d34 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -401,7 +401,13 @@ class account_move_line(osv.osv): self.pool.get('account.move').validate(cr, uid, [line.move_id.id], context=context) return result - def write(self, cr, uid, ids, vals, context={}, check=True, update_check=True): + def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True): + if not context: + context={} + account_obj = self.pool.get('account.account') + + if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']: + raise osv.except_osv('Bad account!', 'You can not use an inactive account!') if update_check: self._update_check(cr, uid, ids, context) result = super(osv.osv, self).write(cr, uid, ids, vals, context) @@ -442,7 +448,13 @@ class account_move_line(osv.osv): done[t] = True return True - def create(self, cr, uid, vals, context={}, check=True): + def create(self, cr, uid, vals, context=None, check=True): + if not context: + context={} + account_obj = self.pool.get('account.account') + + if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']: + raise osv.except_osv('Bad account!', 'You can not use an inactive account!') if 'journal_id' in vals and 'journal_id' not in context: context['journal_id'] = vals['journal_id'] if 'period_id' in vals and 'period_id' not in context: @@ -477,7 +489,7 @@ class account_move_line(osv.osv): ok = not (journal.type_control_ids or journal.account_control_ids) if ('account_id' in vals) and journal.type_control_ids: - type = self.pool.get('account.account').browse(cr, uid, vals['account_id']).type + type = account_obj.browse(cr, uid, vals['account_id']).type for t in journal.type_control_ids: if type==t.code: ok = True