Odoo Help


1 Answer

patrick Netherlands


| 5 4 9
Baarn, Netherlands
patrick Netherlands
5/22/13, 11:33 AM

In order to use python code (in general) within an RML-file, you have to add that method to the localcontext of the report.


The following code I have as sale_order.py in the report-folder of my custom module, where the custom report is as well.

from sale.report import sale_order
from report import report_sxw

# create a custom parser inherited from sale order parser:
class new_order_parser(sale_order.order):
    '''Custom parser with an additional method
    def __init__(self, cr, uid, name, context):
        super(new_order_parser, self).__init__(cr, uid, name, context=context)
            'has_line_discount': self._has_line_discount,

    def _has_line_discount(self, order):
        return any([l.discount for l in order.order_line])

    def _payment_term(self, order):
        return _(order.payment_term.name)

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

# register the new report service :
   'sale.order', #model to use

To use the custom report, I import the above fill in __init__.py (also in the same report-directory):

import sale_order

in the file __init__.py at the root of my custom module, I have the line:

import report

The only issue I run into is that I have to specify manually within openERP where my report.rml is located.

1 Comment
herbert6453 Germany
5/22/13, 12:12 PM

Thanks ... but i think python build in methods e.g. sort() o..line.sort() are direct available --- You can define the location of the new rml file inside a <report> tag in a xml file.

<report id="sale.report_sale_order" model="sale.order" name="newmodul.sale.order" rml="newmodul/report/sale_order.rml" string="Quotation / Order"/>

Ask a Question
Keep Informed
0 follower(s)
About This Community

This platform 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.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now