【问题标题】:How can I implement this function in Odoo 12 or OpenERP?如何在 Odoo 12 或 OpenERP 中实现此功能?
【发布时间】:2021-08-01 22:42:06
【问题描述】:

我正在尝试为发票创建一个条件函数。 我会写,但我不知道如何在 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 中实现此功能? 谢谢

【问题讨论】:

    标签: python xml odoo helper


    【解决方案1】:

    我不喜欢 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>
    

    【讨论】:

    • 嗨@CZoellner 我怎么能做同样的事情,但不是国家ID,而是国家组
    • 取决于现有的“xml id”(外部 id),以便您可以使用 ref 与它。但是,将布尔字段添加到 res.country 并改用它不是更容易吗?代码也会更小,比如&lt;t t-if="o.emb_confirm_message is True and o.partner_id.country_id.new_boolean_field is True"&gt;
    • 但是如果国家组的 id 是 3 我放了什么?
    • 不要在代码中使用数据库 ID。尝试以更清洁的方式满足您的要求。
    • 好吧,但我该怎么做呢? 尝试以更清洁的方式来满足您的要求
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多