Skip to Content
Menu
This question has been flagged
1 Reply
5831 Views

Dear all,

Hope everyone is ok.
I need your help on setting some default values on core Odoo "general settings" and also under "users".

For some fields I was able to do it, but this are normal fields directly related to "res.config.settings/ir.config.parameters".

What I need to do, is to activate/deactivate some core functionalities on module install and I am unable to do it.

For instance:

Under General Settings, by default Odoo activates the option "Import & Export" (module_base_import).

I want to do the same with some other options but cannot find any sample code that allows me to do it.

I have noticed that some options are "permission" related, other are "module" related (instals new modules when selected) and other are normal res.config.settings fields.
- module_base_import: module related
- group_discount_per_so_line: permission related option
- paperformat_id: normal res.config.settings option

Can anyone help me with a sample for each of the options, or some link with information about how to do it on module install?

Thank you all in advance

Best regards

PM


Avatar
Discard
Author Best Answer

Hello everyone,
I have found that for each situation there is a specific approach for activating/deactivating Settings under Res Config Settings.

It's somehow tricky because we have to try to figure out where the settings are.

For settings that are related to "module install/uninstall" (usually started with module_xxxx):

1. Defined on my module "root" __init__.py:

from odoo import api, SUPERUSER_ID
def _auto_install_module(cr, registry):
    env = api.Environment(cr, SUPERUSER_ID, {})   
module_list = ['partner_autocomplete', 'web_unsplash']        #As per an example used those 2 modules for "uninstall"   
module_ids = env['ir.module.module'].search([('name', 'in', module_list), ('state', '=', 'installed')])
   for modules in module_ids:
         modules.sudo().button_uninstall()        #...or button_install() if I want to install

2. Added "post_init_hook" to __manifest__.py:

'post_init_hook': '_my_method_for_install_unninstall',

For settings that are related to permissions (usually started with group_xxxx):

Found the answer here (https://www.odoo.com/fr_FR/forum/aide-1/question/12-0-enable-features-in-the-res-config-settings-149566), but in my case it does not worked with "eval". I had to do it as:

<record id="my_settings_my_module" model="res.config.settings">    
<field name="group_stock_multi_locations">True</field>
    <field name="group_stock_multi_warehouses">True</field>
</record>
<function model="res.config.settings" name="execute">
    <value model="res.config.settings" search="[('id', '=', ref('my_settings_my_module'))]"/>
</function>

As for the last one (for those I call normal settings):

Now the "eval" worked fine like:

<record id="my_settings_my_module" model="res.config.settings">
    <field eval="True" name="group_discount_per_so_line"/>
</record>
<function model="res.config.settings" name="execute">
    <value model="res.config.settings" search="[('id', '=', ref('my_settings_my_module'))]"/>
</function>


As for the last one, we can also use the "set_values()" method and force it via XML, but in this case we have to include the module name where the setting is defined. For instance: "sale.default_email_template"

Note: There still some options I was unable to activate/deactivate with the described methods but I think this will help anyone who needs.

Perhaps there are other easier and best options to use but wanted to share how did I solve my problems.

Best regards

PM

Avatar
Discard
Related Posts Replies Views Activity
3
Aug 20
5211
0
Mar 24
275
0
Oct 22
1521
0
Sep 22
666
1
Jul 22
4088