diff --git a/maintenance_timesheet_time_control/README.rst b/maintenance_timesheet_time_control/README.rst new file mode 100644 index 000000000..d05e4ea78 --- /dev/null +++ b/maintenance_timesheet_time_control/README.rst @@ -0,0 +1,118 @@ +=================================== +Maintenance Timesheets Time Control +=================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmaintenance-lightgray.png?logo=github + :target: https://github.com/OCA/maintenance/tree/13.0/maintenance_timesheet_time_control + :alt: OCA/maintenance +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/maintenance-13-0/maintenance-13-0-maintenance_timesheet_time_control + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/240/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +It allows to track the exact moment when a timesheet line is started (not only +the day, but also the minute and second) and let users start and stop timers +easily. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +This module is auto-installed when ``maintenance_timesheet`` and ``project_timesheet_time_control`` are +installed. + +This module depends on modules found in these repositories: + +* `OCA/timesheet `__ +* `OCA/web `__ +* `OCA/project `__ + +Usage +===== + +In general the usage instructions from ``project_timesheet_time_control`` apply with the following additions. + +Via maintenance requests: + +#. Go to *Maintenance > Maintenance > Maintenance Requests*. +#. If a request has a running timesheet line, it will display a *Stop* button. +#. Other requests that have enabled timesheets will display a *Start* button + that will open the same wizard as the timesheet lines, duplicating task's + last timesheet line. +#. You can see the same in list view. +#. Click on any existing request or create a new one. +#. You can see the same feature in the action buttons box. + +Note: All the *Start/Resume/Stop* features are disabled if you don't belong to +the *Timesheets/User* group or if you are viewing a timesheet that belongs +to another user. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-victoralmau| image:: https://github.com/victoralmau.png?size=40px + :target: https://github.com/victoralmau + :alt: victoralmau + +Current `maintainer `__: + +|maintainer-victoralmau| + +This module is part of the `OCA/maintenance `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/maintenance_timesheet_time_control/__init__.py b/maintenance_timesheet_time_control/__init__.py new file mode 100644 index 000000000..aee8895e7 --- /dev/null +++ b/maintenance_timesheet_time_control/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/maintenance_timesheet_time_control/__manifest__.py b/maintenance_timesheet_time_control/__manifest__.py new file mode 100644 index 000000000..e7806844c --- /dev/null +++ b/maintenance_timesheet_time_control/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Maintenance Timesheets Time Control", + "summary": "Maintenance Timesheets Timesheet Time Control", + "version": "13.0.1.0.0", + "license": "AGPL-3", + "category": "Hidden", + "author": "Tecnativa,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/maintenance", + "depends": ["maintenance_timesheet", "project_timesheet_time_control"], + "data": ["views/maintenance_request_view.xml"], + "auto_install": True, + "maintainers": ["victoralmau"], +} diff --git a/maintenance_timesheet_time_control/i18n/es.po b/maintenance_timesheet_time_control/i18n/es.po new file mode 100644 index 000000000..878162d24 --- /dev/null +++ b/maintenance_timesheet_time_control/i18n/es.po @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * maintenance_timesheet_time_control +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-12-21 10:34+0000\n" +"PO-Revision-Date: 2022-12-21 11:34+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 3.0.1\n" + +#. module: maintenance_timesheet_time_control +#: model:ir.model,name:maintenance_timesheet_time_control.model_hr_timesheet_switch +msgid "Helper to quickly switch between timesheet lines" +msgstr "Ayudante para cambiar rápidamente de línea del parte de horas" + +#. module: maintenance_timesheet_time_control +#: model:ir.model,name:maintenance_timesheet_time_control.model_maintenance_request +msgid "Maintenance Request" +msgstr "Petición de mantenimiento" + +#. module: maintenance_timesheet_time_control +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet_time_control.hr_equipment_request_view_form +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet_time_control.hr_equipment_request_view_kanban +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet_time_control.hr_equipment_request_view_tree +msgid "Start work" +msgstr "Iniciar trabajo" + +#. module: maintenance_timesheet_time_control +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet_time_control.hr_equipment_request_view_form +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet_time_control.hr_equipment_request_view_kanban +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet_time_control.hr_equipment_request_view_tree +msgid "Stop work" +msgstr "Detener trabajo" diff --git a/maintenance_timesheet_time_control/i18n/maintenance_timesheet_time_control.pot b/maintenance_timesheet_time_control/i18n/maintenance_timesheet_time_control.pot new file mode 100644 index 000000000..4ce4d2046 --- /dev/null +++ b/maintenance_timesheet_time_control/i18n/maintenance_timesheet_time_control.pot @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * maintenance_timesheet_time_control +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: maintenance_timesheet_time_control +#: model:ir.model,name:maintenance_timesheet_time_control.model_hr_timesheet_switch +msgid "Helper to quickly switch between timesheet lines" +msgstr "" + +#. module: maintenance_timesheet_time_control +#: model:ir.model,name:maintenance_timesheet_time_control.model_maintenance_request +msgid "Maintenance Request" +msgstr "" + +#. module: maintenance_timesheet_time_control +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet_time_control.hr_equipment_request_view_form +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet_time_control.hr_equipment_request_view_kanban +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet_time_control.hr_equipment_request_view_tree +msgid "Start work" +msgstr "" + +#. module: maintenance_timesheet_time_control +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet_time_control.hr_equipment_request_view_form +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet_time_control.hr_equipment_request_view_kanban +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet_time_control.hr_equipment_request_view_tree +msgid "Stop work" +msgstr "" diff --git a/maintenance_timesheet_time_control/models/__init__.py b/maintenance_timesheet_time_control/models/__init__.py new file mode 100644 index 000000000..df8c9b58f --- /dev/null +++ b/maintenance_timesheet_time_control/models/__init__.py @@ -0,0 +1 @@ +from . import maintenance_request diff --git a/maintenance_timesheet_time_control/models/maintenance_request.py b/maintenance_timesheet_time_control/models/maintenance_request.py new file mode 100644 index 000000000..25f698e1e --- /dev/null +++ b/maintenance_timesheet_time_control/models/maintenance_request.py @@ -0,0 +1,35 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class MaintenanceRequest(models.Model): + _name = "maintenance.request" + _inherit = ["maintenance.request", "hr.timesheet.time_control.mixin"] + + @api.model + def _relation_with_timesheet_line(self): + return "maintenance_request_id" + + @api.depends( + "project_id.allow_timesheets", + "timesheet_ids.employee_id", + "timesheet_ids.unit_amount", + ) + def _compute_show_time_control(self): + result = super()._compute_show_time_control() + self.filtered(lambda x: not x.project_id.allow_timesheets).update( + {"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/maintenance_timesheet_time_control/readme/CONTRIBUTORS.rst b/maintenance_timesheet_time_control/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..5fb713053 --- /dev/null +++ b/maintenance_timesheet_time_control/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza diff --git a/maintenance_timesheet_time_control/readme/DESCRIPTION.rst b/maintenance_timesheet_time_control/readme/DESCRIPTION.rst new file mode 100644 index 000000000..ae06ae9cc --- /dev/null +++ b/maintenance_timesheet_time_control/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +It allows to track the exact moment when a timesheet line is started (not only +the day, but also the minute and second) and let users start and stop timers +easily. diff --git a/maintenance_timesheet_time_control/readme/INSTALL.rst b/maintenance_timesheet_time_control/readme/INSTALL.rst new file mode 100644 index 000000000..97dfcda8b --- /dev/null +++ b/maintenance_timesheet_time_control/readme/INSTALL.rst @@ -0,0 +1,8 @@ +This module is auto-installed when ``maintenance_timesheet`` and ``project_timesheet_time_control`` are +installed. + +This module depends on modules found in these repositories: + +* `OCA/timesheet `__ +* `OCA/web `__ +* `OCA/project `__ diff --git a/maintenance_timesheet_time_control/readme/USAGE.rst b/maintenance_timesheet_time_control/readme/USAGE.rst new file mode 100644 index 000000000..a8ba28b99 --- /dev/null +++ b/maintenance_timesheet_time_control/readme/USAGE.rst @@ -0,0 +1,16 @@ +In general the usage instructions from ``project_timesheet_time_control`` apply with the following additions. + +Via maintenance requests: + +#. Go to *Maintenance > Maintenance > Maintenance Requests*. +#. If a request has a running timesheet line, it will display a *Stop* button. +#. Other requests that have enabled timesheets will display a *Start* button + that will open the same wizard as the timesheet lines, duplicating task's + last timesheet line. +#. You can see the same in list view. +#. Click on any existing request or create a new one. +#. You can see the same feature in the action buttons box. + +Note: All the *Start/Resume/Stop* features are disabled if you don't belong to +the *Timesheets/User* group or if you are viewing a timesheet that belongs +to another user. diff --git a/maintenance_timesheet_time_control/static/description/icon.png b/maintenance_timesheet_time_control/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/maintenance_timesheet_time_control/static/description/icon.png differ diff --git a/maintenance_timesheet_time_control/static/description/index.html b/maintenance_timesheet_time_control/static/description/index.html new file mode 100644 index 000000000..4157e8367 --- /dev/null +++ b/maintenance_timesheet_time_control/static/description/index.html @@ -0,0 +1,458 @@ + + + + + + +Maintenance Timesheets Time Control + + + +
+

