My goal is to have a module do the setup at install: loading dependencies, and settings configuration parameters. The idea is to keep everything in the code (if possible), to have all the information in the same place. In my dream, I'd love to have all the parameters in a key-value based file in my module.
I managed to successfully set parameters in res.company and website (e.g. changing the default favicon), but I have a hard time accessing the parameters in base.config.settings, as it apparently deals with transient models (or is there another way?). My readings lead me to try things like this:
create an object from the transient model with the required values set
call execute() on it
I tried the code below in a module (with the companion view).
class ResBaseConfigSettings(models.TransientModel):
_inherit = "base.config.settings"
@api.model
def set_signup_parameters(self):
_logger.info("> Settings sign-up parameters")
_logger.info(self)
settings = self.env['base.config.settings'].create({
'auth_signup_uninvited': True,
'auth_signup_reset_password': True,
})
settings.execute()
_logger.info("> ... done.")
Here is the view (set_config_parameters.xml):
<odoo>
<data noupdate="1">
<function model="base.config.settings" name="set_signup_parameters"/>
</data>
</odoo>
Unfortunately, when I execute the code (by installing the module) an infinite loop is created, and I can't figure out why.
2017-08-08 06:04:14,308 4649 INFO TFBN01A odoo.modules.loading: loading tfbn_enhancements/views/set_config_parameters.xml
2017-08-08 06:04:14,452 4649 INFO TFBN01A odoo.addons.tfbn_enhancements.models.models: > Settings sign-up parameters
2017-08-08 06:04:14,452 4649 INFO TFBN01A odoo.addons.tfbn_enhancements.models.models: base.config.settings()
2017-08-08 06:04:15,744 4649 INFO TFBN01A odoo.addons.tfbn_enhancements.models.models: > Settings sign-up parameters
2017-08-08 06:04:15,744 4649 INFO TFBN01A odoo.addons.tfbn_enhancements.models.models: base.config.settings(1,)
2017-08-08 06:04:16,929 4649 INFO TFBN01A odoo.addons.tfbn_enhancements.models.models: > Settings sign-up parameters
2017-08-08 06:04:16,929 4649 INFO TFBN01A odoo.addons.tfbn_enhancements.models.models: base.config.settings(2,)
2017-08-08 06:04:18,162 4649 INFO TFBN01A odoo.addons.tfbn_enhancements.models.models: > Settings sign-up parameters
2017-08-08 06:04:18,162 4649 INFO TFBN01A odoo.addons.tfbn_enhancements.models.models: base.config.settings(3,)
(...)
Also, when I'm trying to execute this in the console, it seems to work ok. At least, there is no sign of infinite loop.
>>> c = self.env['base.config.settings'].create({'auth_signup_uninvited': True,'auth_signup_reset_password': True,})
>>> c
base.config.settings(1,)
>>> c.execute()
2017-08-08 06:45:38,182 9929 INFO TFBN01A odoo.addons.base.res.res_config: getting next operation 2017-08-08 06:45:38,183 9929 INFO TFBN01A odoo.addons.base.res.res_config: getting next ir.actions.todo()
2017-08-08 06:45:38,188 9929 INFO TFBN01A odoo.addons.base.res.res_config: next action is None
{'url': '/web', 'type': 'ir.actions.act_url', 'target': 'self'}
I'm also wondering where those settings are stored in the database (in ir_config_parameter?), and the proper way to store these permanently.
What am I missing? Thanks for the help.