From be576987957235da240182f2ee9fd77b20939fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 23 May 2008 12:32:10 +0200 Subject: [PATCH] Add display balance on account type Remove account_type from account type --- account.py | 37 ++++++++++++++++++++++++------------- account.xml | 27 ++++++++++++++++----------- fiscalyear.py | 11 ++++++----- 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/account.py b/account.py index 751beaa20f..4584492072 100644 --- a/account.py +++ b/account.py @@ -30,19 +30,21 @@ class Type(OSV): childs = fields.One2Many('account.account.type', 'parent', 'Childs') sequence = fields.Integer('Sequence', required=True, help='Use to order the account type') - account_type = fields.Boolean('Account Type', - help='Can be use as type for account') #TODO fix digits depend of the currency amount = fields.Function('get_amount', digits=(16, 2), string='Amount') balance_sheet = fields.Boolean('Balance Sheet') income_statement = fields.Boolean('Income Statement') + display_balance = fields.Selection([ + ('debit-credit', 'Debit - Credit'), + ('credit-debit', 'Credit - Debit'), + ], 'Display Balance', required=True) def __init__(self): super(Type, self).__init__() self._order.insert(0, ('sequence', 'ASC')) - def default_account_type(self, cursor, user, context=None): - return False + def default_code(self, cursor, user, context=None): + return 'view' def default_balance_sheet(self, cursor, user, context=None): return False @@ -50,6 +52,9 @@ class Type(OSV): def default_income_statement(self, cursor, user, context=None): return False + def default_display_balance(self, cursor, user, context=None): + return 'debit-credit' + def get_amount(self, cursor, user, ids, name, arg, context=None): company_obj = self.pool.get('company.company') account_obj = self.pool.get('account.account') @@ -81,14 +86,18 @@ class Type(OSV): context=context): type_sum[account.type.id] += currency_obj.round(cursor, user, company.currency, account.debit - account.credit) - for type_id in ids: + + types = self.browse(cursor, user, ids, context=context) + for type in types: child_ids = self.search(cursor, user, [ - ('parent', 'child_of', [type_id]), + ('parent', 'child_of', [type.id]), ], context=context) for child_id in child_ids: - res[type_id] += type_sum[child_id] - res[type_id] = currency_obj.round(cursor, user, - company.currency, res[type_id]) + res[type.id] += type_sum[child_id] + res[type.id] = currency_obj.round(cursor, user, + company.currency, res[type.id]) + if type.display_balance == 'credit-debit': + res[type.id] = - res[type.id] return res Type() @@ -105,8 +114,7 @@ class AccountTemplate(OSV): complete_name = fields.Function('get_complete_name', type='char', string='Name') code = fields.Char('Code', size=None, select=1) - type = fields.Many2One('account.account.type', 'Type', required=True, - domain=[('account_type', '=', True)]) + type = fields.Many2One('account.account.type', 'Type', required=True) parents = fields.Many2Many('account.account.template', 'account_account_template_rel', 'child', 'parent', 'Parents') childs = fields.Many2Many('account.account.template', @@ -212,8 +220,7 @@ class Account(OSV): second_currency = fields.Many2One('currency.currency', 'Secondary currency', help='Force all moves for this account \n' \ 'to have this secondary currency.') - type = fields.Many2One('account.account.type', 'Type', required=True, - domain=[('account_type', '=', True)]) + type = fields.Many2One('account.account.type', 'Type', required=True) parents = fields.Many2Many('account.account', 'account_account_rel', 'child', 'parent', 'Parents') childs = fields.Many2Many('account.account', 'account_account_rel', @@ -341,10 +348,12 @@ class Account(OSV): account2company = {} id2company = {} + id2account = {} accounts = self.browse(cursor, user, all_ids, context=context) for account in accounts: account2company[account.id] = account.company.id id2company[account.company.id] = account.company + id2account[account.id] = account for account_id in ids: res.setdefault(account_id, Decimal('0.0')) @@ -361,6 +370,8 @@ class Account(OSV): to_currency, round=True, context=context) res[account_id] = currency_obj.round(cursor, user, to_currency, res[account_id]) + if id2account[account_id].type.display_balance == 'credit-debit': + res[account_id] = - res[account_id] return res def get_credit_debit(self, cursor, user, ids, name, arg, context=None): diff --git a/account.xml b/account.xml index 078db86922..b3e3598085 100644 --- a/account.xml +++ b/account.xml @@ -40,14 +40,15 @@