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.

4

How to inherit standard report parser class in qweb reports

By
Yogesh
on 10/31/14, 4:53 AM 5,340 views

I am modifying hr_payslip report in custom module. I want to add a custom method to this report for this I need to update localcontext with custom method for this report. I am trying

 

class payslip_report(report_sxw.rml_parse):

    def __init__(self, cr, uid, name, context):
        super(payslip_report, self).__init__(cr, uid, name, context)
        self.localcontext.update({
            'get_payslip_total':self.get_payslip_total,
        })


    def get_payslip_total(self, obj):
        payslip_line = self.pool.get('hr.payslip.line')
        res = []
        total = 0.0
        for id in range(len(obj)):
            if obj[id].appears_on_payslip is True:
                total = total + obj.total

        return total

 

and calling in qweb template like

<td><span t-esc="get_payslip_total(o.line_ids)"/> </td>

 

but getting error  "QWebException: "'NoneType' object is not callable" while evaluating
'get_payslip_lines(o.line_ids)". Can anyone help me what I am missing here?

Hi, I've you solved your issue?

Skillteam, Houssine BAKKALI
on 11/17/14, 10:39 AM

No

Yogesh
on 11/17/14, 10:41 AM

I'm also stuck with this. Just trying to reuse the parser for a new qweb report and it doesn't seems to be possible...

Skillteam, Houssine BAKKALI
on 11/17/14, 11:29 AM

I also got stuck and had to pause the task , if you get solution please post the answer it will help me and others. I have to start that task again in 3-4 days.

Yogesh
on 11/17/14, 11:48 AM

i've maybe go a solution for my case... and I think that for your case you will need to override payslip_report instead of report_sxw.rml_parse with something like : class payslip_report(payslip_report): and importing previously the payslip_report with someting like import addons.hr_payroll.report.report_payslip hope this help

Skillteam, Houssine BAKKALI
on 11/17/14, 12:02 PM

try this, https://www.odoo.com/forum/help-1/question/how-output-a-odoo-8-datetime-field-without-time-on-a-qweb-report-67948#answer-67995

Sajin Aziz
on 11/18/14, 12:27 AM

Did you solve this post? I have the same.

Pascal Tremblay
on 1/23/15, 7:16 AM
2

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 9/4/15, 1:39 AM

Yogesh,

In order to inherit your"payslip_report" class, just inherit your previous class, using python inheritance.....as:

from openerp.addons.[your_mocule_name].[directory_structue/parent_folder] import payslip_report

and then redefine the class,

class payslip_report(payslip_report.payslip_report):

# here you can override or add previous/new functions.......

Don't forget to keep your [your_module_name] dependency in __openerp__.py

Hope it helps you and i am posting this post after so much long time, since i got it now and it may help you or someone else :)

2

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 10/31/14, 8:41 AM

You should be inheriting from the payslip_report class in hr_payroll/report/report_payslip.py.  First, before the class definition you should put: from hr_payroll.report import report_payslip.  Then the class definition should be class payslip_report(report_payslip.payslip_report).  This way, you chain your inheritance (this is python inheritance, not Odoo ORM inheritance) through the class that provides the get_payslip_lines method.

Also don't forget to re-register your report with the new parser.  At the end of the py file, add the following line: report_sxw.report_sxw('report.payslip', 'hr.payslip', 'hr_payroll/report/report_payslip.rml', parser=payslip_report) adjust the information as necessary.

Thanks for your reply. I haven't gave a try yet all seems okay to me except registry of new parser. it is qweb report so no .rml.

Yogesh
on 10/31/14, 8:48 AM
0

Axel Mendoza

--Axel Mendoza--
10318
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 10/15/15, 5:54 AM

I write a more extensive explanation of qweb report parsers at:

https://www.odoo.com/es_ES/forum/help-1/question/how-to-define-a-custom-methods-functions-to-be-used-in-a-qweb-report-how-to-define-and-use-a-report-parser-92244

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

6 follower(s)

Stats

Asked: 10/31/14, 4:53 AM
Seen: 5340 times
Last updated: 10/10/16, 2:31 AM