Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
2926 Näkymät

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
Hylkää

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.

Tekijä

It turns out what I needed was odoo hooks

Paras vastaus

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
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
syysk. 23
2329
1
maalisk. 24
1571
1
huhtik. 24
2681
2
tammik. 24
3716
0
lokak. 23
2138