Maintenance Timesheets Time Control

+ + +

Beta License: AGPL-3 OCA/maintenance Translate me on Weblate Try me on Runbot

+

It allows to track the exact moment when a timesheet line is started (not only +the day, but also the minute and second) and let users start and stop timers +easily.

+

Table of contents

+ +
+

Installation

+

This module is auto-installed when maintenance_timesheet and project_timesheet_time_control are +installed.

+

This module depends on modules found in these repositories:

+ +
+
+

Usage

+

In general the usage instructions from project_timesheet_time_control apply with the following additions.

+

Via maintenance requests:

+
    +
  1. Go to Maintenance > Maintenance > Maintenance Requests.
  2. +
  3. If a request has a running timesheet line, it will display a Stop button.
  4. +
  5. Other requests that have enabled timesheets will display a Start button +that will open the same wizard as the timesheet lines, duplicating task’s +last timesheet line.
  6. +
  7. You can see the same in list view.
  8. +
  9. Click on any existing request or create a new one.
  10. +
  11. You can see the same feature in the action buttons box.
  12. +
+

Note: All the Start/Resume/Stop features are disabled if you don’t belong to +the Timesheets/User group or if you are viewing a timesheet that belongs +to another user.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Víctor Martínez
    • +
    • Pedro M. Baeza
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

