콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
2880 화면

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


Hope it helps

아바타
취소
관련 게시물 답글 화면 활동
1
9월 23
2305
1
3월 24
1558
1
4월 24
2633
2
1월 24
3691
0
10월 23
2112