2020###############################################################################
2121
2222from openerp import models , fields , api
23+ from openerp .exceptions import ValidationError
2324
2425
2526class OpAssignment (models .Model ):
@@ -29,9 +30,12 @@ class OpAssignment(models.Model):
2930
3031 name = fields .Char ('Name' , size = 16 , required = True )
3132 course_id = fields .Many2one ('op.course' , 'Course' , required = True )
32- batch_id = fields .Many2one ('op.batch' , 'Batch' )
33+ batch_id = fields .Many2one ('op.batch' , 'Batch' , required = True )
3334 subject_id = fields .Many2one ('op.subject' , 'Subject' , required = True )
34- faculty_id = fields .Many2one ('op.faculty' , 'Faculty' , required = True )
35+ faculty_id = fields .Many2one (
36+ 'op.faculty' , 'Faculty' , default = lambda self : self .env [
37+ 'op.faculty' ].search ([('user_id' , '=' , self .env .uid )]),
38+ required = True )
3539 assignment_type_id = fields .Many2one (
3640 'op.assignment.type' , 'Assignment Type' , required = True )
3741 marks = fields .Float ('Marks' , track_visibility = 'onchange' )
@@ -51,6 +55,19 @@ class OpAssignment(models.Model):
5155 'op.assignment.sub.line' , 'assignment_id' , 'Submissions' )
5256 reviewer = fields .Many2one ('op.faculty' , 'Reviewer' )
5357
58+ @api .one
59+ @api .constrains ('issued_date' , 'submission_date' )
60+ def check_dates (self ):
61+ issued_date = fields .Date .from_string (self .issued_date )
62+ submission_date = fields .Date .from_string (self .submission_date )
63+ if issued_date > submission_date :
64+ raise ValidationError (
65+ "Submission Date cannot be set before Issue Date." )
66+
67+ @api .onchange ('course_id' )
68+ def onchange_course (self ):
69+ self .batch_id = False
70+
5471 @api .one
5572 def act_publish (self ):
5673 self .state = 'publish'
0 commit comments