Sunday, 14 April 2013

How to Inherit Custom RML Report Parser Class in OpenERP

How to Inherit Custom RML Report Parser Class in OpenERP

RML parser classes are registered globally as Services. For example the Sale Order parser class is registered in addons/sale/report/ with :
report_sxw.report_sxw('', 'sale.order','addons/sale/report/sale_order.rml', parser=order, header="external")
If you try to create another parser with the same name, you get an error : The report "sale.order" already exists!

A simple way to replace the sale.order parser and use a custom parser class is to remove it from the global service registry with :

from netsvc import Service
del Service._services['']
Here is a full example we used to convert amount into text in the sale order report :

from import sale_order
from tools import amount_to_text_en
from report import report_sxw
# create a custom parser inherited from sale order parser:
class new_order_report(sale_order.order):
    '''Custom parser with an additional method
    def __init__(self, cr, uid, name, context):
        super(new_order_report, self).__init__(cr, uid, name, context)
            'convert': self.convert,
 def convert(self, amount, cur):
        return amount_to_text_en.amount_to_text(amount,'en',cur)
# remove previous service :
from netsvc import Service
del Service._services[''] 
# register the new report service :

Copy and past the RML file and add following code :
In Words: [[ convert(o.amount_total, ]]

Now, you need to overwrite report's record in xml :
<report auto="False" id="sale.report_sale_order" model="sale.order" name="sale.order" rml="addons/path/report/sale_order.rml" string="Quotation / Order" usage="default"/>


  1. Arya,
    thanks for the solution was helpful



  2. Thanks Arya, good solution it helps.