This question has been flagged
1 Reply
9486 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

Avatar
Discard
Best Answer

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:
Avatar
Discard

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