2011-08-12 11:23:21 +00:00
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2009 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
|
2011-08-17 12:02:19 +00:00
|
|
|
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.report import report_sxw
|
2011-08-12 11:23:21 +00:00
|
|
|
from common_report_header import common_report_header
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.tools.translate import _
|
2014-04-02 16:40:53 +00:00
|
|
|
from openerp.osv import osv
|
|
|
|
|
2011-08-12 11:23:21 +00:00
|
|
|
|
|
|
|
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( {
|
2011-08-24 12:49:08 +00:00
|
|
|
'get_lines': self.get_lines,
|
2011-08-12 11:23:21 +00:00
|
|
|
'time': time,
|
|
|
|
'get_fiscalyear': self._get_fiscalyear,
|
|
|
|
'get_account': self._get_account,
|
|
|
|
'get_start_period': self.get_start_period,
|
|
|
|
'get_end_period': self.get_end_period,
|
|
|
|
'get_filter': self._get_filter,
|
|
|
|
'get_start_date':self._get_start_date,
|
|
|
|
'get_end_date':self._get_end_date,
|
2013-09-02 12:04:50 +00:00
|
|
|
'get_target_move': self._get_target_move,
|
2011-08-12 11:23:21 +00:00
|
|
|
})
|
|
|
|
self.context = context
|
|
|
|
|
|
|
|
def set_context(self, objects, data, ids, report_type=None):
|
|
|
|
new_ids = ids
|
|
|
|
if (data['model'] == 'ir.ui.menu'):
|
|
|
|
new_ids = 'chart_account_id' in data['form'] and [data['form']['chart_account_id']] or []
|
|
|
|
objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids)
|
|
|
|
return super(report_account_common, self).set_context(objects, data, new_ids, report_type=report_type)
|
|
|
|
|
2011-08-24 12:49:08 +00:00
|
|
|
def get_lines(self, data):
|
|
|
|
lines = []
|
2011-08-31 12:33:35 +00:00
|
|
|
account_obj = self.pool.get('account.account')
|
|
|
|
currency_obj = self.pool.get('res.currency')
|
2011-09-09 05:54:56 +00:00
|
|
|
ids2 = self.pool.get('account.financial.report')._get_children_by_order(self.cr, self.uid, [data['form']['account_report_id'][0]], context=data['form']['used_context'])
|
|
|
|
for report in self.pool.get('account.financial.report').browse(self.cr, self.uid, ids2, context=data['form']['used_context']):
|
2011-08-24 12:49:08 +00:00
|
|
|
vals = {
|
|
|
|
'name': report.name,
|
2013-01-07 10:28:57 +00:00
|
|
|
'balance': report.balance * report.sign or 0.0,
|
2011-08-24 12:49:08 +00:00
|
|
|
'type': 'report',
|
2012-01-26 17:19:55 +00:00
|
|
|
'level': bool(report.style_overwrite) and report.style_overwrite or report.level,
|
|
|
|
'account_type': report.type =='sum' and 'view' or False, #used to underline the financial report balances
|
2011-08-24 12:49:08 +00:00
|
|
|
}
|
2012-02-13 10:49:37 +00:00
|
|
|
if data['form']['debit_credit']:
|
|
|
|
vals['debit'] = report.debit
|
|
|
|
vals['credit'] = report.credit
|
2011-08-25 00:45:35 +00:00
|
|
|
if data['form']['enable_filter']:
|
2013-02-25 18:07:30 +00:00
|
|
|
vals['balance_cmp'] = self.pool.get('account.financial.report').browse(self.cr, self.uid, report.id, context=data['form']['comparison_context']).balance * report.sign or 0.0
|
2011-08-24 12:49:08 +00:00
|
|
|
lines.append(vals)
|
2011-09-21 23:53:24 +00:00
|
|
|
account_ids = []
|
2012-01-26 17:19:55 +00:00
|
|
|
if report.display_detail == 'no_detail':
|
|
|
|
#the rest of the loop is used to display the details of the financial report, so it's not needed here.
|
|
|
|
continue
|
2011-11-30 09:46:48 +00:00
|
|
|
if report.type == 'accounts' and report.account_ids:
|
2011-12-09 16:16:28 +00:00
|
|
|
account_ids = account_obj._get_children_and_consol(self.cr, self.uid, [x.id for x in report.account_ids])
|
2011-09-21 23:53:24 +00:00
|
|
|
elif report.type == 'account_type' and report.account_type_ids:
|
|
|
|
account_ids = account_obj.search(self.cr, self.uid, [('user_type','in', [x.id for x in report.account_type_ids])])
|
|
|
|
if account_ids:
|
2011-08-31 12:33:35 +00:00
|
|
|
for account in account_obj.browse(self.cr, self.uid, account_ids, context=data['form']['used_context']):
|
2012-01-26 19:29:20 +00:00
|
|
|
#if there are accounts to display, we add them to the lines with a level equals to their level in
|
|
|
|
#the COA + 1 (to avoid having them with a too low level that would conflicts with the level of data
|
|
|
|
#financial reports for Assets, liabilities...)
|
2011-12-13 11:45:07 +00:00
|
|
|
if report.display_detail == 'detail_flat' and account.type == 'view':
|
2011-12-09 16:38:36 +00:00
|
|
|
continue
|
2011-12-09 16:16:28 +00:00
|
|
|
flag = False
|
|
|
|
vals = {
|
|
|
|
'name': account.code + ' ' + account.name,
|
|
|
|
'balance': account.balance != 0 and account.balance * report.sign or account.balance,
|
|
|
|
'type': 'account',
|
2012-01-26 19:29:20 +00:00
|
|
|
'level': report.display_detail == 'detail_with_hierarchy' and min(account.level + 1,6) or 6, #account.level + 1
|
2011-12-09 16:16:28 +00:00
|
|
|
'account_type': account.type,
|
|
|
|
}
|
2012-02-13 10:49:37 +00:00
|
|
|
|
|
|
|
if data['form']['debit_credit']:
|
2012-02-10 13:27:42 +00:00
|
|
|
vals['debit'] = account.debit
|
|
|
|
vals['credit'] = account.credit
|
2011-12-09 16:16:28 +00:00
|
|
|
if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance']):
|
|
|
|
flag = True
|
|
|
|
if data['form']['enable_filter']:
|
2013-02-25 18:07:30 +00:00
|
|
|
vals['balance_cmp'] = account_obj.browse(self.cr, self.uid, account.id, context=data['form']['comparison_context']).balance * report.sign or 0.0
|
2011-12-09 16:16:28 +00:00
|
|
|
if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance_cmp']):
|
2011-08-31 12:33:35 +00:00
|
|
|
flag = True
|
2011-12-09 16:16:28 +00:00
|
|
|
if flag:
|
|
|
|
lines.append(vals)
|
2011-08-24 12:49:08 +00:00
|
|
|
return lines
|
2011-08-25 12:13:02 +00:00
|
|
|
|
2011-08-12 11:23:21 +00:00
|
|
|
|
2014-04-02 16:40:53 +00:00
|
|
|
class report_financial(osv.AbstractModel):
|
|
|
|
_name = 'report.account.report_financial'
|
|
|
|
_inherit = 'report.abstract_report'
|
|
|
|
_template = 'account.report_financial'
|
|
|
|
_wrapped_report_class = report_account_common
|
2011-11-22 08:51:38 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|