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

I want to store definitely data of a TransientModel. I notice that after registered data through TransientModel it disappeared after a while. 

I try this but it doesn't worked : 

class BudgLineBudg(models.TransientModel):

_name = "budg_line_budg"

budg_lbudg_id = fields.Many2one("budg_lbudg")
rubrique_id = fields.Many2one("budg_rubrique", string = "Rubrique")
mnt_ant1 = fields.Integer(string = "Montant antérieur 1", size = 15)
mnt_ant2 = fields.Integer(string = "Montant antérieur 2", size = 15)
mnt_precedent = fields.Integer(string = "Montant précédent", size = 15)
mnt_budgetise = fields.Integer(string = "Montant budgétisé", size = 15)


@api.model
def get_lbudg(self,fields):
conf = self.env['ir.config_parameter']
return {
'budg_lbudg_id': str(conf.get_param('line_budg.budg_lbudg_id')),
'rubrique_id': str(conf.get_param('line_budg.rubrique_id')),
'mnt_ant1': int(conf.get_param('line_budg.mnt_ant1')),
'mnt_ant2': int(conf.get_param('line_budg.mnt_ant2')),
'mnt_precedent': int(conf.get_param('line_budg.mnt_precedent')),
'mnt_budgetise': int(conf.get_param('line_budg.mnt_budgetise')),
}

@api.one
def set_lbudg(self,fields):
conf = self.env['ir.config_parameter']
conf.set_param('line_budg.budg_lbudg_id', str(self.budg_lbudg_id)),
conf.set_param('line_budg.rubrique_id', str(self.rubrique_id)),
conf.set_param('line_budg.mnt_ant1', str(self.mnt_ant1)),
conf.set_param('line_budg.mnt_ant2', str(self.mnt_ant2)),
conf.set_param('line_budg.mnt_precedent', str(self.mnt_precedent)),
conf.set_param('line_budg.mnt_budgetise', str(self.mnt_budgetise))


Avatar
Discard
Best Answer

Hi,

Transient models wont store data in the table, once it is created it will be there for sometime and later it will get removed from the table. If you are looking to save some settings you can store it to the model ir.config_parameter

By default in Odoo, all the settings model are transient model and data is stored in the ir.config_parameter table. For storing and retrieving  values in the settings, see this : How to use the default settings value in custom module field?


Thanks

Avatar
Discard

+1 great answer. If you really need to keep record you should not use a Transient model anyways.