mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-21 17:12:03 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
|
|
@ -0,0 +1,4 @@
|
|||
from . import hr_course_schedule
|
||||
from . import hr_course
|
||||
from . import hr_course_attendee
|
||||
from . import survey_user_input
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
# Copyright 2021 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class HrCourse(models.Model):
|
||||
|
||||
_inherit = "hr.course"
|
||||
|
||||
examination_survey_id = fields.Many2one(
|
||||
"survey.survey",
|
||||
domain=[("scoring_type", "!=", "no_scoring")],
|
||||
)
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
# Copyright 2021 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import _, fields, models, tools
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class HrCourseAttendee(models.Model):
|
||||
|
||||
_inherit = "hr.course.attendee"
|
||||
|
||||
survey_answer_id = fields.Many2one("survey.user_input", readonly=True)
|
||||
|
||||
def _get_examination_survey_vals(self):
|
||||
vals = {}
|
||||
if self.employee_id.user_id:
|
||||
vals["user"] = self.employee_id.user_id
|
||||
else:
|
||||
vals["partner"] = (
|
||||
self.employee_id.address_id or self.employee_id.address_home_id
|
||||
)
|
||||
return vals
|
||||
|
||||
def _notify_survey(self):
|
||||
template = self.env.ref("hr_course_survey.mail_template_user_input_invite")
|
||||
subject = (
|
||||
self.env["mail.template"]
|
||||
.with_context(safe=True)
|
||||
._render_template(
|
||||
template.subject,
|
||||
"survey.user_input",
|
||||
[self.survey_answer_id.id],
|
||||
post_process=True,
|
||||
)
|
||||
)[self.survey_answer_id.id]
|
||||
body = self.env["mail.template"]._render_template(
|
||||
template.body_html,
|
||||
"survey.user_input",
|
||||
[self.survey_answer_id.id],
|
||||
post_process=True,
|
||||
)[self.survey_answer_id.id]
|
||||
# post the message
|
||||
mail_values = {
|
||||
"email_from": tools.formataddr((self.env.user.name, self.env.user.email)),
|
||||
"author_id": self.env.user.partner_id.id,
|
||||
"model": None,
|
||||
"res_id": None,
|
||||
"subject": subject,
|
||||
"body_html": body,
|
||||
"auto_delete": True,
|
||||
}
|
||||
if self.survey_answer_id.partner_id:
|
||||
mail_values["recipient_ids"] = [(4, self.survey_answer_id.partner_id.id)]
|
||||
else:
|
||||
mail_values["email_to"] = self.survey_answer_id.email
|
||||
return self.env["mail.mail"].sudo().create(mail_values)
|
||||
|
||||
def _send_survey(self):
|
||||
vals = self._get_examination_survey_vals()
|
||||
survey = self.course_schedule_id.examination_survey_id
|
||||
self.survey_answer_id = survey._create_answer(**vals)
|
||||
self._notify_survey()
|
||||
|
||||
def resend_survey(self):
|
||||
self.ensure_one()
|
||||
if self.survey_answer_id.state != "done":
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Survey cannot be sent because the "
|
||||
"previous survey has not been answered"
|
||||
)
|
||||
)
|
||||
if self.result != "failed":
|
||||
raise ValidationError(_("Survey cannot be sent if the user has not failed"))
|
||||
self._send_survey()
|
||||
self.write({"result": "pending"})
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
# Copyright 2021 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class HrCourseSchedule(models.Model):
|
||||
|
||||
_inherit = "hr.course.schedule"
|
||||
|
||||
examination_survey_id = fields.Many2one(
|
||||
"survey.survey",
|
||||
related="course_id.examination_survey_id",
|
||||
)
|
||||
|
||||
def inprogress2validation(self):
|
||||
result = super().inprogress2validation()
|
||||
for record in self:
|
||||
if record.examination_survey_id:
|
||||
for attendee in record.course_attendee_ids:
|
||||
attendee._send_survey()
|
||||
return result
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
# Copyright 2021 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class SurveyUserInput(models.Model):
|
||||
|
||||
_inherit = "survey.user_input"
|
||||
|
||||
hr_course_attendee_ids = fields.One2many(
|
||||
"hr.course.attendee", inverse_name="survey_answer_id"
|
||||
)
|
||||
|
||||
def _attendee_write_vals(self):
|
||||
return {
|
||||
"result": "failed"
|
||||
if not self.scoring_success and self.survey_id.scoring_type != "no_scoring"
|
||||
else "passed"
|
||||
}
|
||||
|
||||
def _mark_done(self):
|
||||
result = super()._mark_done()
|
||||
for user_input in self:
|
||||
if user_input.hr_course_attendee_ids:
|
||||
user_input.hr_course_attendee_ids.write(
|
||||
user_input._attendee_write_vals()
|
||||
)
|
||||
return result
|
||||
Loading…
Add table
Add a link
Reference in a new issue