diff --git a/data/mail_end_training.xml b/data/mail_end_training.xml index 696a4f2b5d2cecf763e9d1c1e59c680cdf30b315..d94693a33d5eb249a9d8de7a26de75413acc671b 100644 --- a/data/mail_end_training.xml +++ b/data/mail_end_training.xml @@ -55,7 +55,7 @@ </div> </field> <field name="report_template" ref="training.report_attestation_pdf" /> - <field name="report_name">{{ object.get_certification_name() }} - {{ object.partner_id.name }}</field> + <field name="report_name">{{ object.get_certification_name() }} - {{ object.display_name }}</field> <field name="lang">fr_FR</field> <field name="auto_delete" eval="False" /> </record> diff --git a/models/survey.py b/models/survey.py index 302a160281aea488d756c10731ec29647afab88c..60c6fe8a5a54dab1f53f3bfad613c2580f5b3b5e 100644 --- a/models/survey.py +++ b/models/survey.py @@ -139,16 +139,17 @@ class Survey(models.Model): # ------------------------------------------------------ # Business function # ------------------------------------------------------ - def _create_training_survey(self, training_survey_type): + def _create_training_survey(self, training_survey_type, with_questions=True): 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(), } + if with_questions: + survey_values["question_and_page_ids"] = self.env[ + "survey.question" + ]._get_subscribe_question_values() survey_id = self.create(survey_values) return survey_id diff --git a/models/training.py b/models/training.py index 3a2539f0f1aef153d5b9386b6c59db4ac22f40f0..cc9c4e5981759957eae015581422cc01a7767534 100644 --- a/models/training.py +++ b/models/training.py @@ -11,10 +11,7 @@ class Training(models.Model): satisfaction_survey_id = fields.Many2one( comodel_name="survey.survey", string="Satisfaction", - domain=[ - ("survey_type", "=", "training"), - ("training_survey_type", "=", "satisfaction"), - ], + domain="[('survey_type', '=', 'training'),('training_survey_type', '=', 'satisfaction'), ('company_id', '=', company_id)]", ondelete="restrict", ) registration_survey_id = fields.Many2one( @@ -37,6 +34,9 @@ class Training(models.Model): comodel_name="survey.survey", compute="_compute_survey_ids", ) + registration_url = fields.Char( + "Lien d'inscription", compute="_compute_registration_url" + ) # ------------------------------------------------------ # Override ORM @@ -54,6 +54,11 @@ class Training(models.Model): + training.program_id.registration_survey_id ) + def _compute_registration_url(self): + for training in self: + if training.registration_survey_id: + training.registration_url = f"{training.get_base_url()}{training.get_registration_survey_start_url()}" + # ------------------------------------------------------ # Actions # ------------------------------------------------------ @@ -73,6 +78,18 @@ class Training(models.Model): if self.satisfaction_survey_id: return self._get_survey_xlsx(self.satisfaction_survey_id) + def action_create_satisfaction_survey(self): + self.ensure_one() + self.satisfaction_survey_id = self.env["survey.survey"]._create_training_survey( + "satisfaction", with_questions=False + ) + return { + "type": "ir.actions.act_window", + "view_mode": "form", + "res_model": "survey.survey", + "res_id": self.satisfaction_survey_id.id, + } + def action_view_survey(self): self.ensure_one() return { @@ -151,6 +168,5 @@ class Training(models.Model): 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}" diff --git a/models/training_program.py b/models/training_program.py index 55cb1147d20d1eff6c85f0c607fec4b7271c15ae..7234f95cf604e6d6c7b19a7c824941e7575fc70b 100644 --- a/models/training_program.py +++ b/models/training_program.py @@ -11,28 +11,19 @@ class TrainingProgram(models.Model): registration_survey_id = fields.Many2one( comodel_name="survey.survey", string="Pré-inscription/Positionnement", - domain=[ - ("survey_type", "=", "training"), - ("training_survey_type", "=", "subscribe"), - ], + domain="[('survey_type', '=', 'training'),('training_survey_type', '=', 'subscribe'), ('company_id', '=', company_id)]", ondelete="set null", ) aeci_survey_id = fields.Many2one( comodel_name="survey.survey", string="AECI", - domain=[ - ("survey_type", "=", "training"), - ("training_survey_type", "=", "aeci"), - ], + domain="[('survey_type', '=', 'training'),('training_survey_type', '=', 'aeci'), ('company_id', '=', company_id)]", ondelete="set null", ) aect_survey_id = fields.Many2one( comodel_name="survey.survey", string="AECT", - domain=[ - ("survey_type", "=", "training"), - ("training_survey_type", "=", "aect"), - ], + domain="[('survey_type', '=', 'training'),('training_survey_type', '=', 'aect'), ('company_id', '=', company_id)]", ondelete="set null", ) diff --git a/views/training.xml b/views/training.xml index c423cdda8ed41b2068de9d4a4d7780316479ec25..bab001f7b1ac683fa10786c041a62a42996a99d9 100644 --- a/views/training.xml +++ b/views/training.xml @@ -18,6 +18,7 @@ Envoyer questionnaires AECT/Satisfaction et certificats/attestations </button> </xpath> + <xpath expr="//div[@name='button_box']" position="inside"> <button name="action_view_survey" @@ -28,6 +29,15 @@ <span class="o_stat_text">Questionnaires</span> </button> </xpath> + + <xpath expr="//group/group" position="inside"> + <field + name="registration_url" + widget="CopyClipboardChar" + readonly="1" + /> + </xpath> + <xpath expr="//notebook" position="inside"> <page string="Questionnaires" name="survey"> <p class="o_horizontal_separator"> @@ -81,8 +91,15 @@ <p> <field name="satisfaction_survey_id" - class="me-4" - options="{'no_create': 1, 'no_edit': 1}" + class="me-4 col-12 col-md-6" + options="{'no_create': 1}" + /> + <button + name="action_create_satisfaction_survey" + type="object" + class="btn-outline-primary" + string="Créer un nouveau questionnaire de satisfaction" + attrs="{'invisible': [('satisfaction_survey_id', '!=', False)]}" /> <button name="action_export_satisfaction" diff --git a/views/training_program.xml b/views/training_program.xml index a06e31e5008237e76fef8b1bc13f383f977da3ee..2ddd9bae2d77a687e67fe3c563c6ad5915dcb9fa 100644 --- a/views/training_program.xml +++ b/views/training_program.xml @@ -16,6 +16,7 @@ <p class="mb-4"> <field name="registration_survey_id" + domain="[('company_id', '=', company_id)]" options="{'no_create': 1}" class="me-4 col-12 col-md-6" />