Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
336 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

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

Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
5
čvc 15
7604
1
čvc 15
3990
3
led 25
13080
2
zář 23
9897
1
lis 22
3412