Search code examples
odooodoo-8

How to recompute stored functional field values in Odoo?


Sometimes stored fields must be recomputed, but triggers can not be launched (e.g. in case of SQL injection).

How to recompute them an easy way?


Solution

  • In v8.0 (should work in 9.0 too) you can do it like that:

    # Recompute amount_total for account.invoice
    
    env.add_todo(model._fields['amount_total'], object)
    model.recompute()
    
    # where
    # object - recordset of instances to recompute field for
    # model - recordset instances model
    

    Above code can be used in server action directly.