Skip to content

Commit

Permalink
[16.0][IMP] hr_timesheet_project_parent_enhanced
Browse files Browse the repository at this point in the history
  • Loading branch information
rivo2302 committed Feb 20, 2025
1 parent 139bc5f commit 8f9a469
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
10 changes: 9 additions & 1 deletion hr_timesheet_project_parent_enhanced/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ 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.

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:: static/description/error_change_parent_id.png

This setting can be configured in the **project form view** .

.. image:: 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`
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,
}
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>

0 comments on commit 8f9a469

Please sign in to comment.