跳至内容
菜单
此问题已终结
5 回复
31436 查看

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

Any kind examples would be appreciated

形象
丢弃
最佳答案

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

形象
丢弃

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

@Yenthe: Its your link in the answer :)

最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
1
9月 21
3043
1
12月 19
4033
2
1月 19
6429
1
4月 15
4445
1
3月 23
5917