-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from akretion/16-mig-project-time-in-day
16 mig project time in day
- Loading branch information
Showing
10 changed files
with
147 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO |
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 @@ | ||
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,26 @@ | ||
# Copyright 2022 Akretion (https://www.akretion.com). | ||
# @author Sébastien BEAU <sebastien.beau@akretion.com> | ||
# 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": [], | ||
} |
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,2 @@ | ||
from . import project_task | ||
from . import project_project |
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,46 @@ | ||
# Copyright 2022 Akretion (https://www.akretion.com). | ||
# @author Sébastien BEAU <sebastien.beau@akretion.com> | ||
# 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) |
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,34 @@ | ||
# Copyright 2022 Akretion (https://www.akretion.com). | ||
# @author Sébastien BEAU <sebastien.beau@akretion.com> | ||
# 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 | ||
) |
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,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> |
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,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> |
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 @@ | ||
../../../../project_time_in_day |
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,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |