Skip to content

Commit

Permalink
Merge pull request #835 from mehul0812/18.0-mehul-admission-issue
Browse files Browse the repository at this point in the history
[18.0][FIX] fixed sequence and gender issue
  • Loading branch information
parthivgls authored Nov 22, 2024
2 parents e8bd2e2 + f14cbb1 commit ca5c552
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 26 deletions.
1 change: 1 addition & 0 deletions openeducat_admission/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'security/op_admission_security.xml',
'security/ir.model.access.csv',
'data/admission_sequence.xml',
'data/parameter_data.xml',
'views/admission_register_view.xml',
'views/admission_view.xml',
'report/report_admission_analysis.xml',
Expand Down
7 changes: 7 additions & 0 deletions openeducat_admission/data/parameter_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<record id="global_student_user_id" forcecreate="0" model="ir.config_parameter">
<field name="key">openeducat_admission.global_student_user</field>
<field name="value">True</field>
</record>
</odoo>
61 changes: 37 additions & 24 deletions openeducat_admission/models/admission.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class OpAdmission(models.Model):
'res.partner.title', 'Title')
application_number = fields.Char(
'Application Number', size=16, copy=False,
readonly=True, store=True,
)
readonly=True, store=True)
admission_date = fields.Date(
'Admission Date', copy=False)
application_date = fields.Datetime(
Expand Down Expand Up @@ -190,7 +189,7 @@ def _check_admission_register(self):
@api.constrains('birth_date')
def _check_birthdate(self):
for record in self:
if record.birth_date > fields.Date.today():
if record.birth_date and record.birth_date > fields.Date.today():
raise ValidationError(_(
"Birth Date can't be greater than current date!"))
elif record:
Expand All @@ -202,10 +201,12 @@ def _check_birthdate(self):
"Not Eligible for Admission minimum "
"required age is :"
" %s " % self.register_id.minimum_age_criteria))
else:
if not self.application_number:
self.application_number = self.env['ir.sequence'].next_by_code(
'op.admission') or '/'

@api.constrains('name')
def create_sequence(self):
if not self.application_number:
self.application_number = self.env['ir.sequence'].next_by_code(
'op.admission') or '/'

def submit_form(self):
self.state = 'submit'
Expand All @@ -218,18 +219,22 @@ def confirm_in_progress(self):
record.state = 'confirm'

def get_student_vals(self):
is_global_student_user=self.env['ir.config_parameter'].get_param('openeducat_admission.global_student_user')
for student in self:
student_user = self.env['res.users'].create({
'name': student.name,
'login': student.email,
'image_1920': self.image or False,
'is_student': True,
'company_id': self.company_id.id,
'groups_id': [
(6, 0,
[self.env.ref('base.group_portal').id])]
})
student_user=False
if is_global_student_user:
student_user = self.env['res.users'].create({
'name': student.name,
'login': student.email if student.email else student.application_number,
'image_1920': self.image or False,
'is_student': True,
'company_id': self.company_id.id,
'groups_id': [
(6, 0,
[self.env.ref('base.group_portal').id])]
})
details = {
'name': student.name,
'phone': student.phone,
'mobile': student.mobile,
'email': student.email,
Expand All @@ -242,14 +247,14 @@ def get_student_vals(self):
'image_1920': student.image,
'zip': student.zip,
}
student_user.partner_id.write(details)
student.partner_id.write(details)
details.update({
'title': student.title and student.title.id or False,
'first_name': student.first_name,
'middle_name': student.middle_name,
'last_name': student.last_name,
'birth_date': student.birth_date,
'gender': student.gender,
'gender': student.gender if student.gender else False,
'image_1920': student.image or False,
'course_detail_ids': [[0, False, {
'course_id':
Expand All @@ -264,9 +269,9 @@ def get_student_vals(self):
'fees_start_date': student.fees_start_date,
'product_id': student.register_id.product_id.id,
}]],
'user_id': student_user.id,
'user_id': student_user.id if student_user else False,
'company_id': self.company_id.id,
'partner_id': student_user.partner_id.id,
'partner_id': student_user.partner_id.id if student_user else False
})
return details

Expand All @@ -282,9 +287,10 @@ def enroll_student(self):
raise ValidationError(_(msg))
if not record.student_id:
vals = record.get_student_vals()
record.partner_id = vals.get('partner_id')
record.student_id = student_id = self.env[
'op.student'].create(vals).id
if vals:
record.student_id = student_id = self.env[
'op.student'].create(vals).id
record.partner_id = record.student_id.partner_id.id if record else False

else:
student_id = record.student_id.id
Expand Down Expand Up @@ -462,3 +468,10 @@ class OpStudentCourseInherit(models.Model):
product_id = fields.Many2one(
'product.product', 'Course Fees',
domain=[('type', '=', 'service')], tracking=True)


class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

is_global_student_user = fields.Boolean(config_parameter='openeducat_admission.global_student_user',
string='Create Student User')
22 changes: 22 additions & 0 deletions openeducat_admission/views/admission_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,26 @@
</field>
</record>
</data>

<record id="res_config_settings_view_user" model="ir.ui.view">
<field name="name">res.config.settings.view.form.admission</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="40"/>
<field name="inherit_id" ref="openeducat_core.res_config_settings_view_form_core"/>
<field name="arch" type="xml">
<xpath expr="//div[contains(@invisible, 'module_openeducat_admission')]/div[1]" position="inside">
<div class="col-12 col-md-1 col-lg-6 mb16">
<div class="o_setting_left_pane">
<field
name="is_global_student_user"/>
</div>
<div class="o_setting_right_pane">
<label
for="is_global_student_user"/>
<div class="text-muted"> Enable this option to create a student user</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>
2 changes: 1 addition & 1 deletion openeducat_core/models/subject_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class OpSubjectRegistration(models.Model):
_inherit = ["mail.thread"]

name = fields.Char('Name', readonly=True, default='New')
student_id = fields.Many2one('op.student', 'Student', required=True,
student_id = fields.Many2one('op.student', 'Student',
tracking=True)
course_id = fields.Many2one('op.course', 'Course', required=True,
tracking=True)
Expand Down
2 changes: 1 addition & 1 deletion openeducat_core/views/subject_registration_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</h1>
<group>
<group>
<field name="student_id"/>
<field name="student_id" required="1"/>
<field name="batch_id" domain="[('course_id', '=', course_id)]" required='1'/>
<field name="max_unit_load"/>
</group>
Expand Down

0 comments on commit ca5c552

Please sign in to comment.