Skip to content
Extraits de code Groupes Projets
Valider 2565efa3 rédigé par Benjamin - Le Filament's avatar Benjamin - Le Filament
Parcourir les fichiers

Merge branch '16.0-auto-registration' into '16.0'

[UPD] add student registration process

See merge request !2
parents 88217f30 80323c12
Branches
Aucune étiquette associée trouvée
1 requête de fusion!2[UPD] add student registration process
from . import models from . import models
from . import controllers
# -*- encoding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import main
# -*- 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
# Copyright 2019-2022 Le Filament (<https://le-filament.com>) # Copyright 2019-2022 Le Filament (<https://le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # 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): class SurveyUserInput(models.Model):
...@@ -17,6 +17,7 @@ class SurveyUserInput(models.Model): ...@@ -17,6 +17,7 @@ class SurveyUserInput(models.Model):
string="Formation", string="Formation",
ondelete="cascade", ondelete="cascade",
) )
training_survey_type = fields.Selection( training_survey_type = fields.Selection(
string="Type de questionnaire formation", string="Type de questionnaire formation",
related="survey_id.training_survey_type", related="survey_id.training_survey_type",
...@@ -29,6 +30,36 @@ class SurveyUserInput(models.Model): ...@@ -29,6 +30,36 @@ class SurveyUserInput(models.Model):
# ------------------------------------------------------ # ------------------------------------------------------
# Override ORM # 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 # Compute
......
...@@ -138,3 +138,8 @@ class Training(models.Model): ...@@ -138,3 +138,8 @@ class Training(models.Model):
# ------------------------------------------------------ # ------------------------------------------------------
def _get_survey_xlsx(self, survey_id): def _get_survey_xlsx(self, survey_id):
return self.env.ref("survey_xlsx.report_survey_xlsx").report_action(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}"
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter