İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
7049 Görünümler

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

Avatar
Vazgeç

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

En İyi Yanı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

Avatar
Vazgeç
Üretici

Thank you @Cybrosys.

This way you solved my problem.

Best regards

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Ağu 22
15301
4
Eyl 21
15894
7
Ağu 20
5223
1
Ağu 20
5563
2
Ara 19
6770