From f83addcb6f3d9edee3dac0f4c036b8de03218428 Mon Sep 17 00:00:00 2001 From: tarteo Date: Fri, 15 Nov 2024 14:58:33 +0100 Subject: [PATCH] Move task to separate file and make project.sprint.project_id optional --- project_scrum/__manifest__.py | 1 + project_scrum/models/__init__.py | 1 + project_scrum/models/project.py | 37 ++---------- project_scrum/models/project_sprint.py | 1 - project_scrum/models/project_task.py | 30 ++++++++++ project_scrum/static/description/index.html | 11 ++-- project_scrum/views/project_sprint_views.xml | 1 + project_scrum/views/project_task_views.xml | 59 ++++++++++++++++++++ project_scrum/views/project_views.xml | 55 ------------------ 9 files changed, 105 insertions(+), 91 deletions(-) create mode 100644 project_scrum/models/project_task.py create mode 100644 project_scrum/views/project_task_views.xml diff --git a/project_scrum/__manifest__.py b/project_scrum/__manifest__.py index f2c4c32eb0..c0e7aba608 100644 --- a/project_scrum/__manifest__.py +++ b/project_scrum/__manifest__.py @@ -15,6 +15,7 @@ "data": [ "security/ir.model.access.csv", "views/project_sprint_views.xml", + "views/project_task_views.xml", "views/project_views.xml", "data/ir_cron_data.xml", ], diff --git a/project_scrum/models/__init__.py b/project_scrum/models/__init__.py index 1740b86cb1..24b2564564 100644 --- a/project_scrum/models/__init__.py +++ b/project_scrum/models/__init__.py @@ -1,2 +1,3 @@ from . import project_sprint from . import project +from . import project_task diff --git a/project_scrum/models/project.py b/project_scrum/models/project.py index e6aaaddafa..ba38149d6c 100644 --- a/project_scrum/models/project.py +++ b/project_scrum/models/project.py @@ -1,5 +1,4 @@ -from odoo import _, api, fields, models -from odoo.exceptions import ValidationError +from odoo import _, fields, models class ProjectProject(models.Model): @@ -22,8 +21,11 @@ def _compute_backlog_count(self): ) def _compute_sprint_count(self): + unassigned_sprint_count = self.env["project.sprint"].search( + [("project_id", "=", False)], count=True + ) for project in self: - project.sprint_count = len(project.sprint_ids) + project.sprint_count = len(project.sprint_ids) + unassigned_sprint_count def action_sprints(self): self.ensure_one() @@ -32,7 +34,7 @@ def action_sprints(self): "type": "ir.actions.act_window", "res_model": "project.sprint", "view_mode": "tree,form,timeline", - "domain": [("project_id", "=", self.id)], + "domain": ["|", ("project_id", "=", self.id), ("project_id", "=", False)], "context": {"default_project_id": self.id}, } @@ -61,30 +63,3 @@ def action_sprint_timeline(self): "domain": [("project_id", "=", self.id), ("sprint_id", "!=", False)], "context": {"default_project_id": self.id, "no_create": True}, } - - -class ProjectTask(models.Model): - _inherit = "project.task" - - sprint_id = fields.Many2one( - comodel_name="project.sprint", - string="Sprint", - track_visibility="onchange", - ) - - sprint_state = fields.Selection( - related="sprint_id.state", string="Sprint State", store=True - ) - - @api.constrains("user_ids") - def _check_user_ids(self): - for task in self: - if task.user_ids and task.sprint_id: - if not task.user_ids <= task.sprint_id.user_ids: - raise ValidationError( - _("The assignees must be part of the sprint.") - ) - - @api.onchange("sprint_id") - def _onchange_sprint_id(self): - self.user_ids = False diff --git a/project_scrum/models/project_sprint.py b/project_scrum/models/project_sprint.py index 3da5c20c17..694519bc95 100644 --- a/project_scrum/models/project_sprint.py +++ b/project_scrum/models/project_sprint.py @@ -39,7 +39,6 @@ class ProjectSprint(models.Model): comodel_name="project.project", string="Project", track_visibility="onchange", - required=True, ) task_ids = fields.One2many( comodel_name="project.task", diff --git a/project_scrum/models/project_task.py b/project_scrum/models/project_task.py new file mode 100644 index 0000000000..587c568293 --- /dev/null +++ b/project_scrum/models/project_task.py @@ -0,0 +1,30 @@ +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class ProjectTask(models.Model): + _inherit = "project.task" + + sprint_id = fields.Many2one( + comodel_name="project.sprint", + string="Sprint", + track_visibility="onchange", + domain="['|', ('project_id', '=', False), ('project_id', '=', project_id)]", + ) + + sprint_state = fields.Selection( + related="sprint_id.state", string="Sprint State", store=True + ) + + @api.constrains("user_ids") + def _check_user_ids(self): + for task in self: + if task.user_ids and task.sprint_id: + if not task.user_ids <= task.sprint_id.user_ids: + raise ValidationError( + _("The assignees must be part of the sprint.") + ) + + @api.onchange("sprint_id") + def _onchange_sprint_id(self): + self.user_ids = False diff --git a/project_scrum/static/description/index.html b/project_scrum/static/description/index.html index a524a6e97e..c29534e4c5 100644 --- a/project_scrum/static/description/index.html +++ b/project_scrum/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -420,7 +421,9 @@

Contributors

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

diff --git a/project_scrum/views/project_sprint_views.xml b/project_scrum/views/project_sprint_views.xml index 25d2bafbd7..126f293523 100644 --- a/project_scrum/views/project_sprint_views.xml +++ b/project_scrum/views/project_sprint_views.xml @@ -59,6 +59,7 @@ diff --git a/project_scrum/views/project_task_views.xml b/project_scrum/views/project_task_views.xml new file mode 100644 index 0000000000..1247a7d1cc --- /dev/null +++ b/project_scrum/views/project_task_views.xml @@ -0,0 +1,59 @@ + + + + project.task.inherit.form.view + project.task + + + + + + + + + project.task.inherit.tree.view + project.task + + + + + + + + + project.task.inherit.search.view + project.task + + + + + + + + + + + + + project.task + timeline + + + + sprint_id + False + False + + + + + + diff --git a/project_scrum/views/project_views.xml b/project_scrum/views/project_views.xml index 7215bf8b0b..d8ec756639 100644 --- a/project_scrum/views/project_views.xml +++ b/project_scrum/views/project_views.xml @@ -64,59 +64,4 @@ - - project.task.inherit.form.view - project.task - - - - - - - - - project.task.inherit.tree.view - project.task - - - - - - - - - project.task.inherit.search.view - project.task - - - - - - - - - - - - - project.task - timeline - - - - sprint_id - False - False - - - -