Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
379 Lượt xem

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  

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
5
thg 7 15
7613
1
thg 7 15
4014
3
thg 1 25
13105
2
thg 9 23
9931
1
thg 11 22
3419