[FIX]: Add constraints to fix same day overlaps problem
bzr revid: atp@tinyerp.com-20121106135515-3pp7rsrtnspvb28g
This commit is contained in:
parent
1e75bd92cd
commit
54fb04a368
|
@ -112,6 +112,14 @@ class hr_holidays(osv.osv):
|
|||
result[hol.id] = hol.number_of_days_temp
|
||||
return result
|
||||
|
||||
def _check_date(self, cr, uid, ids):
|
||||
for holiday in self.browse(cr, uid, ids):
|
||||
holiday_ids = self.search(cr, uid, [('date_from', '<=', holiday.date_to), ('date_to', '>=', holiday.date_from), ('employee_id', '=', holiday.employee_id.id), ('id', '<>', holiday.id)])
|
||||
if holiday_ids:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Description', size=64),
|
||||
'state': fields.selection([('draft', 'To Submit'), ('cancel', 'Cancelled'),('confirm', 'To Approve'), ('refuse', 'Refused'), ('validate1', 'Second Approval'), ('validate', 'Approved')],
|
||||
|
@ -145,6 +153,11 @@ class hr_holidays(osv.osv):
|
|||
'user_id': lambda obj, cr, uid, context: uid,
|
||||
'holiday_type': 'employee'
|
||||
}
|
||||
|
||||
_constraints = [
|
||||
(_check_date, 'You can not have 2 Leaves that overlaps on same day!', ['date_from','date_to']),
|
||||
]
|
||||
|
||||
_sql_constraints = [
|
||||
('type_value', "CHECK( (holiday_type='employee' AND employee_id IS NOT NULL) or (holiday_type='category' AND category_id IS NOT NULL))", "The employee or employee category of this request is missing."),
|
||||
('date_check2', "CHECK ( (type='add') OR (date_from <= date_to))", "The start date must be before the end date !"),
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
<record model="hr.holidays" id="hr_holidays_employee1_vc">
|
||||
<field name="name">Summer Vacation</field>
|
||||
<field name="holiday_status_id" ref="holiday_status_unpaid"/>
|
||||
<field eval="time.strftime('%Y-%m-20')" name="date_from"/>
|
||||
<field eval="time.strftime('%Y-%m-22')" name="date_to"/>
|
||||
<field eval="time.strftime('%Y-%m-23')" name="date_from"/>
|
||||
<field eval="time.strftime('%Y-%m-25')" name="date_to"/>
|
||||
<field name="type">add</field>
|
||||
<field name="state">draft</field>
|
||||
<field name="number_of_days_temp">7</field>
|
||||
|
@ -45,8 +45,8 @@
|
|||
<record model="hr.holidays" id="hr_holidays_employee1_int_tour">
|
||||
<field name="name">International Tour</field>
|
||||
<field name="holiday_status_id" ref="holiday_status_comp"/>
|
||||
<field eval="time.strftime('%Y-%m-20')" name="date_from"/>
|
||||
<field eval="time.strftime('%Y-%m-22')" name="date_to"/>
|
||||
<field eval="time.strftime('%Y-%m-26')" name="date_from"/>
|
||||
<field eval="time.strftime('%Y-%m-28')" name="date_to"/>
|
||||
<field name="type">add</field>
|
||||
<field name="number_of_days_temp">7</field>
|
||||
<field name="employee_id" ref="hr.employee_fp"/>
|
||||
|
|
Loading…
Reference in New Issue