【问题标题】:Print report if condition in Qweb Odoo 8如果 Qweb Odoo 8 中的条件打印报告
【发布时间】:2016-10-18 14:55:51
【问题描述】:

我正在使用 Qweb 和 Odoo 8,我在 RH 模块中创建了我的报告,问题是我如何在条件下打印此报告

hr_contract 我添加了一个one2many 字段

_columns = {
    'contract_job_ids': fields.one2many(
        'hr.contract.job',
        'contract_id',
        'Jobs',
    ),

我想打印这份报告,只要len(object.contract_job_ids) >= 2

【问题讨论】:

  • 您找到解决方案了吗?

标签: odoo-8 qweb


【解决方案1】:

如果您想在报告打印(或不打印)之前运行特定代码,您可以创建一个定义 render_html 函数的抽象模型,以便您的函数在打印报告时运行,而不是通用 odoo 函数。这在文档中被引用 HERE

看看这个例子。

from openerp import models, fields, api, exceptions

class YourReport(models.AbstractModel):
_name = 'report.your_addon.report_template_id'

@api.multi
def render_html(self, data=None):
    report_obj = self.env['report']
    report = report_obj._get_report_from_name('your_addon.report_template_id')
    docs = self.env['your_addon.your_model'].browse(self._ids)

    for doc in docs:
        if not len(doc.object.contract_job_ids) >= 2:
            raise exceptions.ValidationError("You cant run this report\nYou need more contracts!")

    docargs = {
        'doc_model': report.model,
        'docs': docs,
    }
    return report_obj.render('your_addon.report_template_id', docargs)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多