diff --git a/__manifest__.py b/__manifest__.py index c7078e87d7b1e6319cf230dec5c1e03a52912c86..91494592ccfa22afa4801454f4c1615886c2d532 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -17,10 +17,13 @@ "data/mail_aeci.xml", "data/mail_end_training.xml", "data/mail_subscription.xml", + "data/mail_training_confirmation.xml", # templates "templates/survey_duplicated_answer.xml", "templates/survey_template_management.xml", # views + "views/res_company.xml", + "views/res_config_settings.xml", "views/survey.xml", "views/survey_question.xml", "views/survey_user_input.xml", diff --git a/controllers/survey.py b/controllers/survey.py index eff5fadf3977a048e33d0f43ab01dcf62ddc0794..fcdd137c6fc657c2687f2bae301d6e2c86545446 100644 --- a/controllers/survey.py +++ b/controllers/survey.py @@ -25,18 +25,19 @@ class TrainingSurvey(Survey): contenue dans l'URL """ page = super().survey_start( - survey_token=survey_token, answer_token=None, email=False, **post + survey_token=survey_token, answer_token=answer_token, email=email, **post ) + last_answer_token = answer_token or page.location.split("/")[-1] answer_sudo = ( request.env["survey.user_input"] .sudo() - .search([("access_token", "=", page.location.split("/")[-1])]) + .search([("access_token", "=", last_answer_token)]) ) survey_sudo = ( request.env["survey.survey"] .sudo() - .search([("access_token", "=", page.location.split("/")[-2])]) + .search([("access_token", "=", survey_token)]) ) training_id = post.get("training_id") @@ -61,7 +62,7 @@ class TrainingSurvey(Survey): request.env.cr.rollback() answer_sudo.unlink() response["survey_content"] = request.env["ir.qweb"]._render( - "cgscop_survey.survey_duplicated_answer", + "training_survey.survey_duplicated_answer", {"survey": survey_sudo, "title": survey_sudo.title}, ) _logger.error("Survey answer duplication not allowed") diff --git a/models/survey.py b/models/survey.py index 9b6359bc1a5558ed8f65af111b7d1731d2dc09e1..302a160281aea488d756c10731ec29647afab88c 100644 --- a/models/survey.py +++ b/models/survey.py @@ -58,7 +58,7 @@ class Survey(models.Model): ) # ------------------------------------------------------ - # Override ORM + # Constrains # ------------------------------------------------------ # ------------------------------------------------------ @@ -103,6 +103,19 @@ class Survey(models.Model): # ------------------------------------------------------ # Override ORM # ------------------------------------------------------ + @api.model_create_multi + def create(self, vals_list): + survey_ids = super().create(vals_list) + for survey in survey_ids: + survey._check_survey_subscribe() + return survey_ids + + def write(self, vals): + survey_ids = super().write(vals) + for survey in self: + survey._check_survey_subscribe() + return survey_ids + def unlink(self): for survey in self: if survey.program_ids.filtered(lambda p: p.state == "confirmed"): @@ -127,32 +140,34 @@ class Survey(models.Model): # Business function # ------------------------------------------------------ def _create_training_survey(self, training_survey_type): - survey_id = self.create( - { - "title": "Questionnaire", - "survey_type": "training", - "training_survey_type": training_survey_type, - "is_one_answer": True, - } - ) - survey_id._create_email_question() - survey_id._create_firstname_question() - survey_id._create_lastname_question() - survey_id._create_company_question() + survey_values = { + "title": "Questionnaire", + "survey_type": "training", + "training_survey_type": training_survey_type, + "is_one_answer": True, + "question_and_page_ids": self.env[ + "survey.question" + ]._get_subscribe_question_values(), + } + survey_id = self.create(survey_values) return survey_id - def _create_email_question(self): - self.ensure_one() - self.question_ids._create_email_question(self.id) - - def _create_firstname_question(self): - self.ensure_one() - self.question_ids._create_firstname_question(self.id) - - def _create_lastname_question(self): - self.ensure_one() - self.question_ids._create_lastname_question(self.id) - - def _create_company_question(self): + def _check_survey_subscribe(self): self.ensure_one() - self.question_ids._create_company_question(self.id) + if self.survey_type == "training" and self.training_survey_type == "subscribe": + if ( + not any(self.question_ids.mapped("save_as_email")) + or not any(self.question_ids.mapped("save_as_nickname")) + or not any(self.question_ids.mapped("save_as_firstname")) + ): + raise UserError( + _( + "Pour les questionnaires d'inscription aux formations, " + "il est nécessaire" + "de configurer :\n" + " - une question de type email\n" + " - une question de type prénom\n" + " - une question de type surnom\n" + "Ces questions permettront de valider l'inscription du participant." + ) + ) diff --git a/models/training_student.py b/models/training_student.py index 8ef8f734a81d7715648f6e00b9c0c3a97c3590e4..c63b563f81a7cfb6dda941ba252ed10b7cf5525c 100644 --- a/models/training_student.py +++ b/models/training_student.py @@ -25,6 +25,7 @@ class TrainingStudent(models.Model): store=False, ) survey_count = fields.Integer(compute="_compute_survey_count") + is_aeci = fields.Boolean(compute="_compute_is_aeci") aeci_sent = fields.Boolean(compute="_compute_aeci_sent") # ------------------------------------------------------ @@ -48,6 +49,10 @@ class TrainingStudent(models.Model): ) student.aeci_sent = True if aeci else False + def _compute_is_aeci(self): + for student in self: + student.is_aeci = True if student.training_id.aeci_survey_id else False + # ------------------------------------------------------ # Action buttons # ------------------------------------------------------ diff --git a/views/training_program.xml b/views/training_program.xml index 2144cd2417c406a6dcbad989887d00518cf1ee88..a06e31e5008237e76fef8b1bc13f383f977da3ee 100644 --- a/views/training_program.xml +++ b/views/training_program.xml @@ -42,7 +42,7 @@ type="object" class="btn-outline-primary" string="Créer un nouveau questionnaire AECI" - attrs="{'invisible': [('registration_survey_id', '!=', False)]}" + attrs="{'invisible': [('aeci_survey_id', '!=', False)]}" /> </p> @@ -60,7 +60,7 @@ type="object" class="btn-outline-primary" string="Créer un nouveau questionnaire AECT" - attrs="{'invisible': [('registration_survey_id', '!=', False)]}" + attrs="{'invisible': [('aect_survey_id', '!=', False)]}" /> </p> </page> diff --git a/views/training_student.xml b/views/training_student.xml index 54a2f58e8d8a05576cc8423b9129df659ab66824..a9fbf18e4657780dc3ad26e8e894fde92cc2ccbc 100644 --- a/views/training_student.xml +++ b/views/training_student.xml @@ -26,12 +26,13 @@ <notebook> <page name="survey" string="Questionnaires"> <field name="aeci_sent" invisible="1" /> + <field name="is_aeci" invisible="1" /> <button name="action_create_aeci" type="object" string="Envoyer AECI" class="btn-primary mb-4" - attrs="{'invisible': ['|', ('aeci_sent', '=', True), ('state', '!=', 'confirmed')]}" + attrs="{'invisible': ['|', '|', ('is_aeci', '=', False), ('aeci_sent', '=', True), ('state', '!=', 'confirmed')]}" /> <field name="student_survey_ids" readonly="1"> <tree> @@ -71,20 +72,15 @@ decoration-info="registration_state == 'in_progress'" /> <field name="aeci_sent" invisible="1" /> + <field name="is_aeci" invisible="1" /> <button name="action_create_aeci" type="object" string="Envoyer AECI" class="btn-outline-primary" - attrs="{'invisible': ['|', ('aeci_sent', '=', True), ('state', '!=', 'confirmed')]}" + attrs="{'invisible': ['|', '|', ('is_aeci', '=', False), ('aeci_sent', '=', True), ('state', '!=', 'confirmed')]}" /> </xpath> -<!-- <xpath expr="//button[@name='action_confirmed']" position="attributes">--> -<!-- <attribute name="attrs">{'invisible': ['|', ('state', '=', 'confirmed'), ('registration_state', '!=', 'done')]}</attribute>--> -<!-- </xpath>--> -<!-- <xpath expr="//button[@name='action_unsuitable']" position="attributes">--> -<!-- <attribute name="attrs">{'invisible': ['|', ('state', '=', 'unsuitable'), ('registration_state', '!=', 'done')]}</attribute>--> -<!-- </xpath>--> </field> </record>