如何在 Odoo 12 或 OpenERP 中实现此功能?

问题描述

我正在尝试为发票创建一个条件函数。 我知道怎么写,但我不知道如何通过代码odoo 中实现。

我的功能

if(country_id==base.au || country_id==base.ca || country_id==base.jp || country_id==base.li)
{
   <t t-if="o.emb_confirm_message == True">
       <strong><th t-field="o.emb_message"/></strong>
   </t>
}

当发票有任何国家/地区时,报告上会显示一条消息。 如何在 odoo 12 中实现此功能? 谢谢

解决方法

我不喜欢 QWeb 模板中的太多代码,但这应该可行:

<t t-set="is_for_emb_message_country"
    t-value="o.partner_id.country_id.id in [o.env.ref('base.au').id,o.env.ref('base.ca').id,o.env.ref('base.jp').id,o.env.ref('base.li').id]" />
<t t-if="o.emb_confirm_message is True and is_for_emb_message_country">
       <strong><th t-field="o.emb_message"/></strong>
</t>