From 74adf124cdf4650cdc19c7170e8019e4cca5d742 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 30 Dec 2011 12:44:10 +0100 Subject: [PATCH] move account_financial_report to it's own file, create separate action for PL BS. bzr revid: al@openerp.com-20111230114410-73kvxxvl6vauj6tu --- addons/account/__init__.py | 1 + addons/account/__openerp__.py | 2 +- addons/account/account.py | 92 ------------- addons/account/account_financial_report.py | 125 ++++++++++++++++++ ....xml => account_financial_report_data.xml} | 0 .../wizard/account_financial_report.py | 1 + .../wizard/account_financial_report_view.xml | 56 ++++---- 7 files changed, 157 insertions(+), 120 deletions(-) create mode 100644 addons/account/account_financial_report.py rename addons/account/{data/data_financial_report.xml => account_financial_report_data.xml} (100%) diff --git a/addons/account/__init__.py b/addons/account/__init__.py index a243b94c2da..98f7a7d5134 100644 --- a/addons/account/__init__.py +++ b/addons/account/__init__.py @@ -29,6 +29,7 @@ import account_bank import account_cash_statement import account_move_line import account_analytic_line +import account_financial_report import wizard import report import product diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py index e01dbc70f07..0cd5231ef26 100644 --- a/addons/account/__openerp__.py +++ b/addons/account/__openerp__.py @@ -69,6 +69,7 @@ module named account_voucher. 'wizard/account_period_close_view.xml', 'account_view.xml', 'account_report.xml', + 'account_financial_report_data.xml', 'wizard/account_report_common_view.xml', 'wizard/account_invoice_refund_view.xml', 'wizard/account_fiscalyear_close_state.xml', @@ -104,7 +105,6 @@ 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 f259f682ba1..dc962545599 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2923,98 +2923,6 @@ class account_fiscal_position_account_template(osv.osv): account_fiscal_position_account_template() -# --------------------------------------------------------- -# Account Financial Report -# --------------------------------------------------------- - -class account_financial_report(osv.osv): - _name = "account.financial.report" - _description = "Account Report" - - def _get_level(self, cr, uid, ids, field_name, arg, context=None): - res = {} - for report in self.browse(cr, uid, ids, context=context): - level = 0 - if report.parent_id: - level = report.parent_id.level + 1 - res[report.id] = level - return res - - def _get_children_by_order(self, cr, uid, ids, context=None): - res = [] - for id in ids: - res.append(id) - ids2 = self.search(cr, uid, [('parent_id', '=', id)], order='sequence ASC', context=context) - res += self._get_children_by_order(cr, uid, ids2, context=context) - return res - - def _get_balance(self, cr, uid, ids, name, args, context=None): - account_obj = self.pool.get('account.account') - res = {} - res_all = {} - for report in self.browse(cr, uid, ids, context=context): - balance = 0.0 - if report.id in res_all: - balance = res_all[report.id] - elif report.type == 'accounts': - # it's the sum of balance of the linked accounts - for a in report.account_ids: - balance += a.balance - elif report.type == 'account_type': - # it's the sum of balance of the leaf accounts with such an account type - report_types = [x.id for x in report.account_type_ids] - account_ids = account_obj.search(cr, uid, [('user_type','in', report_types), ('type','!=','view')], context=context) - for a in account_obj.browse(cr, uid, account_ids, context=context): - balance += a.balance - elif report.type == 'account_report' and report.account_report_id: - # it's the amount of the linked report - res2 = self._get_balance(cr, uid, [report.account_report_id.id], 'balance', False, context=context) - res_all.update(res2) - for key, value in res2.items(): - balance += value - elif report.type == 'sum': - # it's the sum of balance of the children of this account.report - #for child in report.children_ids: - res2 = self._get_balance(cr, uid, [rec.id for rec in report.children_ids], 'balance', False, context=context) - res_all.update(res2) - for key, value in res2.items(): - balance += value - res[report.id] = balance - res_all[report.id] = balance - return res - - _columns = { - 'name': fields.char('Report Name', size=128, required=True, translate=True), - 'parent_id': fields.many2one('account.financial.report', 'Parent'), - 'children_ids': fields.one2many('account.financial.report', 'parent_id', 'Account Report'), - 'sequence': fields.integer('Sequence'), - 'balance': fields.function(_get_balance, 'Balance'), - 'level': fields.function(_get_level, string='Level', store=True, type='integer'), - 'type': fields.selection([ - ('sum','View'), - ('accounts','Accounts'), - ('account_type','Account Type'), - ('account_report','Report Value'), - ],'Type'), - 'account_ids': fields.many2many('account.account', 'account_account_financial_report', 'report_line_id', 'account_id', 'Accounts'), - 'display_detail': fields.selection([ - ('no_detail','No detail'), - ('detail_flat','Display children flat'), - ('detail_with_hierarchy','Display children with hierarchy') - ], '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.'), - } - - _defaults = { - 'type': 'sum', - 'display_detail': 'detail_flat', - 'sign': 1, - } - -account_financial_report() - # --------------------------------------------------------- # Account generation from template wizards # --------------------------------------------------------- diff --git a/addons/account/account_financial_report.py b/addons/account/account_financial_report.py new file mode 100644 index 00000000000..4ee8ac3d74b --- /dev/null +++ b/addons/account/account_financial_report.py @@ -0,0 +1,125 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import time +from datetime import datetime +from dateutil.relativedelta import relativedelta +from operator import itemgetter + +import netsvc +import pooler +from osv import fields, osv +import decimal_precision as dp +from tools.translate import _ + +# --------------------------------------------------------- +# Account Financial Report +# --------------------------------------------------------- + +class account_financial_report(osv.osv): + _name = "account.financial.report" + _description = "Account Report" + + def _get_level(self, cr, uid, ids, field_name, arg, context=None): + res = {} + for report in self.browse(cr, uid, ids, context=context): + level = 0 + if report.parent_id: + level = report.parent_id.level + 1 + res[report.id] = level + return res + + def _get_children_by_order(self, cr, uid, ids, context=None): + res = [] + for id in ids: + res.append(id) + ids2 = self.search(cr, uid, [('parent_id', '=', id)], order='sequence ASC', context=context) + res += self._get_children_by_order(cr, uid, ids2, context=context) + return res + + def _get_balance(self, cr, uid, ids, name, args, context=None): + account_obj = self.pool.get('account.account') + res = {} + res_all = {} + for report in self.browse(cr, uid, ids, context=context): + balance = 0.0 + if report.id in res_all: + balance = res_all[report.id] + elif report.type == 'accounts': + # it's the sum of balance of the linked accounts + for a in report.account_ids: + balance += a.balance + elif report.type == 'account_type': + # it's the sum of balance of the leaf accounts with such an account type + report_types = [x.id for x in report.account_type_ids] + account_ids = account_obj.search(cr, uid, [('user_type','in', report_types), ('type','!=','view')], context=context) + for a in account_obj.browse(cr, uid, account_ids, context=context): + balance += a.balance + elif report.type == 'account_report' and report.account_report_id: + # it's the amount of the linked report + res2 = self._get_balance(cr, uid, [report.account_report_id.id], 'balance', False, context=context) + res_all.update(res2) + for key, value in res2.items(): + balance += value + elif report.type == 'sum': + # it's the sum of balance of the children of this account.report + #for child in report.children_ids: + res2 = self._get_balance(cr, uid, [rec.id for rec in report.children_ids], 'balance', False, context=context) + res_all.update(res2) + for key, value in res2.items(): + balance += value + res[report.id] = balance + res_all[report.id] = balance + return res + + _columns = { + 'name': fields.char('Report Name', size=128, required=True, translate=True), + 'parent_id': fields.many2one('account.financial.report', 'Parent'), + 'children_ids': fields.one2many('account.financial.report', 'parent_id', 'Account Report'), + 'sequence': fields.integer('Sequence'), + 'balance': fields.function(_get_balance, 'Balance'), + 'level': fields.function(_get_level, string='Level', store=True, type='integer'), + 'type': fields.selection([ + ('sum','View'), + ('accounts','Accounts'), + ('account_type','Account Type'), + ('account_report','Report Value'), + ],'Type'), + 'account_ids': fields.many2many('account.account', 'account_account_financial_report', 'report_line_id', 'account_id', 'Accounts'), + 'display_detail': fields.selection([ + ('no_detail','No detail'), + ('detail_flat','Display children flat'), + ('detail_with_hierarchy','Display children with hierarchy') + ], '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.'), + } + + _defaults = { + 'type': 'sum', + 'display_detail': 'detail_flat', + 'sign': 1, + } + +account_financial_report() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/data/data_financial_report.xml b/addons/account/account_financial_report_data.xml similarity index 100% rename from addons/account/data/data_financial_report.xml rename to addons/account/account_financial_report_data.xml diff --git a/addons/account/wizard/account_financial_report.py b/addons/account/wizard/account_financial_report.py index 92c623a9524..e0a55374f29 100644 --- a/addons/account/wizard/account_financial_report.py +++ b/addons/account/wizard/account_financial_report.py @@ -39,6 +39,7 @@ class accounting_report(osv.osv_memory): } def _get_account_report(self, cr, uid, context=None): + # TODO deprecate this it doesnt work in web menu_obj = self.pool.get('ir.ui.menu') report_obj = self.pool.get('account.financial.report') report_ids = [] diff --git a/addons/account/wizard/account_financial_report_view.xml b/addons/account/wizard/account_financial_report_view.xml index 4be6fb5e95c..719294fe247 100644 --- a/addons/account/wizard/account_financial_report_view.xml +++ b/addons/account/wizard/account_financial_report_view.xml @@ -30,6 +30,33 @@ + + + + Financial Reports + accounting.report + ir.actions.act_window + form + form + + new + + + + + + Financial Reports + accounting.report + ir.actions.act_window + form + form + + new + + + + + Financial Reports accounting.report @@ -38,33 +65,8 @@ form new - - - - - - - - - + +