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

I'm trying to include an if-else setup for my ir.config_parameter. But I can't think of any way to have it done in the xml with the use of <record id="_____" model="ir.config_parameter">.

So is there a way to have it done in Python and create the following ir.config_parameter just like when you install the module? 

Or maybe there is a way to use if-else in xml when creating ir.config_parameter?

Thanks!

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

In odoo v12, we have field parameter named config_parameter="" in res.config.settings model. 

do_not_use = fields.Boolean(
config_parameter='model_name.do_not_use
)

In other versions, we can use set_param method in res.config.settings and use that to create a new record.


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi Jean: You can create a system parameter from python like this:

self.env['ir.config_parameter'].sudo().set_param('<name of system parameter>', <value of system parameter>)
อวตาร
ละทิ้ง
ผู้เขียน

Hi! Using this creates the ir.config_parameter when installing the module? Thanks!

You will need to define a post_init_hook in the manifest file of the module and write this code inside it to do this during installation. Here is an example from the Sales module.

Manifest file: https://github.com/odoo/odoo/blob/12.0/addons/sale_management/__manifest__.py#L58

Function definition: https://github.com/odoo/odoo/blob/12.0/addons/sale_management/__init__.py#L18

ผู้เขียน

Will look into it! Thank you so much, Paresh!

คำตอบที่ดีที่สุด

Yes, you can add the default value from python itself like this : 

self.env['ir.config_parameter'].sudo().get_param('your_module.your_field', default='[]')

The "[]" is best to use if you are using many2many fields. You can set your own default based on value you need.

Best regards

Altela (altelasoftware.com)

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ค. 24
2462
1
มิ.ย. 24
4983
1
ต.ค. 23
10664
1
ต.ค. 23
98
Data for relations table แก้ไขแล้ว
1
เม.ย. 24
2175