diff --git a/studies_base/__init__.py b/studies_base/__init__.py index 9a7e03e..aee8895 100644 --- a/studies_base/__init__.py +++ b/studies_base/__init__.py @@ -1 +1,2 @@ -from . import models \ No newline at end of file +from . import models +from . import wizards diff --git a/studies_base/__manifest__.py b/studies_base/__manifest__.py index eaa5196..b741e1b 100644 --- a/studies_base/__manifest__.py +++ b/studies_base/__manifest__.py @@ -12,18 +12,19 @@ "summary": "Module containing base fields and views for studies", # any module necessary for this one to work correctly "depends": [ - "base", - "partner_firstname" + "base", + "partner_firstname" ], "qweb": [], "external_dependencies": { "python": [], }, # always loaded - "data": [ - # "security/security.xml", - "data/studies_base_data.xml", - "security/ir.model.access.csv", + "data": [ + # "security/security.xml", + "data/studies_base_data.xml", + "security/ir.model.access.csv", + "wizards/create_progress_status.xml", "views/study_config_views.xml", "views/study_study_views.xml", "views/study_progress_status_views.xml", @@ -41,4 +42,4 @@ # and independently installed. Used for synergetic or glue modules. "auto_install": False, "application": False, -} \ No newline at end of file +} diff --git a/studies_base/models/study_progress_status.py b/studies_base/models/study_progress_status.py index 9e85dae..c04dcd1 100644 --- a/studies_base/models/study_progress_status.py +++ b/studies_base/models/study_progress_status.py @@ -17,6 +17,11 @@ class StudyProgressStatus(models.Model): ('ACTIVE-BUT-NOT-RECRUITING', 'Active mais ne recrute plus'), ('COMPLETED', 'Terminée'), ('WITHDRAWN', 'Annulé')], string="Avancement de l'étude") - actual = fields.Boolean("Statut actuel") + actual = fields.Boolean("Statut actuel", compute="_compute_actual") date_begin = fields.Datetime("Date de début de l'état") date_end = fields.Datetime("Date de fin de l'état") + + @api.depends("date_end") + def _compute_actual(self): + for record in self: + record.actual = (record.date_end is False) or (record.state == "COMPLETED") diff --git a/studies_base/models/study_study.py b/studies_base/models/study_study.py index c263f85..a152365 100644 --- a/studies_base/models/study_study.py +++ b/studies_base/models/study_study.py @@ -19,7 +19,8 @@ class StudyStudy(models.Model): "study.progress.status", string="Avancement de l'étude", domain="[('study_id', '=', id)]", - ) # should be computed to actual progress status + compute="_compute_progress_status_id" + ) progress_status = fields.One2many( "study.progress.status", "study_id", "All progress status" ) @@ -83,6 +84,7 @@ class StudyStudy(models.Model): updated = fields.Datetime( "Updated", readonly=True, compute="_compute_updated", store=True ) + active = fields.Boolean("Actif", default=True) @api.depends("create_date") def _compute_created(self): @@ -96,7 +98,11 @@ class StudyStudy(models.Model): _logger.info(f"Record ID: {record.id}, write_date: {record.write_date}") record.updated = record.write_date - active = fields.Boolean("Actif", default=True) + @api.depends("progress_status") + def _compute_progress_status_id(self): + for record in self: + unfinished_progress_status = record.progress_status.filtered(lambda x: x.actual == True) + record.progress_status_id = unfinished_progress_status.id if len(unfinished_progress_status) == 1 else None def copy(self, default=None): default = dict(default or {}, identifier_primary_id=None) diff --git a/studies_base/security/ir.model.access.csv b/studies_base/security/ir.model.access.csv index e6edefc..8d58c5c 100644 --- a/studies_base/security/ir.model.access.csv +++ b/studies_base/security/ir.model.access.csv @@ -22,4 +22,5 @@ access_study_questionnaire_status_admin,study.questionnaire.status.admin,model_s access_study_participant_progress_status_admin,study.participant.progress.status.admin,model_study_participant_progress_status,base.group_user,1,1,1,1 access_study_participant_state_admin,study.participant.state.admin,model_study_participant_state,base.group_user,1,1,1,1 access_study_questionnaire_response_progress_status_admin,study.questionnaire.response.progress.status.admin,model_study_questionnaire_response_progress_status,base.group_user,1,1,1,1 -access_study_author_admin,study.author.admin,model_study_author,base.group_user,1,1,1,1 \ No newline at end of file +access_study_author_admin,study.author.admin,model_study_author,base.group_user,1,1,1,1 +access_create_progress_status_wizard,create_progress_status_wizard.access,model_create_progress_status,base.group_user,1,1,1,0 diff --git a/studies_base/views/study_study_views.xml b/studies_base/views/study_study_views.xml index b8cb4d3..7f76e5b 100644 --- a/studies_base/views/study_study_views.xml +++ b/studies_base/views/study_study_views.xml @@ -22,7 +22,12 @@
- + +
@@ -96,6 +101,16 @@ + + + + + + + + + + @@ -125,4 +140,4 @@ - \ No newline at end of file + diff --git a/studies_base/wizards/__init__.py b/studies_base/wizards/__init__.py new file mode 100644 index 0000000..da05e50 --- /dev/null +++ b/studies_base/wizards/__init__.py @@ -0,0 +1 @@ +from . import create_progress_status diff --git a/studies_base/wizards/create_progress_status.py b/studies_base/wizards/create_progress_status.py new file mode 100644 index 0000000..883a8a6 --- /dev/null +++ b/studies_base/wizards/create_progress_status.py @@ -0,0 +1,28 @@ +from datetime import datetime +from odoo import fields, models + + +class CreateProgressStatus(models.TransientModel): + _name = "create.progress.status" + _description = "create Progress Status" + + state = fields.Selection([ + ('DRAFT', 'Brouillon'), + ('NOT-YET-RECRUITING', 'À venir'), + ('RECRUITING', 'En cours de recrutement'), + ('ACTIVE-BUT-NOT-RECRUITING', 'Active mais ne recrute plus'), + ('COMPLETED', 'Terminée'), + ('WITHDRAWN', 'Annulé')], string="Avancement de l'étude") + + + def create_progress_status(self): + study = self.env["study.study"].browse(self._context.get("active_ids")) + study.progress_status_id.date_end = datetime.now() + values = { + "study_id": study.id, + "state": self.state, + "date_begin": datetime.now(), + "date_end": None, + } + self.env["study.progress.status"].create(values) + study.write({"updated": datetime.now()}) diff --git a/studies_base/wizards/create_progress_status.xml b/studies_base/wizards/create_progress_status.xml new file mode 100644 index 0000000..16f562e --- /dev/null +++ b/studies_base/wizards/create_progress_status.xml @@ -0,0 +1,30 @@ + + + + create.progress.status.wizard.view.form + create.progress.status + +
+ + + + + +
+
+
+
+
+ + + Create Progress Status + create.progress.status + form + + new + +