How to recompute stored functional field values in Odoo?

前端 未结 4 1270
日久生厌
日久生厌 2020-12-09 21:50

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?

相关标签:
4条回答
  • 2020-12-09 22:29

    (Because I came here via google:)

    You can also do this from the Odoo Shell:

    # python odoo.py shell -c openerp-server.conf  -d <database>
    
    >>> model = env['account.invoice']
    >>> env.add_todo(model._fields['amount_total'], model.search([]))
    >>> model.recompute()
    >>> env.cr.commit()
    

    Odoo shell is available in 9, 10 and via an OCA module in 8.

    0 讨论(0)
  • 2020-12-09 22:35

    In v13 the above syntax still works, but the add_todo should be replaced by add_to_compute:

    env.add_to_compute(model._fields['amount_total'], model.search([]))
    model.recompute()
    
    0 讨论(0)
  • 2020-12-09 22:43

    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.

    0 讨论(0)
  • 2020-12-09 22:47

    in the odoo11

    env.add_todo(model._fields['loading_time'], env['product.product'].search([]))
    model.recompute()
    
    0 讨论(0)
提交回复
热议问题