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