I\'m trying to store config data in odoo, I need to store 3 reference to \'account.journal\'. The model is created in database, the view is shown in configuration base menu, th
TransientModel
s are designed to be temporary, just so you can get the values and do with them whatever you want to. They are periodically removed from the database.
You need to implement your own means of saving those settings. You need to implement (at least) two methods:
set_foo
(where foo is an arbitrary string) for saving the values.get_default_foo
(where foo once more is an arbitrary string) for getting the saved values (for displaying them in the configuration user interface)A simple example:
class AgeLimitSetting(models.TransientModel):
_inherit = 'res.config.settings'
min_age = fields.Integer(
string=u"Age limit",
)
@api.model
def get_default_age_values(self, fields):
conf = self.env['ir.config_parameter']
return {
'min_age': int(conf.get_param('age_verification.min_age')),
}
@api.one
def set_age_values(self):
conf = self.env['ir.config_parameter']
conf.set_param('age_verification.min_age', str(self.min_age))
ir.config_parameter
(providing the set_param
and get_param
methods) is just a simple key-value store built into Odoo that let you store arbitrary strings. I used it as an example, but in reality you can store settings wherever you like.