Skip to Content

Contributors

Compute and Onchange after create

I am building an API in Odoo 16.0. As we know, there are fields that can be computed (compute) and others that change their value (onchange) depending on the change in another one. Well, what I need to know is if there is a standard way for after creating the object ("model.create") to launch all these computations without having to worry about calling these methods

by Fernando La Chica - 04:26 - 4 Aug 2023

Follow-Ups

  • Re: Compute and Onchange after create
    Onchange might be hard to manage. I would recomend you to use a compute with store=True and readonly=False. This kind of fields are editable, and you can allways add the change there. In order to ensure the execution inside the ORM you just need to use the flush method.

    Kind regards,

    El vie, 4 ago 2023 a las 16:42, Graeme Gellatly (<notifications@odoo-community.org>) escribió:
    The only truly reliable ways for onchanges is the tests.Form class or an OCA module onchange_helper (something like that). But Form is dog slow, like 2 or 3 seconds sometimes and onchange_helper has its oddities too. For these new writable computed fields, my belief is that was kind of the point. Not the computation per se, but the very fact it has an inverse argument so in theory, both the computation and if written the inverse would be called. But tbh, I find them much harder to work with.

    On Sat, Aug 5, 2023 at 2:28 AM Fernando La Chica <notifications@odoo-community.org> wrote:
    I am building an API in Odoo 16.0. As we know, there are fields that can be computed (compute) and others that change their value (onchange) depending on the change in another one. Well, what I need to know is if there is a standard way for after creating the object ("model.create") to launch all these computations without having to worry about calling these methods

    _______________________________________________
    Mailing-List: https://odoo-community.org/groups/contributors-15
    Post to: mailto:contributors@odoo-community.org
    Unsubscribe: https://odoo-community.org/groups?unsubscribe

    _______________________________________________
    Mailing-List: https://odoo-community.org/groups/contributors-15
    Post to: mailto:contributors@odoo-community.org
    Unsubscribe: https://odoo-community.org/groups?unsubscribe



    --
    Enric Tobella Alomar
    CEO & Founder


    by Enric Tobella Alomar - 04:47 - 4 Aug 2023
  • Re: Compute and Onchange after create
    The only truly reliable ways for onchanges is the tests.Form class or an OCA module onchange_helper (something like that). But Form is dog slow, like 2 or 3 seconds sometimes and onchange_helper has its oddities too. For these new writable computed fields, my belief is that was kind of the point. Not the computation per se, but the very fact it has an inverse argument so in theory, both the computation and if written the inverse would be called. But tbh, I find them much harder to work with.

    On Sat, Aug 5, 2023 at 2:28 AM Fernando La Chica <notifications@odoo-community.org> wrote:
    I am building an API in Odoo 16.0. As we know, there are fields that can be computed (compute) and others that change their value (onchange) depending on the change in another one. Well, what I need to know is if there is a standard way for after creating the object ("model.create") to launch all these computations without having to worry about calling these methods

    _______________________________________________
    Mailing-List: https://odoo-community.org/groups/contributors-15
    Post to: mailto:contributors@odoo-community.org
    Unsubscribe: https://odoo-community.org/groups?unsubscribe


    by Graeme Gellatly - 04:42 - 4 Aug 2023
  • Re: Compute and Onchange after create
    What I usually do is to create a specific method to be used by the API.
    It will create the record and then call the relevant onchanges.

    I find that often there is more than that, and this pattern is convenient:
    You may also need to set some sane defaults, run specific checks, do some data conversion cleaning, or even some automation.


    On 04/08/2023 15:28, Fernando La Chica wrote:
    I am building an API in Odoo 16.0. As we know, there are fields that can be computed (compute) and others that change their value (onchange) depending on the change in another one. Well, what I need to know is if there is a standard way for after creating the object ("model.create") to launch all these computations without having to worry about calling these methods

    _______________________________________________
    Mailing-List: https://odoo-community.org/groups/contributors-15
    Post to: mailto:contributors@odoo-community.org
    Unsubscribe: https://odoo-community.org/groups?unsubscribe


    --
    DANIEL REIS
    MANAGING PARTNER

    M: +351 919 991 307
    E: dreis@OpenSourceIntegrators.com
    A: Avenida da República 3000, Estoril Office B, 3º Escr.34, 2649-517 Cascais


    by Daniel Reis - 04:35 - 4 Aug 2023