Skip to content

[..,16,17,18,19] server_environement: Fields managed by server.env.mixin cannot be edited in some states #289

Description

@lmignon

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:

  • All versions

Steps to reproduce the behavior:

  1. 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}},
    )
  2. Make the field managed by the server environment.

  3. Open a record in the draft state.

  4. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions