diff --git a/hr_timesheet_sheet_quick_add/README.rst b/hr_timesheet_sheet_quick_add/README.rst new file mode 100644 index 000000000..cdc4561ba --- /dev/null +++ b/hr_timesheet_sheet_quick_add/README.rst @@ -0,0 +1,110 @@ +====================== +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_sheet_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_sheet_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 tasks 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_sheet_quick_add/static/description/im1.png + :alt: Timesheet candidates field + + +This module is especially useful when your week timesheet is empty and you have worked on same tasks than previous week. + + +Your timesheet tasks from last 14 days are suggested to be added to the timesheet + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + + +Just remove proposed tasks and save. + + +.. figure:: https://raw.githubusercontent.com/OCA/timesheet/16.0/hr_timesheet_sheet_quick_add/static/description/im2.png + + + + +Previous proposed tasks are now tasks with timesheet of 1 hour in this case + + +.. figure:: https://raw.githubusercontent.com/OCA/timesheet/16.0/hr_timesheet_sheet_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_sheet_quick_add/__init__.py b/hr_timesheet_sheet_quick_add/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/hr_timesheet_sheet_quick_add/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_timesheet_sheet_quick_add/__manifest__.py b/hr_timesheet_sheet_quick_add/__manifest__.py new file mode 100644 index 000000000..6b40bf8cc --- /dev/null +++ b/hr_timesheet_sheet_quick_add/__manifest__.py @@ -0,0 +1,18 @@ +# 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", + "views/users.xml", + ], + "installable": True, +} diff --git a/hr_timesheet_sheet_quick_add/models/__init__.py b/hr_timesheet_sheet_quick_add/models/__init__.py new file mode 100644 index 000000000..d2f71cc1e --- /dev/null +++ b/hr_timesheet_sheet_quick_add/models/__init__.py @@ -0,0 +1,2 @@ +from . import hr_timesheet_sheet +from . import users diff --git a/hr_timesheet_sheet_quick_add/models/hr_timesheet_sheet.py b/hr_timesheet_sheet_quick_add/models/hr_timesheet_sheet.py new file mode 100644 index 000000000..fa253063e --- /dev/null +++ b/hr_timesheet_sheet_quick_add/models/hr_timesheet_sheet.py @@ -0,0 +1,89 @@ +from datetime import timedelta + +from odoo import api, fields, models + +from .users import TASK_DAYS_HELP + + +class Hr_TimesheetSheet(models.Model): + _inherit = "hr_timesheet.sheet" + + proposed_task_ids = fields.Many2many( + comodel_name="project.task", + readonly=False, + store=False, + compute="_compute_recent_tasks", + help="Last timesheet tasks by you.\n" + "If no time tasks is set, your tasks with no timesheet are added.", + ) + default_hour = fields.Integer(string="Hours", default=1, help="Default hours") + last_tasks_days = fields.Integer( + default=lambda s: s.env.user.last_tasks_days, help=TASK_DAYS_HELP + ) + no_time_tasks = fields.Boolean( + help="Complete proposed tasks with no time assigned tasks" + ) + + @api.depends("timesheet_ids") + def _compute_recent_tasks(self): + "It get tasks on which you recorded time recently" + for rec in self: + recent = fields.Date.today() - timedelta(days=rec.last_tasks_days) + # tasks with timesheet + 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"], + ) + tasks = self.env["project.task"].browse( + [x["task_id"] and x["task_id"][0] for x in tasks] + ) + if rec.no_time_tasks: + # tasks attached to employee without timesheet + tasks |= self._get_employee_tasks_without_timesheet() + rec.proposed_task_ids = tasks + + def write(self, vals): + residual_tasks = "proposed_task_ids" in vals and vals["proposed_task_ids"][0][2] + for rec in self: + if "proposed_task_ids" in vals: + rec._add_timesheet_from_proposed(residual_tasks) + vals["name"] = "/" + return super().write(vals) + + def _add_timesheet_from_proposed(self, residual_tasks): + self.ensure_one() + residual_tasks = residual_tasks or [] + task_ids = [x for x in self.proposed_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): + tvals = values.copy() + tvals.update( + { + "project_id": task.project_id.id, + "task_id": task.id, + "unit_amount": self.default_hour, + "name": "/", + } + ) + date = fields.Date.today() + if date >= self.date_start and date <= self.date_end: + tvals["date"] = date + self.timesheet_ids |= self.env["account.analytic.line"]._sheet_create(tvals) + + def _get_employee_tasks_without_timesheet(self): + tasks = self.env["project.task"].search(self._get_domain_wo_timesheet()) + user = self.employee_id.user_id + return tasks.filtered(lambda s: not s.timesheet_ids.employee_id.user_id == user) + + def _get_domain_wo_timesheet(self): + "You may inherit to customize your conditions" + return [ + ("is_closed", "=", False), + ("user_ids", "in", self.employee_id.user_id.id), + ] diff --git a/hr_timesheet_sheet_quick_add/models/users.py b/hr_timesheet_sheet_quick_add/models/users.py new file mode 100644 index 000000000..67ed7d1c1 --- /dev/null +++ b/hr_timesheet_sheet_quick_add/models/users.py @@ -0,0 +1,11 @@ +from odoo import _, fields, models + +TASK_DAYS_HELP = _( + "Horizon from which we search for the tasks on which we have entered timesheets" +) + + +class ResUsers(models.Model): + _inherit = "res.users" + + last_tasks_days = fields.Integer(default=14, help=TASK_DAYS_HELP) diff --git a/hr_timesheet_sheet_quick_add/readme/CONTRIBUTORS.rst b/hr_timesheet_sheet_quick_add/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..3a2d4494b --- /dev/null +++ b/hr_timesheet_sheet_quick_add/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Akretion `_: + + * David BEAL + diff --git a/hr_timesheet_sheet_quick_add/readme/DESCRIPTION.rst b/hr_timesheet_sheet_quick_add/readme/DESCRIPTION.rst new file mode 100644 index 000000000..e16b5552b --- /dev/null +++ b/hr_timesheet_sheet_quick_add/readme/DESCRIPTION.rst @@ -0,0 +1,14 @@ +Add a field to select tasks 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 + + +This module is especially useful when your week timesheet is empty and you have worked on same tasks than previous week. + + +Your timesheet tasks from last 14 days are suggested to be added to the timesheet diff --git a/hr_timesheet_sheet_quick_add/readme/USAGE.rst b/hr_timesheet_sheet_quick_add/readme/USAGE.rst new file mode 100644 index 000000000..1fde30fea --- /dev/null +++ b/hr_timesheet_sheet_quick_add/readme/USAGE.rst @@ -0,0 +1,14 @@ + +Just remove proposed tasks and save. + + +.. figure:: ../static/description/im2.png + + + + +Previous proposed tasks are now tasks with timesheet of 1 hour in this case + + +.. figure:: ../static/description/im3.png + diff --git a/hr_timesheet_sheet_quick_add/static/description/im1.png b/hr_timesheet_sheet_quick_add/static/description/im1.png new file mode 100644 index 000000000..6c02a7c5b Binary files /dev/null and b/hr_timesheet_sheet_quick_add/static/description/im1.png differ diff --git a/hr_timesheet_sheet_quick_add/static/description/im2.png b/hr_timesheet_sheet_quick_add/static/description/im2.png new file mode 100644 index 000000000..045ef5a04 Binary files /dev/null and b/hr_timesheet_sheet_quick_add/static/description/im2.png differ diff --git a/hr_timesheet_sheet_quick_add/static/description/im3.png b/hr_timesheet_sheet_quick_add/static/description/im3.png new file mode 100644 index 000000000..e0aec62c6 Binary files /dev/null and b/hr_timesheet_sheet_quick_add/static/description/im3.png differ diff --git a/hr_timesheet_sheet_quick_add/static/description/index.html b/hr_timesheet_sheet_quick_add/static/description/index.html new file mode 100644 index 000000000..2a73f5aa8 --- /dev/null +++ b/hr_timesheet_sheet_quick_add/static/description/index.html @@ -0,0 +1,441 @@ + + + + + +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 tasks among last used timesheet ones

