From c878a07cc5b73fc9a30a1f37d5441b42a99a5ca0 Mon Sep 17 00:00:00 2001 From: benjamin <benjamin@le-filament.com> Date: Tue, 7 Jan 2025 11:19:20 +0100 Subject: [PATCH] [ADD] closed training & training max templates and redirections & add _create_student function --- __manifest__.py | 2 ++ controllers/survey.py | 29 +++++++++++++++++- models/survey_user_input.py | 51 +++++++++++++++++--------------- templates/survey_closed.xml | 18 +++++++++++ templates/survey_max_student.xml | 18 +++++++++++ views/survey.xml | 8 +++-- 6 files changed, 99 insertions(+), 27 deletions(-) create mode 100644 templates/survey_closed.xml create mode 100644 templates/survey_max_student.xml diff --git a/__manifest__.py b/__manifest__.py index 9149459..1894c9c 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -19,7 +19,9 @@ "data/mail_subscription.xml", "data/mail_training_confirmation.xml", # templates + "templates/survey_closed.xml", "templates/survey_duplicated_answer.xml", + "templates/survey_max_student.xml", "templates/survey_template_management.xml", # views "views/res_company.xml", diff --git a/controllers/survey.py b/controllers/survey.py index fcdd137..5214036 100644 --- a/controllers/survey.py +++ b/controllers/survey.py @@ -2,6 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging +from datetime import date from odoo import http from odoo.http import request @@ -42,7 +43,33 @@ class TrainingSurvey(Survey): training_id = post.get("training_id") if training_id: - training = request.env["training.training"].browse(int(training_id)) + training = request.env["training.training"].sudo().browse(int(training_id)) + if training.date_limit and date.today() > training.date_limit: + return request.env["ir.qweb"]._render( + "training_survey.survey_closed", + { + "title": survey_sudo.title, + "training": training, + "website": training.website_id, + "main_object": training, + }, + ) + if ( + training.nb_student_max > 0 + and ( + training.students_waiting_count + training.students_confirmed_count + ) + >= training.nb_student_max + ): + return request.env["ir.qweb"]._render( + "training_survey.survey_max_student", + { + "title": survey_sudo.title, + "training": training, + "website": training.website_id, + "main_object": training, + }, + ) if training and training.registration_survey_id == survey_sudo: answer_sudo.training_id = training diff --git a/models/survey_user_input.py b/models/survey_user_input.py index 4e70ab2..674d9d5 100644 --- a/models/survey_user_input.py +++ b/models/survey_user_input.py @@ -91,32 +91,12 @@ class SurveyUserInput(models.Model): super()._mark_done() # Pré-inscription du stagiaire - if ( - self.survey_id.survey_type == "training" - and self.survey_id.training_survey_type == "subscribe" - and self.training_id - and not self.student_id - ): - student_model = self.env["training.student"].sudo() - student_id = student_model.create( - { - "partner_id": self.partner_id.id if self.partner_id else None, - "training_id": self.training_id.id, - "student_company": self.company, - "student_firstname": self.firstname, - "student_lastname": self.nickname, - "email": self.email, - } - ) - # Mise à jour de la réponse au sondage et inscription - self.student_id = student_id - - template_id = ( - self.student_id.training_id.company_id._get_subscription_email() - ) + student_id = self._create_student() + if student_id: + template_id = student_id.training_id.company_id._get_subscription_email() if template_id: template_id.send_mail( - self.student_id.id, + student_id.id, email_layout_xmlid="training.mail_training_layout", ) @@ -193,3 +173,26 @@ class SurveyUserInput(models.Model): ] } ) + + def _create_student(self): + self.ensure_one() + if ( + self.survey_id.survey_type == "training" + and self.survey_id.training_survey_type == "subscribe" + and self.training_id + and not self.student_id + ): + student_model = self.env["training.student"].sudo() + student_id = student_model.create( + { + "partner_id": self.partner_id.id if self.partner_id else None, + "training_id": self.training_id.id, + "student_company": self.company, + "student_firstname": self.firstname, + "student_lastname": self.nickname, + "email": self.email, + } + ) + # Mise à jour de la réponse au sondage et inscription + self.student_id = student_id + return student_id diff --git a/templates/survey_closed.xml b/templates/survey_closed.xml new file mode 100644 index 0000000..27d6f33 --- /dev/null +++ b/templates/survey_closed.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8" ?> +<odoo> + <template id="survey_closed" name="Survey: Training subscription closed"> + <t t-call="web.frontend_layout"> + <t t-set="html_data" t-value="{'style': 'height: 100%;'}"/> + <t t-set="no_header" t-value="True"/> + <t t-set="no_footer" t-value="True"/> + + <div class="wrap d-flex align-items-center h-100"> + <div class="container"> + <div class="fs-3 fw-light"> + Les inscriptions à la formation <span t-out="training.display_name" /> sont closes. + </div> + </div> + </div> + </t> + </template> +</odoo> diff --git a/templates/survey_max_student.xml b/templates/survey_max_student.xml new file mode 100644 index 0000000..da1e446 --- /dev/null +++ b/templates/survey_max_student.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8" ?> +<odoo> + <template id="survey_max_student" name="Survey: Max Student"> + <t t-call="web.frontend_layout"> + <t t-set="html_data" t-value="{'style': 'height: 100%;'}"/> + <t t-set="no_header" t-value="True"/> + <t t-set="no_footer" t-value="True"/> + + <div class="wrap d-flex align-items-center h-100"> + <div class="container"> + <div class="fs-3 fw-light"> + Le nombre de participants maximum à la formation <span t-out="training.display_name" /> a été atteint. + </div> + </div> + </div> + </t> + </template> +</odoo> diff --git a/views/survey.xml b/views/survey.xml index de9a778..ae99ba5 100644 --- a/views/survey.xml +++ b/views/survey.xml @@ -143,13 +143,17 @@ <!-- Actions --> <!-- Inherit parent action for domain --> <record model="ir.actions.act_window" id="survey.action_survey_form"> - <field name="domain">[("survey_type", "=", False), ("company_id", "in", allowed_company_ids)]</field> + <field + name="domain" + >[("survey_type", "=", False), ("company_id", "in", allowed_company_ids)]</field> </record> <!-- New Actions --> <record model="ir.actions.act_window" id="action_training_survey"> <field name="name">Questionnaires formation</field> <field name="res_model">survey.survey</field> - <field name="domain">[("survey_type", "=", "training"), ("company_id", "in", allowed_company_ids)]</field> + <field + name="domain" + >[("survey_type", "=", "training"), ("company_id", "in", allowed_company_ids)]</field> <field name="view_mode">kanban,tree,form,activity</field> <field name="context">{"default_survey_type": "training"}</field> <field name="search_view_id" ref="training_survey_search" /> -- GitLab