4 ##############################################################################
6 # OpenERP, Open Source Management Solution
7 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Affero General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU Affero General Public License for more details.
20 # You should have received a copy of the GNU Affero General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ##############################################################################
25 from report import report_sxw
26 from tools import amount_to_text_en
28 class payslip_details_report(report_sxw.rml_parse):
30 def __init__(self, cr, uid, name, context):
31 super(payslip_details_report, self).__init__(cr, uid, name, context)
32 self.localcontext.update({
33 'get_details_by_rule_category': self.get_details_by_rule_category,
34 'get_lines_by_contribution_register': self.get_lines_by_contribution_register,
37 def get_details_by_rule_category(self, obj):
38 payslip_line = self.pool.get('hr.payslip.line')
39 rule_cate_obj = self.pool.get('hr.salary.rule.category')
41 def get_recursive_parent(rule_categories):
42 if not rule_categories:
44 if rule_categories[0].parent_id:
45 rule_categories.insert(0, rule_categories[0].parent_id)
46 get_recursive_parent(rule_categories)
47 return rule_categories
53 for id in range(len(obj)):
54 ids.append(obj[id].id)
56 self.cr.execute('''SELECT pl.id, pl.category_id FROM hr_payslip_line as pl \
57 LEFT JOIN hr_salary_rule_category AS rc on (pl.category_id = rc.id) \
59 GROUP BY rc.parent_id, pl.sequence, pl.id, pl.category_id \
60 ORDER BY pl.sequence, rc.parent_id''',(tuple(ids),))
61 for x in self.cr.fetchall():
62 result.setdefault(x[1], [])
63 result[x[1]].append(x[0])
64 for key, value in result.iteritems():
65 rule_categories = rule_cate_obj.browse(self.cr, self.uid, [key])
66 parents = get_recursive_parent(rule_categories)
68 for line in payslip_line.browse(self.cr, self.uid, value):
69 category_total += line.total
71 for parent in parents:
73 'rule_category': parent.name,
77 'total': category_total,
80 for line in payslip_line.browse(self.cr, self.uid, value):
82 'rule_category': line.name,
90 def get_lines_by_contribution_register(self, obj):
91 payslip_line = self.pool.get('hr.payslip.line')
95 for id in range(len(obj)):
96 if obj[id].register_id:
97 result.setdefault(obj[id].register_id.name, [])
98 result[obj[id].register_id.name].append(obj[id].id)
99 for key, value in result.iteritems():
101 for line in payslip_line.browse(self.cr, self.uid, value):
102 register_total += line.total
104 'register_name': key,
105 'total': register_total,
107 for line in payslip_line.browse(self.cr, self.uid, value):
111 'quantity': line.quantity,
112 'amount': line.amount,
117 report_sxw.report_sxw('report.paylip.details', 'hr.payslip', 'hr_payroll/report/report_payslip_details.rml', parser=payslip_details_report)
119 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: