Skip to content

Commit accdf50

Browse files
Merge pull request #310 from akretion/16-mig-project-time-in-day
16 mig project time in day
2 parents d104027 + 87a1734 commit accdf50

File tree

10 files changed

+147
-0
lines changed

10 files changed

+147
-0
lines changed

project_time_in_day/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO

project_time_in_day/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

project_time_in_day/__manifest__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2022 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <[email protected]>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
{
6+
"name": "Project time in days",
7+
"summary": "Compute time in days",
8+
"version": "16.0.1.0.0",
9+
"development_status": "Beta",
10+
"category": "Uncategorized",
11+
"website": "https://github.com/akretion/ak-odoo-incubator",
12+
"author": " Akretion",
13+
"license": "AGPL-3",
14+
"external_dependencies": {
15+
"python": [],
16+
"bin": [],
17+
},
18+
"depends": [
19+
"hr_timesheet",
20+
],
21+
"data": [
22+
"views/project_task_view.xml",
23+
"views/project_project_view.xml",
24+
],
25+
"demo": [],
26+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import project_task
2+
from . import project_project
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2022 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <[email protected]>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
6+
from odoo import fields, models
7+
8+
9+
class ProjectProject(models.Model):
10+
_inherit = "project.project"
11+
12+
def _get_hour_domain(self):
13+
return [
14+
("category_id", "=", self.env.ref("uom.uom_categ_wtime").id),
15+
("uom_type", "=", "smaller"),
16+
]
17+
18+
hour_uom_id = fields.Many2one(
19+
"uom.uom",
20+
"Hour Uom",
21+
help="Used for conversion between day and hours",
22+
domain=_get_hour_domain,
23+
)
24+
25+
def _get_hour_uom(self):
26+
# By default in Odoo the uom of reference is the day
27+
# so depending of your location and multicompany case
28+
# you can have a different unit for hours (7h per day, 8h per day...)
29+
if self.hour_uom_id:
30+
return self.hour_uom_id
31+
else:
32+
return self.env.ref("uom.product_uom_hour")
33+
34+
def convert_hours_to_days(self, value):
35+
return self._convert_to(value, "hours2days")
36+
37+
def convert_days_to_hours(self, value):
38+
return self._convert_to(value, "days2hours")
39+
40+
def _convert_to(self, value, conversion):
41+
uom_day = self.env.ref("uom.product_uom_day")
42+
uom_hour = self._get_hour_uom()
43+
if conversion == "days2hours":
44+
return uom_day._compute_quantity(value, uom_hour)
45+
elif conversion == "hours2days":
46+
return uom_hour._compute_quantity(value, uom_day)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2022 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <[email protected]>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
from odoo import api, fields, models
6+
7+
8+
class ProjectTask(models.Model):
9+
_inherit = "project.task"
10+
11+
planned_days = fields.Float(compute="_compute_planned_days", store=True)
12+
remaining_days = fields.Float(compute="_compute_remaining_days", store=True)
13+
effective_days = fields.Float(compute="_compute_effective_days", store=True)
14+
15+
@api.depends("planned_hours", "project_id.hour_uom_id")
16+
def _compute_planned_days(self):
17+
for record in self:
18+
record.planned_days = record.project_id.convert_hours_to_days(
19+
record.planned_hours
20+
)
21+
22+
@api.depends("remaining_hours", "project_id.hour_uom_id")
23+
def _compute_remaining_days(self):
24+
for record in self:
25+
record.remaining_days = record.project_id.convert_hours_to_days(
26+
record.remaining_hours
27+
)
28+
29+
@api.depends("effective_hours", "project_id.hour_uom_id")
30+
def _compute_effective_days(self):
31+
for record in self:
32+
record.effective_days = record.project_id.convert_hours_to_days(
33+
record.effective_hours
34+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo>
3+
4+
<record id="edit_project" model="ir.ui.view">
5+
<field name="model">project.project</field>
6+
<field name="inherit_id" ref="project.edit_project" />
7+
<field name="arch" type="xml">
8+
<xpath expr="//group[@name='extra_settings']" position="inside">
9+
<field name="hour_uom_id" />
10+
</xpath>
11+
</field>
12+
</record>
13+
14+
</odoo>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo>
3+
4+
<record id="view_task_tree2_inherited" model="ir.ui.view">
5+
<field name="model">project.task</field>
6+
<field name="inherit_id" ref="hr_timesheet.view_task_tree2_inherited" />
7+
<field name="arch" type="xml">
8+
<field name="planned_hours" position="before">
9+
<field name="planned_days" sum="Initially Planned Days" />
10+
<field name="remaining_days" sum="Remaining Days" />
11+
<field name="effective_days" sum="Spent Days" />
12+
</field>
13+
</field>
14+
</record>
15+
16+
</odoo>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../project_time_in_day

setup/project_time_in_day/setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

0 commit comments

Comments
 (0)