This question has been flagged
2 Replies
5149 Views

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
Discard

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

Best Answer

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
Discard
Author

Thank you @Cybrosys.

This way you solved my problem.

Best regards