跳至內容
選單
此問題已被標幟

Hello,

I am building a module containing a custom paperformat and external layout for a company.


I created a paperformat record my_module.my_paperformat and an external layout template my_module.my_external_layout in the module. They can be selected in the settings panel and work just fine.

I) I want them to "auto-install" when the module is being installed. This means that I want to assign my custom record/ template to the fields paperformat_id and external_layout_id in res.config.settings. How can I achieve this? I tried to use a post_init_hook function, but I somehow can not make it work.

II) How can I define that the fields of res.config.settings can not be modified by users anymore? The goal is that no system administrator can accidentally change these settings and thus destroy all documents and reports which are automatically created.


Thank you for your great help,

Markus


I am using Odoo 14 Enterprise

頭像
捨棄
最佳答案

Hi,

No need to use hooks for this. Just set the field's default value using the 'ir.model.data' model's method _xmlid_to_res_id() with the parameter as the module_name.xml_id of the record. Also If the field is to be set as not modifiable by anyone, just set the attribute readonly="True".

In your case, please try the code

paperformat_id = fields.Many2one('comodel_to_select_the_format',
default=lambda self: self.env['ir.model.data']._xmlid_to_res_id(
'my_module.my_paperformat),readonly = "True")
external_layout_id = fields.Many2one('comodel_to_select_the_layout',
default=lambda self: self.env['ir.model.data']._xmlid_to_res_id( 'my_module.my_external_layout),readonly = "True")

Regards

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
4月 23
17371
1
8月 23
1730
4
1月 23
17075
3
2月 24
2747
1
10月 24
1393