Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

RFC: Add oca.decorators.onwrite #6

@yajo

Description

@yajo

This is something I've been waiting for a long time, but now that we have this, I don't know which one would be the way to go.

Read the motivation and discussion on implementation from odoo/odoo#11042.

Summarizing, basically I'd love to legally abuse @api.constrains to have a method that gets executed whenever write() or create() are called and include the defined fields.

One way to do it would be just onwrite = odoo.api.constrains, and leave further work when a incompatibility arises, given the decorator can actually be abused.

Another way to do it would be to do it fine from the beginning. The decorator would be something like:

def onwrite(*fields):
    ...

When no fields come in, it is called on every write and create. When there are fields, it is called only when write and create dicts include keys those fields. Recursion should be prevented automatically.

The doubt is how to overload both methods automatically when all I have is a decorator... 🤔

Ideas?

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