If you want to restrict user for some operations within the limitation of python program itself then you need to define _constraint attribute in any model.
For knowledge :- For restriction of data inputs from database side, you need to define _sql_constraint attribute within your model.
Example of _constraint :
That attribute needs 3 arguments :
1. Function ( Which will be called to restrict user for some operations )
2. Warning ( Which will be shown to user when condition will be overruled )
3. List of fields ( If you want to show affected field names to user )
go to project.py of project module. There is following constraint,
_constraints = [
(_check_dates, 'Error! project start-date must be lower than project end-date.', ['date_start', 'date'])
_check_dates is the function, definition of that will be as follows,
def _check_dates(self, cr, uid, ids, context=None):
for leave in self.read(cr, uid, ids, ['date_start', 'date'], context=context):
if leave['date_start'] and leave['date']:
if leave['date_start'] > leave['date']:
Evaluation : When you create/edit the project system will go to verify this constraint in which the rule is project start date must not be greater then project end date. That will be tested in _check_dates function. If that function will return False then warning will be displayed which will not let user to save entire record till you not input right values. If this function return true then no message will be displayed to end user._constraints will work within python code. So every restriction will be calculated from python function. You will get the current record's ID within function, so you can browse whole record and check your preferred condition.
I hope this helps,