diff --git a/hr_timesheet_project_parent_enhanced/README.rst b/hr_timesheet_project_parent_enhanced/README.rst index c7086f5..9b5aa38 100644 --- a/hr_timesheet_project_parent_enhanced/README.rst +++ b/hr_timesheet_project_parent_enhanced/README.rst @@ -1,7 +1,8 @@ Hr Timesheet Project Parent Enhanced ==================================== -This module adds constraints and features related to timesheets and parent-child relationships between projects. It enhances the existing functionalities provided by the OCA module `project_parent`, with a focus on timesheets and their integration into project hierarchies. +This module adds constraints and features related to timesheets and parent-child relationships between projects. +It enhances the existing functionalities provided by the OCA module `project_parent`, with a focus on timesheets and their integration into project hierarchies. Dependencies ------------ @@ -22,21 +23,28 @@ Features **Constraints on Parent Project Changes** - - Raise ValidationError on changing parent project if timesheets already exist for the project. +This module introduces a configuration option that allows changing the parent project of a project even if it already contains timesheet entries. -.. image:: static/description/error_change_parent_id.png +By default, this option is disabled, to **Raise ValidationError** on changing parent project if timesheets already exist for the project.However, when enabled for a specific project, users can +update the parent project without encountering validation constraints. + +.. image:: https://raw.githubusercontent.com/Numigi/odoo-timesheet-addons/16.0/hr_timesheet_project_parent_enhanced/static/description/error_change_parent_id.png + +This setting can be configured in the **project form view** . + +.. image:: https://raw.githubusercontent.com/Numigi/odoo-timesheet-addons/16.0/hr_timesheet_project_parent_enhanced/static/description/project_form_view.png **Enhanced Views** - Displays the parent project in analytic line views for better visibility (either in list or form view). eg. : `My parent project, My iteration` -.. image:: static/description/parent_project_name_list_view.png +.. image:: https://raw.githubusercontent.com/Numigi/odoo-timesheet-addons/16.0/hr_timesheet_project_parent_enhanced/static/description/parent_project_name_list_view.png -.. image:: static/description/parent_project_name_form_view.png +.. image:: https://raw.githubusercontent.com/Numigi/odoo-timesheet-addons/16.0/hr_timesheet_project_parent_enhanced/static/description/parent_project_name_form_view.png - Allows filtering timesheets based on the parent project. -.. image:: static/description/hr_timesheet_search_view.png +.. image:: https://raw.githubusercontent.com/Numigi/odoo-timesheet-addons/16.0/hr_timesheet_project_parent_enhanced/static/description/hr_timesheet_search_view.png Contributors ------------ diff --git a/hr_timesheet_project_parent_enhanced/__manifest__.py b/hr_timesheet_project_parent_enhanced/__manifest__.py index f0c5e5d..9a7b2e5 100644 --- a/hr_timesheet_project_parent_enhanced/__manifest__.py +++ b/hr_timesheet_project_parent_enhanced/__manifest__.py @@ -16,6 +16,7 @@ "depends": ["hr_timesheet", "project_parent_enhanced"], "data": [ "views/account_analytic_line_views.xml", + "views/project_project_views.xml", ], "installable": True, } diff --git a/hr_timesheet_project_parent_enhanced/i18n/fr.po b/hr_timesheet_project_parent_enhanced/i18n/fr.po index 2eadf3f..b5ed7ed 100644 --- a/hr_timesheet_project_parent_enhanced/i18n/fr.po +++ b/hr_timesheet_project_parent_enhanced/i18n/fr.po @@ -15,11 +15,34 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: hr_timesheet_project_parent_enhanced +#: model:ir.model.fields,field_description:hr_timesheet_project_parent_enhanced.field_project_project__is_parent_editable +#: model_terms:ir.ui.view,arch_db:hr_timesheet_project_parent_enhanced.project_invoice_form +msgid "Allow Parent Project Edit" +msgstr "Autoriser la modification du projet parent" + +#. module: hr_timesheet_project_parent_enhanced +#: model_terms:ir.ui.view,arch_db:hr_timesheet_project_parent_enhanced.project_invoice_form +msgid "" +"Allow modifying the parent project even if there are existing timesheet " +"lines." +msgstr "" +"Permettre de modifier le projet parent même s'il existe des lignes de feuille de temps." + #. module: hr_timesheet_project_parent_enhanced #: model:ir.model,name:hr_timesheet_project_parent_enhanced.model_account_analytic_line msgid "Analytic Line" msgstr "Ligne analytique" +#. module: hr_timesheet_project_parent_enhanced +#: model:ir.model.fields,help:hr_timesheet_project_parent_enhanced.field_project_project__is_parent_editable +msgid "" +"If checked, allows modifying the parent project even\n" +" if there are existing timesheet lines." +msgstr "" +"Si coché, permet de modifier le projet parent même\n" +" s'il existe des lignes de feuille de temps." + #. module: hr_timesheet_project_parent_enhanced #: model:ir.model.fields,field_description:hr_timesheet_project_parent_enhanced.field_account_analytic_line__project_id msgid "Iteration" diff --git a/hr_timesheet_project_parent_enhanced/models/account_analytic_line.py b/hr_timesheet_project_parent_enhanced/models/account_analytic_line.py index 1756265..3eee1c0 100644 --- a/hr_timesheet_project_parent_enhanced/models/account_analytic_line.py +++ b/hr_timesheet_project_parent_enhanced/models/account_analytic_line.py @@ -1,5 +1,6 @@ # Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + from odoo import api, fields, models diff --git a/hr_timesheet_project_parent_enhanced/models/project_project.py b/hr_timesheet_project_parent_enhanced/models/project_project.py index b9658e3..1fceff3 100644 --- a/hr_timesheet_project_parent_enhanced/models/project_project.py +++ b/hr_timesheet_project_parent_enhanced/models/project_project.py @@ -1,7 +1,7 @@ # Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -from odoo import api, models, _ +from odoo import api, fields, models, _ from odoo.exceptions import ValidationError @@ -9,15 +9,22 @@ class ProjectProject(models.Model): _inherit = "project.project" + is_parent_editable = fields.Boolean( + string="Allow Parent Project Edit", + help="""If checked, allows modifying the parent project even + if there are existing timesheet lines.""", + ) + @api.constrains("parent_id") def _check_cannot_change_parent_while_existing_timesheet(self): - analytic_line_env = self.env["account.analytic.line"] + analytic_line = self.env["account.analytic.line"] for project in self: - if analytic_line_env.search([("project_id", "=", project.id)], limit=1): + if not project.is_parent_editable and analytic_line.search( + [("project_id", "=", project.id)], limit=1 + ): raise ValidationError( _( "Timesheet already exists on this project, to update the Parent " - "Project field, the Project " - "must have no Timesheets." + "Project field, the Project must have no Timesheets." ) ) diff --git a/hr_timesheet_project_parent_enhanced/static/description/project_form_view.png b/hr_timesheet_project_parent_enhanced/static/description/project_form_view.png new file mode 100644 index 0000000..9e1b83c Binary files /dev/null and b/hr_timesheet_project_parent_enhanced/static/description/project_form_view.png differ diff --git a/hr_timesheet_project_parent_enhanced/tests/test_account_analytic_line.py b/hr_timesheet_project_parent_enhanced/tests/test_account_analytic_line.py index be5e44e..2147dca 100644 --- a/hr_timesheet_project_parent_enhanced/tests/test_account_analytic_line.py +++ b/hr_timesheet_project_parent_enhanced/tests/test_account_analytic_line.py @@ -45,9 +45,14 @@ def test_analytic_line_parent_project_id(self): self.assertEqual(line_2.parent_project_id, self.project_2) def test_block_setting_parent_on_project_with_timesheet(self): - self._create_timesheet(self.project_1) + self._create_timesheet(self.iteration_1) with pytest.raises(ValidationError): - self.project_1.parent_id = self.project_2 + self.iteration_1.parent_id = self.project_2 + + def test_change_parent_on_project_with_timesheet(self): + self._create_timesheet(self.iteration_1) + self.iteration_1.is_parent_editable = True + self.iteration_1.parent_id = self.project_2 def test_allow_setting_project_with_timesheet_as_parent(self): self._create_timesheet(self.project_1) diff --git a/hr_timesheet_project_parent_enhanced/views/project_project_views.xml b/hr_timesheet_project_parent_enhanced/views/project_project_views.xml new file mode 100644 index 0000000..dd175e5 --- /dev/null +++ b/hr_timesheet_project_parent_enhanced/views/project_project_views.xml @@ -0,0 +1,21 @@ + + + + Add timesheet time controls + project.project + + +
+
+ +
+
+
+
+
+
+
\ No newline at end of file