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