如何link自定义python函数到odoo中表单视图的创建按钮

How to link custom python function to the create button of form view in odoo

我想在用户单击 'create' 按钮时调用此 python 方法

def _validate_remaining_area(self):
    for land in self:
        if (land.remaining_area <= 0):
            raise ValidationError('You cannot more plot in this land')

我该怎么做?

如果按 create 按钮,你的意思是标准的 odoo Model create 方法,然后覆盖该模型的 create 方法并在那里调用你的方法。

例如(res.partner型号):

from odoo import models, api


class ResPartner(models.Model):
    """Extend to modify create method."""

    _inherit = 'res.partner'

    @api.model
    def create(self, vals):
        """Override to call _validate_remaining_area."""
        record = super(ResPartner, self).create(vals)
        # Assuming this method is defined in res.partner model..
        record._validate_remaining_area()
        return record