From 4c012b6db65ef5741d5c6c33795885080be4237e Mon Sep 17 00:00:00 2001 From: aromera Date: Wed, 18 Aug 2021 16:02:23 +0200 Subject: [PATCH] [MIG] helpdesk_mgmt_timesheet: Migration to 14.0 --- helpdesk_mgmt_timesheet/__manifest__.py | 6 +++- .../models/helpdesk_ticket.py | 32 ++++++++++++++++++- .../test_helpdesk_timesheet_time_control.py | 11 ++++++- .../views/helpdesk_ticket_view.xml | 8 +++++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/helpdesk_mgmt_timesheet/__manifest__.py b/helpdesk_mgmt_timesheet/__manifest__.py index 9ebba6a6e2..415da3586b 100644 --- a/helpdesk_mgmt_timesheet/__manifest__.py +++ b/helpdesk_mgmt_timesheet/__manifest__.py @@ -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", diff --git a/helpdesk_mgmt_timesheet/models/helpdesk_ticket.py b/helpdesk_mgmt_timesheet/models/helpdesk_ticket.py index 8e04fc5aa9..304682a3ae 100644 --- a/helpdesk_mgmt_timesheet/models/helpdesk_ticket.py +++ b/helpdesk_mgmt_timesheet/models/helpdesk_ticket.py @@ -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", @@ -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 diff --git a/helpdesk_mgmt_timesheet/tests/test_helpdesk_timesheet_time_control.py b/helpdesk_mgmt_timesheet/tests/test_helpdesk_timesheet_time_control.py index f7d94dd0c9..039426f028 100644 --- a/helpdesk_mgmt_timesheet/tests/test_helpdesk_timesheet_time_control.py +++ b/helpdesk_mgmt_timesheet/tests/test_helpdesk_timesheet_time_control.py @@ -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( @@ -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)) diff --git a/helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml b/helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml index 644cbdfc49..2e2f29203d 100644 --- a/helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml +++ b/helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml @@ -63,6 +63,7 @@