diff --git a/__init__.py b/__init__.py
index 0650744f6bc69b9f0b865e8c7174c813a5f5995e..f7209b17100218a42c80c8e984c08597d630b188 100644
--- a/__init__.py
+++ b/__init__.py
@@ -1 +1,2 @@
from . import models
+from . import controllers
diff --git a/controllers/__init__.py b/controllers/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e425c18c14ba72b12d8086c870cdcd5f615f23f4
--- /dev/null
+++ b/controllers/__init__.py
@@ -0,0 +1,4 @@
+# -*- encoding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import main
diff --git a/controllers/main.py b/controllers/main.py
new file mode 100644
index 0000000000000000000000000000000000000000..ffbbae975814cc7e93b394f1c127b3f7d6bb1ffc
--- /dev/null
+++ b/controllers/main.py
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import logging
+
+from odoo.addons.survey.controllers.main import Survey
+from odoo import http
+from odoo.exceptions import UserError
+from odoo.http import request
+
+
+_logger = logging.getLogger(__name__)
+
+
+class TrainingSurvey(Survey):
+ #
+ # ------------------------------------------------------------
+ # TAKING SURVEY ROUTES
+ # ------------------------------------------------------------
+
+ @http.route(
+ "/survey/start/<string:survey_token>", type="http", auth="public", website=True
+ )
+ def survey_start(self, survey_token, answer_token=None, email=False, **post):
+ """Start a survey by providing
+ * a token linked to a survey;
+ * a token linked to an answer or generate a new token if access is allowed;
+ """
+
+ page = super().survey_start(
+ survey_token=survey_token, answer_token=None, email=False, **post
+ )
+
+ answer_sudo = (
+ request.env["survey.user_input"]
+ .sudo()
+ .search([("access_token", "=", page.location.split("/")[-1])])
+ )
+ survey_sudo = (
+ request.env["survey.survey"]
+ .sudo()
+ .search([("access_token", "=", page.location.split("/")[-2])])
+ )
+
+ training_id = post.get("training_id")
+ if training_id:
+ training = request.env["training.training"].browse(int(training_id))
+ if training and training.registration_survey_id == survey_sudo:
+ answer_sudo.training_id = training
+
+ return page
diff --git a/models/survey_user_input.py b/models/survey_user_input.py
index dd6b6adc541e42b7b95fc46206c5d2c11ac95edf..bbf109ea971d0ad4336cbf7707390929765f7eff 100644
--- a/models/survey_user_input.py
+++ b/models/survey_user_input.py
@@ -1,7 +1,7 @@
# Copyright 2019-2022 Le Filament (<https://le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-from odoo import fields, models
+from odoo import fields, models, api
class SurveyUserInput(models.Model):
@@ -17,6 +17,7 @@ class SurveyUserInput(models.Model):
string="Formation",
ondelete="cascade",
)
+
training_survey_type = fields.Selection(
string="Type de questionnaire formation",
related="survey_id.training_survey_type",
@@ -29,6 +30,36 @@ class SurveyUserInput(models.Model):
# ------------------------------------------------------
# Override ORM
# ------------------------------------------------------
+ def _mark_done(self):
+ """
+ Hérite la fonction parente pour gérer les inscriptions aux formations au moment
+ de la validation du questionnaire
+ """
+ super()._mark_done()
+
+ student_model = self.env["training.student"].sudo()
+
+ student_id = student_model.create(
+ {
+ "partner_id": self.partner_id.id,
+ "training_id": self.training_id.id,
+ "student_company": self.company,
+ }
+ )
+ # Création de la réponse au sondage et inscription
+ self.create(
+ {
+ "partner_id": self.partner_id.id,
+ "email": self.partner_id.email,
+ "nickname": self.partner_id.lastname,
+ "firstname": self.partner_id.firstname,
+ "company": self.company,
+ "survey_id": self.training_id.registration_survey_id.id,
+ "student_id": student_id.id,
+ "training_id": self.training_id.id,
+ }
+ )
+
# ------------------------------------------------------
# Compute
diff --git a/models/training.py b/models/training.py
index bf64ddd12a32753fefd023f479d6aecd60532df3..95c3651bfa20a6ed8dce912977fc19e2d988ff19 100644
--- a/models/training.py
+++ b/models/training.py
@@ -138,3 +138,8 @@ class Training(models.Model):
# ------------------------------------------------------
def _get_survey_xlsx(self, survey_id):
return self.env.ref("survey_xlsx.report_survey_xlsx").report_action(survey_id)
+
+ def get_registration_survey_start_url(self):
+
+ url = self.registration_survey_id.get_start_url()
+ return f"{url}?training_id={self.id}"