-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG][16.0] hr_timesheet_project_parent (#51)
- Loading branch information
Showing
16 changed files
with
263 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Hr Timesheet Project Parent | ||
==================================== | ||
|
||
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 | ||
------------ | ||
This module depends on the following OCA module: | ||
- `project_parent`: https://github.com/OCA/project/tree/16.0/project_parent | ||
|
||
Features | ||
-------- | ||
|
||
**Parent Project on Timesheets** | ||
- Adds the `parent_project_id` field to timesheets (`account.analytic.line`) to store the parent project of the linked iteration or project. | ||
|
||
- Automatically computes the parent project based on the hierarchy: | ||
|
||
- If the project has no parent, the `parent_project_id` is the project itself. | ||
|
||
- Otherwise, the `parent_project_id` corresponds to the direct parent of the project. | ||
|
||
**Constraints on Parent Project Changes** | ||
|
||
- Raise ValidationError on changing parent project if timesheets already exist for the project. | ||
|
||
.. image:: static/description/error_change_parent_id.png | ||
|
||
**Enhanced Views** | ||
- Displays the parent project in analytic line views for better visibility. | ||
|
||
- Allows filtering timesheets based on the parent project. | ||
|
||
.. image:: static/description/hr_timesheet_search_view.png | ||
|
||
Contributors | ||
------------ | ||
- Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
|
||
More Information | ||
---------------- | ||
For more details, visit: | ||
- https://github.com/OCA/project/tree/16.0/project_parent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# 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 . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
{ | ||
"name": "Hr Timesheet Project Parent", | ||
"version": "16.0.1.0.0", | ||
"author": "Numigi", | ||
"maintainer": "Numigi", | ||
"website": "https://bit.ly/numigi-com", | ||
"license": "LGPL-3", | ||
"category": "Project", | ||
"depends": ["hr_timesheet", "project_parent"], | ||
"data": [ | ||
"views/account_analytic_line_views.xml", | ||
], | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * hr_timesheet_project_parent | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-12-10 13:48+0000\n" | ||
"PO-Revision-Date: 2024-12-10 13:48+0000\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: hr_timesheet_project_parent | ||
#: model:ir.model,name:hr_timesheet_project_parent.model_account_analytic_line | ||
msgid "Analytic Line" | ||
msgstr "Ligne analytique" | ||
|
||
#. module: hr_timesheet_project_parent | ||
#: model:ir.model.fields,field_description:hr_timesheet_project_parent.field_account_analytic_line__project_id | ||
msgid "Iteration" | ||
msgstr "Projet" | ||
|
||
#. module: hr_timesheet_project_parent | ||
#: model:ir.model.fields,field_description:hr_timesheet_project_parent.field_account_analytic_line__parent_project_id | ||
msgid "Parent Project" | ||
msgstr "" | ||
|
||
#. module: hr_timesheet_project_parent | ||
#: model:ir.model,name:hr_timesheet_project_parent.model_project_project | ||
msgid "Project" | ||
msgstr "Projet" | ||
|
||
#. module: hr_timesheet_project_parent | ||
#. odoo-python | ||
#: code:addons/hr_timesheet_project_parent/models/project_project.py:0 | ||
#, python-format | ||
msgid "" | ||
"Timesheet already exists on this project, to update the Parent Project " | ||
"field, the Project must have no Timesheets." | ||
msgstr "" | ||
"Une feuille de temps existe déjà pour ce projet." | ||
" Pour modifier le champ Projet Parent, le projet ne doit avoir aucune feuille de temps." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# 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 . import account_analytic_line | ||
from . import project_project |
32 changes: 32 additions & 0 deletions
32
hr_timesheet_project_parent/models/account_analytic_line.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 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 | ||
|
||
|
||
class AccountAnalyticLine(models.Model): | ||
|
||
_inherit = "account.analytic.line" | ||
|
||
project_id = fields.Many2one(string="Iteration") | ||
parent_project_id = fields.Many2one( | ||
"project.project", | ||
"Parent Project", | ||
compute="_compute_parent_project_id", | ||
store=True, | ||
index=True, | ||
compute_sudo=True, | ||
) | ||
|
||
@api.depends("project_id", "project_id.child_ids_count", "project_id.parent_id") | ||
def _compute_parent_project_id(self): | ||
""" | ||
Compute the parent project of an analytic line. | ||
If the project has no parent, then the parent | ||
project is the project itself. | ||
""" | ||
for line in self: | ||
line.parent_project_id = ( | ||
line.project_id.parent_id | ||
if line.project_id.parent_id | ||
else line.project_id | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# 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.exceptions import ValidationError | ||
|
||
|
||
class ProjectProject(models.Model): | ||
|
||
_inherit = "project.project" | ||
|
||
@api.constrains("parent_id") | ||
def _check_cannot_change_parent_while_existing_timesheet(self): | ||
analytic_line_env = self.env["account.analytic.line"] | ||
for project in self: | ||
if analytic_line_env.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." | ||
) | ||
) |
Binary file added
BIN
+120 KB
hr_timesheet_project_parent/static/description/error_change_parent_id.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+222 KB
hr_timesheet_project_parent/static/description/hr_timesheet_search_view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# 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 . import test_account_analytic_line |
57 changes: 57 additions & 0 deletions
57
hr_timesheet_project_parent/tests/test_account_analytic_line.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
|
||
import pytest | ||
from odoo.exceptions import ValidationError | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestProjectIterationWithTimeSheet(TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.project_1 = cls.env["project.project"].create({"name": "Project 1"}) | ||
cls.project_2 = cls.env["project.project"].create({"name": "Project 2"}) | ||
|
||
cls.iteration_1 = cls.env["project.project"].create( | ||
{ | ||
"name": "Iteration 1", | ||
"parent_id": cls.project_1.id, | ||
} | ||
) | ||
cls.iteration_2 = cls.env["project.project"].create( | ||
{ | ||
"name": "Iteration 2", | ||
"parent_id": cls.project_1.id, | ||
} | ||
) | ||
|
||
def _create_timesheet(self, project): | ||
|
||
return self.env["account.analytic.line"].create( | ||
{ | ||
"name": "Do something", | ||
"unit_amount": 1, | ||
"project_id": project.id, | ||
"employee_id": self.env.ref("hr.employee_admin").id, | ||
} | ||
) | ||
|
||
def test_analytic_line_parent_project_id(self): | ||
line_1 = self._create_timesheet(self.iteration_1) | ||
self.assertEqual(line_1.parent_project_id, self.project_1) | ||
line_2 = self._create_timesheet(self.project_2) | ||
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) | ||
with pytest.raises(ValidationError): | ||
self.project_1.parent_id = self.project_2 | ||
|
||
def test_allow_setting_project_with_timesheet_as_parent(self): | ||
self._create_timesheet(self.project_1) | ||
self.project_2.parent_id = self.project_1 | ||
|
||
def test_allow_setting_project_without_timesheet_as_parent(self): | ||
self.project_2.parent_id = self.project_1 |
26 changes: 26 additions & 0 deletions
26
hr_timesheet_project_parent/views/account_analytic_line_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
|
||
<record id="view_account_analytic_line_filter" model="ir.ui.view"> | ||
<field name="name">Analytic Line Search With Parent Project</field> | ||
<field name="model">account.analytic.line</field> | ||
<field name="inherit_id" ref="analytic.view_account_analytic_line_filter"/> | ||
<field name="arch" type="xml"> | ||
<field name="account_id" position="after"> | ||
<field name="parent_project_id"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record id="hr_timesheet_line_search" model="ir.ui.view"> | ||
<field name="name">Timesheet Line Search With Parent Project</field> | ||
<field name="model">account.analytic.line</field> | ||
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_search"/> | ||
<field name="arch" type="xml"> | ||
<field name="project_id" position="after"> | ||
<field name="parent_project_id"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |