Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
4730 Vistas

I had a doubt regarding the .py code to print a report.For purchase order the code in the .py file is being provided below.But I didn't understand the last line report_sxw.report_sxw('report.purchase.order','purchase.order','addons/purchase/report/order.rml',parser=order).

class order(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(order, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({'time': time})

report_sxw.report_sxw('report.purchase.order','purchase.order','addons/purchase/report/order.rml',parser=order)

How is purchase.order given in that line.What is its significance and where is it taken from?The class name is order yet the report.sxw is given the name purchase.order.Can anyone please give me a clarification.

Avatar
Descartar
Autor

Can you please give explanation for the purchase.order given in report_sxw

Mejor respuesta

The parser inherit from the report_sxw.rml_parse object and it add to the localcontext, the function time so it will be possible to call it in the report.

After an instance of report_sxw.report_sxw is created with the parameters

  1. the name of the report
  2. the object name on which the report is defined
  3. the path to the rml file
  4. the parser to use for the report (by default rml_parse)
  5. a boolean to add or not the company header on the report (default True)

report_sxw The second parameter is object name 'purchase.order' for Purchase Module

from openerp.report import report_sxw File Location server\server\openerp\report\report_sxw.py

Avatar
Descartar
Mejor respuesta

As prakash suggested: See this for clarification.

order is a custom parser that inherits from report_sxw.rml_parse.
The __ini__ function is overridden to give access to the time via the localcontext.

From the given link above:

After, an instance of report_sxw.report_sxw is created with the parameters:
- the name of the report
- the object name on which the report is defined
- the path to the rml file
- the parser to use for the report (by default rml_parse)
- a boolean to add or not the company header on the report (default True)

If you check the code of report_sxw.report_sxw you will find the definition of its __init__ function:

class report_sxw(report_rml, preprocess.report):
def __init__(self, name, table, rml=False, parser=rml_parse, header='external', store=False):
    report_rml.__init__(self, name, table, rml, '')
    self.name = name
    self.parser = parser
    self.header = header
    self.store = store
    self.internal_header=False
    if header=='internal' or header=='internal landscape':
        self.internal_header=True

There you can see what the documentation already told you: The second argument is the table/model/object on which you create the report.
In your case 'purchase.order'. It has nothing to do with the name of the parser; this is the fourth argument.

Regards.

Avatar
Descartar
Autor

I tried the code for printing in the warranty module.But on clicking the print button error occurs that

AttributeError: 'warranty_warranty' object has no attribute '%(collection_docket)d'

Publicaciones relacionadas Respuestas Vistas Actividad
1
nov 16
4420
2
feb 24
14076
1
oct 22
5698
1
ago 21
4134
0
jul 21
2140