+

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

+
+Timesheet candidates field +
+

This module is especially useful when your week timesheet is empty and you have worked on same tasks than previous week.

+

Your timesheet tasks from last 14 days are suggested to be added to the timesheet

+

Table of contents

+ +
+

Usage

+

Just remove proposed tasks and save.

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

Previous proposed tasks are now tasks with timesheet of 1 hour in this case

+
+https://raw.githubusercontent.com/OCA/timesheet/16.0/hr_timesheet_sheet_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_sheet_quick_add/tests/__init__.py b/hr_timesheet_sheet_quick_add/tests/__init__.py new file mode 100644 index 000000000..99a973297 --- /dev/null +++ b/hr_timesheet_sheet_quick_add/tests/__init__.py @@ -0,0 +1 @@ +from . import test_timesheet_quick diff --git a/hr_timesheet_sheet_quick_add/tests/test_timesheet_quick.py b/hr_timesheet_sheet_quick_add/tests/test_timesheet_quick.py new file mode 100644 index 000000000..a958c2c26 --- /dev/null +++ b/hr_timesheet_sheet_quick_add/tests/test_timesheet_quick.py @@ -0,0 +1,73 @@ +from odoo.addons.hr_timesheet_sheet.tests import test_hr_timesheet_sheet + + +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(test_hr_timesheet_sheet.TestHrTimesheetSheetCommon): + @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.proposed_task_ids + + def test_remove_proposed_adding_analytic_line(self): + assert len(self.july.proposed_task_ids) == 3 + # we only have 1 analytic.line entry for this timesheet.sheet + assert len(self.july.timesheet_ids) == 1 + self.july.proposed_task_ids = [(6, 0, self.july.proposed_task_ids[2:].ids)] + assert len(self.july.proposed_task_ids) == 1 + # we now have 3 analytic.line entries + assert len(self.july.timesheet_ids) == 3 + + def test_one_proposed_to_remove(self): + self.july.proposed_task_ids = [(6, 0, self.july.proposed_task_ids[2:].ids)] + assert len(self.july.proposed_task_ids) == 1 + self.july.proposed_task_ids = False + assert len(self.july.proposed_task_ids) == 0 diff --git a/hr_timesheet_sheet_quick_add/views/hr_timesheet.xml b/hr_timesheet_sheet_quick_add/views/hr_timesheet.xml new file mode 100644 index 000000000..47b73f374 --- /dev/null +++ b/hr_timesheet_sheet_quick_add/views/hr_timesheet.xml @@ -0,0 +1,31 @@ + + + + + hr_timesheet.sheet + + + + + +
If you remove these tasks and save, they'll be populated as timesheets with 'Hours'
+
+ + + + + + + + + +
+
+
+ +
diff --git a/hr_timesheet_sheet_quick_add/views/users.xml b/hr_timesheet_sheet_quick_add/views/users.xml new file mode 100644 index 000000000..50fa8711a --- /dev/null +++ b/hr_timesheet_sheet_quick_add/views/users.xml @@ -0,0 +1,27 @@ + + + + + res.users + + + + + + + + + + + + res.users + + + + + + + + + + diff --git a/setup/hr_timesheet_sheet_quick_add/odoo/addons/hr_timesheet_sheet_quick_add b/setup/hr_timesheet_sheet_quick_add/odoo/addons/hr_timesheet_sheet_quick_add new file mode 120000 index 000000000..e327b3f00 --- /dev/null +++ b/setup/hr_timesheet_sheet_quick_add/odoo/addons/hr_timesheet_sheet_quick_add @@ -0,0 +1 @@ +../../../../hr_timesheet_sheet_quick_add \ No newline at end of file diff --git a/setup/hr_timesheet_sheet_quick_add/setup.py b/setup/hr_timesheet_sheet_quick_add/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/hr_timesheet_sheet_quick_add/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)