diff --git a/models/__init__.py b/models/__init__.py index 972ef021af9da20427819f3be9338325a87dee67..f4c21ac1e850190a616b0db239b6098d3034f837 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -1,3 +1,5 @@ from . import survey +from . import survey_user_input from . import training from . import training_program +from . import training_student diff --git a/models/survey.py b/models/survey.py index be2104dc8b427feb5e11775e920c771df5e50a27..388c46ebc465dcff6ff05e7d0c43d0bd0a7dde56 100644 --- a/models/survey.py +++ b/models/survey.py @@ -20,7 +20,7 @@ class Survey(models.Model): ("aect", "AECT"), ("satisfaction", "Satisfaction"), ], - string="Type de questionnaire", + string="Type de questionnaire formation", ) training_ids = fields.One2many( comodel_name="training.training", diff --git a/models/survey_user_input.py b/models/survey_user_input.py new file mode 100644 index 0000000000000000000000000000000000000000..0d691009023389e7f255f89c006a9d3a3e6bcd56 --- /dev/null +++ b/models/survey_user_input.py @@ -0,0 +1,29 @@ +# Copyright 2019-2022 Le Filament (<https://le-filament.com>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class SurveyUserInput(models.Model): + _inherit = "survey.user_input" + + student_id = fields.Many2one( + comodel_name="training.student", + string="Stagiaire", + ) + + # ------------------------------------------------------ + # Inherit parent + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Override ORM + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Compute + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Buttons + # ------------------------------------------------------ diff --git a/models/training.py b/models/training.py index ab4f3fa86bde34b39a76724e15ca053430fc60a6..3b294f7e86719f4a8d9eeba7d8258da255b540bd 100644 --- a/models/training.py +++ b/models/training.py @@ -18,6 +18,11 @@ class Training(models.Model): ondelete="restrict", ) + survey_ids = fields.One2many( + comodel_name="survey.survey", + compute="_compute_survey_ids", + ) + # ------------------------------------------------------ # Override ORM # ------------------------------------------------------ @@ -25,6 +30,28 @@ class Training(models.Model): # ------------------------------------------------------ # Compute # ------------------------------------------------------ + def _compute_survey_ids(self): + for training in self: + training.survey_ids = ( + training.satisfaction_survey_id + + training.program_id.aeci_survey_id + + training.program_id.aect_survey_id + + training.program_id.registration_survey_id + ) + + # ------------------------------------------------------ + # Actions + # ------------------------------------------------------ + def action_view_survey(self): + self.ensure_one() + return { + "name": f"Questionnaires {self.program_id.name}", + "type": "ir.actions.act_window", + "view_mode": "kanban,tree,form,activity", + "res_model": "survey.survey", + "domain": [("id", "in", self.survey_ids.ids)], + "context": {"create": 0, "delete": 0}, + } # ------------------------------------------------------ # Inherit parent diff --git a/models/training_student.py b/models/training_student.py new file mode 100644 index 0000000000000000000000000000000000000000..f4ebb5611116fd03142cc9bcfdde0058699d4f82 --- /dev/null +++ b/models/training_student.py @@ -0,0 +1,22 @@ +# Copyright 2024 Le Filament (<https://le-filament.com>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class TrainingStudent(models.Model): + _inherit = "training.student" + + student_survey_ids = fields.One2many( + comodel_name="survey.user_input", + inverse_name="student_id", + string="Questionnaires", + ) + + # ------------------------------------------------------ + # Compute + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Inherit parent + # ------------------------------------------------------ diff --git a/views/survey.xml b/views/survey.xml index 88027b300c6e6e2aa1bb1fb260db32ce72f5fc26..1a6cd7253e009575e585a35c403b2d520cf88303 100644 --- a/views/survey.xml +++ b/views/survey.xml @@ -118,7 +118,7 @@ </xpath> <xpath expr="//group" position="after"> <searchpanel> - <field name="training_survey_type" enable_counters="1"/> + <field name="training_survey_type" enable_counters="1" /> </searchpanel> </xpath> </field> diff --git a/views/training.xml b/views/training.xml index 0a4ca8509f763e61e04b42de08c52a203b9f65f5..e3c4765924c08d400f8a9397772aa5c55b9ba1f4 100644 --- a/views/training.xml +++ b/views/training.xml @@ -1,12 +1,21 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- Copyright 2019-2022 Le Filament (<https://le-filament.com>) - License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> <odoo> + <!-- Form View --> <record id="training_training_form" model="ir.ui.view"> <field name="name">training.training.survey.form</field> <field name="model">training.training</field> <field name="inherit_id" ref="training.training_training_form" /> <field name="arch" type="xml"> + <xpath expr="//div[@name='button_box']" position="inside"> + <button + name="action_view_survey" + type="object" + icon="fa-question-circle-o" + class="oe_stat_button" + > + <span class="o_stat_text">Questionnaires</span> + </button> + </xpath> <xpath expr="//notebook" position="inside"> <page string="Questionnaires" name="survey"> <group> @@ -22,4 +31,21 @@ </field> </record> + <!-- Tree View --> + <record id="training_training_tree" model="ir.ui.view"> + <field name="name">training.training.survey.tree</field> + <field name="model">training.training</field> + <field name="inherit_id" ref="training.training_training_tree" /> + <field name="arch" type="xml"> + <xpath expr="//field[@name='price_intra']" position="after"> + <button + name="action_view_survey" + type="object" + string="Questionnaires" + class="border" + /> + </xpath> + </field> + </record> + </odoo>