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 19, 2024
1 parent 9ef0511 commit eceada9
Show file tree
Hide file tree
Showing 17 changed files with 760 additions and 0 deletions.
100 changes: 100 additions & 0 deletions hr_timesheet_sheet_quick_add/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
======================
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.

**Table of contents**

.. contents::
:local:

Usage
=====



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



.. 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
15 changes: 15 additions & 0 deletions hr_timesheet_sheet_quick_add/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
1 change: 1 addition & 0 deletions hr_timesheet_sheet_quick_add/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import hr_timesheet_sheet
72 changes: 72 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,72 @@
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",
help="Tasks candidates to timesheet",
)
default_hour = fields.Integer(string="Hours", default=1, help="Default hours")
default_description = fields.Char(
string="Description", default="/", help="Default description"
)

@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 "candidate_task_ids" in vals:
rec._add_timesheet_from_candidates(residual_tasks)
vals["name"] = "/"
return super().write(vals)

def _add_timesheet_from_candidates(self, residual_tasks):
self.ensure_one()
residual_tasks = residual_tasks or []
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):
tvals = values.copy()
tvals.update(
{
"project_id": task.project_id.id,
"task_id": task.id,
"unit_amount": self.default_hour,
"name": self.default_description or "/",
}
)
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_default_days_history(self):
return 20
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]>

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


.. figure:: ../static/description/im2.png



.. 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 eceada9

Please sign in to comment.