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

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

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

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

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

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

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you @Cybrosys.

This way you solved my problem.

Best regards

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 8 22
15320
4
thg 9 21
15900
7
thg 8 20
5229
1
thg 8 20
5570
2
thg 12 19
6774