1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 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
30 class budget_report(report_sxw.rml_parse):
31 def __init__(self, cr, uid, name, context):
32 super(budget_report, self).__init__(cr, uid, name, context=context)
33 self.localcontext.update({
35 'funct_total': self.funct_total,
38 self.context = context
40 def funct(self, object, form, ids={}, done=None, level=1):
54 budgets = self.pool.get('crossovered.budget').browse(self.cr, self.uid, [object.id], self.context.copy())
55 c_b_lines_obj = self.pool.get('crossovered.budget.lines')
56 acc_analytic_obj = self.pool.get('account.analytic.account')
57 for budget_id in budgets:
61 d_from = form['date_from']
62 d_to = form['date_to']
64 for line in budget_id.crossovered_budget_line:
65 budget_ids.append(line.id)
70 self.cr.execute('SELECT DISTINCT(analytic_account_id) FROM crossovered_budget_lines WHERE id = ANY(%s)',(budget_ids,))
71 an_ids = self.cr.fetchall()
73 context = {'wizard_date_from': d_from, 'wizard_date_to': d_to}
74 for i in range(0, len(an_ids)):
77 analytic_name = acc_analytic_obj.browse(self.cr, self.uid, [an_ids[i][0]])
81 'name': analytic_name[0].name,
90 line_ids = c_b_lines_obj.search(self.cr, self.uid, [('id', 'in', budget_ids), ('analytic_account_id','=',an_ids[i][0])])
91 line_id = c_b_lines_obj.browse(self.cr, self.uid, line_ids)
92 tot_theo = tot_pln = tot_prac = tot_perc = 0.00
96 if line.id in budget_ids:
98 theo = c_b_lines_obj._theo_amt(self.cr, self.uid, [line.id], context)[line.id]
99 pract = c_b_lines_obj._prac_amt(self.cr, self.uid, [line.id], context)[line.id]
100 if line.general_budget_id.id in done_budget:
101 for record in result:
102 if record['b_id'] == line.general_budget_id.id and record['a_id'] == line.analytic_account_id.id:
103 record['theo'] += theo
104 record['pln'] += line.planned_amount
105 record['prac'] += pract
106 if record['theo'] <> 0.00:
107 perc = (record['prac'] / record['theo']) * 100
110 record['perc'] = perc
112 tot_pln += line.planned_amount
117 perc = (pract / theo) * 100
121 'a_id': line.analytic_account_id.id,
122 'b_id': line.general_budget_id.id,
123 'name': line.general_budget_id.name,
126 'pln': line.planned_amount,
131 tot_pln += line.planned_amount
134 if form['report'] == 'analytic-full':
136 done_budget.append(line.general_budget_id.id)
139 if line.general_budget_id.id in done_budget:
143 'a_id': line.analytic_account_id.id,
144 'b_id': line.general_budget_id.id,
145 'name': line.general_budget_id.name,
152 if form['report'] == 'analytic-full':
154 done_budget.append(line.general_budget_id.id)
158 tot_perc = float(tot_prac / tot_theo) * 100
159 if form['report'] == 'analytic-full':
160 result[-(len(done_budget) +1)]['theo'] = tot_theo
161 tot['theo'] += tot_theo
162 result[-(len(done_budget) +1)]['pln'] = tot_pln
163 tot['pln'] += tot_pln
164 result[-(len(done_budget) +1)]['prac'] = tot_prac
165 tot['prac'] += tot_prac
166 result[-(len(done_budget) +1)]['perc'] = tot_perc
168 result[-1]['theo'] = tot_theo
169 tot['theo'] += tot_theo
170 result[-1]['pln'] = tot_pln
171 tot['pln'] += tot_pln
172 result[-1]['prac'] = tot_prac
173 tot['prac'] += tot_prac
174 result[-1]['perc'] = tot_perc
175 if tot['theo'] == 0.00:
178 tot['perc'] = float(tot['prac'] / tot['theo']) * 100
181 def funct_total(self, form):
185 'tot_theo': tot['theo'],
186 'tot_pln': tot['pln'],
187 'tot_prac': tot['prac'],
188 'tot_perc': tot['perc']
193 report_sxw.report_sxw('report.crossovered.budget.report', 'crossovered.budget', 'addons/account_budget/report/crossovered_budget_report.rml',parser=budget_report,header='internal')
195 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: