1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
25
from report import report_sxw
26
from openerp.addons.account_report_alt.report import account_profit_loss
27
from common_report_header import common_report_header
28
from tools.translate import _
30
class report_balancesheet_horizontal(report_sxw.rml_parse, common_report_header):
31
def __init__(self, cr, uid, name, context=None):
32
super(report_balancesheet_horizontal, self).__init__(cr, uid, name, context=context)
33
self.obj_pl = account_profit_loss.report_pl_account_horizontal(cr, uid, name, context=context)
34
self.result_sum_dr = 0.0
35
self.result_sum_cr = 0.0
39
self.localcontext.update({
41
'get_lines': self.get_lines,
42
'get_lines_another': self.get_lines_another,
43
'get_company': self._get_company,
44
'get_currency': self._get_currency,
45
'sum_dr': self.sum_dr,
46
'sum_cr': self.sum_cr,
47
'get_data':self.get_data,
48
'get_pl_balance':self.get_pl_balance,
49
'get_fiscalyear': self._get_fiscalyear,
50
'get_account': self._get_account,
51
'get_start_period': self.get_start_period,
52
'get_end_period': self.get_end_period,
53
'get_sortby': self._get_sortby,
54
'get_filter': self._get_filter,
55
'get_journal': self._get_journal,
56
'get_start_date':self._get_start_date,
57
'get_end_date':self._get_end_date,
58
'get_company':self._get_company,
59
'get_target_move': self._get_target_move,
61
self.context = context
63
def set_context(self, objects, data, ids, report_type=None):
65
if (data['model'] == 'ir.ui.menu'):
66
new_ids = 'chart_account_id' in data['form'] and data['form']['chart_account_id'] and [data['form']['chart_account_id'][0]] or []
67
objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids)
68
lang_dict = self.pool.get('res.users').read(self.cr,self.uid,self.uid,['context_lang'])
69
data['lang'] = lang_dict.get('context_lang') or False
70
return super(report_balancesheet_horizontal, self).set_context(objects, data, new_ids, report_type=report_type)
73
if self.res_bl['type'] == _('Net Profit'):
74
self.result_sum_dr += self.res_bl['balance']
75
return self.result_sum_dr
78
if self.res_bl['type'] == _('Net Loss'):
79
self.result_sum_cr += self.res_bl['balance']
80
return self.result_sum_cr
82
def get_pl_balance(self):
85
def get_data(self,data):
86
cr, uid = self.cr, self.uid
87
db_pool = pooler.get_pool(self.cr.dbname)
89
#Getting Profit or Loss Balance from profit and Loss report
90
self.obj_pl.get_data(data)
91
self.res_bl = self.obj_pl.final_result()
93
account_pool = db_pool.get('account.account')
94
currency_pool = db_pool.get('res.currency')
101
ctx = self.context.copy()
102
ctx['fiscalyear'] = data['form'].get('fiscalyear_id', False)
103
if ctx['fiscalyear']:
104
ctx['fiscalyear'] = ctx['fiscalyear'][0]
106
if data['form']['filter'] == 'filter_period':
107
ctx['periods'] = data['form'].get('periods', False)
108
elif data['form']['filter'] == 'filter_date':
109
ctx['date_from'] = data['form'].get('date_from', False)
110
ctx['date_to'] = data['form'].get('date_to', False)
111
ctx['state'] = data['form'].get('target_move', 'all')
115
account_id = data['form'].get('chart_account_id', False)
117
account_id = account_id[0]
118
account_ids = account_pool._get_children_and_consol(cr, uid, account_id, context=ctx)
119
accounts = account_pool.browse(cr, uid, account_ids, context=ctx)
122
self.res_bl['type'] = _('Net Profit')
123
self.res_bl['balance'] = 0.0
125
if self.res_bl['type'] == _('Net Profit'):
126
self.res_bl['type'] = _('Net Profit')
128
self.res_bl['type'] = _('Net Loss')
130
'code': self.res_bl['type'],
131
'name': self.res_bl['type'],
133
'balance':self.res_bl['balance'],
137
for account in accounts:
138
if (account.user_type.report_type) and (account.user_type.report_type == typ):
141
'code': account.code,
142
'name': account.name,
143
'level': account.level,
144
'balance': (account.balance and typ == 'liability' and -1 or 1 ) * account.balance,
146
currency = account.currency_id and account.currency_id or account.company_id.currency_id
147
if typ == 'liability' and account.type <> 'view' and (account.debit <> account.credit):
148
self.result_sum_dr += account_dict['balance']
149
if typ == 'asset' and account.type <> 'view' and (account.debit <> account.credit):
150
self.result_sum_cr += account_dict['balance']
151
if data['form']['display_account'] == 'bal_movement':
152
if (not currency_pool.is_zero(self.cr, self.uid, currency, account.credit)) or (not currency_pool.is_zero(self.cr, self.uid, currency, account.debit)) or (not currency_pool.is_zero(self.cr, self.uid, currency, account.balance)):
153
accounts_temp.append(account_dict)
154
elif data['form']['display_account'] == 'bal_solde':
155
if not currency_pool.is_zero(self.cr, self.uid, currency, account.balance):
156
accounts_temp.append(account_dict)
158
accounts_temp.append(account_dict)
160
self.result[typ] = accounts_temp
161
cal_list[typ]=self.result[typ]
163
if pl_dict['code'] == _('Net Loss'):
164
self.result['asset'].append(pl_dict)
166
self.result['liability'].append(pl_dict)
170
for i in range(0,max(len(cal_list['liability']),len(cal_list['asset']))):
171
if i < len(cal_list['liability']) and i < len(cal_list['asset']):
173
'code': cal_list['liability'][i]['code'],
174
'name': cal_list['liability'][i]['name'],
175
'level': cal_list['liability'][i]['level'],
176
'balance':cal_list['liability'][i]['balance'],
177
'code1': cal_list['asset'][i]['code'],
178
'name1': cal_list['asset'][i]['name'],
179
'level1': cal_list['asset'][i]['level'],
180
'balance1':cal_list['asset'][i]['balance'],
182
self.result_temp.append(temp)
184
if i < len(cal_list['asset']):
190
'code1': cal_list['asset'][i]['code'],
191
'name1': cal_list['asset'][i]['name'],
192
'level1': cal_list['asset'][i]['level'],
193
'balance1':cal_list['asset'][i]['balance'],
195
self.result_temp.append(temp)
196
if i < len(cal_list['liability']):
198
'code': cal_list['liability'][i]['code'],
199
'name': cal_list['liability'][i]['name'],
200
'level': cal_list['liability'][i]['level'],
201
'balance':cal_list['liability'][i]['balance'],
207
self.result_temp.append(temp)
211
return self.result_temp
213
def get_lines_another(self, group):
214
return self.result.get(group, [])
216
report_sxw.report_sxw('report.account.balancesheet.horizontal', 'account.account',
217
'addons/account_report_alt/report/account_balance_sheet_horizontal.rml',parser=report_balancesheet_horizontal,
218
header='internal landscape')
220
report_sxw.report_sxw('report.account.balancesheet', 'account.account',
221
'addons/account_report_alt/report/account_balance_sheet.rml',parser=report_balancesheet_horizontal,
224
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: