How to recompute stored functional field values in Odoo?

一世执手 提交于 2019-12-21 02:26:09

问题


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?


回答1:


(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.




回答2:


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.




回答3:


in the odoo11

env.add_todo(model._fields['loading_time'], env['product.product'].search([]))
model.recompute()


来源:https://stackoverflow.com/questions/34089393/how-to-recompute-stored-functional-field-values-in-odoo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!