From d26f77ca1d49d2c9a624adc25565bcda5a23c4c5 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 9 Dec 2011 16:18:47 +0100 Subject: [PATCH] [IMP] account: set report_type field of account_account_type as fields.function + set the main account types as data (instead of demo data) (and did the same for financial reports BS & PL) bzr revid: qdp-launchpad@openerp.com-20111209151847-u63ur1o7wt017885 --- addons/account/__openerp__.py | 1 + addons/account/account.py | 60 ++++-- addons/account/configurable_account_chart.xml | 179 ++---------------- addons/account/data/data_account_type.xml | 4 + addons/account/demo/account_minimal.xml | 174 ++++------------- 5 files changed, 102 insertions(+), 316 deletions(-) diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index 12df75b98c7..ea6142b0c89 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -104,6 +104,7 @@ module named account_voucher. 'account_invoice_view.xml', 'partner_view.xml', 'data/account_data.xml', + 'data/data_financial_report.xml', 'data/data_account_type.xml', 'account_invoice_workflow.xml', 'project/project_view.xml', diff --git a/addons/account/account.py b/addons/account/account.py index 8e9bdbc4866..d32fb5879ab 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -130,20 +130,43 @@ account_payment_term_line() class account_account_type(osv.osv): _name = "account.account.type" _description = "Account Type" - - def _get_report_type(self, cr, uid, context=None): - report_obj = self.pool.get('account.financial.report') - report_ids = report_obj.search(cr, uid, [], context=context) - report_type = [('none','/')] - for report in report_obj.browse(cr, uid, report_ids, context=context): - type = report.account_type_ids and report.account_type_ids[0] or False - if type: - if type.code in ('income', 'expense'): - report_name = 'Profit & Loss ('+type.code+' accounts)' - elif type.code in ('asset','liability'): - report_name = 'Balance Sheet ('+type.code+' accounts)' - report_type.append((type.code, report_name)) - return report_type + + def _get_current_report_type(self, cr, uid, ids, name, arg, context=None): + obj_data = self.pool.get('ir.model.data') + obj_financial_report = self.pool.get('account.financial.report') + res = {} + financial_report_ref = { + 'asset': obj_financial_report.browse(cr, uid, obj_data.get_object_reference(cr, uid, 'account','account_financial_report_assets0')[1], context=context), + 'liability': obj_financial_report.browse(cr, uid, obj_data.get_object_reference(cr, uid, 'account','account_financial_report_liability0')[1], context=context), + 'income': obj_financial_report.browse(cr, uid, obj_data.get_object_reference(cr, uid, 'account','account_financial_report_income0')[1], context=context), + 'expense': obj_financial_report.browse(cr, uid, obj_data.get_object_reference(cr, uid, 'account','account_financial_report_expense0')[1], context=context), + } + for record in self.browse(cr, uid, ids, context=context): + res[record.id] = 'none' + for key, financial_report in financial_report_ref.items(): + list_ids = [x.id for x in financial_report.account_type_ids] + if record.id in list_ids: + res[record.id] = key + return res + + def _save_report_type(self, cr, uid, account_type_id, field_name, field_value, arg, context=None): + import pdb;pdb.set_trace() + obj_data = self.pool.get('ir.model.data') + obj_financial_report = self.pool.get('account.financial.report') + #unlink if it exists somewhere in the financial reports related to BS or PL + financial_report_ref = { + 'asset': obj_financial_report.browse(cr, uid, obj_data.get_object_reference(cr, uid, 'account','account_financial_report_assets0')[1], context=context), + 'liability': obj_financial_report.browse(cr, uid, obj_data.get_object_reference(cr, uid, 'account','account_financial_report_liability0')[1], context=context), + 'income': obj_financial_report.browse(cr, uid, obj_data.get_object_reference(cr, uid, 'account','account_financial_report_income0')[1], context=context), + 'expense': obj_financial_report.browse(cr, uid, obj_data.get_object_reference(cr, uid, 'account','account_financial_report_expense0')[1], context=context), + } + for key, financial_report in financial_report_ref.items(): + list_ids = [x.id for x in financial_report.account_type_ids] + if account_type_id in list_ids: + obj_financial_report.write(cr, uid, [financial_report.id], {'account_type_ids': [(3, account_type_id)]}) + #write it in the good place + if field_value != 'none': + return obj_financial_report.write(cr, uid, [financial_report_ref[field_value].id], {'account_type_ids': [(4, account_type_id)]}) _columns = { 'name': fields.char('Account Type', size=64, required=True, translate=True), @@ -154,7 +177,12 @@ class account_account_type(osv.osv): 'Balance' will generally be used for cash accounts. 'Detail' will copy each existing journal item of the previous year, even the reconciled ones. 'Unreconciled' will copy only the journal items that were unreconciled on the first day of the new fiscal year."""), - 'report_type': fields.selection(_get_report_type, 'P&L / BS Category', help="This field is used to generate legal reports: profit and loss, balance sheet.", required=True), + 'report_type': fields.function(_get_current_report_type, fnct_inv=_save_report_type, type='selection', string='P&L / BS Category', + selection= [('none','/'), + ('income', _('Profit & Loss (Income account)')), + ('expense', _('Profit & Loss (Expense account)')), + ('asset', _('Balance Sheet (Asset account)')), + ('liability', _('Balance Sheet (Liability account)'))], help="This field is used to generate legal reports: profit and loss, balance sheet.", required=True), 'note': fields.text('Description'), } _defaults = { @@ -2975,7 +3003,7 @@ class account_financial_report(osv.osv): ], 'Display details'), 'account_report_id': fields.many2one('account.financial.report', 'Report Value'), 'account_type_ids': fields.many2many('account.account.type', 'account_account_financial_report_type', 'report_id', 'account_type_id', 'Account Types'), - 'sign': fields.selection([(-1, 'Reverse balance sign'), (1, 'Preserve balance sign')], 'Sign on Reports', required=True, help='For accounts that are typically more debited than credited and that you would like to print as negative amounts in your reports, you should reverse the sign of the balance; e.g.: Expense account. The same applies for accounts that are typically more credited than debited and that you would like to print as positive amounts in your reports; e.g.: Income account.'), + 'sign': fields.selection([(-1, 'Reverse balance sign'), (1, 'Preserve balance sign')], 'Sign on Reports', required=True, help='For accounts that are typically more debited than credited and that you would like to print as negative amounts in your reports, you should reverse the sign of the balance; e.g.: Expense account. The same applies for accounts that are typically more credited than debited and that you would like to print as positive amounts in your reports; e.g.: Income account.'), } _defaults = { diff --git a/addons/account/configurable_account_chart.xml b/addons/account/configurable_account_chart.xml index 8486e2fb008..fa0aa3459dd 100644 --- a/addons/account/configurable_account_chart.xml +++ b/addons/account/configurable_account_chart.xml @@ -1,181 +1,44 @@ - - Receivable - receivable - unreconciled - - - - Payable - payable - unreconciled - - - - View - view - none - - Income View view + income Expense View expense + expense Asset View asset + asset Liability View liability + liability - - - Income - income - none - - - - Expense - expense - none - - Tax tax unreconciled + expense - - - Cash - cash - balance - - - - Liability - liability - balance - - - - Asset - asset - balance - - Equity equity balance - - - - Bank - bank - balance + liability Check check balance - - - - - Balance Sheet - sum - - - Assets - - - detail_with_hierarchy - account_type - - - Liability - - - detail_with_hierarchy - account_type - - - - Profit and Loss - sum - - - Income - - - detail_with_hierarchy - account_type - - - Expense - - - detail_with_hierarchy - account_type - - - - - - asset - - - liability - - - income - - - expense - - - asset - - - liability - - - liability - - - asset - - - income - - - expense - - - asset - - - liability - - - expense - - asset - - asset - - @@ -183,7 +46,7 @@ Configurable Account Chart view - + @@ -193,7 +56,7 @@ Balance Sheet view - + @@ -233,7 +96,7 @@ Purchased Stocks other - + @@ -242,7 +105,7 @@ receivable - + @@ -250,7 +113,7 @@ Tax Paid other - + @@ -266,7 +129,7 @@ Opening Income Account other - + @@ -283,7 +146,7 @@ payable - + @@ -291,7 +154,7 @@ Tax Received other - + @@ -300,7 +163,7 @@ other - + @@ -308,7 +171,7 @@ Opening Expense Account other - + @@ -318,7 +181,7 @@ Profit and Loss view - + @@ -334,7 +197,7 @@ Product Sales other - + @@ -350,7 +213,7 @@ Cost of Goods Sold other - + @@ -366,7 +229,7 @@ Expenses other - + @@ -374,7 +237,7 @@ Salary Expenses other - + diff --git a/addons/account/data/data_account_type.xml b/addons/account/data/data_account_type.xml index ebed0ebb5de..590357ef080 100644 --- a/addons/account/data/data_account_type.xml +++ b/addons/account/data/data_account_type.xml @@ -30,21 +30,25 @@ Asset asset balance + asset Liability liability balance + liability Income income none + income Expense expense none + expense diff --git a/addons/account/demo/account_minimal.xml b/addons/account/demo/account_minimal.xml index f11a72ce7b4..baa94450f02 100644 --- a/addons/account/demo/account_minimal.xml +++ b/addons/account/demo/account_minimal.xml @@ -5,50 +5,11 @@ Account Type --> - - View - view - none - - - Asset - asset - balance - - - Receivable - receivable - unreconciled - - - Liability - liability - balance - - - Payable - payable - unreconciled - - - Income - income - none - - - Expense - expense - none - Equity equity balance - - - Cash - cash - balance + liability @@ -70,14 +31,14 @@ Balance Sheet - (test) view - + Assets - (test) X10 view - + @@ -87,7 +48,7 @@ Fixed Assets - (test) view - + @@ -95,7 +56,7 @@ Fixed Asset Account - (test) other - + @@ -103,7 +64,7 @@ Net Current Assets - (test) view - + @@ -111,7 +72,7 @@ Current Assets - (test) view - + @@ -119,7 +80,7 @@ Purchased Stocks - (test) other - + @@ -128,7 +89,7 @@ receivable - + @@ -136,7 +97,7 @@ Output VAT - (test) other - + @@ -144,7 +105,7 @@ Bank Current Account - (test) liquidity - + @@ -152,7 +113,7 @@ Cash - (test) liquidity - + @@ -160,14 +121,14 @@ Opening Income - (test) other - + Liabilities - (test) X11 view - + @@ -177,7 +138,7 @@ Current Liabilities - (test) view - + @@ -186,7 +147,7 @@ payable - + @@ -194,7 +155,7 @@ Input VAT - (test) other - + @@ -202,7 +163,7 @@ Reserve and Profit/Loss - (test) other - + @@ -210,7 +171,7 @@ Opening Expense - (test) other - + @@ -220,14 +181,14 @@ Profit and Loss - (test) view - + Income - (test) X20 view - + @@ -236,7 +197,7 @@ Foreign Exchange Gain - (test) X201 other - + @@ -246,7 +207,7 @@ Revenue - (test) view - + @@ -254,14 +215,14 @@ Product Sales - (test) other - + Expense - (test) X21 view - + @@ -272,7 +233,7 @@ Cost of Sales - (test) view - + @@ -280,7 +241,7 @@ Cost of Goods Sold - (test) other - + @@ -288,7 +249,7 @@ Overheads - (test) view - + @@ -296,14 +257,14 @@ Expenses - (test) other - + Foreign Exchange Loss - (test) X2111 other - + @@ -313,7 +274,7 @@ Salary Expenses - (test) other - + @@ -463,76 +424,5 @@ - - - - Balance Sheet - sum - - - Assets - - - detail_with_hierarchy - account_type - - - Liability - - - detail_with_hierarchy - account_type - - - - Profit and Loss - sum - - - Income - - - detail_with_hierarchy - account_type - - - Expense - - - detail_with_hierarchy - account_type - - - - - - asset - - - liability - - - income - - - expense - - - asset - - - liability - - - liability - - - asset - -