Skip to content

Commit

Permalink
[MIG] helpdesk_mgmt_timesheet: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aromera committed Aug 31, 2021
1 parent f560c05 commit 4c012b6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
6 changes: 5 additions & 1 deletion helpdesk_mgmt_timesheet/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
"license": "AGPL-3",
"category": "After-Sales",
"version": "14.0.1.0.0",
"depends": ["helpdesk_mgmt_project", "hr_timesheet"],
"depends": [
"helpdesk_mgmt_project",
"hr_timesheet",
"project_timesheet_time_control",
],
"data": [
"views/helpdesk_team_view.xml",
"views/helpdesk_ticket_view.xml",
Expand Down
32 changes: 31 additions & 1 deletion helpdesk_mgmt_timesheet/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@


class HelpdeskTicket(models.Model):
_inherit = "helpdesk.ticket"
_name = "helpdesk.ticket"
_inherit = ["helpdesk.ticket", "hr.timesheet.time_control.mixin"]

@api.model
def _relation_with_timesheet_line(self):
return "ticket_id"

allow_timesheet = fields.Boolean(
string="Allow Timesheet",
Expand Down Expand Up @@ -73,3 +78,28 @@ def _compute_last_timesheet_activity(self):
record.timesheet_ids
and record.timesheet_ids.sorted(key="date", reverse=True)[0].date
) or False

@api.depends(
"team_id.allow_timesheet",
"project_id.allow_timesheets",
"timesheet_ids.employee_id",
"timesheet_ids.unit_amount",
)
def _compute_show_time_control(self):
result = super()._compute_show_time_control()
for ticket in self:
if not (
ticket.project_id.allow_timesheets and ticket.team_id.allow_timesheet
):
ticket.show_time_control = False
return result

def button_start_work(self):
result = super().button_start_work()
result["context"].update(
{
"default_project_id": self.project_id.id,
"default_task_id": self.task_id.id,
}
)
return result
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ class TestHelpdeskTimesheetTimeControl(common.TransactionCase):
def setUp(self):
super().setUp()
admin = self.browse_ref("base.user_admin")
# Stop any timer running
self.env["account.analytic.line"].search(
[
("date_time", "!=", False),
("user_id", "=", admin.id),
("project_id.allow_timesheets", "=", True),
("unit_amount", "=", 0),
]
).button_end_work()
admin.groups_id |= self.browse_ref("hr_timesheet.group_hr_timesheet_user")
self.uid = admin.id
self.project = self.env["project.project"].create(
Expand Down Expand Up @@ -83,7 +92,7 @@ def test_ticket_time_control_flow(self):
self.ticket.invalidate_cache()
self.assertEqual(self.ticket.show_time_control, "start")
start_action = self.ticket.button_start_work()
wizard = self._create_wizard(start_action, self.ticket)
wizard = self._create_wizard(start_action, self.ticket_line)
self.assertFalse(wizard.amount)
self.assertLessEqual(wizard.date_time, datetime.now())
self.assertLessEqual(wizard.date, fields.Date.context_today(wizard))
Expand Down
8 changes: 8 additions & 0 deletions helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<field name="show_time_control" invisible="1" />
<button
name="button_start_work"
title="Start work"
string="Start work"
tabindex="-1"
type="object"
Expand All @@ -72,6 +73,7 @@
/>
<button
name="button_end_work"
title="End work"
string="Stop work"
tabindex="-1"
type="object"
Expand All @@ -96,6 +98,7 @@
<field name="show_time_control" invisible="1" />
<button
name="button_start_work"
title="Start work"
string="Start work"
type="object"
icon="fa-play-circle text-success"
Expand All @@ -104,6 +107,7 @@
/>
<button
name="button_end_work"
title="End work"
string="Stop work"
type="object"
icon="fa-stop-circle text-warning"
Expand Down Expand Up @@ -158,6 +162,7 @@
/>
<button
name="button_end_work"
title="End work"
string="Stop work"
tabindex="-1"
type="object"
Expand All @@ -181,6 +186,7 @@
/>
<button
name="button_end_work"
title="End work"
string="Stop work"
tabindex="-1"
type="object"
Expand Down Expand Up @@ -224,6 +230,7 @@
<field name="show_time_control" invisible="1" />
<a
name="button_start_work"
title="Start work"
attrs="{'invisible': [('show_time_control', '!=', 'start')]}"
class="o_kanban_inline_block fa fa-lg fa-play-circle text-success"
string="Start work"
Expand All @@ -232,6 +239,7 @@
/>
<a
name="button_end_work"
title="End work"
attrs="{'invisible': [('show_time_control', '!=', 'stop')]}"
class="o_kanban_inline_block fa fa-lg fa-stop-circle text-warning"
string="Stop work"
Expand Down

0 comments on commit 4c012b6

Please sign in to comment.