Skip to content

Commit

Permalink
[ADD][16.0] module hr_timesheet_sheet_quick_add
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Aug 30, 2024
1 parent 9ef0511 commit 7936e0b
Show file tree
Hide file tree
Showing 19 changed files with 843 additions and 0 deletions.
110 changes: 110 additions & 0 deletions hr_timesheet_sheet_quick_add/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/timesheet/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 <https://github.com/OCA/timesheet/issues/new?body=module:%20hr_timesheet_sheet_quick_add%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Akretion

Contributors
~~~~~~~~~~~~

* `Akretion <https://www.akretion.com>`_:

* David BEAL <[email protected]>


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 <https://github.com/OCA/timesheet/tree/16.0/hr_timesheet_sheet_quick_add>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions hr_timesheet_sheet_quick_add/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions hr_timesheet_sheet_quick_add/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
2 changes: 2 additions & 0 deletions hr_timesheet_sheet_quick_add/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import hr_timesheet_sheet
from . import users
89 changes: 89 additions & 0 deletions hr_timesheet_sheet_quick_add/models/hr_timesheet_sheet.py
Original file line number Diff line number Diff line change
@@ -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()

Check warning on line 48 in hr_timesheet_sheet_quick_add/models/hr_timesheet_sheet.py

View check run for this annotation

Codecov / codecov/patch

hr_timesheet_sheet_quick_add/models/hr_timesheet_sheet.py#L48

Added line #L48 was not covered by tests
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

Check warning on line 76 in hr_timesheet_sheet_quick_add/models/hr_timesheet_sheet.py

View check run for this annotation

Codecov / codecov/patch

hr_timesheet_sheet_quick_add/models/hr_timesheet_sheet.py#L76

Added line #L76 was not covered by tests
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

Check warning on line 81 in hr_timesheet_sheet_quick_add/models/hr_timesheet_sheet.py

View check run for this annotation

Codecov / codecov/patch

hr_timesheet_sheet_quick_add/models/hr_timesheet_sheet.py#L80-L81

Added lines #L80 - L81 were not covered by tests
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 [

Check warning on line 86 in hr_timesheet_sheet_quick_add/models/hr_timesheet_sheet.py

View check run for this annotation

Codecov / codecov/patch

hr_timesheet_sheet_quick_add/models/hr_timesheet_sheet.py#L86

Added line #L86 was not covered by tests
("is_closed", "=", False),
("user_ids", "in", self.employee_id.user_id.id),
]
11 changes: 11 additions & 0 deletions hr_timesheet_sheet_quick_add/models/users.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions hr_timesheet_sheet_quick_add/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Akretion <https://www.akretion.com>`_:

* David BEAL <[email protected]>

14 changes: 14 additions & 0 deletions hr_timesheet_sheet_quick_add/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions hr_timesheet_sheet_quick_add/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7936e0b

Please sign in to comment.