move account_financial_report to it's own file, create separate action for PL BS.
bzr revid: al@openerp.com-20111230114410-73kvxxvl6vauj6tu
This commit is contained in:
parent
2ebdb9f3ef
commit
74adf124cd
|
@ -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
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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
|
||||
# ---------------------------------------------------------
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
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:
|
|
@ -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 = []
|
||||
|
|
|
@ -30,6 +30,33 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<menuitem parent="account.menu_finance_legal_statement" id="final_accounting_reports" name="Accounting Reports"/>
|
||||
|
||||
<record id="action_account_report_bs" model="ir.actions.act_window">
|
||||
<field name="name">Financial Reports</field>
|
||||
<field name="res_model">accounting.report</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="accounting_report_view"/>
|
||||
<field name="target">new</field>
|
||||
<field name="context" eval="{'default_account_report_id':ref('account.account_financial_report_balancesheet0')}"/>
|
||||
</record>
|
||||
<menuitem icon="STOCK_PRINT" name="Balance Sheet" action="action_account_report_bs" id="menu_account_report_bs" parent="final_accounting_reports"/>
|
||||
|
||||
<record id="action_account_report_pl" model="ir.actions.act_window">
|
||||
<field name="name">Financial Reports</field>
|
||||
<field name="res_model">accounting.report</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="accounting_report_view"/>
|
||||
<field name="target">new</field>
|
||||
<field name="context"></field>
|
||||
<field name="context" eval="{'default_account_report_id':ref('account.account_financial_report_profitandloss0')}"/>
|
||||
</record>
|
||||
<menuitem icon="STOCK_PRINT" name="Profit And Loss" action="action_account_report_pl" id="menu_account_report_pl" parent="final_accounting_reports"/>
|
||||
|
||||
<record id="action_account_report" model="ir.actions.act_window">
|
||||
<field name="name">Financial Reports</field>
|
||||
<field name="res_model">accounting.report</field>
|
||||
|
@ -38,33 +65,8 @@
|
|||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="accounting_report_view"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
parent="account.menu_finance_legal_statement"
|
||||
id="final_accounting_reports"
|
||||
name="Accounting Reports"/>
|
||||
|
||||
<menuitem icon="STOCK_PRINT"
|
||||
name="Profit And Loss"
|
||||
action="account.action_account_report"
|
||||
id="menu_account_pl_report"
|
||||
parent="final_accounting_reports"/>
|
||||
|
||||
<menuitem icon="STOCK_PRINT"
|
||||
name="Balance Sheet"
|
||||
action="account.action_account_report"
|
||||
groups="group_account_user,group_account_manager"
|
||||
id="menu_account_bs_report"
|
||||
parent="final_accounting_reports"/>
|
||||
|
||||
<menuitem icon="STOCK_PRINT"
|
||||
name="Financial Report"
|
||||
action="action_account_report"
|
||||
groups="group_account_user,group_account_manager"
|
||||
id="menu_account_report"
|
||||
parent="final_accounting_reports"
|
||||
sequence="100"/>
|
||||
</record>
|
||||
<menuitem icon="STOCK_PRINT" name="Financial Report" action="action_account_report" id="menu_account_report" parent="final_accounting_reports" sequence="100"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
Loading…
Reference in New Issue