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.

5

How can i use a python Built-in Function (e.g. sorted) in a rml file?

By
herbert6453
on 5/22/13, 7:06 AM 3,472 views

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

1

patrick

--patrick--
1958
| 5 4 7
Baarn, Netherlands
--patrick--
patrick
On 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.

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"/>

herbert6453
on 5/22/13, 12:12 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

0 follower(s)

Stats

Asked: 5/22/13, 7:06 AM
Seen: 3472 times
Last updated: 3/16/15, 8:10 AM