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 Inherit Custom RML Report Parser Class in OpenERP

By
feriel bendimerad
on 2/9/14, 6:18 AM 5,462 views

hey everybody, i'm working on how to inherit custom RML report parser calss in openERP , here my essay... python file:

from account.report import account_print_invoice
from tools.integerToWords_fr import final_result

from openerp.report import report_sxw
from netsvc import Service
del Service._services['report.account.print.invoice'] 


# create a custom parser inherited from sale order parser:
class new_invoice_report(account_print_invoice.account_invoice):
    '''Custom parser with an additional method
    '''
    def __init__(self, cr, uid, name, context):
        super(new_invoice_report, self).__init__(cr, uid, name, context)
        self.localcontext.update({
            'final_result':final_result,
        }) 



# remove previous sale.report service :


# register the new report service :
report_sxw.report_sxw(
    'report.account.print.invoice',
    'account.print.invoice',
    'addons/l10n/report/account_print_invoice_d.rml',
    parser=new_invoice_report
)

xml file:

 <?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
 <report
            auto="False"
            id="account_invoices_d"
            model="account.invoice"
            name="account.invoice_d"
            rml="l10n/report/account_print_invoice_d.rml"
            string="Invoices"
            attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
            attachment_use="True"
            usage="default"
            />
 </data>
 </openerp>

i have done the code below but still taking the original parser

2
NSC
On 2/9/14, 1:37 PM

I think you should either change id or name inside your .xml file. Recently, I chose id, but I have a really strange side effect on printing (sometimes, it is loading, but not showing - I do not know, why) - therefore I would suggest you to leave id as original and only change name. Inside your report parser's registration block for your new service, you have to take care that the first line (name of new service) should be equal with the one chosen in xml file with the difference that it needs the prefix "report.". In your case, it should be like that: report.account.invoice_d. And you should unregister old service before registering replacement. Look at my code:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report>
        auto="False"
        id="account_invoices"
        model="account.invoice"
        name="fq.account.invoice"
        rml="fq_reports/report/fq_account_print_invoice.rml"
        string="Invoices"
        attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
        attachment_use="False"
        usage="default"
 />
</data>
</openerp>

import time
from openerp.report import report_sxw

class fq_account_invoice(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
    super(fq_account_invoice, self).__init__(cr, uid, name, context=context)
    self.localcontext.update({
        'time': time,
    })

# remove previous sale.report service :
from netsvc import Service
del Service._services['report.account.invoice']

report_sxw.report_sxw(
'report.fq.account.invoice',
'account.invoice',
'fq_reports/report/fq_account_print_invoice.rml',
parser=fq_account_invoice
)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

After having changed your module, you should update it (Settings --> installed modules) and restart your openerp server.

NSC
on 2/9/14, 1:40 PM

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

2 follower(s)

Stats

Asked: 2/9/14, 6:18 AM
Seen: 5462 times
Last updated: 3/16/15, 8:10 AM