Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to override _get_payslip_lines() method of the classe contribution_register_report?

By
Pascal Tremblay
on 1/22/15, 2:19 PM 1,001 views

Hello once again,

I'm still lost with all this inheritance problems!

COuld you help me to define this override?

I only want to redefine the method _get_payslip_lines in the class contribution_register_report.

For the moment, I have this code in my custom module :

import time
from datetime import datetime
from dateutil import relativedelta
from openerp.osv import osv
from openerp.report import report_sxw

class contribution_register_report(report_sxw.rml_parse):
    _inherit = 'contribution_register_report'

    def _get_payslip_lines(self, obj):
        payslip_line = self.pool.get('hr.payslip.line')
        payslip_lines = []
        res = []
        self.regi_total = 0.0
        self.cr.execute("SELECT pl.id from hr_payslip_line as pl "\
                        "LEFT JOIN hr_payslip AS hp on (pl.slip_id = hp.id) "\
                        "WHERE (hp.date_from >= %s) AND (hp.date_to <= %s) "\
                        "AND pl.register_id = %s "\
                        "AND hp.state = 'done' "\
                        "ORDER BY pl.slip_id, pl.sequence",
                        (self.date_from, self.date_to, obj.id))
        payslip_lines = [x[0] for x in self.cr.fetchall()]
        for line in payslip_line.browse(self.cr, self.uid, payslip_lines):
            res.append({
                'payslip_name': line.slip_id.name,
                'name': line.name,
                'code': line.code,
                'quantity': line.quantity,
                'amount': line.amount,
                'total': line.total,
                'number': line.slip_id.number,
            })
            self.regi_total += line.total
        return res

BIG THANKS!!!!

UPDATE :

Also tried 

class contribution_register_report(report_sxw.rml_parse):
    _inherit = 'hr_payroll.report.report.contribution_register_report'

Also tried 

class contribution_register_report(report_sxw.rml_parse):
    _inherit = 'hr_payroll.report.contribution_register_report'

May be I should use a « super » somewhere?

Pascal Tremblay
on 1/22/15, 2:45 PM

A little up here! I have still not found how to inherit contribution_register_report class to override the method _get_payslip_lines.... Do you know how to do it?

Pascal Tremblay
on 7/24/15, 7:09 PM
0

Pascal Tremblay

--Pascal Tremblay--
1312
| 5 2 7
Alma, Canada
--Pascal Tremblay--


Pascal Tremblay
On 9/7/16, 3:05 PM

Here is our solution to override the _get_payslip_lines method in a custom module.


from openerp.osv import osv
from openerp.addons.hr_payroll.report.report_contribution_register import contribution_register_report
import logging
_logger = logging.getLogger(__name__)
 
class contribution_register_report_pt(contribution_register_report):
    
    def __init__(self, cr, uid, name, context):
        _logger.error("init NEW BEGIN")
        super(contribution_register_report_pt, self).__init__(cr, uid, name, context)
        self.localcontext.update({
            'report': 'contribution_register_report_pt',
            
        })
        _logger.error("init new END")
        
    def _get_payslip_lines(self, obj):
        _logger.error("_get_payslip_lines NEW BEGIN")
        payslip_line = self.pool.get('hr.payslip.line')
        
        payslip_lines = []
        res = []
        self.regi_total = 0.0
        self.cr.execute("SELECT pl.id from hr_payslip_line as pl "\
                        "LEFT JOIN hr_payslip AS hp on (pl.slip_id = hp.id) "\
                        "WHERE (hp.date_from >= %s) AND (hp.date_to <= %s) "\
                        "AND pl.register_id = %s "\
                        "AND hp.state = 'done' "\
                        "ORDER BY pl.slip_id, pl.sequence",
                        (self.date_from, self.date_to, obj.id))
        payslip_lines = [x[0] for x in self.cr.fetchall()]
        for line in payslip_line.browse(self.cr, self.uid, payslip_lines):
            res.append({
                'payslip_name': line.slip_id.name,
                'name': line.name,
                'code': line.code,
                'quantity': line.quantity,
                'amount': line.amount,
                'total': line.total,
                'number': line.slip_id.number,
            })
            self.regi_total += line.total
        _logger.error("_get_payslip_lines NEW END")
        return res
class wrapped_report_contribution_register_pt(osv.AbstractModel):
    _name = 'report.hr_payroll.report_contributionregister'
    _inherit = 'report.abstract_report'
    _template = 'hr_payroll.report_contributionregister'
    _wrapped_report_class = contribution_register_report_pt

1
David Dufresne
On 1/28/15, 11:44 AM

Hello Pascal,

Just to let you know that we are finishing the quebec and canada payroll for version 7.0. You can test and review the modules here :

https://github.com/OCA/hr/pulls/dufresnedavid

https://github.com/OCA/l10n-canada/pulls/dufresnedavid

Documentation will be posted on this forum soon.

 

Yes I know. but i'm in odoo v8.

Pascal Tremblay
on 1/28/15, 11:48 AM

I understand, but we will port it to v8, when all the code is merged in the v7.

David Dufresne
on 1/28/15, 11:57 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/22/15, 2:19 PM
Seen: 1001 times
Last updated: 9/7/16, 3:05 PM