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 account.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']] or []
67 objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids)
68 return super(report_balancesheet_horizontal, self).set_context(objects, data, new_ids, report_type=report_type)
71 if self.res_bl['type'] == _('Net Profit'):
72 self.result_sum_dr += self.res_bl['balance']*-1
73 return self.result_sum_dr
76 if self.res_bl['type'] == _('Net Loss'):
77 self.result_sum_cr += self.res_bl['balance']
78 return self.result_sum_cr
80 def get_pl_balance(self):
83 def get_data(self,data):
84 cr, uid = self.cr, self.uid
85 db_pool = pooler.get_pool(self.cr.dbname)
87 #Getting Profit or Loss Balance from profit and Loss report
88 self.obj_pl.get_data(data)
89 self.res_bl = self.obj_pl.final_result()
91 account_pool = db_pool.get('account.account')
92 currency_pool = db_pool.get('res.currency')
99 ctx = self.context.copy()
100 ctx['fiscalyear'] = data['form'].get('fiscalyear_id', False)
102 if data['form']['filter'] == 'filter_period':
103 ctx['period_from'] = data['form'].get('period_from', False)
104 ctx['period_to'] = data['form'].get('period_to', False)
105 elif data['form']['filter'] == 'filter_date':
106 ctx['date_from'] = data['form'].get('date_from', False)
107 ctx['date_to'] = data['form'].get('date_to', False)
108 ctx['state'] = data['form'].get('target_move', 'all')
112 account_id = data['form'].get('chart_account_id', False)
113 account_ids = account_pool._get_children_and_consol(cr, uid, account_id, context=ctx)
114 accounts = account_pool.browse(cr, uid, account_ids, context=ctx)
117 self.res_bl['type'] = _('Net Profit')
118 self.res_bl['balance'] = 0.0
120 if self.res_bl['type'] == _('Net Profit'):
121 self.res_bl['type'] = _('Net Profit')
123 self.res_bl['type'] = _('Net Loss')
125 'code': self.res_bl['type'],
126 'name': self.res_bl['type'],
128 'balance':self.res_bl['balance'],
132 for account in accounts:
133 if (account.user_type.report_type) and (account.user_type.report_type == typ):
136 'code': account.code,
137 'name': account.name,
138 'level': account.level,
139 'balance': account.balance != 0 and account.balance * account.user_type.sign or account.balance,
140 'type': account.type,
142 currency = account.currency_id and account.currency_id or account.company_id.currency_id
143 if typ == 'liability' and account.type <> 'view' and (account.debit <> account.credit):
144 self.result_sum_dr += account.balance
145 if typ == 'asset' and account.type <> 'view' and (account.debit <> account.credit):
146 self.result_sum_cr += account.balance
147 if data['form']['display_account'] == 'movement':
148 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):
149 accounts_temp.append(account_dict)
150 elif data['form']['display_account'] == 'not_zero':
151 if not currency_pool.is_zero(self.cr, self.uid, currency, account.balance):
152 accounts_temp.append(account_dict)
154 accounts_temp.append(account_dict)
155 if account.id == data['form']['reserve_account_id']:
156 pl_dict['level'] = account['level'] + 1
157 accounts_temp.append(pl_dict)
159 self.result[typ] = accounts_temp
160 cal_list[typ]=self.result[typ]
164 for i in range(0,max(len(cal_list['liability']),len(cal_list['asset']))):
165 if i < len(cal_list['liability']) and i < len(cal_list['asset']):
167 'type': cal_list['liability'][i]['type'],
168 'code': cal_list['liability'][i]['code'],
169 'name': cal_list['liability'][i]['name'],
170 'level': cal_list['liability'][i]['level'],
171 'balance':cal_list['liability'][i]['balance'],
172 'type1': cal_list['asset'][i]['type'],
173 'code1': cal_list['asset'][i]['code'],
174 'name1': cal_list['asset'][i]['name'],
175 'level1': cal_list['asset'][i]['level'],
176 'balance1':cal_list['asset'][i]['balance'],
178 self.result_temp.append(temp)
180 if i < len(cal_list['asset']):
187 'type1': cal_list['asset'][i]['type'],
188 'code1': cal_list['asset'][i]['code'],
189 'name1': cal_list['asset'][i]['name'],
190 'level1': cal_list['asset'][i]['level'],
191 'balance1':cal_list['asset'][i]['balance'],
193 self.result_temp.append(temp)
194 if i < len(cal_list['liability']):
196 'type': cal_list['liability'][i]['type'],
197 'code': cal_list['liability'][i]['code'],
198 'name': cal_list['liability'][i]['name'],
199 'level': cal_list['liability'][i]['level'],
200 '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/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/account_balance_sheet.rml',parser=report_balancesheet_horizontal,
224 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: