Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged

I am trying to migrate a module from Odoo 16 to Odoo 18, but I have an error this code block:

                <field name="vat" placeholder="e.g. 123456789" string="RNC"

                       readonly="not parent_id"

                       invisible="country_id != ref('base.do') or not is_company"

                       required="is_fiscal_info_required" />


                <field name="vat" placeholder="e.g. 00112345678" string="Cédula"

                       readonly="not parent_id"

                       invisible="country_id != ref('base.do') or is_company"

                       required="is_fiscal_info_required" />

country_id != ref('base.do') is a valid expretion  

Avatar
Opusti
Best Answer

Hi,

In Odoo 17+ (and now 18), XML expressions in views use a limited domain-like syntax, and ref('base.do') is not valid within a field attribute, such as invisible or readonly.


Please refer to the code below:


Python


from odoo import models, fields, api


class ResPartner(models.Model):

    _inherit = 'res.partner'


    is_dominican = fields.Boolean(compute="_compute_is_dominican", store=False)


    @api.depends('country_id')

    def _compute_is_dominican(self):

        dom_country = self.env.ref('base.do', raise_if_not_found=False)

        for rec in self:

            rec.is_dominican = rec.country_id == dom_country


XML


<field name="vat" placeholder="e.g. 123456789" string="RNC"

       readonly="not parent_id"

       invisible="not is_dominican or not is_company"

       required="is_fiscal_info_required"/>


<field name="vat" placeholder="e.g. 00112345678" string="Cédula"

       readonly="not parent_id"

       invisible="not is_dominican or is_company"

       required="is_fiscal_info_required"/>


Hope it helps.

Avatar
Opusti
Avtor

This only shows the first one, only the field with RNC as the string.

Best Answer

Your best bet is to define a computed boolean field on that model, i.e. show_child_contact_vat, and use it as the invisible condition.

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
5
jul. 15
7605
1
jul. 15
3991
3
jan. 25
13086
2
sep. 23
9923
1
nov. 22
3414