Dealing Readonly attributes with onchange function – Odoo

Dear Readers,

Coming back with great functionality, which is strenuous task for odoo developers i.e is dealing with readonly fields in onchange method of odoo.

Being an odoo consultant, came across the situation where I had to change field value on onchange function and keep some field(s) readonly. With inbuilt framework, it’s not possible to edit that field, hence either we have to make those field(s) as a function or related field(s).

To solve this problem, ASCONE SA/NV came as rescuer for those who were struggling for such functionality, with their module Read Only Bypass. This module provides a solution to the problem of the interaction between ‘readonly’ and ‘on_change’ attributes when used together.

How to use this functionality:

  1. Install the module
  2. To change that behavior you have to set context in xml file on “ir.actions.act_window“:<record id=”sale.action_quotations” model=”ir.actions.act_window”>
    <field name=”context”>{‘readonly_by_pass’: True}</field>

    or by setting fields with additional readonly_by_pass parameter:
    <record id=”sale.action_quotations” model=”ir.actions.act_window”>
    <field name=”context”>
    {‘readonly_by_pass’: [‘readonly_field_1’, ‘readonly_field_2’,]}

    On one2many field(s), you can also pass the context in the field definition:
    <field name=”one2many_field” context=”{‘readonly_by_pass’: True}”/>

I believe this functionality will be very much useful for odoo developers. For any queries just drop in a line, will be happy to assist.

Hope you found this article helpful.

Bharat R. Devnani
ERP Consultant – Odoo