Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TA#72158 [16.0][IMP] hr_timesheet_project_parent_enhanced #58

Merged
merged 4 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions hr_timesheet_project_parent_enhanced/README.rst
Original file line number Diff line number Diff line change
@@ -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
------------
Expand All @@ -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
------------
Expand Down
1 change: 1 addition & 0 deletions hr_timesheet_project_parent_enhanced/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"depends": ["hr_timesheet", "project_parent_enhanced"],
"data": [
"views/account_analytic_line_views.xml",
"views/project_project_views.xml",
],
"installable": True,
}
Original file line number Diff line number Diff line change
@@ -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


Expand Down
17 changes: 12 additions & 5 deletions hr_timesheet_project_parent_enhanced/models/project_project.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
# 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


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."
)
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="project_invoice_form" model="ir.ui.view">
<field name="name">Add timesheet time controls</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="hr_timesheet.project_invoice_form" />
<field name="arch" type="xml">
<div id="timesheet_settings" position="inside" >
<div class="o_setting_left_pane" attrs="{'invisible': [('allow_timesheets', '=', False)]}">
<field name="is_parent_editable" />
</div>
<div class="o_setting_right_pane" attrs="{'invisible': [('allow_timesheets', '=', False)]}">
<label for="is_parent_editable" string="Allow Parent Project Edit" />
<div class="text-muted">
Allow modifying the parent project even if there are existing timesheet lines.
</div>
</div>
</div>
</field>
</record>
</odoo>
Loading