Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
3043 Weergaven

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
Annuleer

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.

Auteur

It turns out what I needed was odoo hooks

Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
sep. 23
2464
1
mrt. 24
1679
1
apr. 24
2843
2
jan. 24
3846
0
okt. 23
2259