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 ##############################################################################
26 from report import report_sxw
27 from account.report import report_pl
28 from common_report_header import common_report_header
30 class report_balancesheet_horizontal(rml_parse.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 = report_pl.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_abs' : self.get_abs,
42 'get_lines' : self.get_lines,
43 'get_lines_another' : self.get_lines_another,
44 'get_company': self._get_company,
45 'get_currency': self._get_currency,
46 'sum_dr' : self.sum_dr,
47 'sum_cr' : self.sum_cr,
48 'get_data':self.get_data,
49 'get_pl_balance':self.get_pl_balance,
50 'get_fiscalyear': self._get_fiscalyear,
51 'get_account': self._get_account,
52 'get_start_period': self.get_start_period,
53 'get_end_period': self.get_end_period,
54 'get_sortby': self._get_sortby,
55 'get_filter': self._get_filter,
56 'get_journal': self._get_journal,
57 'get_start_date':self._get_start_date,
58 'get_end_date':self._get_end_date,
59 'get_company':self._get_company,
62 self.context = context
64 def get_abs(self,amount):
68 if self.res_bl['type'] == 'Net Profit':
69 self.result_sum_dr += self.res_bl['balance']
70 return self.result_sum_dr or 0.0
73 if self.res_bl['type'] == 'Net Loss':
74 self.result_sum_cr += self.res_bl['balance']
75 return self.result_sum_cr or 0.0
77 def get_pl_balance(self):
78 return self.res_bl or 0.0
80 def get_data(self,data):
81 cr, uid = self.cr, self.uid
82 db_pool = pooler.get_pool(self.cr.dbname)
84 #Getting Profit or Loss Balance from profit and Loss report
85 result_pl=self.obj_pl.get_data(data)
86 self.res_bl = self.obj_pl.final_result()
88 type_pool = db_pool.get('account.account.type')
89 account_pool = db_pool.get('account.account')
90 year_pool = db_pool.get('account.fiscalyear')
97 ctx = self.context.copy()
98 # ctx['state'] = form['context'].get('state','filter_no')
99 ctx['fiscalyear'] = data['form'].get('fiscalyear_id', False)
101 if data['form']['filter'] == 'filter_period' :
102 ctx['periods'] = data['form'].get('periods', False)
103 elif data['form']['filter'] == 'filter_date':
104 ctx['date_from'] = data['form'].get('date_from', False)
105 ctx['date_to'] = data['form'].get('date_to', False)
110 account_id = data['form'].get('chart_account_id', False)
111 account_ids = account_pool._get_children_and_consol(cr, uid, account_id, context=ctx)
112 accounts = account_pool.browse(cr, uid, account_ids, context=ctx)
114 if self.res_bl['type'] == 'Net Profit C.F.B.L.':
115 self.res_bl['type'] = 'Net Profit'
117 self.res_bl['type'] = 'Net Loss'
120 'name' : self.res_bl['type'],
122 'balance':self.res_bl['balance'],
126 for account in accounts:
127 if (account.user_type.report_type) and (account.user_type.report_type == typ):
130 'code' : account.code,
131 'name' : account.name,
132 'level': account.level,
133 'balance':account.balance,
135 if typ == 'liability' and account.type <> 'view' and (account.debit <> account.credit):
136 self.result_sum_dr += abs(account.debit - account.credit)
137 if typ == 'asset' and account.type <> 'view' and (account.debit <> account.credit):
138 self.result_sum_cr += abs(account.debit - account.credit)
139 if data['form']['display_account'] == 'bal_movement':
140 if account.credit > 0 or account.debit > 0 or account.balance > 0 :
141 accounts_temp.append(account_dict)
142 elif data['form']['display_account'] == 'bal_solde':
143 if account.balance != 0:
144 accounts_temp.append(account_dict)
146 accounts_temp.append(account_dict)
147 if account.id == data['form']['reserve_account_id']:
148 pl_dict['level'] = account['level'] + 1
149 accounts_temp.append(pl_dict)
151 self.result[typ] = accounts_temp
152 cal_list[typ]=self.result[typ]
156 for i in range(0,max(len(cal_list['liability']),len(cal_list['asset']))):
157 if i < len(cal_list['liability']) and i < len(cal_list['asset']):
159 'code' : cal_list['liability'][i]['code'],
160 'name' : cal_list['liability'][i]['name'],
161 'level': cal_list['liability'][i]['level'],
162 'balance':cal_list['liability'][i]['balance'],
163 'code1' : cal_list['asset'][i]['code'],
164 'name1' : cal_list['asset'][i]['name'],
165 'level1': cal_list['asset'][i]['level'],
166 'balance1':cal_list['asset'][i]['balance'],
168 self.result_temp.append(temp)
170 if i < len(cal_list['asset']):
176 'code1' : cal_list['asset'][i]['code'],
177 'name1' : cal_list['asset'][i]['name'],
178 'level1': cal_list['asset'][i]['level'],
179 'balance1':cal_list['asset'][i]['balance'],
181 self.result_temp.append(temp)
182 if i < len(cal_list['liability']):
184 'code' : cal_list['liability'][i]['code'],
185 'name' : cal_list['liability'][i]['name'],
186 'level': cal_list['liability'][i]['level'],
187 'balance':cal_list['liability'][i]['balance'],
193 self.result_temp.append(temp)
197 return self.result_temp
199 def get_lines_another(self, group):
200 return self.result.get(group, [])
202 report_sxw.report_sxw('report.account.balancesheet.horizontal', 'account.account',
203 'addons/account/report/report_balance_sheet_horizontal.rml',parser=report_balancesheet_horizontal,
206 report_sxw.report_sxw('report.account.balancesheet', 'account.account',
207 'addons/account/report/report_balance_sheet.rml',parser=report_balancesheet_horizontal,
210 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: