From a3052f3ab6b4d0d0b10d35c0741ded4e94d8ae4d Mon Sep 17 00:00:00 2001 From: ced <> Date: Fri, 5 Oct 2007 13:30:46 +0000 Subject: [PATCH] Improve deactivate account - don't deactivate account if there is at least one child that have an account move bzr revid: ced-8b7a5bd5ade1647daa12998eed60e7af36bb3694 --- addons/account/account.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/account/account.py b/addons/account/account.py index 8d6bce5d3f3..9e1f92dffe5 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -180,6 +180,7 @@ class account_account(osv.osv): return dict(map(lambda x: (x, 0.0), ids)) ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) + ids2 = {}.fromkeys(ids + ids2).keys() acc_set = ",".join(map(str, ids2)) query = self.pool.get('account.move.line')._query_get(cr, uid, context=context) cr.execute(("SELECT a.id, COALESCE(SUM((l.debit-l.credit)),0) FROM account_account a LEFT JOIN account_move_line l ON (a.id=l.account_id) WHERE a.id IN (%s) and "+query+" GROUP BY a.id") % (acc_set, )) @@ -190,6 +191,7 @@ class account_account(osv.osv): resc = dict(cr.fetchall()) cr.execute("SELECT id, currency_id FROM res_company") rescur = dict(cr.fetchall()) + for id in ids: ids3 = self.search(cr, uid, [('parent_id', 'child_of', [id])]) to_currency_id = rescur[resc[id]] @@ -325,7 +327,8 @@ class account_account(osv.osv): 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)]): + account_ids = self.search(cr, uid, [('parent_id', 'child_of', ids)]) + if line_obj.search(cr, uid, [('account_id', 'in', account_ids)]): vals=vals.copy() del vals['active'] return super(account_account, self).write(cr, uid, ids, vals, context=context)