Module
server_environment
Describe the bug
Fields managed by server.env.mixin cannot be manually edited in a state where the original field is writable if the field uses the readonly attribute together with states.
The issue is caused by the sparse field generated by Odoo to store the server environment value. This sparse field does not get an inverse method when the original field is declared with readonly=True and a state overriding it to make it writable.
As a result, the field remains readonly from the ORM's perspective, even when the original field is writable in the current state.
To Reproduce
Affected versions:
Steps to reproduce the behavior:
-
Define a field managed by server.env.mixin with readonly=True and make it writable in a specific state, for example:
my_field = fields.Char(
readonly=True,
states={"draft": {"readonly": False}},
)
-
Make the field managed by the server environment.
-
Open a record in the draft state.
-
Try to manually edit my_field.
Expected behavior
The field should be editable in the draft state, as specified by the field's states definition.
Actual behavior
The field cannot be edited manually because the sparse field generated by Odoo is readonly and has no inverse method.
Additional context
The root cause is related to the way server.env.mixin uses a sparse field as the source field for the original field.
When the original field is declared as:
readonly=True,
states={"draft": {"readonly": False}},
the sparse field generated by Odoo does not get an inverse method and is therefore a purely readonly field.
This can be seen in Odoo's base_sparse_field implementation:
https://github.com/odoo/odoo/blob/19.0/addons/base_sparse_field/models/fields.py#L46
Consequently, even though the original field is writable in the draft state, assigning a value to it is prevented by the readonly sparse field used by server.env.mixin.
Module
server_environmentDescribe the bug
Fields managed by
server.env.mixincannot be manually edited in a state where the original field is writable if the field uses thereadonlyattribute together withstates.The issue is caused by the sparse field generated by Odoo to store the server environment value. This sparse field does not get an inverse method when the original field is declared with
readonly=Trueand a state overriding it to make it writable.As a result, the field remains readonly from the ORM's perspective, even when the original field is writable in the current state.
To Reproduce
Affected versions:
Steps to reproduce the behavior:
Define a field managed by
server.env.mixinwithreadonly=Trueand make it writable in a specific state, for example:Make the field managed by the server environment.
Open a record in the
draftstate.Try to manually edit
my_field.Expected behavior
The field should be editable in the
draftstate, as specified by the field'sstatesdefinition.Actual behavior
The field cannot be edited manually because the sparse field generated by Odoo is readonly and has no inverse method.
Additional context
The root cause is related to the way
server.env.mixinuses a sparse field as the source field for the original field.When the original field is declared as:
the sparse field generated by Odoo does not get an inverse method and is therefore a purely readonly field.
This can be seen in Odoo's
base_sparse_fieldimplementation:https://github.com/odoo/odoo/blob/19.0/addons/base_sparse_field/models/fields.py#L46
Consequently, even though the original field is writable in the
draftstate, assigning a value to it is prevented by the readonly sparse field used byserver.env.mixin.