Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
7079 มุมมอง

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ส.ค. 22
15341
4
ก.ย. 21
15918
7
ส.ค. 20
5242
Working with xml and xsd... how to? แก้ไขแล้ว
1
ส.ค. 20
5574
Use the popup view instead of a new page แก้ไขแล้ว
2
ธ.ค. 19
6788