2
votes

I've a conditional readonly field in the view of a model. This model is used as a One2many field on it's parent model. When I edit one of the elements of the One2many field, click another of the elements the value of the field that has the conditional readonly disappears.

In my searches for this problem I've found the next related issue on odoo github.

My problem is quite similar, but the value of the field completely disappears when the readonly condition is False. When the condition is True the value reappears after clicking outside of the element (another element or outside of the form).

Basically, the models are:

One2many class:

class ChildClass(models.Model):
    _name = 'child.class'
    some_field = fields.Integer()
    conditional_field = fields.Boolean()
    conditional_readonly_field = fields.Integer()
    parent_field = fields.Many2one(
        'parent.class'
    )

Parent class:

class ParentClass(models.Model):
    _name = 'parent.class'
    one2many_field = fields.One2many(
        'child.class',
        'parent_field'
    )

View

<odoo>
  <data>
    <record model="ir.ui.view" id="view_draft_order_form">
      <field name="name">parent.class.form</field>
      <field name="model">parent.class</field>
      <field name="arch" type="xml">
        <form>
          <field name="one2many_field">
            <form>
              <field name="some_field"/>
              <field name="conditional_readonly_field" attrs="{'readonly': [('conditional_field', '=', True)]}"/>
            </form>
          </field>
        </form>
      </field>
  </data>
<odoo>

So, the value of the conditional_readonly_field disappears after editing some_field and clicking on another element of the One2many field. The problem is that it may be after the first, second or some number of clicks (I've been trying and it's not consistent).

For the record, when the readonly condition is removed, the problem disappears.

Thanks in advance for any suggestions!

1

1 Answers

0
votes

Yes, It will disappear when you give readonly attributes. For overcome this problem, pass the value in create method as well in the write method. This will solve your problem.