diff --git a/project_time_in_day/README.rst b/project_time_in_day/README.rst new file mode 100644 index 000000000..1333ed77b --- /dev/null +++ b/project_time_in_day/README.rst @@ -0,0 +1 @@ +TODO diff --git a/project_time_in_day/__init__.py b/project_time_in_day/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/project_time_in_day/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/project_time_in_day/__manifest__.py b/project_time_in_day/__manifest__.py new file mode 100644 index 000000000..9f1003659 --- /dev/null +++ b/project_time_in_day/__manifest__.py @@ -0,0 +1,26 @@ +# Copyright 2022 Akretion (https://www.akretion.com). +# @author Sébastien BEAU +# 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": [], +} diff --git a/project_time_in_day/models/__init__.py b/project_time_in_day/models/__init__.py new file mode 100644 index 000000000..97799a87f --- /dev/null +++ b/project_time_in_day/models/__init__.py @@ -0,0 +1,2 @@ +from . import project_task +from . import project_project diff --git a/project_time_in_day/models/project_project.py b/project_time_in_day/models/project_project.py new file mode 100644 index 000000000..c149571da --- /dev/null +++ b/project_time_in_day/models/project_project.py @@ -0,0 +1,46 @@ +# Copyright 2022 Akretion (https://www.akretion.com). +# @author Sébastien BEAU +# 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) diff --git a/project_time_in_day/models/project_task.py b/project_time_in_day/models/project_task.py new file mode 100644 index 000000000..18ccd00c6 --- /dev/null +++ b/project_time_in_day/models/project_task.py @@ -0,0 +1,34 @@ +# Copyright 2022 Akretion (https://www.akretion.com). +# @author Sébastien BEAU +# 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 + ) diff --git a/project_time_in_day/views/project_project_view.xml b/project_time_in_day/views/project_project_view.xml new file mode 100644 index 000000000..a7c971d58 --- /dev/null +++ b/project_time_in_day/views/project_project_view.xml @@ -0,0 +1,14 @@ + + + + + project.project + + + + + + + + + diff --git a/project_time_in_day/views/project_task_view.xml b/project_time_in_day/views/project_task_view.xml new file mode 100644 index 000000000..765151e1f --- /dev/null +++ b/project_time_in_day/views/project_task_view.xml @@ -0,0 +1,16 @@ + + + + + project.task + + + + + + + + + + + diff --git a/setup/project_time_in_day/odoo/addons/project_time_in_day b/setup/project_time_in_day/odoo/addons/project_time_in_day new file mode 120000 index 000000000..83d6525d3 --- /dev/null +++ b/setup/project_time_in_day/odoo/addons/project_time_in_day @@ -0,0 +1 @@ +../../../../project_time_in_day \ No newline at end of file diff --git a/setup/project_time_in_day/setup.py b/setup/project_time_in_day/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/project_time_in_day/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)