Skip to Content
Menu
This question has been flagged
1 Reply
1939 Views

Hi, I was reading about Odoo Guidelines, expecially this: 

  • In a Model attribute order should be
    1. Private attributes (_name, _description, _inherit, …)

    2. Default method and _default_get

    3. Field declarations

    4. Compute, inverse and search methods in the same order as field declaration

    5. Selection method (methods used to return computed values for selection fields)

    6. Constrains methods (@api.constrains) and onchange methods (@api.onchange)

    7. CRUD methods (ORM overrides)

    8. Action methods

    9. And finally, other business methods.

I see that in 'sale' addon within sale_order.py (sale.py in Odoo14 and previous version), @api.depends like amount_all, get_invoiced, get_invoiced_status and many others have been declared BEFORE field declaration.


Since I'm extending sale order model for my company and I also re-defined _amount_all() method, I was wondering if there is a specific reason behind this choice. 


Thanks, and have a good day !

Avatar
Discard
Best Answer

Hi, 

These methods  _amount_all, _get_invoiced, _get_invoiced_status called computed methods which used by computed fields and they are private ( Private methods have a name starting with an underscore _) and per the guideline (Compute, inverse and search methods in the same order as field declaration) so you can define them before or after field declaration as they are in the same order of field declaration. 

Fields can be computed (instead of read straight from the database) using the compute parameter. It must assign the computed value to the field. If it uses the values of other fields, it should specify those fields using depends().

Avatar
Discard
Related Posts Replies Views Activity
2
Nov 24
476
4
Feb 24
10162
1
Jan 24
369
0
May 23
831
4
Apr 23
38311