Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
4738 Visualizzazioni

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
Abbandona
Autore

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

Risposta migliore

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
Abbandona
Risposta migliore

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
Abbandona
Autore

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'

Post correlati Risposte Visualizzazioni Attività
1
nov 16
4432
2
feb 24
14088
1
ott 22
5700
1
ago 21
4140
0
lug 21
2146