From 08f87199857900c61931a9f62d3abb011985e6ef Mon Sep 17 00:00:00 2001 From: Rohan Patel Date: Fri, 10 Jun 2016 14:45:25 +0530 Subject: [PATCH] [MIG,IMP] l10n_fr_hr_payroll : Migrated reports to new API. --- .../l10n_fr_hr_payroll/report/fiche_paye.py | 82 ++++++++----------- .../report/l10n_fr_hr_payroll_report.xml | 4 +- .../report/report_l10n_fr_fiche_paye.xml | 6 +- 3 files changed, 40 insertions(+), 52 deletions(-) diff --git a/addons/l10n_fr_hr_payroll/report/fiche_paye.py b/addons/l10n_fr_hr_payroll/report/fiche_paye.py index 995f0009164..664fbab8e93 100644 --- a/addons/l10n_fr_hr_payroll/report/fiche_paye.py +++ b/addons/l10n_fr_hr_payroll/report/fiche_paye.py @@ -1,57 +1,45 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from openerp.osv import osv -from openerp.report import report_sxw +from odoo import api, models -class fiche_paye_parser(report_sxw.rml_parse): +class FichePayeParser(models.AbstractModel): + _name = 'report.l10n_fr_hr_payroll.report_l10n_fr_fiche_paye' - def __init__(self, cr, uid, name, context): - super(fiche_paye_parser, self).__init__(cr, uid, name, context) - self.localcontext.update({ + def get_payslip_lines(self, objs): + res = [] + ids = [] + for item in objs: + if item.appears_on_payslip is True and not item.salary_rule_id.parent_rule_id: + ids.append(item.id) + if ids: + res = self.env['hr.payslip.line'].browse(ids) + return res + + def get_total_by_rule_category(self, obj, code): + category_total = 0 + category_id = self.env['hr.salary.rule.category'].search([('code', '=', code)], limit=1).id + if category_id: + line_ids = self.env['hr.payslip.line'].search([('slip_id', '=', obj.id), ('category_id', 'child_of', category_id)]) + for line in line_ids: + category_total += line.total + return category_total + + def get_employer_line(self, obj, parent_line): + return self.env['hr.payslip.line'].search([('slip_id', '=', obj.id), ('salary_rule_id.parent_rule_id.id', '=', parent_line.salary_rule_id.id)], limit=1) + + @api.multi + def render_html(self, data): + payslip = self.env['hr.payslip'].browse(self.ids) + docargs = { + 'doc_ids': self.ids, + 'doc_model': 'hr.payslip', + 'data': data, + 'docs': payslip, 'lang': "fr_FR", 'get_payslip_lines': self.get_payslip_lines, 'get_total_by_rule_category': self.get_total_by_rule_category, 'get_employer_line': self.get_employer_line, - }) - - def get_payslip_lines(self, objs): - payslip_line = self.pool.get('hr.payslip.line') - res = [] - ids = [] - for item in objs: - if item.appears_on_payslip == True and not item.salary_rule_id.parent_rule_id : - ids.append(item.id) - if ids: - res = payslip_line.browse(self.cr, self.uid, ids) - return res - - def get_total_by_rule_category(self, obj, code): - payslip_line = self.pool.get('hr.payslip.line') - rule_cate_obj = self.pool.get('hr.salary.rule.category') - - cate_ids = rule_cate_obj.search(self.cr, self.uid, [('code', '=', code)]) - - category_total = 0 - if cate_ids: - line_ids = payslip_line.search(self.cr, self.uid, [('slip_id', '=', obj.id), ('category_id', 'child_of', cate_ids)]) - for line in payslip_line.browse(self.cr, self.uid, line_ids): - category_total += line.total - - return category_total - - def get_employer_line(self, obj, parent_line): - payslip_line = self.pool.get('hr.payslip.line') - - 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 )]) - res = line_ids and payslip_line.browse(self.cr, self.uid, line_ids[0]) or False - - return res - - -class wrapped_report_fiche_paye(osv.AbstractModel): - _name = 'report.l10n_fr_hr_payroll.report_l10nfrfichepaye' - _inherit = 'report.abstract_report' - _template = 'l10n_fr_hr_payroll.report_l10nfrfichepaye' - _wrapped_report_class = fiche_paye_parser + } + return self.env['report'].render('l10n_fr_hr_payroll.report_l10n_fr_fiche_paye', docargs) diff --git a/addons/l10n_fr_hr_payroll/report/l10n_fr_hr_payroll_report.xml b/addons/l10n_fr_hr_payroll/report/l10n_fr_hr_payroll_report.xml index 3768e483e44..43e8734c2b9 100644 --- a/addons/l10n_fr_hr_payroll/report/l10n_fr_hr_payroll_report.xml +++ b/addons/l10n_fr_hr_payroll/report/l10n_fr_hr_payroll_report.xml @@ -5,7 +5,7 @@ model="hr.payslip" string="Fiche de paye" report_type="qweb-pdf" - name="l10n_fr_hr_payroll.report_l10nfrfichepaye" - file="l10n_fr_hr_payroll.report_l10nfrfichepaye" + name="l10n_fr_hr_payroll.report_l10n_fr_fiche_paye" + file="l10n_fr_hr_payroll.report_l10n_fr_fiche_paye" /> diff --git a/addons/l10n_fr_hr_payroll/report/report_l10n_fr_fiche_paye.xml b/addons/l10n_fr_hr_payroll/report/report_l10n_fr_fiche_paye.xml index 60d24c7094c..883a7c75f1e 100644 --- a/addons/l10n_fr_hr_payroll/report/report_l10n_fr_fiche_paye.xml +++ b/addons/l10n_fr_hr_payroll/report/report_l10n_fr_fiche_paye.xml @@ -1,15 +1,15 @@ -