[REM]: Remove python action field from stage
[odoo/odoo.git] / addons / l10n_fr_hr_payroll / report / fiche_paye.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3
4 ##############################################################################
5 #
6 #    OpenERP, Open Source Management Solution
7 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 #    d$
9 #
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.
14 #
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.
19 #
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/>.
22 #
23 ##############################################################################
24
25 from openerp.report import report_sxw
26
27 class fiche_paye_parser(report_sxw.rml_parse):
28
29     def __init__(self, cr, uid, name, context):
30         super(fiche_paye_parser, self).__init__(cr, uid, name, context)
31         self.localcontext.update({
32             'get_payslip_lines': self.get_payslip_lines,
33             'get_total_by_rule_category': self.get_total_by_rule_category,
34             'get_employer_line': self.get_employer_line,
35         })
36
37     def get_payslip_lines(self, objs):
38         payslip_line = self.pool.get('hr.payslip.line')
39         res = []
40         ids = []
41         for item in objs:
42             if item.appears_on_payslip == True and not item.salary_rule_id.parent_rule_id :
43                 ids.append(item.id)
44         if ids:
45             res = payslip_line.browse(self.cr, self.uid, ids)
46         return res
47
48
49     def get_total_by_rule_category(self, obj, code):
50         payslip_line = self.pool.get('hr.payslip.line')
51         rule_cate_obj = self.pool.get('hr.salary.rule.category')
52
53         cate_ids = rule_cate_obj.search(self.cr, self.uid, [('code', '=', code)])
54
55         category_total = 0
56         if cate_ids:
57             line_ids = payslip_line.search(self.cr, self.uid, [('slip_id', '=', obj.id),('category_id.id', '=', cate_ids[0] )])
58             for line in payslip_line.browse(self.cr, self.uid, line_ids):
59                  category_total += line.total
60
61         return category_total
62
63
64     def get_employer_line(self, obj, parent_line):
65         
66         payslip_line = self.pool.get('hr.payslip.line')
67
68         line_ids = payslip_line.search(self.cr, self.uid, [('slip_id', '=', obj.id), ('salary_rule_id.parent_rule_id.id', '=', parent_line.salary_rule_id.id )])
69         res = line_ids and payslip_line.browse(self.cr, self.uid, line_ids[0]) or False
70
71         return res
72
73
74 report_sxw.report_sxw('report.fiche.paye', 'hr.payslip', 'l10n_fr_hr_payroll/report/fiche_paye.rml', parser=fiche_paye_parser)
75
76 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: