From cfab7f39f044ac48921a3de52146c5dd98154d63 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 24 Aug 2011 14:49:08 +0200 Subject: [PATCH] [IMP] account: account_report improvements. BTW, now it's called 'low level report' bzr revid: qdp-launchpad@openerp.com-20110824124908-nz0j00v7s6qka0o1 --- addons/account/__openerp__.py | 2 +- addons/account/account.py | 36 ++++++++++++++----- addons/account/account_view.xml | 31 ++++++++-------- addons/account/report/__init__.py | 2 +- ..._common.py => account_low_level_report.py} | 27 ++++++++++++-- ...ommon.rml => account_low_level_report.rml} | 10 ++++-- addons/account/wizard/__init__.py | 2 +- ..._report.py => account_low_level_report.py} | 18 ++++++++-- ....xml => account_low_level_report_view.xml} | 23 ++++++------ 9 files changed, 104 insertions(+), 47 deletions(-) rename addons/account/report/{account_report_common.py => account_low_level_report.py} (82%) rename addons/account/report/{account_report_common.rml => account_low_level_report.rml} (98%) rename addons/account/wizard/{account_report.py => account_low_level_report.py} (66%) rename addons/account/wizard/{account_report_view.xml => account_low_level_report_view.xml} (60%) diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index a7336e9eb02..812aab5b378 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -98,7 +98,7 @@ module named account_voucher. 'wizard/account_reconcile_view.xml', 'wizard/account_reconcile_partner_process_view.xml', 'wizard/account_automatic_reconcile_view.xml', - 'wizard/account_report_view.xml', + 'wizard/account_low_level_report_view.xml', 'project/wizard/project_account_analytic_line_view.xml', 'account_end_fy.xml', 'account_invoice_view.xml', diff --git a/addons/account/account.py b/addons/account/account.py index 6723cdfe2c1..a03e29e711d 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2607,30 +2607,48 @@ class account_fiscal_position_account_template(osv.osv): account_fiscal_position_account_template() -class account_report(osv.osv): - _name = "account.report" +class account_low_level_report(osv.osv): + _name = "account.low.level.report" _description = "Account Report" + def _get_balance(self, cr, uid, ids, context=None): + balance = 0.0 + for report in self.browse(cr, uid, ids, context=context): + if report.type == 'accounts': + # it's the sum of balance of the linked accounts + for a in child.account_ids: + balance += a.balance + elif report.type == 'account_report' and report.account_report_id: + # it's the amount of the linked report + balance = report.account_report_id.balance + elif report.type == 'sum': + # it's the sum of balance of the children of this account.report + for child in report.children_ids: + balance += child.balance + return balance + _columns = { - 'name': fields.char('Name', size=32, required=True), - 'parent_id': fields.many2one('account.report', 'Parent'), + 'name': fields.char('Report Name', size=128, required=True), + 'parent_id': fields.many2one('account.low.level.report', 'Parent'), + 'children_ids': fields.one2many('account.low.level.report', 'parent_id', 'Account Report'), 'sequence': fields.integer('Sequence'), 'type': fields.selection([ ('sum','Sum'), ('accounts','Accounts'), ('account_report','Account Report'), - ],'Report Type'), - 'account_ids': fields.many2many('account.account', 'account_account_report', 'report_line_id', 'account_id', 'Accounts'), + ],'Type'), + 'account_ids': fields.many2many('account.account', 'account_account_low_level_report', 'report_line_id', 'account_id', 'Accounts'), 'note': fields.text('Notes'), - 'account_report_id': fields.many2one('account.report', 'Account Report'), - 'child_ids': fields.one2many('account.report','parent_id','Children'), + 'account_report_id': fields.many2one('account.low.level.report', 'Account Report'), + 'balance': fields.function(_get_balance, 'Balance'), + 'display_detail': fields.boolean('Display the account list'), } _defaults = { 'type': 'sum', } -account_report() +account_low_level_report() # Multi charts of Accounts wizard diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 618e1c2b198..4a88d4545f2 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -2707,9 +2707,9 @@ action = self.pool.get('res.config').next(cr, uid, [], context) Account Reports --> - - account.report.form - account.report + + account.low.level.report.form + account.low.level.report form
@@ -2717,18 +2717,19 @@ action = self.pool.get('res.config').next(cr, uid, [], context) - + - + +
- - account.report.tree - account.report + + account.low.level.report.tree + account.low.level.report tree @@ -2740,8 +2741,8 @@ action = self.pool.get('res.config').next(cr, uid, [], context) - - account.report.search + + account.low.level.report.search account.report search @@ -2761,17 +2762,17 @@ action = self.pool.get('res.config').next(cr, uid, [], context) - + Account Reports ir.actions.act_window - account.report + account.low.level.report form tree,form - - + + - + account.report.hierarchy diff --git a/addons/account/report/__init__.py b/addons/account/report/__init__.py index 86c13a85582..a6763895a6c 100644 --- a/addons/account/report/__init__.py +++ b/addons/account/report/__init__.py @@ -42,7 +42,7 @@ import account_analytic_entries_report import account_balance_sheet import account_profit_loss import account_treasury_report -import account_report_common +import account_low_level_report # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/report/account_report_common.py b/addons/account/report/account_low_level_report.py similarity index 82% rename from addons/account/report/account_report_common.py rename to addons/account/report/account_low_level_report.py index e2ba966e09e..18b6386e9f5 100644 --- a/addons/account/report/account_report_common.py +++ b/addons/account/report/account_low_level_report.py @@ -29,6 +29,8 @@ class report_account_common(report_sxw.rml_parse, common_report_header): def __init__(self, cr, uid, name, context=None): super(report_account_common, self).__init__(cr, uid, name, context=context) self.localcontext.update( { + 'get_lines': self.get_lines, + 'time': time, 'get_report_details': self._get_report_details, 'get_fiscalyear': self._get_fiscalyear, @@ -90,6 +92,27 @@ class report_account_common(report_sxw.rml_parse, common_report_header): accounts = [acc for acc in rpt.account_ids if acc.level != 0] return accounts + def get_lines(self, data): + lines = [] + import pdb;pdb.set_trace() + ids2 = self.search(cr, uid, [('parent_id', 'child_of', data['form']['report_id'])], context=self.context) + for report in self.pool.get('account.low.level.report').browse(self.cr, self.uid, ids2, context=self.context): + vals = { + 'name': report.name, + 'balance': report.balance, + 'type': 'report', + } + lines.append(vals) + if report.type == 'accounts' and report.display_detail: + for account in report.account_ids: + vals = { + 'name': account.code + ' ' + account.name, + 'balance': account.balance, + 'type': 'account', + } + lines.append(vals) + return lines + def get_report_balance(self, child, child_ids, context=None): cr, uid = self.cr, self.uid report_obj = self.pool.get('account.report') @@ -109,6 +132,6 @@ class report_account_common(report_sxw.rml_parse, common_report_header): balance += a.balance return balance -report_sxw.report_sxw('report.accounting.report', 'account.account', - 'addons/account/report/account_report_common.rml', parser=report_account_common, header='internal') +report_sxw.report_sxw('report.account.low.level.report', 'account.low.level.report', + 'addons/account/report/account_low_level_report.rml', parser=report_account_common, header='internal') diff --git a/addons/account/report/account_report_common.rml b/addons/account/report/account_low_level_report.rml similarity index 98% rename from addons/account/report/account_report_common.rml rename to addons/account/report/account_low_level_report.rml index 9c9132a2911..3d241997417 100644 --- a/addons/account/report/account_report_common.rml +++ b/addons/account/report/account_low_level_report.rml @@ -216,7 +216,7 @@ - [[ repeatIn(get_report_details(data),'r') ]] + @@ -247,6 +247,11 @@ + [[ repeatIn(get_lines(r['id'], data), 'a') ]] + [[a.name]] + [[a.balance]] + + diff --git a/addons/account/wizard/__init__.py b/addons/account/wizard/__init__.py index f6090539b73..fdd7539d74f 100644 --- a/addons/account/wizard/__init__.py +++ b/addons/account/wizard/__init__.py @@ -47,7 +47,7 @@ import account_open_closed_fiscalyear import account_invoice_state import account_chart import account_tax_chart -import account_report +import account_low_level_report #TODO: remove this file no moe used # also remove related view fiel diff --git a/addons/account/wizard/account_report.py b/addons/account/wizard/account_low_level_report.py similarity index 66% rename from addons/account/wizard/account_report.py rename to addons/account/wizard/account_low_level_report.py index d738831dd0c..4b168fcd412 100644 --- a/addons/account/wizard/account_report.py +++ b/addons/account/wizard/account_low_level_report.py @@ -29,10 +29,22 @@ class accounting_report(osv.osv_memory): _columns = { 'enable_filter': fields.boolean('Enable Comparison'), 'account_details': fields.boolean('Details by Account', help="Print Report with the account details."), - 'account_report_id': fields.many2one('account.report', 'Account Report', required=True), - 'label_filter': fields.char('Filters Label', size=32, help="This label will be displayed on report to show the balance computed for the given comparison filter."), + 'account_report_id': fields.many2one('account.report', 'Account Reports', required=True), + 'label_filter': fields.char('Column Label', size=32, help="This label will be displayed on report to show the balance computed for the given comparison filter."), + 'fiscalyear_id_cmp': fields.many2one('account.fiscalyear', 'Fiscal Year', help='Keep empty for all open fiscal year'), + 'filter_cmp': fields.selection([('filter_no', 'No Filters'), ('filter_date', 'Date'), ('filter_period', 'Periods')], "Filter by", required=True), + 'period_from_cmp': fields.many2one('account.period', 'Start Period'), + 'period_to_cmp': fields.many2one('account.period', 'End Period'), + 'date_from_cmp': fields.date("Start Date"), + 'date_to_cmp': fields.date("End Date"), + } + + _defaults = { + 'filter_cmp': 'filter_no', + 'target_move': 'posted', } def _print_report(self, cr, uid, ids, data, context=None): + #TODO: must read new fields, for comporison. Maybe better to do it at the end of check method data['form'].update(self.read(cr, uid, ids, ['account_report_id', 'enable_filter', 'account_details', 'label_filter'], context=context)[0]) return { 'type': 'ir.actions.report.xml', @@ -42,4 +54,4 @@ class accounting_report(osv.osv_memory): accounting_report() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/wizard/account_report_view.xml b/addons/account/wizard/account_low_level_report_view.xml similarity index 60% rename from addons/account/wizard/account_report_view.xml rename to addons/account/wizard/account_low_level_report_view.xml index 647ed54cf7a..e48ae5bb1f2 100644 --- a/addons/account/wizard/account_report_view.xml +++ b/addons/account/wizard/account_low_level_report_view.xml @@ -8,25 +8,22 @@ form - - - + - - - - - - + + + + + - - + + - - + +