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

HI,

I have a model1(current code) with a button to create a new model named model.controle, I want to fill the id_controle by the id of the new created model. Any help. Thanks


id_controle = fields.Many2one('model.controle', strong='ID Controle')

@api.multi

def controle(self):

        body = _("Dossier déplacé vers contrôle interne")

        id_controle = ??

        vals = {

            'name': self.name,

            'status_update': self.status_update,

            'partner_id': self.partner_id.id,

                            }

        self.env['model.controle'].sudo().create(vals)

        self.message_post(body=body)

        return self.write({'state': 'Controle', 'status_update': True})

Avatar
Discard
Best Answer

Hi,

Please update your code like this,

@api.multi
def controle(self):
body = _("Dossier déplacé vers contrôle interne")
vals = {
'name': self.name,
'status_update': self.status_update,
'partner_id': self.partner_id.id}
id_controle = self.env['model.controle'].sudo().create(vals)
self.message_post(body=body)
return self.write({'state': 'Controle',
'status_update': True,
'id_controle': id_controle.id})

Thanks

Avatar
Discard
Author

Thanks it work