From c3753418a1edc9f86fd1fa7279e8a5f3b00eca14 Mon Sep 17 00:00:00 2001 From: "David Alonso (Solvos)" Date: Tue, 28 Jul 2020 18:32:56 +0200 Subject: [PATCH] [ADD] helpdesk_mgmt_timesheet: work in progress Pending: * demo data * i18n * README rebuild --- helpdesk_mgmt_timesheet/__manifest__.py | 13 ++- helpdesk_mgmt_timesheet/models/__init__.py | 2 +- .../models/account_analytic_line.py | 13 --- .../models/helpdesk_ticket.py | 13 +-- .../models/helpdesk_ticket_team.py | 14 +-- .../models/hr_timesheet.py | 27 ++++++ helpdesk_mgmt_timesheet/readme/CONFIGURE.rst | 4 +- .../readme/CONTRIBUTORS.rst | 6 +- .../readme/DESCRIPTION.rst | 2 +- helpdesk_mgmt_timesheet/readme/USAGE.rst | 2 +- .../helpdesk_mgmt_timesheet_security.xml | 10 ++ helpdesk_mgmt_timesheet/tests/__init__.py | 2 +- ...ket.py => test_helpdesk_mgmt_timesheet.py} | 36 +++++--- ...lpdesk_team.xml => helpdesk_team_view.xml} | 6 +- .../views/helpdesk_ticket.xml | 49 ---------- .../views/helpdesk_ticket_view.xml | 91 +++++++++++++++++++ .../views/hr_timesheet_view.xml | 83 +++++++++++++++++ 17 files changed, 267 insertions(+), 106 deletions(-) delete mode 100644 helpdesk_mgmt_timesheet/models/account_analytic_line.py create mode 100644 helpdesk_mgmt_timesheet/models/hr_timesheet.py create mode 100644 helpdesk_mgmt_timesheet/security/helpdesk_mgmt_timesheet_security.xml rename helpdesk_mgmt_timesheet/tests/{tests_helpdesk_ticket.py => test_helpdesk_mgmt_timesheet.py} (50%) rename helpdesk_mgmt_timesheet/views/{helpdesk_team.xml => helpdesk_team_view.xml} (62%) delete mode 100644 helpdesk_mgmt_timesheet/views/helpdesk_ticket.xml create mode 100644 helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml create mode 100644 helpdesk_mgmt_timesheet/views/hr_timesheet_view.xml diff --git a/helpdesk_mgmt_timesheet/__manifest__.py b/helpdesk_mgmt_timesheet/__manifest__.py index 6d15c26994..4081087517 100644 --- a/helpdesk_mgmt_timesheet/__manifest__.py +++ b/helpdesk_mgmt_timesheet/__manifest__.py @@ -9,17 +9,20 @@ 'author': 'Aresoltec Canarias, ' 'Punt Sistemes, ' 'SDi Soluciones Digitales, ' + 'Solvos, ' 'Odoo Community Association (OCA)', - 'website': 'https://github.com/oca/helpdesk', + 'website': 'https://github.com/OCA/helpdesk', 'license': 'AGPL-3', 'category': 'After-Sales', 'version': '12.0.1.0.0', 'depends': [ - 'helpdesk_mgmt', - 'account', + 'helpdesk_mgmt_project', + 'hr_timesheet', ], 'data': [ - 'views/helpdesk_team.xml', - 'views/helpdesk_ticket.xml', + 'security/helpdesk_mgmt_timesheet_security.xml', + 'views/helpdesk_team_view.xml', + 'views/helpdesk_ticket_view.xml', + 'views/hr_timesheet_view.xml', ] } diff --git a/helpdesk_mgmt_timesheet/models/__init__.py b/helpdesk_mgmt_timesheet/models/__init__.py index 0aaaabcaae..e3a546702d 100644 --- a/helpdesk_mgmt_timesheet/models/__init__.py +++ b/helpdesk_mgmt_timesheet/models/__init__.py @@ -1,6 +1,6 @@ ############################################################################### # For copyright and license notices, see __manifest__.py file in root directory ############################################################################### -from . import account_analytic_line +from . import hr_timesheet from . import helpdesk_ticket from . import helpdesk_ticket_team diff --git a/helpdesk_mgmt_timesheet/models/account_analytic_line.py b/helpdesk_mgmt_timesheet/models/account_analytic_line.py deleted file mode 100644 index 655e8f59ce..0000000000 --- a/helpdesk_mgmt_timesheet/models/account_analytic_line.py +++ /dev/null @@ -1,13 +0,0 @@ -############################################################################### -# For copyright and license notices, see __manifest__.py file in root directory -############################################################################### -from odoo import fields, models - - -class AccountAnalyticLine(models.Model): - _inherit = 'account.analytic.line' - - ticket_id = fields.Many2one( - comodel_name='helpdesk.ticket', - string='Ticket', - ) diff --git a/helpdesk_mgmt_timesheet/models/helpdesk_ticket.py b/helpdesk_mgmt_timesheet/models/helpdesk_ticket.py index fdcc7b5440..d8cad205f0 100644 --- a/helpdesk_mgmt_timesheet/models/helpdesk_ticket.py +++ b/helpdesk_mgmt_timesheet/models/helpdesk_ticket.py @@ -11,10 +11,6 @@ class HelpdeskTicket(models.Model): string='Allow Timesheet', related='team_id.allow_timesheet', ) - analytic_account_id = fields.Many2one( - comodel_name='account.analytic.account', - string='Analityc Account', - ) planned_hours = fields.Float( string='Planned Hours', track_visibility='onchange', @@ -50,18 +46,17 @@ def impute_hours(self): record.timesheet_ids.mapped('unit_amount') ) - @api.constrains('analytic_account_id') - def _constrains_account_timesheets(self): + @api.constrains('project_id') + def _constrains_project_timesheets(self): for record in self: record.timesheet_ids.update({ - 'account_id': record.analytic_account_id.id + 'project_id': record.project_id.id }) @api.onchange('team_id') def _onchange_team_id(self): for record in self: - record.analytic_account_id = \ - record.team_id.default_analytic_account + record.project_id = record.team_id.default_project_id @api.depends('planned_hours', 'total_hours') def _compute_progress_hours(self): diff --git a/helpdesk_mgmt_timesheet/models/helpdesk_ticket_team.py b/helpdesk_mgmt_timesheet/models/helpdesk_ticket_team.py index 616e6bf190..26265fe580 100644 --- a/helpdesk_mgmt_timesheet/models/helpdesk_ticket_team.py +++ b/helpdesk_mgmt_timesheet/models/helpdesk_ticket_team.py @@ -10,18 +10,18 @@ class HelpdeskTicketTeam(models.Model): allow_timesheet = fields.Boolean( string='Allow Timesheet', ) - default_analytic_account = fields.Many2one( - comodel_name='account.analytic.account', - string='Default Analytic Account', + default_project_id = fields.Many2one( + comodel_name='project.project', + string='Default Project', ) - reset_default_analytic_account = fields.Boolean( - string='Reset Analytic Account', + reset_default_project = fields.Boolean( + string='Reset Project', ) @api.constrains('allow_timesheet') def _constrains_allow_timesheet(self): if not self.allow_timesheet: - self.default_analytic_account = False + self.default_project = False def action_clear(self): - self.default_analytic_account = False + self.default_project_id = False diff --git a/helpdesk_mgmt_timesheet/models/hr_timesheet.py b/helpdesk_mgmt_timesheet/models/hr_timesheet.py new file mode 100644 index 0000000000..1cef8be38b --- /dev/null +++ b/helpdesk_mgmt_timesheet/models/hr_timesheet.py @@ -0,0 +1,27 @@ +############################################################################### +# For copyright and license notices, see __manifest__.py file in root directory +############################################################################### +from odoo import api, fields, models + + +class AccountAnalyticLine(models.Model): + _inherit = 'account.analytic.line' + + ticket_id = fields.Many2one( + comodel_name='helpdesk.ticket', + string='Ticket', + groups="helpdesk_mgmt.group_helpdesk_user", + ) + ticket_partner_id = fields.Many2one( + comodel_name='res.partner', + related="ticket_id.partner_id", + string="Ticket partner", + store=True, + groups="helpdesk_mgmt.group_helpdesk_user", + ) + + @api.onchange("ticket_id") + def onchange_ticket_id(self): + for record in self: + record.project_id = record.ticket_id.project_id + record.task_id = record.ticket_id.task_id diff --git a/helpdesk_mgmt_timesheet/readme/CONFIGURE.rst b/helpdesk_mgmt_timesheet/readme/CONFIGURE.rst index 3b54e97e47..d85d8e4d31 100644 --- a/helpdesk_mgmt_timesheet/readme/CONFIGURE.rst +++ b/helpdesk_mgmt_timesheet/readme/CONFIGURE.rst @@ -1,7 +1,7 @@ To configure this module, you need to: #. Allow Timesheet for a Helpdesk's Team -#. Set a Default Analytic Account (optional) +#. Set a Default Project (optional) Allow Timesheet ~~~~~~~~~~~~~~~ @@ -9,4 +9,4 @@ Allow Timesheet #. Go to Helpdesk > Configuration > Teams. #. Edit or create a new team. #. Check Allow Timesheet option to allow timesheets for that team. -#. Select a Default Analytic Account for that team (optional). +#. Select a Project for that team (optional). diff --git a/helpdesk_mgmt_timesheet/readme/CONTRIBUTORS.rst b/helpdesk_mgmt_timesheet/readme/CONTRIBUTORS.rst index 8c4b94511a..8578ddda9c 100644 --- a/helpdesk_mgmt_timesheet/readme/CONTRIBUTORS.rst +++ b/helpdesk_mgmt_timesheet/readme/CONTRIBUTORS.rst @@ -9,4 +9,8 @@ * `Punt Sistemes, S.L. `_: - * Carlos Ramos \ No newline at end of file + * Carlos Ramos + +* `Solvos Consultoría Informática, S.L. `_: + + * David Alonso diff --git a/helpdesk_mgmt_timesheet/readme/DESCRIPTION.rst b/helpdesk_mgmt_timesheet/readme/DESCRIPTION.rst index ff803e9c8d..2fc3327cbd 100644 --- a/helpdesk_mgmt_timesheet/readme/DESCRIPTION.rst +++ b/helpdesk_mgmt_timesheet/readme/DESCRIPTION.rst @@ -1 +1 @@ -This module add Timesheet funcionality in Helpdesk module. \ No newline at end of file +This module adds Timesheet funcionality in Helpdesk module. diff --git a/helpdesk_mgmt_timesheet/readme/USAGE.rst b/helpdesk_mgmt_timesheet/readme/USAGE.rst index ba663c8733..35662be7a1 100644 --- a/helpdesk_mgmt_timesheet/readme/USAGE.rst +++ b/helpdesk_mgmt_timesheet/readme/USAGE.rst @@ -1,3 +1,3 @@ #. Go to *Helpdesk* or *Helpdesk > Dashboard* to see the tickets dashboard. #. In the Kanban view, click in the kanban card of a team to see their tickets and create new ones. -#. If there is not a Default Analytic Account you will need select an Analytic Account for the Ticket to show the Timesheet Table. \ No newline at end of file +#. If there is not a Default Project you will need select a Project for the Ticket to show the Timesheet Table. diff --git a/helpdesk_mgmt_timesheet/security/helpdesk_mgmt_timesheet_security.xml b/helpdesk_mgmt_timesheet/security/helpdesk_mgmt_timesheet_security.xml new file mode 100644 index 0000000000..c275c1b58f --- /dev/null +++ b/helpdesk_mgmt_timesheet/security/helpdesk_mgmt_timesheet_security.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/helpdesk_mgmt_timesheet/tests/__init__.py b/helpdesk_mgmt_timesheet/tests/__init__.py index f16bea3d00..1df5365371 100644 --- a/helpdesk_mgmt_timesheet/tests/__init__.py +++ b/helpdesk_mgmt_timesheet/tests/__init__.py @@ -1,4 +1,4 @@ ############################################################################### # For copyright and license notices, see __manifest__.py file in root directory ############################################################################### -from . import tests_helpdesk_ticket +from . import test_helpdesk_mgmt_timesheet diff --git a/helpdesk_mgmt_timesheet/tests/tests_helpdesk_ticket.py b/helpdesk_mgmt_timesheet/tests/test_helpdesk_mgmt_timesheet.py similarity index 50% rename from helpdesk_mgmt_timesheet/tests/tests_helpdesk_ticket.py rename to helpdesk_mgmt_timesheet/tests/test_helpdesk_mgmt_timesheet.py index 907eb70371..12cc8d2c32 100644 --- a/helpdesk_mgmt_timesheet/tests/tests_helpdesk_ticket.py +++ b/helpdesk_mgmt_timesheet/tests/test_helpdesk_mgmt_timesheet.py @@ -8,41 +8,49 @@ _log = logging.getLogger(__name__) -class TestHelpdeskTicketTimesheet(test_helpdesk_ticket.TestHelpdeskTicket): +class TestHelpdeskMgmtTimesheet(test_helpdesk_ticket.TestHelpdeskTicket): @classmethod def setUpClass(cls): - super(TestHelpdeskTicketTimesheet, cls).setUpClass() - cls.account_id = cls.env['account.analytic.account'].create({ - 'name': 'Test Account', + super(TestHelpdeskMgmtTimesheet, cls).setUpClass() + cls.project_id = cls.env['project.project'].create({ + 'name': 'Project', }) cls.team_id = cls.env['helpdesk.ticket.team'].create({ 'name': "Team 1", 'allow_timesheet': True, - 'default_analytic_account': cls.account_id.id, + 'default_project_id': cls.project_id.id, }) - def generate_timesheet(self, hours=1.0): + def generate_timesheet(self, ticket, hours=1.0): return self.env['account.analytic.line'].create({ 'amount': 0, - 'company_id': 1, + #'company_id': 1, 'date': fields.Date.today(), 'name': 'Test Timesheet', 'unit_amount': hours, + 'ticket_id': ticket.id, + 'project_id': ticket.project_id.id, }) def generate_ticket(self): return self.env['helpdesk.ticket'].create({ 'name': 'Test Ticket 1', + 'description': 'Test ticket description', 'team_id': self.team_id.id, }) - def test_total_and_remaining_hours(self): + def test_helpdesk_mgmt_timesheet(self): ticket = self.generate_ticket() + ticket._onchange_team_id() + self.assertEqual( + ticket.project_id.id, self.team_id.default_project_id.id) ticket.planned_hours = 5 - timesheet1 = self.generate_timesheet(2) - timesheet1.ticket_id = ticket.id - timesheet2 = self.generate_timesheet(1) - timesheet2.ticket_id = ticket.id - self.assertEqual(ticket.total_hours, 3) - self.assertEqual(ticket.remaining_hours, 2) + timesheet1 = self.generate_timesheet(ticket, 2) + timesheet2 = self.generate_timesheet(ticket, 1) + self.assertEqual( + ticket.total_hours, + timesheet1.unit_amount + timesheet2.unit_amount) + self.assertEqual( + ticket.remaining_hours, + ticket.planned_hours - ticket.total_hours) diff --git a/helpdesk_mgmt_timesheet/views/helpdesk_team.xml b/helpdesk_mgmt_timesheet/views/helpdesk_team_view.xml similarity index 62% rename from helpdesk_mgmt_timesheet/views/helpdesk_team.xml rename to helpdesk_mgmt_timesheet/views/helpdesk_team_view.xml index 91b2e0a219..d8a4f13c48 100644 --- a/helpdesk_mgmt_timesheet/views/helpdesk_team.xml +++ b/helpdesk_mgmt_timesheet/views/helpdesk_team_view.xml @@ -8,8 +8,10 @@ - - diff --git a/helpdesk_mgmt_timesheet/views/helpdesk_ticket.xml b/helpdesk_mgmt_timesheet/views/helpdesk_ticket.xml deleted file mode 100644 index 0b0349148d..0000000000 --- a/helpdesk_mgmt_timesheet/views/helpdesk_ticket.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - timesheet.helpdesk.ticket.form.view - helpdesk.ticket - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - -
-
- - - - -
-
-
-
-
diff --git a/helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml b/helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml new file mode 100644 index 0000000000..b9c2c9000f --- /dev/null +++ b/helpdesk_mgmt_timesheet/views/helpdesk_ticket_view.xml @@ -0,0 +1,91 @@ + + + + helpdesk.ticket.view.search + helpdesk.ticket + + + + + + + + + + + + + helpdesk.ticket.view.tree + helpdesk.ticket + + + + remaining_hours < 0 + + + + + + + + + + + timesheet.helpdesk.ticket.form.view + helpdesk.ticket + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + +
+
+ + + + +
+
+
+
+ + + timesheet.helpdesk.ticket.form.view project required + helpdesk.ticket + + + + {'required': [('allow_timesheet', '=', True)]} + + + +
diff --git a/helpdesk_mgmt_timesheet/views/hr_timesheet_view.xml b/helpdesk_mgmt_timesheet/views/hr_timesheet_view.xml new file mode 100644 index 0000000000..8688e94e57 --- /dev/null +++ b/helpdesk_mgmt_timesheet/views/hr_timesheet_view.xml @@ -0,0 +1,83 @@ + + + + + account.analytic.line + + + + + + + + + + + + + + + + + + + account.analytic.line + + + + + + + + + + + account.analytic.line + + + + + + + + + + + Timesheets + ir.actions.act_window + account.analytic.line + tree,kanban,form,pivot + form + [('ticket_id', '!=', False)] + { + 'ticket_required': True, + 'search_default_groupby_ticket_partner': 1, + 'search_default_groupby_ticket': 1, + } + + + + form + + + + + + + tree + + + + + + + +