diff --git a/hr_timesheet_quick_add/README.rst b/hr_timesheet_quick_add/README.rst new file mode 100644 index 000000000..3fabd98f8 --- /dev/null +++ b/hr_timesheet_quick_add/README.rst @@ -0,0 +1,97 @@ +====================== +HR Timesheet Quick Add +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:732c6e94ddd590e84afec2ba2b55fdc8ce00580ae7ad90563d87f992e5c653b9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Ftimesheet-lightgray.png?logo=github + :target: https://github.com/OCA/timesheet/tree/16.0/hr_timesheet_quick_add + :alt: OCA/timesheet +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/timesheet-16-0/timesheet-16-0-hr_timesheet_quick_add + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/timesheet&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Add a field to select task among last used timesheet ones + + +Here is `Timesheet candidates` field display tasks on which you recorded time recently. + + +.. figure:: https://raw.githubusercontent.com/OCA/timesheet/16.0/hr_timesheet_quick_add/static/description/im1.png + :alt: Timesheet candidates field + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + + + +.. figure:: https://raw.githubusercontent.com/OCA/timesheet/16.0/hr_timesheet_quick_add/static/description/im2.png + + + +.. figure:: https://raw.githubusercontent.com/OCA/timesheet/16.0/hr_timesheet_quick_add/static/description/im3.png + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* `Akretion `_: + + * David BEAL + + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/timesheet `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_timesheet_quick_add/__init__.py b/hr_timesheet_quick_add/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/hr_timesheet_quick_add/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_timesheet_quick_add/__manifest__.py b/hr_timesheet_quick_add/__manifest__.py new file mode 100644 index 000000000..1fb888151 --- /dev/null +++ b/hr_timesheet_quick_add/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Akretion + +{ + "name": "HR Timesheet Quick Add", + "version": "16.0.1.0.0", + "author": "Akretion, Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Human Resources", + "depends": ["hr_timesheet_sheet"], + "website": "https://github.com/OCA/timesheet", + "data": [ + "views/hr_timesheet.xml", + ], + "installable": True, +} diff --git a/hr_timesheet_quick_add/models/__init__.py b/hr_timesheet_quick_add/models/__init__.py new file mode 100644 index 000000000..5858a8189 --- /dev/null +++ b/hr_timesheet_quick_add/models/__init__.py @@ -0,0 +1 @@ +from . import hr_timesheet_sheet diff --git a/hr_timesheet_quick_add/models/hr_timesheet_sheet.py b/hr_timesheet_quick_add/models/hr_timesheet_sheet.py new file mode 100644 index 000000000..9d5b0a1df --- /dev/null +++ b/hr_timesheet_quick_add/models/hr_timesheet_sheet.py @@ -0,0 +1,67 @@ +from datetime import timedelta + +from odoo import api, fields, models + + +class Hr_TimesheetSheet(models.Model): + _inherit = "hr_timesheet.sheet" + + candidate_task_ids = fields.Many2many( + comodel_name="project.task", + string="Timesheet candidates", + readonly=False, + store=False, + compute="_compute_recent_tasks", + ) + default_hour = fields.Integer(default=1) + default_name = fields.Char(default="/") + + @api.depends("timesheet_ids") + def _compute_recent_tasks(self): + "It get tasks on which you recorded time recently" + recent = fields.Date.today() - timedelta(days=self._get_default_days_history()) + for rec in self: + tasks = self.env["account.analytic.line"].read_group( + [ + ("employee_id", "=", rec.employee_id.id), + ("task_id", "not in", rec.timesheet_ids.mapped("task_id").ids), + ("sheet_id", "!=", rec.id), + ("date", ">", recent), + ], + ["task_id", "unit_amount"], + ["task_id"], + ) + rec.candidate_task_ids = [ + (6, 0, [x["task_id"] and x["task_id"][0] for x in tasks]) + ] + + def write(self, vals): + residual_tasks = ( + "candidate_task_ids" in vals and vals["candidate_task_ids"][0][2] + ) + for rec in self: + if residual_tasks or rec.candidate_task_ids: + rec._add_timesheet_from_candidates(residual_tasks) + return super().write(vals) + + def _add_timesheet_from_candidates(self, residual_tasks): + self.ensure_one() + task_ids = [x for x in self.candidate_task_ids.ids if x not in residual_tasks] + values = self._prepare_empty_analytic_line() + for task in self.env["project.task"].browse(task_ids): + vals = values.copy() + vals.update( + { + "project_id": task.project_id.id, + "task_id": task.id, + "unit_amount": self.default_hour, + "name": self.default_name or "/", + } + ) + date = fields.Date.today() + if date >= self.date_start and date <= self.date_end: + vals["date"] = date + self.timesheet_ids |= self.env["account.analytic.line"]._sheet_create(vals) + + def _get_default_days_history(self): + return 20 diff --git a/hr_timesheet_quick_add/readme/CONTRIBUTORS.rst b/hr_timesheet_quick_add/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..3a2d4494b --- /dev/null +++ b/hr_timesheet_quick_add/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Akretion `_: + + * David BEAL + diff --git a/hr_timesheet_quick_add/readme/DESCRIPTION.rst b/hr_timesheet_quick_add/readme/DESCRIPTION.rst new file mode 100644 index 000000000..e996d78ea --- /dev/null +++ b/hr_timesheet_quick_add/readme/DESCRIPTION.rst @@ -0,0 +1,8 @@ +Add a field to select task among last used timesheet ones + + +Here is `Timesheet candidates` field display tasks on which you recorded time recently. + + +.. figure:: ../static/description/im1.png + :alt: Timesheet candidates field diff --git a/hr_timesheet_quick_add/readme/USAGE.rst b/hr_timesheet_quick_add/readme/USAGE.rst new file mode 100644 index 000000000..c20a897e4 --- /dev/null +++ b/hr_timesheet_quick_add/readme/USAGE.rst @@ -0,0 +1,7 @@ + + +.. figure:: ../static/description/im2.png + + + +.. figure:: ../static/description/im3.png diff --git a/hr_timesheet_quick_add/static/description/im1.png b/hr_timesheet_quick_add/static/description/im1.png new file mode 100644 index 000000000..aa373f0f5 Binary files /dev/null and b/hr_timesheet_quick_add/static/description/im1.png differ diff --git a/hr_timesheet_quick_add/static/description/im2.png b/hr_timesheet_quick_add/static/description/im2.png new file mode 100644 index 000000000..4ca7a9a78 Binary files /dev/null and b/hr_timesheet_quick_add/static/description/im2.png differ diff --git a/hr_timesheet_quick_add/static/description/im3.png b/hr_timesheet_quick_add/static/description/im3.png new file mode 100644 index 000000000..a199ce14c Binary files /dev/null and b/hr_timesheet_quick_add/static/description/im3.png differ diff --git a/hr_timesheet_quick_add/static/description/index.html b/hr_timesheet_quick_add/static/description/index.html new file mode 100644 index 000000000..38dd4f161 --- /dev/null +++ b/hr_timesheet_quick_add/static/description/index.html @@ -0,0 +1,437 @@ + + + + + +HR Timesheet Quick Add + + + +
+

