Skip to Content
Menu
This question has been flagged

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

Avatar
Discard
Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
2
Apr 23
16161
1
Aug 23
853
4
Jan 23
15723
3
Feb 24
1339
1
Oct 24
250