跳至內容
選單
此問題已被標幟
1 回覆
2018 瀏覽次數

I have a new field for a model with existing records. It works on new records but I also want old records to have a value on the field. How can I achieve this?

頭像
捨棄

What is the type of your new field? Is it a normal field or compute field?
It would be better if you share your code.

作者

It turns out what I needed was odoo hooks

最佳答案

Hi,

You can use odoo Post hooks for this problem:

You need to post_init_function in your manifest file:

              'post_init_hook':'add_field_test'

Import the post_init_hook function in your __init__.py file and define the function

from . hooks import add_field_test

Inside the hooks.py file define the function as follows,

from odoo import api,SUPERUSER_ID

def add_field_test(cr,registry):
​env=api.Environment(cr,SUPERUSER_ID,{})
​for rec in env[demo.model].search([]):
​rec.field="value"

For more information refer: https://www.cybrosys.com/blog/how-to-use-hooks-in-odoo-development

Regards

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
9月 23
1460
1
3月 24
894
1
4月 24
1658
2
1月 24
2684
0
10月 23
1328