How overwrite default function of a field in odoo new api

眉间皱痕 提交于 2019-12-06 06:21:28

You're linking a method directly on field definition. So overriding the method isn't enough anymore. Just define the field user_id again with default as the only parameter and ofc your new method:

The original model:

class MyModel(models.Model):
    _name = "my.model"

    def default_user_id(self):
        return self.env.context.get("default_user_id", self.env.user)

    user_id = fields.Many2one(
        comodel_name='res.users', string="User", required=True,
        default=default_user_id)

The inherited model:

class MyModelInherit(models.Model):
    _inherit = "my.model"

    def default_user_id(self):
        return self.env['res.users']

    user_id = fields.Many2one(default=default_user_id)

Please check this

user_id = fields.Many2one('res.users', string='User',readonly=True, default=lambda self: self.env.user)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!