I want to use a python Built-in Function for example reversed() and sorted() in a rml file. I got a name is not defined error.
Is there a special syntax to use python Built-in Functions or they are not available at all in rml?
Thanks
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
I want to use a python Built-in Function for example reversed() and sorted() in a rml file. I got a name is not defined error.
Is there a special syntax to use python Built-in Functions or they are not available at all in rml?
Thanks
In order to use python code (in general) within an RML-file, you have to add that method to the localcontext of the report.
Example
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)
self.localcontext.update({
'has_line_discount': self._has_line_discount,
})
self.localcontext.update({
'show_discount':self._show_discount,
'payment_term':self._payment_term,
})
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 :
report_sxw.report_sxw(
'report.sale.order',
'sale.order', #model to use
'path/to/new/report.rml',
parser=new_order_parser
)
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.
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"/>