【问题标题】:Odoo11 Custom Report with Wizard带有向导的 Odoo11 自定义报告
【发布时间】:2018-09-03 07:49:58
【问题描述】:

我想使用自定义配置打印一些产品条形码。

现在,问题是,我已经创建了向导,但是当我单击打印按钮时,没有数据传输到报告中。

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 不在这里,这就是我遇到的问题。

谁能帮我解释一下为什么会这样?或者还有其他方法可以实现吗?

【问题讨论】:

标签: odoo odoo-11 odoo-wizard


【解决方案1】:

我已经通过get_report_values方法解决了这个问题。

class classname(models.AbstractModel):
_name = 'report.modulename.templatename'

@api.model
def get_report_values(self, docids, data=None):
    # docids: pass from the wizard print button.
    records = self.env[objectname].browse(docids)
    return {
        'doc_ids': docids,
        'doc_model': objectname,
        'docs': records,
        'data': data,}                                                                    

【讨论】:

    猜你喜欢
    • 2019-01-15
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 2010-12-16
    相关资源
    最近更新 更多