Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
9860 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 22
44852
3
thg 8 15
12511
0
thg 3 15
3991
0
thg 3 15
11586
0
thg 7 25
5137