I managed to set up my custom module settings as described by the first answer here
https://www.odoo.com/forum/help-1/question/create-a-custom-configuration-page-for-custom-module-51842
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
...
I read that in this model one are supposed to be able to use these custom settings as default values in other models, but how? I read all the source code on other models from the core, but cant seem to find the answer.
This article (old) states that this is possible
http://ludwiktrammer.github.io/odoo/custom-settings-odoo.html
“Default” settings
The value of a field nameddefault_foo
will be set as a default value for a field namedfoo
on a model given as adefault_model
argument.
..but I can't make it work, so in the mean time I havea default method to set the value from the settings
@api.model
def _get_default_foobar(self):
res = self.env['res.config.settings'].get_values()
return res['foobar'] or 1
which works, but seems like the wrong solution.
Any ideas? Code example would be great.
UPDATE
default_foo = fields.Integer(default_model='some_model')
I try to set the default value in the model "some_model", but that model's property "foo" does not get the default value.
@Zbik: Thanks for trying, but none of your answers really answers what I'm really asking. I'm looking for a way to set default values in other models from the ResConfigSettings
All solutions are related + default_foo. My answer updated.
Thanks again. Let me just say I _really_ looked into the source code, so I'm familiar with the code you pasted from the source. I added an update to my question, because I tried what you said. In my case I'm trying to set the default value (an integer)
@Hiren Dangar: Thanks, but that will only set the value "foobar" in the ir.config_paramanter model. I already did that. Still doesnt "transfer" the foobar value as default to another model.
In my system default_foo type Integer works without any problems. You must STORE config after set value, onchanage on default_foo is not implemented in this case. Sugestiona: a) you change name "foo" to "xyz" and repeat test. b) You verify, in global settings, values in ir.default (may be here are duplicates)
Thanks again guys, so I got it working in the end when storing the default_foo in the table ir.config_parameter as well as the "foo" value. It didn't make sense to me to store this value more than once, I thought the code could handle it. I mean, lets say I have a value ResConfigSetting that I want to be default in two other models. Then I must basically store 3 values in ir.config_parameter. Anyway, it works so I'm not going to complain :)
urk, so I notice now that I need to save twice in the settings for new defalut value to take affect. After saving once, I see the updated value in ir.config_parameter table, but the default value is still the previous value. Saving one more time will set the default value properly. This is extremely weird