victoralmau

+

This module is part of the OCA/maintenance project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/maintenance_timesheet_time_control/tests/__init__.py b/maintenance_timesheet_time_control/tests/__init__.py new file mode 100644 index 000000000..83469cf09 --- /dev/null +++ b/maintenance_timesheet_time_control/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0 + +from . import test_maintenance_timesheet_time_control diff --git a/maintenance_timesheet_time_control/tests/test_maintenance_timesheet_time_control.py b/maintenance_timesheet_time_control/tests/test_maintenance_timesheet_time_control.py new file mode 100644 index 000000000..e457fe55a --- /dev/null +++ b/maintenance_timesheet_time_control/tests/test_maintenance_timesheet_time_control.py @@ -0,0 +1,104 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0 + +from datetime import datetime, timedelta + +from odoo import exceptions, fields +from odoo.tests import common, new_test_user, users + + +class TestMaintenanceTimesheetTimeControl(common.SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + ctx = { + "mail_create_nolog": True, + "mail_create_nosubscribe": True, + "mail_notrack": True, + "no_reset_password": True, + } + maintenance_group = "maintenance.group_equipment_manager" + timesheet_group = "hr_timesheet.group_hr_timesheet_user" + cls.user = new_test_user( + cls.env, + login="test-maintenance-user", + groups="%s,%s" % (maintenance_group, timesheet_group), + context=ctx, + ) + cls.employee = cls.env["hr.employee"].create( + {"name": "Test employee", "user_id": cls.user.id} + ) + cls.project = cls.env["project.project"].create( + {"name": "Test project", "allow_timesheets": True} + ) + cls.equipment = cls.env["maintenance.equipment"].create( + { + "name": "Test computer", + "category_id": cls.env.ref("maintenance.equipment_computer").id, + "project_id": cls.project.id, + "maintenance_team_id": cls.env.ref( + "maintenance.equipment_team_maintenance" + ).id, + } + ) + + def _create_analytic_line(self, request): + return self.env["account.analytic.line"].create( + { + "date_time": datetime.now() - timedelta(hours=1), + "maintenance_request_id": request.id, + "project_id": request.project_id.id, + "account_id": request.project_id.analytic_account_id.id, + "name": "Test Maintenance Request Timesheet line", + "user_id": self.env.user.id, + } + ) + + def _create_wizard(self, action, active_record): + self.assertEqual(action["res_model"], "hr.timesheet.switch") + self.assertEqual(action["target"], "new") + self.assertEqual(action["type"], "ir.actions.act_window") + self.assertEqual(action["view_mode"], "form") + return ( + active_record.env[action["res_model"]] + .with_context( + active_id=active_record.id, + active_ids=active_record.ids, + active_model=active_record._name, + **action.get("context", {}), + ) + .create({}) + ) + + @users("test-maintenance-user") + def test_maintenance_request_time_control_flow(self): + request = self.env["maintenance.request"].create( + {"name": "Test computer request", "equipment_id": self.equipment.id} + ) + analytic_line = self._create_analytic_line(request) + # Running line found, stop the timer + self.assertEqual(request.show_time_control, "stop") + request.button_end_work() + # No more running lines, cannot stop again + with self.assertRaises(exceptions.UserError): + request.button_end_work() + # All lines stopped, start new one + self.assertEqual(request.show_time_control, "start") + start_action = request.button_start_work() + wizard = self._create_wizard(start_action, request) + self.assertFalse(wizard.amount) + self.assertLessEqual(wizard.date_time, datetime.now()) + self.assertLessEqual(wizard.date, fields.Date.context_today(wizard)) + self.assertFalse(wizard.unit_amount) + self.assertEqual(wizard.account_id, request.project_id.analytic_account_id) + self.assertEqual(wizard.employee_id, self.env.user.employee_id) + self.assertEqual(wizard.name, analytic_line.name) + self.assertEqual(wizard.project_id, request.project_id) + self.assertEqual(wizard.maintenance_request_id, request) + new_act = wizard.with_context(show_created_timer=True).action_switch() + new_line = self.env[new_act["res_model"]].browse(new_act["res_id"]) + self.assertEqual(new_line.employee_id, self.env.user.employee_id) + self.assertEqual(new_line.project_id, self.project) + self.assertEqual(new_line.maintenance_request_id, request) + self.assertEqual(new_line.unit_amount, 0) + self.assertTrue(analytic_line.unit_amount) diff --git a/maintenance_timesheet_time_control/views/maintenance_request_view.xml b/maintenance_timesheet_time_control/views/maintenance_request_view.xml new file mode 100644 index 000000000..0df460a00 --- /dev/null +++ b/maintenance_timesheet_time_control/views/maintenance_request_view.xml @@ -0,0 +1,107 @@ + + + + maintenance.request.form (in maintenance_timesheet_time_control) + maintenance.request + + + +
+ +
+
+
+ + maintenance.request.kanban (in maintenance_timesheet_time_control) + maintenance.request + + + + + + + + + + + + maintenance.request.tree (in maintenance_timesheet_time_control) + maintenance.request + + + + + +