Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
5 Risposte
31459 Visualizzazioni

How to override create/write method and call your function during this methods?

Any kind examples would be appreciated

Avatar
Abbandona
Risposta migliore

Hi,

You can override the create and write method as follows,

Inherit the corresponding model first, then


from odoo import models, fields, api
 
class ResPartner(models.Model):
    _inherit = 'res.partner'

    @api.model
    def create(self, values):
        res = super(ResPartner, self).create(values)
        # here you can do accordingly
        return res


    @api.multi
    def write(self, values):
        res = super(ResPartner, self).write(values)
        # here you can do accordingly
        return res


For more you can check this: https://www.odoo.yenthevg.com/override-create-functions-odoo/

Thanks

Avatar
Abbandona

+1, accepted your answer. Thanks for the good answer.

@Yenthe: Its your link in the answer :)

Risposta migliore

what happend when i do not return res. just use res = super(ResPartner, self).write(values).

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
set 21
3076
1
dic 19
4054
2
gen 19
6462
1
apr 15
4470
1
mar 23
5943