Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
333 Представления

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  

Аватар
Отменить
Лучший ответ

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.

Аватар
Отменить
Автор

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

Лучший ответ

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.

Аватар
Отменить
Related Posts Ответы Просмотры Активность
5
июл. 15
7603
1
июл. 15
3990
3
янв. 25
13078
2
сент. 23
9896
1
нояб. 22
3410