Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2008 มุมมอง

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?

อวตาร
ละทิ้ง

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

คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ย. 23
1455
1
มี.ค. 24
888
1
เม.ย. 24
1649
2
ม.ค. 24
2674
0
ต.ค. 23
1310