diff --git a/__manifest__.py b/__manifest__.py index 91494592ccfa22afa4801454f4c1615886c2d532..1894c9caa418cc8f4346d68b9d701c6a734caacf 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 fcdd137c6fc657c2687f2bae301d6e2c86545446..5214036ef76683d6218fb0a9fa2511f17f5c708d 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 4e70ab2b4264a6a61c392c340977ce355223e5fc..674d9d56efe125c8dd2ea2c7eeadd842b5533d93 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 0000000000000000000000000000000000000000..27d6f333bb2b32ced688f13e34cf6c60fc50f97e --- /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 0000000000000000000000000000000000000000..da1e446aaf9ba6150822d269e38493312c165193 --- /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 de9a77825e3ecffd1a91b8d32606786f75db214f..ae99ba58cfd55fdc0b4ab0ea3dee55c44e768286 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" />