Ir al contenido
Menú
Se marcó esta pregunta

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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
abr 23
17359
1
ago 23
1715
4
ene 23
17048
3
feb 24
2706
1
oct 24
1382