Skip to content

Commit

Permalink
[MIG][16.0] hr_timesheet_project_parent (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
rivo2302 authored Dec 10, 2024
1 parent e579ff8 commit b67e1f0
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 3 deletions.
4 changes: 1 addition & 3 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"license": "LGPL-3",
"category": "Other",
"summary": "Install all addons required for testing.",
"depends": [
"hr_timesheet",
],
"depends": ["hr_timesheet", "hr_timesheet_project_parent"],
"installable": True,
}
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ RUN gitoo install-all --conf_file /gitoo.yml --destination "${THIRD_PARTY_ADDONS

USER odoo

COPY hr_timesheet_project_parent /mnt/extra-addons/hr_timesheet_project_parent

COPY .docker_files/main /mnt/extra-addons/main
COPY .docker_files/odoo.conf /etc/odoo
2 changes: 2 additions & 0 deletions gitoo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
branch: "16.0"
includes:
- project_timesheet_time_control
- project_parent

- url: https://github.com/OCA/timesheet
branch: "16.0"
Expand All @@ -15,3 +16,4 @@
includes:
- web_ir_actions_act_multi
- web_widget_x2many_2d_matrix

43 changes: 43 additions & 0 deletions hr_timesheet_project_parent/README.rst
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
4 changes: 4 additions & 0 deletions hr_timesheet_project_parent/__init__.py
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
17 changes: 17 additions & 0 deletions hr_timesheet_project_parent/__manifest__.py
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,
}
47 changes: 47 additions & 0 deletions hr_timesheet_project_parent/i18n/fr.po
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."
5 changes: 5 additions & 0 deletions hr_timesheet_project_parent/models/__init__.py
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 hr_timesheet_project_parent/models/account_analytic_line.py
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
)
23 changes: 23 additions & 0 deletions hr_timesheet_project_parent/models/project_project.py
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."
)
)
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions hr_timesheet_project_parent/tests/__init__.py
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 hr_timesheet_project_parent/tests/test_account_analytic_line.py
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 hr_timesheet_project_parent/views/account_analytic_line_views.xml
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>

0 comments on commit b67e1f0

Please sign in to comment.