Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
3055 Представления

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


Hope it helps

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
сент. 23
2469
1
мар. 24
1684
1
апр. 24
2851
2
янв. 24
3849
0
окт. 23
2262