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
|
|
|
|
2011-08-12 11:23:21 +00:00
|
|
|
from report import report_sxw
|
|
|
|
from common_report_header import common_report_header
|
|
|
|
from tools.translate import _
|
|
|
|
|
|
|
|
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,
|
2011-08-25 06:49:46 +00:00
|
|
|
# 'get_report_details': self._get_report_details,
|
2011-08-12 11:23:21 +00:00
|
|
|
'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,
|
2011-08-25 06:49:46 +00:00
|
|
|
# 'get_account_details': self.get_account_details,
|
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-25 06:37:38 +00:00
|
|
|
#
|
|
|
|
# def _get_report_details(self, data):
|
|
|
|
# cr, uid = self.cr, self.uid
|
|
|
|
# report_obj = self.pool.get('account.report')
|
|
|
|
# datas = []
|
|
|
|
# balance = 0.0
|
|
|
|
# name = data['form'].get('account_report_id') and data['form']['account_report_id'][1] or ''
|
|
|
|
# report_id = data['form'].get('account_report_id') and data['form']['account_report_id'][0] or False
|
|
|
|
# label = data['form']['label_filter'] or ''
|
|
|
|
# datas.append({'id': report_id, 'label': label})
|
|
|
|
# ctx = self.context.copy()
|
|
|
|
# if report_id:
|
|
|
|
# child_ids = report_obj.search(cr, uid, [('parent_id','=',report_id)])
|
|
|
|
# child_ids.append(datas[0]['id'])
|
|
|
|
# for child in report_obj.browse(cr, uid, child_ids, context=ctx):
|
|
|
|
# balance = self.get_report_balance(child, child_ids, ctx)
|
|
|
|
# if child.id == datas[0]['id']:
|
|
|
|
# datas[0].update({'name': child.name, 'balance': balance})
|
|
|
|
# else:
|
|
|
|
# datas.append({'id': child.id, 'name': child.name, 'balance': balance, 'label': label})
|
|
|
|
# return datas
|
2011-08-25 06:49:46 +00:00
|
|
|
#
|
|
|
|
# def get_account_details(self, acc_id, data):
|
|
|
|
# cr, uid = self.cr, self.uid
|
|
|
|
# report_obj = self.pool.get('account.report')
|
|
|
|
# accounts = []
|
|
|
|
#
|
|
|
|
# ctx = self.context.copy()
|
|
|
|
# ctx['fiscalyear'] = data['form'].get('fiscalyear_id', False)
|
|
|
|
#
|
|
|
|
# if data['form']['filter'] == 'filter_period':
|
|
|
|
# ctx['period_from'] = data['form'].get('period_from', False)
|
|
|
|
# ctx['period_to'] = data['form'].get('period_to', False)
|
|
|
|
# elif data['form']['filter'] == 'filter_date':
|
|
|
|
# ctx['date_from'] = data['form'].get('date_from', False)
|
|
|
|
# ctx['date_to'] = data['form'].get('date_to', False)
|
|
|
|
#
|
|
|
|
# if acc_id and data['form'].get('account_details', False):
|
|
|
|
# for rpt in report_obj.browse(cr, uid, [acc_id], context=ctx):
|
|
|
|
# accounts = [acc for acc in rpt.account_ids if acc.level != 0]
|
|
|
|
# return accounts
|
2011-08-12 11:23:21 +00:00
|
|
|
|
2011-08-24 12:49:08 +00:00
|
|
|
def get_lines(self, data):
|
|
|
|
lines = []
|
2011-08-24 23:31:51 +00:00
|
|
|
ids2 = self.pool.get('account.low.level.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.low.level.report').browse(self.cr, self.uid, ids2, context=data['form']['used_context']):
|
2011-08-24 12:49:08 +00:00
|
|
|
vals = {
|
|
|
|
'name': report.name,
|
|
|
|
'balance': report.balance,
|
|
|
|
'type': 'report',
|
2011-08-31 11:54:59 +00:00
|
|
|
'level': report.level,
|
2011-08-24 12:49:08 +00:00
|
|
|
}
|
2011-08-25 00:45:35 +00:00
|
|
|
if data['form']['enable_filter']:
|
|
|
|
vals['balance_cmp'] = self.pool.get('account.low.level.report').browse(self.cr, self.uid, report.id, context=data['form']['comparison_context']).balance
|
2011-08-24 12:49:08 +00:00
|
|
|
lines.append(vals)
|
|
|
|
if report.type == 'accounts' and report.display_detail:
|
|
|
|
for account in report.account_ids:
|
2011-08-25 12:13:02 +00:00
|
|
|
if account.level != 0:
|
|
|
|
vals = {
|
|
|
|
'name': account.code + ' ' + account.name,
|
|
|
|
'balance': account.balance,
|
|
|
|
'type': 'account',
|
2011-08-31 11:54:59 +00:00
|
|
|
'level': 6,
|
2011-08-25 12:13:02 +00:00
|
|
|
'account_type': account.type,
|
|
|
|
}
|
|
|
|
if data['form']['enable_filter']:
|
|
|
|
vals['balance_cmp'] = self.pool.get('account.account').browse(self.cr, self.uid, account.id, context=data['form']['comparison_context']).balance
|
|
|
|
lines.append(vals)
|
2011-08-24 12:49:08 +00:00
|
|
|
return lines
|
2011-08-25 12:13:02 +00:00
|
|
|
|
2011-08-25 06:49:46 +00:00
|
|
|
# def get_report_balance(self, child, child_ids, context=None):
|
|
|
|
# cr, uid = self.cr, self.uid
|
|
|
|
# report_obj = self.pool.get('account.report')
|
|
|
|
# balance = 0.0
|
|
|
|
# # it's the sum of balance of the linked accounts
|
|
|
|
# if child.type == 'accounts':
|
|
|
|
# for a in child.account_ids:
|
|
|
|
# balance += a.balance
|
|
|
|
# # it's the balance of the linked account.report (so it means it's only a way to reuse figures coming from another report)
|
|
|
|
# if child.type == 'account_report' and child.account_report_id:
|
|
|
|
# for a in child.account_report_id.account_ids:
|
|
|
|
# balance += a.balance
|
|
|
|
# # it's the sum of balance of the children of this account.report (if there isn't, then it's 0.0)
|
|
|
|
# if child.type == 'sum':
|
|
|
|
# for child in report_obj.browse(cr, uid, child_ids, context=context):
|
|
|
|
# for a in child.account_ids:
|
|
|
|
# balance += a.balance
|
|
|
|
# return balance
|
2011-08-12 12:22:34 +00:00
|
|
|
|
2011-08-24 12:49:08 +00:00
|
|
|
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')
|
2011-08-12 11:23:21 +00:00
|
|
|
|