我想使用自定义配置打印一些产品条形码。
现在,问题是,我已经创建了向导,但是当我单击打印按钮时,没有数据传输到报告中。
class BarcodeConfig(models.Model):
_name = 'report.barcode.print'
@api.model
def _default_product_line(self):
active_ids = self._context.get('active_ids', [])
products = self.env['product.product'].browse(active_ids)
return [(0, 0, {'product_id': x.id, 'qty': 1}) for x in products]
product_line = fields.One2many('product.print.wizard', 'barcode_id', string="Products",
default=_default_product_line)
@api.multi
def print_report(self):
data = self.read()[0]
ids = [x.product_id.id for x in self.product_line]
config = self.env['barcode.config'].get_values()
data.update({
'config': config
})
datas = {'ids': ids,
'form': data
}
return self.env.ref('odoo_barcode.barcode_report').report_action(self,data=datas)
在上面的代码中,我也有ids
模型product.product
。
<template id="report_barcode_temp">
<t t-call="web.html_container">
<t t-call="web.internal_layout">
<div class="page">
<h2>Report title</h2>
<strong t-esc="docs"/>
<strong t-esc="doc_ids"/>
<span t-esc="data"/>
<t t-foreach="docs" t-as="o">
<span t-esc="o"/>
<p>This object's name is
<span t-field="o.name"/>
</p>
</t>
</div>
</t>
</t>
在上面的代码中,我只是想打印我拥有的数据,但我在文档中什么都没有。
<strong t-esc="docs"/>
这行打印product.product
模型也是如此。但ids
不是在这里,这就是我遇到的问题。
谁能帮我解释为什么会这样?或者有没有其他方法可以实现这一目标?