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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Księgowość
- Zapasy
- PoS
- Project
- MRP
To pytanie dostało ostrzeżenie
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
Podoba Ci się ta dyskusja? Dołącz do niej!
Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!
Zarejestruj sięPowiązane posty | Odpowiedzi | Widoki | Czynność | |
---|---|---|---|---|
|
1
wrz 23
|
2145 | ||
|
1
mar 24
|
1393 | ||
|
1
kwi 24
|
2354 | ||
|
2
sty 24
|
3496 | ||
|
0
paź 23
|
1917 |
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