Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
3052 Zobrazení

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?

Avatar
Zrušit

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.

Autor

It turns out what I needed was odoo hooks

Nejlepší odpověď

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

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
zář 23
2467
1
bře 24
1683
1
dub 24
2850
2
led 24
3848
0
říj 23
2262