1 ##############################################################################
3 # OpenERP, Open Source Management Solution
4 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 ##############################################################################
25 from report import report_sxw
26 from common_report_header import common_report_header
28 class report_pl_account_horizontal(rml_parse.rml_parse, common_report_header):
30 def __init__(self, cr, uid, name, context=None):
31 super(report_pl_account_horizontal, self).__init__(cr, uid, name, context=context)
32 self.result_sum_dr = 0.0
33 self.result_sum_cr = 0.0
37 self.localcontext.update( {
39 'get_abs' : self.get_abs,
40 'get_lines' : self.get_lines,
41 'get_lines_another' : self.get_lines_another,
42 'get_currency': self._get_currency,
43 'get_data': self.get_data,
44 'sum_dr' : self.sum_dr,
45 'sum_cr' : self.sum_cr,
46 'final_result' : self.final_result,
47 'get_fiscalyear': self._get_fiscalyear,
48 'get_account': self._get_account,
49 'get_start_period': self.get_start_period,
50 'get_end_period': self.get_end_period,
51 'get_sortby': self._get_sortby,
52 'get_filter': self._get_filter,
53 'get_journal': self._get_journal,
54 'get_start_date':self._get_start_date,
55 'get_end_date':self._get_end_date,
56 'get_company':self._get_company,
58 self.context = context
60 def get_abs(self,amount):
63 def final_result(self):
67 if self.res_pl['type'] == 'Net Profit C.F.B.L.':
68 self.result_sum_dr += self.res_pl['balance']
69 return self.result_sum_dr or 0.0
72 if self.res_pl['type'] == 'Net Loss C.F.B.L.':
73 self.result_sum_cr += self.res_pl['balance']
74 return self.result_sum_cr or 0.0
76 def get_data(self, data):
77 cr, uid = self.cr, self.uid
78 db_pool = pooler.get_pool(self.cr.dbname)
80 type_pool = db_pool.get('account.account.type')
81 account_pool = db_pool.get('account.account')
82 year_pool = db_pool.get('account.fiscalyear')
89 ctx = self.context.copy()
90 ctx['fiscalyear'] = data['form'].get('fiscalyear_id', False)
92 if data['form']['filter'] == 'filter_period' :
93 ctx['periods'] = data['form'].get('periods', False)
94 elif data['form']['filter'] == 'filter_date':
95 ctx['date_from'] = data['form'].get('date_from', False)
96 ctx['date_to'] = data['form'].get('date_to', False)
99 account_id = data['form'].get('chart_account_id', False)
100 account_ids = account_pool._get_children_and_consol(cr, uid, account_id, context=ctx)
101 accounts = account_pool.browse(cr, uid, account_ids, context=ctx)
105 for account in accounts:
106 if (account.user_type.report_type) and (account.user_type.report_type == typ):
107 if typ == 'expense' and account.type <> 'view' and (account.debit <> account.credit):
108 self.result_sum_dr += abs(account.debit - account.credit)
109 if typ == 'income' and account.type <> 'view' and (account.debit <> account.credit):
110 self.result_sum_cr += abs(account.debit - account.credit)
111 if data['form']['display_account'] == 'bal_movement':
112 if account.credit > 0 or account.debit > 0 or account.balance > 0 :
113 accounts_temp.append(account)
114 elif data['form']['display_account'] == 'bal_solde':
115 if account.balance != 0:
116 accounts_temp.append(account)
118 accounts_temp.append(account)
119 if self.result_sum_dr > self.result_sum_cr:
120 self.res_pl['type'] = 'Net Loss C.F.B.L.'
121 self.res_pl['balance'] = (self.result_sum_dr - self.result_sum_cr)
123 self.res_pl['type'] = 'Net Profit C.F.B.L.'
124 self.res_pl['balance'] = (self.result_sum_cr - self.result_sum_dr)
125 self.result[typ] = accounts_temp
126 cal_list[typ] = self.result[typ]
129 for i in range(0,max(len(cal_list['expense']),len(cal_list['income']))):
130 if i < len(cal_list['expense']) and i < len(cal_list['income']):
132 'code' : cal_list['expense'][i].code,
133 'name' : cal_list['expense'][i].name,
134 'level': cal_list['expense'][i].level,
135 'balance':cal_list['expense'][i].balance,
136 'code1' : cal_list['income'][i].code,
137 'name1' : cal_list['income'][i].name,
138 'level1': cal_list['income'][i].level,
139 'balance1':cal_list['income'][i].balance,
141 self.result_temp.append(temp)
143 if i < len(cal_list['income']):
149 'code1' : cal_list['income'][i].code,
150 'name1' : cal_list['income'][i].name,
151 'level1': cal_list['income'][i].level,
152 'balance1':cal_list['income'][i].balance,
154 self.result_temp.append(temp)
155 if i < len(cal_list['expense']):
157 'code' : cal_list['expense'][i].code,
158 'name' : cal_list['expense'][i].name,
159 'level': cal_list['expense'][i].level,
160 'balance':cal_list['expense'][i].balance,
166 self.result_temp.append(temp)
170 return self.result_temp
172 def get_lines_another(self, group):
173 return self.result.get(group, [])
175 report_sxw.report_sxw('report.pl.account.horizontal', 'account.account',
176 'addons/account/report/report_pl_account_horizontal.rml',parser=report_pl_account_horizontal, header='internal')
178 report_sxw.report_sxw('report.pl.account', 'account.account',
179 'addons/account/report/report_pl_account.rml',parser=report_pl_account_horizontal, header='internal')
181 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: