From d84d6fd10a6c1ff6ee374af2171a74c01d0b35cd Mon Sep 17 00:00:00 2001 From: Aromera Date: Tue, 4 Jul 2023 10:45:43 +0200 Subject: [PATCH] [MIG] helpdesk_mgmt_timesheet: Migration 16.0 --- helpdesk_mgmt_timesheet/__manifest__.py | 2 +- .../demo/helpdesk_mgmt_timesheet_demo.xml | 70 +++++++++---------- .../models/helpdesk_ticket.py | 6 +- .../models/helpdesk_ticket_team.py | 4 +- .../tests/test_helpdesk_mgmt_timesheet.py | 34 +++++---- .../wizards/hr_timesheet_switch.py | 26 +++---- .../odoo/addons/helpdesk_mgmt_timesheet | 1 + setup/helpdesk_mgmt_timesheet/setup.py | 6 ++ 8 files changed, 80 insertions(+), 69 deletions(-) create mode 120000 setup/helpdesk_mgmt_timesheet/odoo/addons/helpdesk_mgmt_timesheet create mode 100644 setup/helpdesk_mgmt_timesheet/setup.py diff --git a/helpdesk_mgmt_timesheet/__manifest__.py b/helpdesk_mgmt_timesheet/__manifest__.py index d748ad130b..9136443bca 100644 --- a/helpdesk_mgmt_timesheet/__manifest__.py +++ b/helpdesk_mgmt_timesheet/__manifest__.py @@ -15,7 +15,7 @@ "website": "https://github.com/OCA/helpdesk", "license": "AGPL-3", "category": "After-Sales", - "version": "14.0.1.0.1", + "version": "16.0.1.0.0", "depends": [ "helpdesk_mgmt_project", "hr_timesheet", diff --git a/helpdesk_mgmt_timesheet/demo/helpdesk_mgmt_timesheet_demo.xml b/helpdesk_mgmt_timesheet/demo/helpdesk_mgmt_timesheet_demo.xml index efbadd1b15..a496dffbab 100644 --- a/helpdesk_mgmt_timesheet/demo/helpdesk_mgmt_timesheet_demo.xml +++ b/helpdesk_mgmt_timesheet/demo/helpdesk_mgmt_timesheet_demo.xml @@ -1,38 +1,36 @@ - - - - Helpdesk general project - - - Helpdesk general task - - - - - - - - - - - - - - - Initial analysis - - - - - - - - Resolution - - - - - - + + + Helpdesk general project + + + Helpdesk general task + + + + + + + + + + + + + + + Initial analysis + + + + + + + + Resolution + + + + + diff --git a/helpdesk_mgmt_timesheet/models/helpdesk_ticket.py b/helpdesk_mgmt_timesheet/models/helpdesk_ticket.py index 304682a3ae..d8bc1193ca 100644 --- a/helpdesk_mgmt_timesheet/models/helpdesk_ticket.py +++ b/helpdesk_mgmt_timesheet/models/helpdesk_ticket.py @@ -16,18 +16,16 @@ def _relation_with_timesheet_line(self): string="Allow Timesheet", related="team_id.allow_timesheet", ) - planned_hours = fields.Float(string="Planned Hours", tracking=True) + planned_hours = fields.Float(tracking=True) progress = fields.Float( compute="_compute_progress_hours", group_operator="avg", store=True, - string="Progress", ) remaining_hours = fields.Float( compute="_compute_progress_hours", readonly=True, store=True, - string="Remaining Hours", ) timesheet_ids = fields.One2many( comodel_name="account.analytic.line", @@ -35,7 +33,7 @@ def _relation_with_timesheet_line(self): string="Timesheet", ) total_hours = fields.Float( - compute="_compute_total_hours", readonly=True, store=True, string="Total Hours" + compute="_compute_total_hours", readonly=True, store=True ) last_timesheet_activity = fields.Date( compute="_compute_last_timesheet_activity", diff --git a/helpdesk_mgmt_timesheet/models/helpdesk_ticket_team.py b/helpdesk_mgmt_timesheet/models/helpdesk_ticket_team.py index 95be41eaba..32ac584e17 100644 --- a/helpdesk_mgmt_timesheet/models/helpdesk_ticket_team.py +++ b/helpdesk_mgmt_timesheet/models/helpdesk_ticket_team.py @@ -7,9 +7,7 @@ class HelpdeskTicketTeam(models.Model): _inherit = "helpdesk.ticket.team" - allow_timesheet = fields.Boolean( - string="Allow Timesheet", - ) + allow_timesheet = fields.Boolean() default_project_id = fields.Many2one( comodel_name="project.project", string="Default Project", diff --git a/helpdesk_mgmt_timesheet/tests/test_helpdesk_mgmt_timesheet.py b/helpdesk_mgmt_timesheet/tests/test_helpdesk_mgmt_timesheet.py index 8a76d0ec7f..2301a4a798 100644 --- a/helpdesk_mgmt_timesheet/tests/test_helpdesk_mgmt_timesheet.py +++ b/helpdesk_mgmt_timesheet/tests/test_helpdesk_mgmt_timesheet.py @@ -25,16 +25,7 @@ def setUpClass(cls): ) def generate_timesheet(self, ticket, hours=1.0, days_ago=0): - return self.env["account.analytic.line"].create( - { - "amount": 0, - "date": fields.Date.today() - timedelta(days=days_ago), - "name": "Test Timesheet", - "unit_amount": hours, - "ticket_id": ticket.id, - "project_id": ticket.project_id.id, - } - ) + return def generate_ticket(self): return self.env["helpdesk.ticket"].create( @@ -46,18 +37,37 @@ def generate_ticket(self): ) def test_helpdesk_mgmt_timesheet(self): + Timesheet = self.env["account.analytic.line"] ticket = self.generate_ticket() self.assertFalse(ticket.last_timesheet_activity) ticket._onchange_team_id() self.assertEqual(ticket.project_id.id, self.team_id.default_project_id.id) ticket.planned_hours = 5 days_ago = 1 - timesheet1 = self.generate_timesheet(ticket, hours=2, days_ago=days_ago) + timesheet1 = Timesheet.with_user().create( + { + "amount": 0, + "date": fields.Date.today() - timedelta(days=days_ago), + "name": "Test Timesheet", + "unit_amount": 2, + "ticket_id": ticket.id, + "project_id": ticket.project_id.id, + } + ) self.assertEqual( ticket.last_timesheet_activity, fields.Date.today() - timedelta(days=days_ago), ) - timesheet2 = self.generate_timesheet(ticket, hours=1) + timesheet2 = Timesheet.with_user().create( + { + "amount": 0, + "date": fields.Date.today() - timedelta(days=0), + "name": "Test Timesheet", + "unit_amount": 1, + "ticket_id": ticket.id, + "project_id": ticket.project_id.id, + } + ) self.assertEqual(ticket.last_timesheet_activity, fields.Date.today()) self.assertEqual( ticket.total_hours, timesheet1.unit_amount + timesheet2.unit_amount diff --git a/helpdesk_mgmt_timesheet/wizards/hr_timesheet_switch.py b/helpdesk_mgmt_timesheet/wizards/hr_timesheet_switch.py index 9b0d07cdaf..e98f039bb8 100644 --- a/helpdesk_mgmt_timesheet/wizards/hr_timesheet_switch.py +++ b/helpdesk_mgmt_timesheet/wizards/hr_timesheet_switch.py @@ -11,17 +11,17 @@ class HrTimesheetSwitch(models.TransientModel): def _closest_suggestion(self): """Allow searching best suggestion by helpdesk.ticket.""" result = super()._closest_suggestion() - try: - if not result and self.env.context["active_model"] == "helpdesk.ticket": - return self.env["account.analytic.line"].search( - [ - ("user_id", "=", self.env.user.id), - ("ticket_id", "=", self.env.context["active_id"]), - ], - order="date_time DESC", - limit=1, - ) - except KeyError: - # If I don't know where's the user, I don't know what to suggest - pass + if ( + not result + and self.env.context["active_model"] == "helpdesk.ticket" + and self.env.user + ): + return self.env["account.analytic.line"].search( + [ + ("user_id", "=", self.env.user.id), + ("ticket_id", "=", self.env.context["active_id"]), + ], + order="date_time DESC", + limit=1, + ) return result diff --git a/setup/helpdesk_mgmt_timesheet/odoo/addons/helpdesk_mgmt_timesheet b/setup/helpdesk_mgmt_timesheet/odoo/addons/helpdesk_mgmt_timesheet new file mode 120000 index 0000000000..70624cc2d8 --- /dev/null +++ b/setup/helpdesk_mgmt_timesheet/odoo/addons/helpdesk_mgmt_timesheet @@ -0,0 +1 @@ +../../../../helpdesk_mgmt_timesheet \ No newline at end of file diff --git a/setup/helpdesk_mgmt_timesheet/setup.py b/setup/helpdesk_mgmt_timesheet/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/helpdesk_mgmt_timesheet/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)