0

I'm trying to make a conditional function for the invoices. I know how to write but I don't know how can I implement in Odoo by code.

My function

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>
}

When the invoice has any of does countries a message will appear on the report. How can I implement this function in Odoo 12? Thanks

1 Answers1

1

I'm not a fan of too much code in QWeb templates, but this should work:

<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
  • 13,553
  • 3
  • 25
  • 38
  • Hi @CZoellner how can I do the same but instead of countries id, with a country group –  May 12 '21 at 08:42
  • Depends on an existing "xml id" (external id) so that you can use `ref` with it. But wouldn't it be easier to just add a boolean field to `res.country` and using that instead. The code would be smaller too, like ``. – CZoellner May 12 '21 at 08:46
  • But if there id of country group is 3 what I put? –  May 12 '21 at 08:52
  • Don't use database IDs in code. Try to get a cleaner way to fulfill your requirement. – CZoellner May 12 '21 at 09:42
  • Okey, but how can I do that? *Try to get a cleaner way to fulfill your requirement* –  May 12 '21 at 09:47
  • I've given you an alternative. Extend `res.country` with a new boolean field and use that directly like in my comment. – CZoellner May 12 '21 at 11:57