Skip to content

Commit

Permalink
Merge pull request #310 from akretion/16-mig-project-time-in-day
Browse files Browse the repository at this point in the history
16 mig project time in day
  • Loading branch information
florian-dacosta authored Jul 16, 2024
2 parents d104027 + 87a1734 commit accdf50
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 0 deletions.
1 change: 1 addition & 0 deletions project_time_in_day/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
1 change: 1 addition & 0 deletions project_time_in_day/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
26 changes: 26 additions & 0 deletions project_time_in_day/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2022 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Project time in days",
"summary": "Compute time in days",
"version": "16.0.1.0.0",
"development_status": "Beta",
"category": "Uncategorized",
"website": "https://github.com/akretion/ak-odoo-incubator",
"author": " Akretion",
"license": "AGPL-3",
"external_dependencies": {
"python": [],
"bin": [],
},
"depends": [
"hr_timesheet",
],
"data": [
"views/project_task_view.xml",
"views/project_project_view.xml",
],
"demo": [],
}
2 changes: 2 additions & 0 deletions project_time_in_day/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import project_task
from . import project_project
46 changes: 46 additions & 0 deletions project_time_in_day/models/project_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2022 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).


from odoo import fields, models


class ProjectProject(models.Model):
_inherit = "project.project"

def _get_hour_domain(self):
return [
("category_id", "=", self.env.ref("uom.uom_categ_wtime").id),
("uom_type", "=", "smaller"),
]

hour_uom_id = fields.Many2one(
"uom.uom",
"Hour Uom",
help="Used for conversion between day and hours",
domain=_get_hour_domain,
)

def _get_hour_uom(self):
# By default in Odoo the uom of reference is the day
# so depending of your location and multicompany case
# you can have a different unit for hours (7h per day, 8h per day...)
if self.hour_uom_id:
return self.hour_uom_id
else:
return self.env.ref("uom.product_uom_hour")

def convert_hours_to_days(self, value):
return self._convert_to(value, "hours2days")

def convert_days_to_hours(self, value):
return self._convert_to(value, "days2hours")

def _convert_to(self, value, conversion):
uom_day = self.env.ref("uom.product_uom_day")
uom_hour = self._get_hour_uom()
if conversion == "days2hours":
return uom_day._compute_quantity(value, uom_hour)
elif conversion == "hours2days":
return uom_hour._compute_quantity(value, uom_day)
34 changes: 34 additions & 0 deletions project_time_in_day/models/project_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2022 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ProjectTask(models.Model):
_inherit = "project.task"

planned_days = fields.Float(compute="_compute_planned_days", store=True)
remaining_days = fields.Float(compute="_compute_remaining_days", store=True)
effective_days = fields.Float(compute="_compute_effective_days", store=True)

@api.depends("planned_hours", "project_id.hour_uom_id")
def _compute_planned_days(self):
for record in self:
record.planned_days = record.project_id.convert_hours_to_days(
record.planned_hours
)

@api.depends("remaining_hours", "project_id.hour_uom_id")
def _compute_remaining_days(self):
for record in self:
record.remaining_days = record.project_id.convert_hours_to_days(
record.remaining_hours
)

@api.depends("effective_hours", "project_id.hour_uom_id")
def _compute_effective_days(self):
for record in self:
record.effective_days = record.project_id.convert_hours_to_days(
record.effective_hours
)
14 changes: 14 additions & 0 deletions project_time_in_day/views/project_project_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="edit_project" model="ir.ui.view">
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project" />
<field name="arch" type="xml">
<xpath expr="//group[@name='extra_settings']" position="inside">
<field name="hour_uom_id" />
</xpath>
</field>
</record>

</odoo>
16 changes: 16 additions & 0 deletions project_time_in_day/views/project_task_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="view_task_tree2_inherited" model="ir.ui.view">
<field name="model">project.task</field>
<field name="inherit_id" ref="hr_timesheet.view_task_tree2_inherited" />
<field name="arch" type="xml">
<field name="planned_hours" position="before">
<field name="planned_days" sum="Initially Planned Days" />
<field name="remaining_days" sum="Remaining Days" />
<field name="effective_days" sum="Spent Days" />
</field>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions setup/project_time_in_day/odoo/addons/project_time_in_day
6 changes: 6 additions & 0 deletions setup/project_time_in_day/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit accdf50

Please sign in to comment.