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 ##############################################################################
25 from openerp.report import report_sxw
27 class analytic_account_budget_report(report_sxw.rml_parse):
28 def __init__(self, cr, uid, name, context):
29 super(analytic_account_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=None, done=None, level=1):
53 accounts = self.pool.get('account.analytic.account').browse(self.cr, self.uid, [object.id], self.context.copy())
54 c_b_lines_obj = self.pool.get('crossovered.budget.lines')
55 obj_c_budget = self.pool.get('crossovered.budget')
57 for account_id in accounts:
60 for line in account_id.crossovered_budget_line:
61 b_line_ids.append(line.id)
64 d_from = form['date_from']
65 d_to = form['date_to']
67 self.cr.execute('SELECT DISTINCT(crossovered_budget_id) FROM crossovered_budget_lines WHERE id =ANY(%s)',(b_line_ids,))
68 budget_ids = self.cr.fetchall()
70 context = {'wizard_date_from':d_from,'wizard_date_to':d_to}
71 for i in range(0, len(budget_ids)):
72 budget_name = obj_c_budget.browse(self.cr, self.uid, [budget_ids[i][0]])
76 'name':budget_name[0].name,
85 line_ids = c_b_lines_obj.search(self.cr, self.uid, [('id', 'in', b_line_ids), ('crossovered_budget_id','=',budget_ids[i][0])])
86 line_id = c_b_lines_obj.browse(self.cr, self.uid, line_ids)
87 tot_theo = tot_pln = tot_prac = tot_perc = 0
91 if line.id in b_line_ids:
93 theo = c_b_lines_obj._theo_amt(self.cr, self.uid, [line.id], context)[line.id]
94 pract = c_b_lines_obj._prac_amt(self.cr, self.uid, [line.id], context)[line.id]
95 if line.general_budget_id.id in done_budget:
97 if record['b_id'] == line.general_budget_id.id and record['a_id'] == line.analytic_account_id.id:
98 record['theo'] += theo
99 record['pln'] += line.planned_amount
100 record['prac'] += pract
101 record['perc'] += line.percentage
103 tot_pln += line.planned_amount
105 tot_perc += line.percentage
108 'b_id': line.general_budget_id.id,
109 'a_id': line.analytic_account_id.id,
110 'name': line.general_budget_id.name,
113 'pln': line.planned_amount,
115 'perc': line.percentage
118 tot_pln += line.planned_amount
120 tot_perc += line.percentage
122 done_budget.append(line.general_budget_id.id)
124 if line.general_budget_id.id in done_budget:
128 'b_id': line.general_budget_id.id,
129 'a_id': line.analytic_account_id.id,
130 'name': line.general_budget_id.name,
138 done_budget.append(line.general_budget_id.id)
142 tot_perc = float(tot_prac / tot_theo) * 100
144 result[-(len(done_budget) +1)]['theo'] = tot_theo
145 tot['theo'] +=tot_theo
146 result[-(len(done_budget) +1)]['pln'] = tot_pln
148 result[-(len(done_budget) +1)]['prac'] = tot_prac
149 tot['prac'] +=tot_prac
150 result[-(len(done_budget) +1)]['perc'] = tot_perc
151 if tot['theo'] == 0.00:
154 tot['perc'] = float(tot['prac'] / tot['theo']) * 100
157 def funct_total(self, form):
161 'tot_theo': tot['theo'],
162 'tot_pln': tot['pln'],
163 'tot_prac': tot['prac'],
164 'tot_perc': tot['perc']
169 report_sxw.report_sxw('report.account.analytic.account.budget', 'account.analytic.account', 'addons/account_budget/report/analytic_account_budget_report.rml',parser=analytic_account_budget_report,header='internal')
171 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: