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 ##############################################################################
23 from report import report_sxw
27 class budget_report(report_sxw.rml_parse):
28 def __init__(self, cr, uid, name, context):
29 super(budget_report, self).__init__(cr, uid, name, context=context)
30 self.localcontext.update({
32 'funct_total': self.funct_total,
35 self.context = context
37 def funct(self, object, form, ids={}, done=None, level=1):
51 budgets = self.pool.get('account.budget.post').browse(self.cr, self.uid, [object.id], self.context.copy())
52 c_b_lines_obj = self.pool.get('crossovered.budget.lines')
53 acc_analytic_obj = self.pool.get('account.analytic.account')
54 for budget_id in budgets:
57 d_from = form['date_from']
58 d_to = form['date_to']
60 for line in budget_id.crossovered_budget_line:
61 budget_ids.append(line.id)
65 self.cr.execute('SELECT DISTINCT(analytic_account_id) FROM crossovered_budget_lines WHERE id = ANY(%s)',(budget_ids,))
66 an_ids = self.cr.fetchall()
68 context = {'wizard_date_from': d_from, 'wizard_date_to': d_to}
69 for i in range(0, len(an_ids)):
70 analytic_name = acc_analytic_obj.browse(self.cr, self.uid, [an_ids[i][0]])
74 'name': analytic_name[0].name,
83 line_ids = c_b_lines_obj.search(self.cr, self.uid, [('id', 'in', budget_ids), ('analytic_account_id','=',an_ids[i][0])])
84 line_id = c_b_lines_obj.browse(self.cr, self.uid, line_ids)
85 tot_theo = tot_pln = tot_prac = tot_perc = 0.00
89 if line.id in budget_ids:
91 theo = c_b_lines_obj._theo_amt(self.cr, self.uid, [line.id], context)[line.id]
92 pract = c_b_lines_obj._prac_amt(self.cr, self.uid, [line.id], context)[line.id]
93 if line.general_budget_id.id in done_budget:
95 if record['b_id'] == line.general_budget_id.id and record['a_id'] == line.analytic_account_id.id:
96 record['theo'] += theo
97 record['pln'] += line.planned_amount
98 record['prac'] += pract
99 if record['theo'] <> 0.00:
100 perc = (record['prac'] / record['theo']) * 100
103 record['perc'] = perc
105 tot_pln += line.planned_amount
110 perc = (pract / theo) * 100
114 'a_id': line.analytic_account_id.id,
115 'b_id': line.general_budget_id.id,
116 'name': line.general_budget_id.name,
119 'pln': line.planned_amount,
124 tot_pln += line.planned_amount
127 if form['report'] == 'analytic-full':
129 done_budget.append(line.general_budget_id.id)
132 if line.general_budget_id.id in done_budget:
136 'a_id': line.analytic_account_id.id,
137 'b_id': line.general_budget_id.id,
138 'name': line.general_budget_id.name,
145 if form['report'] == 'analytic-full':
147 done_budget.append(line.general_budget_id.id)
151 tot_perc = float(tot_prac / tot_theo) * 100
152 if form['report'] == 'analytic-full':
153 result[-(len(done_budget) +1)]['theo'] = tot_theo
154 tot['theo'] += tot_theo
155 result[-(len(done_budget) +1)]['pln'] = tot_pln
156 tot['pln'] += tot_pln
157 result[-(len(done_budget) +1)]['prac'] = tot_prac
158 tot['prac'] += tot_prac
159 result[-(len(done_budget) +1)]['perc'] = tot_perc
161 result[-1]['theo'] = tot_theo
162 tot['theo'] += tot_theo
163 result[-1]['pln'] = tot_pln
164 tot['pln'] += tot_pln
165 result[-1]['prac'] = tot_prac
166 tot['prac'] += tot_prac
167 result[-1]['perc'] = tot_perc
168 if tot['theo'] == 0.00:
171 tot['perc'] = float(tot['prac'] / tot['theo']) * 100
174 def funct_total(self, form):
178 'tot_theo': tot['theo'],
179 'tot_pln': tot['pln'],
180 'tot_prac': tot['prac'],
181 'tot_perc': tot['perc']
186 report_sxw.report_sxw('report.account.budget', 'account.budget.post', 'addons/account_budget/report/budget_report.rml', parser=budget_report, header='internal')
188 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: