get_pdf api.v8 Odoo。我应该发送什么参数 "records"

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

在record.py的源代码中我找到了

@api.v8
    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)

我在自定义模块中继承了 "record"。我定义了一个这样的按钮:

<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">
                            <form>
                                    <header>
                                            <button string="Envoyer le rapport" type="object" name="send_report_cust"/>
                                    </header>
                                    <sheet>
                                            <group>
                                                    <field name='date'/>
                                            </group>
                                    </sheet>
                            </form>
                    </field>
            </record>

函数send_report_cust在继承的report.py中是这样定义的。

@api.one
    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)

所以 "report_vote_document" 是我的 report_name。我只是在测试用最少的模板创建一个报告。 report_vote_document还不需要任何特定的记录,它只是一个模板格式的测试文本。所以我在 get_pdf 的参数中发送 "records" : "None"。 我收到此错误:

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

这是一个明显的错误,因为 get_pdf 的正文中需要 "records",但我不知道这些记录应该是什么。谁能告诉我这个 "records" 中应该有什么?我应该发送什么?

编辑:我正在尝试调用 get_pdf 但我提供的参数有问题。

这是我所做的:

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

最后一行我也试过了。

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

我得到的错误是:

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

我试图在 "report/models/report.py" 模块 "report" 的源代码中找到一些 pdb.set_trace 的错误。我使用 "send_report_cust" 测试了我的按钮(我们称它为案例 A)和报告的基本自动使用(案例 B)(有效但不允许我拥有自己的按钮并进行一些更改在同一个函数中创建 pdf 之前和之后。)

首先在get_pdf@api.v8中,这表明一切顺利。但是这个 get_pdf 调用了 get_pdf@api.v7 。在这一行中,错误发生在这一行:

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

所以在这里,我再次进入 _get_report_from_name 并使用 pdb.set_trace()。

整个函数运行正确,每个变量在情况 A 中的值与情况 B 中的值完全相同,但是当 _get_report_from_name 转到行

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

错误发生在案例 A 而不是案例 B。

所以我做了 "print report_obj.search(cr, uid, conditions)",这是案例 A 的一个空列表(这是错误描述的内容,但我不明白)和一个包含一个整数的案例 B 的列表。我检查了每一个我用 pdb.set_trace() 测试的 3 个函数中的变量,一切都是相同的。

记录是对象形式的数据库条目。例如account.invoice:当您按下发票上的打印按钮时,它将成为报告的记录。在您的示例中,self 将是您按下按钮的模型 cust_report 模型的记录。

每个 Odoo 报告都是为一个模型定义的。打印时至少需要记录一个型号。