summaryrefslogtreecommitdiff
path: root/addons/hr_skills_survey/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/hr_skills_survey/models
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/hr_skills_survey/models')
-rw-r--r--addons/hr_skills_survey/models/__init__.py4
-rw-r--r--addons/hr_skills_survey/models/survey_user.py41
2 files changed, 45 insertions, 0 deletions
diff --git a/addons/hr_skills_survey/models/__init__.py b/addons/hr_skills_survey/models/__init__.py
new file mode 100644
index 00000000..25325ac6
--- /dev/null
+++ b/addons/hr_skills_survey/models/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import survey_user
diff --git a/addons/hr_skills_survey/models/survey_user.py b/addons/hr_skills_survey/models/survey_user.py
new file mode 100644
index 00000000..9e2faff8
--- /dev/null
+++ b/addons/hr_skills_survey/models/survey_user.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import fields, models
+from odoo.tools import html2plaintext
+
+
+class SurveyUserInput(models.Model):
+ _inherit = 'survey.user_input'
+
+ def _mark_done(self):
+ """ Will add certification to employee's resumé if
+ - The survey is a certification
+ - The user is linked to an employee
+ - The user succeeded the test """
+
+ super(SurveyUserInput, self)._mark_done()
+
+ certification_user_inputs = self.filtered(lambda user_input: user_input.survey_id.certification and user_input.scoring_success)
+ partner_has_completed = {user_input.partner_id.id: user_input.survey_id for user_input in certification_user_inputs}
+ employees = self.env['hr.employee'].sudo().search([('user_id.partner_id', 'in', certification_user_inputs.mapped('partner_id').ids)])
+ for employee in employees:
+ line_type = self.env.ref('hr_skills_survey.resume_type_certification', raise_if_not_found=False)
+ survey = partner_has_completed.get(employee.user_id.partner_id.id)
+ self.env['hr.resume.line'].create({
+ 'employee_id': employee.id,
+ 'name': survey.title,
+ 'date_start': fields.Date.today(),
+ 'date_end': fields.Date.today(),
+ 'description': html2plaintext(survey.description),
+ 'line_type_id': line_type and line_type.id,
+ 'display_type': 'certification',
+ 'survey_id': survey.id
+ })
+
+
+class ResumeLine(models.Model):
+ _inherit = 'hr.resume.line'
+
+ display_type = fields.Selection(selection_add=[('certification', 'Certification')])
+ survey_id = fields.Many2one('survey.survey', string='Certification', readonly=True)