HR Timesheet Quick Add

+ + +

Beta License: AGPL-3 OCA/timesheet Translate me on Weblate Try me on Runboat

+

Add a field to select task among last used timesheet ones

+

Here is Timesheet candidates field display tasks on which you recorded time recently.

+
+Timesheet candidates field +
+

Table of contents

+ +
+

Usage

+
+https://raw.githubusercontent.com/OCA/timesheet/16.0/hr_timesheet_quick_add/static/description/im2.png +
+
+https://raw.githubusercontent.com/OCA/timesheet/16.0/hr_timesheet_quick_add/static/description/im3.png +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/timesheet project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/hr_timesheet_quick_add/tests/__init__.py b/hr_timesheet_quick_add/tests/__init__.py new file mode 100644 index 000000000..99a973297 --- /dev/null +++ b/hr_timesheet_quick_add/tests/__init__.py @@ -0,0 +1 @@ +from . import test_timesheet_quick diff --git a/hr_timesheet_quick_add/tests/test_timesheet_quick.py b/hr_timesheet_quick_add/tests/test_timesheet_quick.py new file mode 100644 index 000000000..ab96cfef6 --- /dev/null +++ b/hr_timesheet_quick_add/tests/test_timesheet_quick.py @@ -0,0 +1,67 @@ +from odoo.addons.hr_timesheet_sheet.tests import common + + +def sheet_vals(self, date, task, sheet): + return { + "name": "/", + "employee_id": self.employee.id, + "sheet_id": sheet.id, + "unit_amount": 1, + "date": date, + "task_id": task.id, + "project_id": task.project_id.id, + } + + +def create_sheet(self, start, end): + return self.env["hr_timesheet.sheet"].create( + { + "company_id": self.employee.company_id.id, + "employee_id": self.employee.id, + "date_start": start, + "date_end": end, + } + ) + + +class Test(common.HrTimesheetSheetCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.task_3 = cls.task_model.create( + { + "name": "Task 3", + "project_id": cls.project_2.id, + "company_id": cls.user.company_id.id, + } + ) + cls.task_4 = cls.task_model.create( + { + "name": "Task 4", + "project_id": cls.project_2.id, + "company_id": cls.user.company_id.id, + } + ) + cls.july = create_sheet(cls, "2030-07-01", "2030-07-07") + cls.june = create_sheet(cls, "2030-06-17", "2030-06-23") + vals_list = [ + sheet_vals(cls, "2030-06-18", cls.task_1, cls.june), + sheet_vals(cls, "2030-06-20", cls.task_2, cls.june), + sheet_vals(cls, "2030-06-22", cls.task_3, cls.june), + sheet_vals(cls, "2030-07-03", cls.task_4, cls.july), + ] + cls.env["account.analytic.line"].create(vals_list) + + def test_after_setup(self): + assert len(self.june.timesheet_ids) == 3 + assert len(self.july.timesheet_ids) == 1 + assert self.july.candidate_task_ids + + def test_remove_candidates_adding_analytic_line(self): + assert len(self.july.candidate_task_ids) == 3 + # we only have 1 analytic.line entry for this timesheet.sheet + assert len(self.july.timesheet_ids) == 1 + self.july.candidate_task_ids = [(6, 0, self.july.candidate_task_ids[2:].ids)] + assert len(self.july.candidate_task_ids) == 1 + # we now have 3 analytic.line entries + assert len(self.july.timesheet_ids) == 3 diff --git a/hr_timesheet_quick_add/views/hr_timesheet.xml b/hr_timesheet_quick_add/views/hr_timesheet.xml new file mode 100644 index 000000000..774cd1b13 --- /dev/null +++ b/hr_timesheet_quick_add/views/hr_timesheet.xml @@ -0,0 +1,31 @@ + + + + + hr_timesheet.sheet + + + + + +
If you remove candidates and save, they'll be populated as real timesheets
+
+ + + + + + + + +
+
+
+ +
diff --git a/setup/hr_timesheet_quick_add/odoo/addons/hr_timesheet_quick_add b/setup/hr_timesheet_quick_add/odoo/addons/hr_timesheet_quick_add new file mode 120000 index 000000000..de22c2e47 --- /dev/null +++ b/setup/hr_timesheet_quick_add/odoo/addons/hr_timesheet_quick_add @@ -0,0 +1 @@ +../../../../hr_timesheet_quick_add \ No newline at end of file diff --git a/setup/hr_timesheet_quick_add/setup.py b/setup/hr_timesheet_quick_add/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/hr_timesheet_quick_add/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)