T.Nel T.Nel - 1 year ago 138
Python Question

get_pdf api.v8 Odoo. What parameter should I send as "records"

In the source code of record.py I found

def get_pdf(self, records, report_name, html=None, data=None):
return Report.get_pdf(self._model, self._cr, self._uid, records.ids,
report_name, html=html, data=data, context=self._context)

I inherited "record" in my custom module. And I defined a button like this:

<record id="report_maker_form" model="ir.ui.view">
<field name="name">Impression</field>
<field name="model">cust_report</field>
<field eval="1" name="priority"/>
<field name="arch" type="xml">
<button string="Envoyer le rapport" type="object" name="send_report_cust"/>
<field name='date'/>

The function send_report_cust is defined like this in the inherited report.py.

def send_report_cust(self):
#self.pool.get('report').get_pdf(self, None, "report_vote_document", None, None)
self.get_pdf(None, "report_vote_document", None, None)

So "report_vote_document" is my report_name. I'm just testing to create a report with minimal template. report_vote_document doesn't require any specific records yet, it's just a testing text in template format. So I send as "records" : "None" in parameters for get_pdf.
I get this error:

AttributeError: 'NoneType' object has no attribute 'ids'

Which is kind of an obvious error since "records" is needed in the get_pdf's body, but I don't know what thoses records are supposed to be. Can anyone tell me what's supposed to be in this "records". What should I send?

EDIT: I'm trying to call get_pdf but something is wrong with the arguments I give to it.

Here is what I did:

def send_report_cust(self):
self.get_pdf(self, "my_report_name", "my_report_template", None)

I also tried this for the last line.

self.get_pdf(**my_model_name** , "my_report_name", "my_report_template", None)

The error I get is :

File "/usr/lib/python2.7/dist-packages/openerp/addons/report/models/report.py", line 508, in _get_report_from_name
idreport = report_obj.search(cr, uid, conditions)[0]
IndexError: list index out of range

I tried to get the error with some pdb.set_trace in the source code of the module "report", in "report/models/report.py". Which I tested with my button using "send_report_cust" (let's call it case A) and the basic automatic use of report (case B) with (which works but won't allow me to have my own button and to do some changes before and after the pdf creation in the same function.)

First in the
, which show all went right in this. But this get_pdf call the
. In this one, the error occurs on this line:

report = self._get_report_from_name(cr, uid, report_name)

So here again, I went in _get_report_from_name and used pdb.set_trace().

The whole function goes right and every single variable as exactly the same value in case A than in case B but when _get_report_from_name goes to the line

idreport = report_obj.search(cr, uid, conditions)[0]

The error occurs on case A but not on case B.

So I did "print report_obj.search(cr, uid, conditions)" which is an empty list for case A (which is what the error describes but I don't get it) and a list with one int for case B. I checked every single variables amongs the 3 functions I tested with pdb.set_trace() and everythings are identical.

Answer Source

Records are database entries in object form. For example account.invoice: when you press the print button on an invoice, it will be the record for the report. In your example, self will be the record of the model cust_report model you pressed the button on.

Every Odoo report is defined for a model. It will need at least one record of the model while printing.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download