Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2677 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ

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.

Tác giả

It turns out what I needed was odoo hooks

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 9 23
2169
1
thg 3 24
1436
1
thg 4 24
2386
2
thg 1 24
3521
0
thg 10 23
1944