diff --git a/addons/account/account.py b/addons/account/account.py index f6dd36c01fc..b3b6016fc74 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -340,9 +340,11 @@ class account_account(osv.osv): accounts = self.browse(cr, uid, ids, context=context) for account in accounts: level = 0 - if account.parent_id: - obj = self.browse(cr, uid, account.parent_id.id) - level = obj.level + 1 + parent_id = account.parent_id + while parent_id: + obj = self.browse(cr, uid, parent_id.id) + level += 1 + parent_id = obj.parent_id res[account.id] = level return res @@ -390,7 +392,10 @@ class account_account(osv.osv): 'manage this. So if you import from another software system you may have to use the rate at date. ' \ 'Incoming transactions always use the rate at date.', \ required=True), - 'level': fields.function(_get_level, string='Level', method=True, store=True, type='integer'), + 'level': fields.function(_get_level, string='Level', method=True, type='integer', + store={ + 'account.account': (lambda self, cr, uid, ids, c={}: ids, ['parent_id'], 10), + }), } _defaults = {