Reputation: 17
I want to call this python method when user click on 'create' button
def _validate_remaining_area(self):
for land in self:
if (land.remaining_area <= 0):
raise ValidationError('You cannot more plot in this land')
How can I do it?
Upvotes: 0
Views: 452
Reputation: 21188
If by create
button, you mean standard odoo Model
create
method, then override that model's create
method and call your method there.
For example (res.partner
model):
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
Upvotes: 1