Skip to Content
Menu
This question has been flagged
6 Replies
3489 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'

Avatar
Discard
Author

May be I should use a « super » somewhere?

Author

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?

Author Best Answer

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

Avatar
Discard
Best Answer

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.

 

Avatar
Discard
Author

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

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