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

Hello everyone,

I am using Odoo 12 and have the need to use a value from "res_config_settings" on attributes in xml.

For this, and with the help of @Haresh Kansara on this post: https://www.odoo.com/fr_FR/forum/aide-1/question/direct-access-to-ir-config-parameter-on-field-definition-167424

... I have defined on my model:

def get_field_value(self):
config = self.env['ir.config_parameter']
return config.sudo().get_param('my_model.my_key')

my_field = fields.Char('My Field String', default='get_field_value')

This is allowing me to get the current value from key on ir_config_parameter and use it as attribute condition on XML.

My problem is I don't want to save this value on the database and just need id for XML attribute condition purposes and tried to use "store=False", but this way, my field is not shown anymore.

my_field = fields.Char('My Field String', default='get_field_value', store=False)

Adding "store=False", the field is not shown on form view anymore.

I actually need it for use on XML attribute conditions, but do want it to be saved on the database.

My question is: How to use it on XML attribute condition, without saving it to database? I want it to be loaded when user is working on form view and at the end have it "discarded".

Thank you in advance

Best regards

PM

아바타
취소

Why don't you use compute='get_field_value' Instead of default?

베스트 답변

Hi,
Please try the below code which we changed default to a compute function.

my_field = fields.Char('My Field String', compute='get_field_value')

def get_field_value(self):
config = self.env['ir.config_parameter']
return config.sudo().get_param('my_model.my_key')

Regards

아바타
취소
작성자

Thank you @Cybrosys.

This way you solved my problem.

Best regards

관련 게시물 답글 화면 활동
1
8월 22
15301
4
9월 21
15897
7
8월 20
5224
1
8월 20
5570
2
12월 19
6770