Skip to Content
Menu
This question has been flagged
4 Replies
7721 Views

How inverse attribute works in Odoo for compute fields?

Avatar
Discard
Best Answer

Hi,

Suppose if you have two fields in your model, lets say, small_letter and capital_letter, and capital_letter is a computed field which computes the value from small_letter field in capitalized form.

ie, if you enter value as cat in small_letter field , then compute function will compute the value as CAT , ie in capitalized version of small_letter field value.

Suppose if we need to record value directly in the capital_letter field, user enter value as ODOO in capital_letter field, then the inverse function can be used to set odoo in small_letter field.


Inverse is the reverse process of computing. I hope the above example will give you idea. 

For more: How To Set Inverse Function For Computed Field In Odoo


Thanks

Avatar
Discard
Best Answer

Reply : In Odoo, the "inverse" attribute is used in the definition of computed fields to specify a method that will be called when the value of the computed field is set. The purpose of the "inverse" method is to update the underlying fields that contribute to the computed field based on the new value assigned to it. When a computed field is defined in Odoo, it is typically based on other fields or data within the record. These fields are referred to as the "dependencies" of the computed field. The "inverse" method provides a way to update those dependencies when the value of the computed field is changed. Note that for the inverse method to work correctly, the computed field should be defined with the store=True attribute. This tells Odoo to store the computed field's value in the database, allowing it to be set explicitly and triggering the inverse method appropriately.

Regards,

Ksolves Team!

Avatar
Discard
Best Answer

Hi,

The inverse attribute in Odoo for compute fields is used to reverse the computation of the field. This means that if you change the value of the field, the inverse method will be called to update the values of the fields that the compute field depends on.

For example, let's say you have a compute field called total_price that depends on the quantity and price_unit fields. If you change the value of the quantity field, the inverse method for the total_price field will be called to update the value of the total_price field.

The inverse method is defined in the model definition file. The method takes the record as an argument and returns the updated values of the fields that the compute field depends on.

Hope it helps

Avatar
Discard
Best Answer

Hello,

Consider a scenario where your model has two fields: "small_letter" and "capital_letter." The "capital_letter" field is a computed field that automatically capitalizes the value from the "small_letter" field.

For example, if the user enters "cat" in the "small_letter" field, the compute function will transform it to "CAT," representing the capitalized version of the "small_letter" field value.

Now, let's say the user directly enters "ODOO" in the "capital_letter" field. In this case, you can use an inverse function. The inverse function will set "odoo" in the "small_letter" field, ensuring both fields remain synchronized.

Unique value: By employing computed fields and inverse functions, you can create a seamless and automated process that ensures consistency between the "small_letter" and "capital_letter" fields, reducing manual efforts and data entry errors.


Avatar
Discard
Related Posts Replies Views Activity
2
Aug 23
2360
1
Jul 23
2518
0
Jul 23
2183
0
Jul 23
1975
0
Jan 21
3078