Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Aug 19, 2024
1 parent 1a8a6f8 commit ce8ba94
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
5 changes: 4 additions & 1 deletion hr_timesheet_quick_add/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ HR Timesheet Quick Add

|badge1| |badge2| |badge3| |badge4| |badge5|

Add a field to select task among last used timesheet ones
Add a field to select tasks among last used timesheet ones


Here is `Timesheet candidates` field display tasks on which you recorded time recently.
Expand All @@ -37,6 +37,9 @@ Here is `Timesheet candidates` field display tasks on which you recorded time re
.. figure:: https://raw.githubusercontent.com/OCA/timesheet/16.0/hr_timesheet_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::
Expand Down
21 changes: 13 additions & 8 deletions hr_timesheet_quick_add/models/hr_timesheet_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ class Hr_TimesheetSheet(models.Model):
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"
)
default_hour = fields.Integer(default=1)
default_name = fields.Char(default="/")

@api.depends("timesheet_ids")
def _compute_recent_tasks(self):
Expand All @@ -40,28 +43,30 @@ def write(self, vals):
"candidate_task_ids" in vals and vals["candidate_task_ids"][0][2]
)
for rec in self:
if residual_tasks or rec.candidate_task_ids:
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):
vals = values.copy()
vals.update(
tvals = values.copy()
tvals.update(
{
"project_id": task.project_id.id,
"task_id": task.id,
"unit_amount": self.default_hour,
"name": self.default_name or "/",
"name": self.default_description 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)
tvals["date"] = date

Check warning on line 68 in hr_timesheet_quick_add/models/hr_timesheet_sheet.py

View check run for this annotation

Codecov / codecov/patch

hr_timesheet_quick_add/models/hr_timesheet_sheet.py#L68

Added line #L68 was not covered by tests
self.timesheet_ids |= self.env["account.analytic.line"]._sheet_create(tvals)

def _get_default_days_history(self):
return 20
5 changes: 4 additions & 1 deletion hr_timesheet_quick_add/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
Add a field to select task among last used timesheet ones
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.
3 changes: 2 additions & 1 deletion hr_timesheet_quick_add/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,12 @@ <h1 class="title">HR Timesheet Quick Add</h1>
!! source digest: sha256:732c6e94ddd590e84afec2ba2b55fdc8ce00580ae7ad90563d87f992e5c653b9
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/timesheet/tree/16.0/hr_timesheet_quick_add"><img alt="OCA/timesheet" src="https://img.shields.io/badge/github-OCA%2Ftimesheet-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/timesheet-16-0/timesheet-16-0-hr_timesheet_quick_add"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/timesheet&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Add a field to select task among last used timesheet ones</p>
<p>Add a field to select tasks among last used timesheet ones</p>
<p>Here is <cite>Timesheet candidates</cite> field display tasks on which you recorded time recently.</p>
<div class="figure">
<img alt="Timesheet candidates field" src="https://raw.githubusercontent.com/OCA/timesheet/16.0/hr_timesheet_quick_add/static/description/im1.png" />
</div>
<p>This module is especially useful when your week timesheet is empty and you have worked on same tasks than previous week.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down
6 changes: 6 additions & 0 deletions hr_timesheet_quick_add/tests/test_timesheet_quick.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ def test_remove_candidates_adding_analytic_line(self):
assert len(self.july.candidate_task_ids) == 1
# we now have 3 analytic.line entries
assert len(self.july.timesheet_ids) == 3

def test_one_candidate_to_remove(self):
self.july.candidate_task_ids = [(6, 0, self.july.candidate_task_ids[2:].ids)]
assert len(self.july.candidate_task_ids) == 1
self.july.candidate_task_ids = False
assert len(self.july.candidate_task_ids) == 0
7 changes: 3 additions & 4 deletions hr_timesheet_quick_add/views/hr_timesheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
widget="many2many_tags"
colspan="4"
/>
<div
colspan="4"
>If you remove candidates and save, they'll be populated as real timesheets</div>
<div colspan="4"><blockquote
>If you remove these candidates and save, they'll be populated as real timesheets with 'Hours' and 'Description'</blockquote></div>
</group>
<group col="4">
<group colspan="2">
<field name="default_hour" />
</group>
<group colspan="2">
<field name="default_name" />
<field name="default_description" />
</group>
</group>
</xpath>
Expand Down

0 comments on commit ce8ba94

Please sign in to comment.