diff --git a/education_university_management/__manifest__.py b/education_university_management/__manifest__.py index 460bb8cc4..3414da04c 100644 --- a/education_university_management/__manifest__.py +++ b/education_university_management/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################### { 'name': ' University Education Management', - 'version': '17.0.1.0.0', + 'version': '17.0.1.0.1', 'category': 'Industries', 'summary': """This modules helps to manage the university education system""", diff --git a/education_university_management/controllers/education_online_application.py b/education_university_management/controllers/education_online_application.py index 237061396..82c58119c 100644 --- a/education_university_management/controllers/education_online_application.py +++ b/education_university_management/controllers/education_online_application.py @@ -38,7 +38,7 @@ class OnlineAdmission(http.Controller): to the website registration form.""" vals = { 'department': request.env['university.department'].sudo().search( - []), + [('semester_ids', '!=', False)]), 'course': request.env['university.course'].sudo().search([]), 'semester': request.env['university.semester'].sudo().search([]), 'year': request.env['university.academic.year'].sudo().search([]), @@ -58,7 +58,7 @@ class OnlineAdmission(http.Controller): 'name': post.get('father'), 'is_parent': True }) - request.env['university.application'].sudo().create({ + application = request.env['university.application'].sudo().create({ 'name': post.get('first_name'), 'last_name': post.get('last_name'), 'mother_name': post.get('mother'), @@ -74,7 +74,18 @@ class OnlineAdmission(http.Controller): 'street': post.get('communication_address'), 'per_street': post.get('communication_address'), 'guardian_id': guardian.id, - 'image': base64.b64encode(post.get('image').encode('utf-8')) + 'image': base64.b64encode((post.get('image')).read()) + }) + doc_attachment = request.env['ir.attachment'].sudo().create({ + 'name': post.get('att').filename, + 'res_name': 'Document', + 'type': 'binary', + 'datas': base64.encodebytes((post.get('att')).read()), + }) + request.env['university.document'].sudo().create({ + 'document_type_id': post.get('doc_type'), + 'attachment_ids': doc_attachment, + 'application_ref_id': application.id }) return request.render( "education_university_management.submit_admission", diff --git a/education_university_management/models/university_department.py b/education_university_management/models/university_department.py index 870c516ea..062d03694 100644 --- a/education_university_management/models/university_department.py +++ b/education_university_management/models/university_department.py @@ -35,5 +35,5 @@ class UniversityDepartment(models.Model): help="In what course the department belongs") semester_ids = fields.One2many('university.semester', 'department_id', - string="Semester", readonly=True, + string="Semester", required=1, help="List of semesters under every course") diff --git a/education_university_management/static/src/js/online_application.js b/education_university_management/static/src/js/online_application.js index 968131aa4..656b97399 100644 --- a/education_university_management/static/src/js/online_application.js +++ b/education_university_management/static/src/js/online_application.js @@ -6,7 +6,8 @@ publicWidget.registry.OnlineApplication = publicWidget.Widget.extend({ selector: '#online_appl_form', events: { 'change select[name="course"]': '_onCourseChange', - 'change select[name="department"]': '_onDepartmentChange', + 'change select[name="semester"]': '_onSemesterChange', + 'submit form': '_onFormSubmit', }, init() { this._super(...arguments); @@ -16,27 +17,46 @@ publicWidget.registry.OnlineApplication = publicWidget.Widget.extend({ ev.preventDefault(); var self = this var course = ev.currentTarget.value; - self.$el.find('select[name="department"]').find('option').remove() - self.$el.find('select[name="department"]').append(""); + self.$el.find('select[name="semester"]').find('option').remove() + self.$el.find('select[name="semester"]').append(""); + self.$el.find('select[name="department"]').append(""); const result = await this.orm.searchRead( - 'university.department', - [['course_id', '=', parseInt(course)]],['name'] + 'university.semester', + [['department_id.course_id', '=', parseInt(course)]],['name'] ) result.forEach(function(item){ - self.$el.find('select[name="department"]').append(""); + self.$el.find('select[name="semester"]').append(""); }) }, - async _onDepartmentChange(ev){ + async _onSemesterChange(ev){ var self = this - var department = ev.currentTarget.value; - self.$el.find('select[name="semester"]').find('option').remove() - self.$el.find('select[name="semester"]').append(""); + var semester = ev.currentTarget.value; + self.$el.find('select[name="department"]').find('option').remove() + self.$el.find('select[name="department"]').append(""); const result = await this.orm.searchRead( - 'university.semester', - [['department_id', '=', parseInt(department)]],['name'] + 'university.department', + [['semester_ids', 'in', [parseInt(semester)]]],['name'] ) result.forEach(function(item){ - self.$el.find('select[name="semester"]').append(""); + self.$el.find('select[name="department"]').append(""); }) - } + }, + _onFormSubmit(ev) { + ev.preventDefault(); + // Validate fields + const course = this.$('select[name="course"]').val(); + const semester = this.$('select[name="semester"]').val(); + const department = this.$('select[name="department"]').val(); + if (!course || !semester || department==0) { + // If any required field is empty, show validation error + this._displayErrorMessage('Some Fields are Empty!'); + return; + } + ev.currentTarget.submit(); + }, + _displayErrorMessage(message) { + // Display error message near the submit button or form + const errorMessage = `