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
This commit is contained in:
ced 2007-07-26 08:31:22 +00:00
parent 9afe3f7a36
commit 659c467b37
2 changed files with 24 additions and 3 deletions

View File

@ -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):

View File

@ -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