Skip to content

Commit

Permalink
[IMP] check for session conflict for faculty with alrady created lect…
Browse files Browse the repository at this point in the history
…ures
  • Loading branch information
Siddharth Kanojiya committed Sep 25, 2017
1 parent bfae6bc commit 5118d1a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions openeducat_timetable/models/timetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ class OpSession(models.Model):
'res.users', compute='_compute_batch_users',
store=True, string='Users')

@api.constrains('faculty_id')
def _check_faculty_sessions(self):
for record in self:
if record.faculty_id and record.start_datetime and record.end_datetime:
sessions = self.search(
['&',
('faculty_id', '=', record.faculty_id.id),
'|', '&',
('start_datetime', '<=', record.start_datetime),
('end_datetime', '>=', record.start_datetime),
'&',
('start_datetime', '<=', record.end_datetime),
('end_datetime', '>=', record.end_datetime)])
if len(sessions) > 1:
msg = ''
for x in sessions:
if not x.id == record.id:
msg += (x.name + '\n')
raise ValidationError(
_('Session will conflict with : \n %s' % msg))

@api.multi
@api.depends('faculty_id', 'subject_id', 'start_datetime')
def _compute_name(self):
Expand Down

0 comments on commit 5118d1a

Please sign in to comment.