diff --git a/maintenance_timesheet/README.rst b/maintenance_timesheet/README.rst new file mode 100644 index 000000000..3a8ade7b0 --- /dev/null +++ b/maintenance_timesheet/README.rst @@ -0,0 +1,78 @@ +====================== +Maintenance Timesheets +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:a3af16571faa620b072191148b6b2117b43fcbef94109d9af481ffedd60afdfe + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.0/maintenance_timesheet + :alt: OCA/maintenance +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/maintenance-16-0/maintenance-16-0-maintenance_timesheet + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/maintenance&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds timesheets to a request. + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Solvos + +Contributors +~~~~~~~~~~~~ + +* David Alonso +* Luisa Miguéns +* Christian Ramos + +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. + +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/__init__.py b/maintenance_timesheet/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/maintenance_timesheet/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/maintenance_timesheet/__manifest__.py b/maintenance_timesheet/__manifest__.py new file mode 100644 index 000000000..ae5acc80b --- /dev/null +++ b/maintenance_timesheet/__manifest__.py @@ -0,0 +1,20 @@ +# © 2020 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +{ + "name": "Maintenance Timesheets", + "summary": "Adds timesheets to maintenance requests", + "author": "Odoo Community Association (OCA), Solvos", + "license": "AGPL-3", + "version": "16.0.1.0.0", + "category": "Human Resources", + "website": "https://github.com/OCA/maintenance", + "depends": ["base_maintenance", "maintenance_project", "hr_timesheet"], + "data": [ + "security/maintenance_timesheet_security.xml", + "views/hr_timesheet_views.xml", + "views/maintenance_request_views.xml", + "report/maintenance_request_report.xml", + ], + "demo": ["data/demo_maintenance_timesheet.xml"], + "installable": True, +} diff --git a/maintenance_timesheet/data/demo_maintenance_timesheet.xml b/maintenance_timesheet/data/demo_maintenance_timesheet.xml new file mode 100644 index 000000000..3ba82b2a5 --- /dev/null +++ b/maintenance_timesheet/data/demo_maintenance_timesheet.xml @@ -0,0 +1,45 @@ + + + + + + Corrective #1 for Generic Monitor + + + + + + corrective + + + + Request tasks done + + + + + + + + + + + + + Touchpad repaired + + + + + + + diff --git a/maintenance_timesheet/i18n/es.po b/maintenance_timesheet/i18n/es.po new file mode 100644 index 000000000..b7474206c --- /dev/null +++ b/maintenance_timesheet/i18n/es.po @@ -0,0 +1,158 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * maintenance_timesheet +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-10-04 08:28+0000\n" +"PO-Revision-Date: 2023-07-06 20:08+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.hr_equipment_request_view_form +msgid "Hours" +msgstr "horas" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.hr_equipment_request_view_kanban +msgid "Hours" +msgstr "horas" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Timesheet Entries" +msgstr "" +"Entradas en la hoja de horas" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Timesheet Total Hours:" +msgstr "Horas totales de la hoja de horas:" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Total" +msgstr "Total" + +#. module: maintenance_timesheet +#: model:ir.model,name:maintenance_timesheet.model_account_analytic_line +msgid "Analytic Line" +msgstr "Cuenta analítica" + +#. module: maintenance_timesheet +#: code:addons/maintenance_timesheet/models/hr_timesheet.py:0 +#, python-format +msgid "" +"Cannot save or delete a timesheet for a maintenance request already done" +msgstr "" +"No se puede editar o borrar un parte de trabajo de una petición de " +"mantenimiento ya finalizada" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Date" +msgstr "fecha" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Description" +msgstr "descripción" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_account_analytic_line__display_name +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_equipment__display_name +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__display_name +msgid "Display Name" +msgstr "nombre para mostrar" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.equipment_request_view_form +msgid "Duration (Hour(s))" +msgstr "Duración (Hora(s))" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_account_analytic_line__id +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_equipment__id +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__id +msgid "ID" +msgstr "ID(identificador)" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_account_analytic_line____last_update +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_equipment____last_update +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request____last_update +msgid "Last Modified on" +msgstr "modificado por última vez el" + +#. module: maintenance_timesheet +#: model:ir.model,name:maintenance_timesheet.model_maintenance_equipment +msgid "Maintenance Equipment" +msgstr "Equipo" + +#. module: maintenance_timesheet +#: model:ir.model,name:maintenance_timesheet.model_maintenance_request +#: model:ir.model.fields,field_description:maintenance_timesheet.field_account_analytic_line__maintenance_request_id +#: model:ir.model.fields,field_description:maintenance_timesheet.field_hr_timesheet_switch__maintenance_request_id +msgid "Maintenance Request" +msgstr "Petición de mantenimiento" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__planned_hours +msgid "Planned Hours" +msgstr "Horas planificadas" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__progress +msgid "Progress" +msgstr "progreso" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Project -" +msgstr "proyecto-" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__remaining_hours +msgid "Remaining Hours" +msgstr "Horas restantes" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.hr_timesheet_line_search +msgid "Request" +msgstr "Petición" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Responsible" +msgstr "Responsable" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Task" +msgstr "Tarea" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Time" +msgstr "Tiempo" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__timesheet_total_hours +msgid "Timesheet Total Hours" +msgstr "Horas totales en partes de trabajo" + +#. module: maintenance_timesheet +#: model:ir.actions.act_window,name:maintenance_timesheet.timesheet_action_from_request +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__timesheet_ids +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.equipment_request_view_form +msgid "Timesheets" +msgstr "Partes de trabajo" diff --git a/maintenance_timesheet/i18n/it.po b/maintenance_timesheet/i18n/it.po new file mode 100644 index 000000000..cec436c4f --- /dev/null +++ b/maintenance_timesheet/i18n/it.po @@ -0,0 +1,157 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * maintenance_timesheet +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-07-04 09:09+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.hr_equipment_request_view_form +msgid "Hours" +msgstr "Ore" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.hr_equipment_request_view_kanban +msgid "Hours" +msgstr "Ore" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Timesheet Entries" +msgstr "" +"Registrazioni foglio presenze" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Timesheet Total Hours:" +msgstr "Ore totali foglio presenze:" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Total" +msgstr "Totale" + +#. module: maintenance_timesheet +#: model:ir.model,name:maintenance_timesheet.model_account_analytic_line +msgid "Analytic Line" +msgstr "Riga analitica" + +#. module: maintenance_timesheet +#: code:addons/maintenance_timesheet/models/hr_timesheet.py:0 +#, python-format +msgid "" +"Cannot save or delete a timesheet for a maintenance request already done" +msgstr "" +"Non si può salvare o cancellare un foglio presenze per una richiesta di " +"manutenzione già eseguita" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Date" +msgstr "Data" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Description" +msgstr "Descrizione" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_account_analytic_line__display_name +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_equipment__display_name +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.equipment_request_view_form +msgid "Duration (Hour(s))" +msgstr "Durata (ora(e))" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_account_analytic_line__id +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_equipment__id +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__id +msgid "ID" +msgstr "ID" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_account_analytic_line____last_update +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_equipment____last_update +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: maintenance_timesheet +#: model:ir.model,name:maintenance_timesheet.model_maintenance_equipment +msgid "Maintenance Equipment" +msgstr "Attrezzatura manutenzione" + +#. module: maintenance_timesheet +#: model:ir.model,name:maintenance_timesheet.model_maintenance_request +#: model:ir.model.fields,field_description:maintenance_timesheet.field_account_analytic_line__maintenance_request_id +#: model:ir.model.fields,field_description:maintenance_timesheet.field_hr_timesheet_switch__maintenance_request_id +msgid "Maintenance Request" +msgstr "Richiesta manutenzione" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__planned_hours +msgid "Planned Hours" +msgstr "Ore pianificate" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__progress +msgid "Progress" +msgstr "Avanzamento" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Project -" +msgstr "Progetto -" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__remaining_hours +msgid "Remaining Hours" +msgstr "Ore residue" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.hr_timesheet_line_search +msgid "Request" +msgstr "Richiesta" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Responsible" +msgstr "Responsabile" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Task" +msgstr "Lavoro" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Time" +msgstr "Orario" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__timesheet_total_hours +msgid "Timesheet Total Hours" +msgstr "Ore totali foglio presenze" + +#. module: maintenance_timesheet +#: model:ir.actions.act_window,name:maintenance_timesheet.timesheet_action_from_request +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__timesheet_ids +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.equipment_request_view_form +msgid "Timesheets" +msgstr "Foglio presenze" diff --git a/maintenance_timesheet/i18n/maintenance_timesheet.pot b/maintenance_timesheet/i18n/maintenance_timesheet.pot new file mode 100644 index 000000000..bc45e4a9c --- /dev/null +++ b/maintenance_timesheet/i18n/maintenance_timesheet.pot @@ -0,0 +1,129 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * maintenance_timesheet +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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 +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.hr_equipment_request_view_form +msgid "Hours" +msgstr "" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.hr_equipment_request_view_kanban +msgid "Hours" +msgstr "" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Timesheet Entries" +msgstr "" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Timesheet Total Hours:" +msgstr "" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Total" +msgstr "" + +#. module: maintenance_timesheet +#: model:ir.model,name:maintenance_timesheet.model_account_analytic_line +msgid "Analytic Line" +msgstr "" + +#. module: maintenance_timesheet +#: code:addons/maintenance_timesheet/models/hr_timesheet.py:0 +#, python-format +msgid "" +"Cannot save or delete a timesheet for a maintenance request already done" +msgstr "" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Date" +msgstr "" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Description" +msgstr "" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.equipment_request_view_form +msgid "Duration (Hour(s))" +msgstr "" + +#. module: maintenance_timesheet +#: model:ir.model,name:maintenance_timesheet.model_maintenance_equipment +msgid "Maintenance Equipment" +msgstr "" + +#. module: maintenance_timesheet +#: model:ir.model,name:maintenance_timesheet.model_maintenance_request +#: model:ir.model.fields,field_description:maintenance_timesheet.field_account_analytic_line__maintenance_request_id +msgid "Maintenance Request" +msgstr "" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__planned_hours +msgid "Planned Hours" +msgstr "" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__progress +msgid "Progress" +msgstr "" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Project -" +msgstr "" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__remaining_hours +msgid "Remaining Hours" +msgstr "" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.hr_timesheet_line_search +msgid "Request" +msgstr "" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Responsible" +msgstr "" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Task" +msgstr "" + +#. module: maintenance_timesheet +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.report_maintenance_request_document +msgid "Time" +msgstr "" + +#. module: maintenance_timesheet +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__timesheet_total_hours +msgid "Timesheet Total Hours" +msgstr "" + +#. module: maintenance_timesheet +#: model:ir.actions.act_window,name:maintenance_timesheet.timesheet_action_from_request +#: model:ir.model.fields,field_description:maintenance_timesheet.field_maintenance_request__timesheet_ids +#: model_terms:ir.ui.view,arch_db:maintenance_timesheet.equipment_request_view_form +msgid "Timesheets" +msgstr "" diff --git a/maintenance_timesheet/models/__init__.py b/maintenance_timesheet/models/__init__.py new file mode 100644 index 000000000..b7f7bd17c --- /dev/null +++ b/maintenance_timesheet/models/__init__.py @@ -0,0 +1,3 @@ +from . import hr_timesheet +from . import maintenance_equipment +from . import maintenance_request diff --git a/maintenance_timesheet/models/hr_timesheet.py b/maintenance_timesheet/models/hr_timesheet.py new file mode 100644 index 000000000..8ca67430d --- /dev/null +++ b/maintenance_timesheet/models/hr_timesheet.py @@ -0,0 +1,49 @@ +# © 2019 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class AccountAnalyticLine(models.Model): + _inherit = "account.analytic.line" + + maintenance_request_id = fields.Many2one(comodel_name="maintenance.request") + + @api.onchange("maintenance_request_id") + def onchange_maintenance_request_id(self): + if self.maintenance_request_id and not self.project_id: + self.project_id = self.maintenance_request_id.project_id + self.task_id = self.maintenance_request_id.task_id + + @api.model + def create(self, values): + if values.get("maintenance_request_id"): + self._check_request_done(values.get("maintenance_request_id")) + return super().create(values) + + def write(self, values): + current_request = self.maintenance_request_id + new_request_id = values.get("maintenance_request_id", False) + if current_request: + self._check_request_done(current_request.id) + if new_request_id: + self._check_request_done(new_request_id) + return super().write(values) + + def unlink(self): + for timesheet in self.filtered(lambda x: x.maintenance_request_id): + self._check_request_done(timesheet.maintenance_request_id.id) + return super().unlink() + + def _check_request_done(self, request_id): + """ + Editing a timesheet related to a finished request is forbidden. + """ + if self.env["maintenance.request"].browse(request_id).stage_id.done: + raise ValidationError( + _( + "Cannot save or delete a timesheet for " + "a maintenance request already done" + ) + ) diff --git a/maintenance_timesheet/models/maintenance_equipment.py b/maintenance_timesheet/models/maintenance_equipment.py new file mode 100644 index 000000000..a5753ba03 --- /dev/null +++ b/maintenance_timesheet/models/maintenance_equipment.py @@ -0,0 +1,13 @@ +# Copyright 2019 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import models + + +class MaintenanceEquipment(models.Model): + _inherit = "maintenance.equipment" + + def _prepare_project_from_equipment_values(self, values): + data = super()._prepare_project_from_equipment_values(values) + data["allow_timesheets"] = True + return data diff --git a/maintenance_timesheet/models/maintenance_request.py b/maintenance_timesheet/models/maintenance_request.py new file mode 100644 index 000000000..43b68a0c1 --- /dev/null +++ b/maintenance_timesheet/models/maintenance_request.py @@ -0,0 +1,82 @@ +# © 2019 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import api, fields, models + + +class MaintenanceRequest(models.Model): + _inherit = "maintenance.request" + + timesheet_ids = fields.One2many( + string="Timesheets", + comodel_name="account.analytic.line", + inverse_name="maintenance_request_id", + ) + timesheet_total_hours = fields.Float( + compute="_compute_timesheet_total_hours", readonly=True, store=True + ) + planned_hours = fields.Float(tracking=True) + progress = fields.Float( + compute="_compute_progress_hours", + group_operator="avg", + store=True, + ) + remaining_hours = fields.Float( + compute="_compute_progress_hours", + readonly=True, + store=True, + ) + + @api.depends("planned_hours", "timesheet_total_hours") + def _compute_progress_hours(self): + for item in self: + item.progress = 0.0 + if item.planned_hours > 0.0: + if item.timesheet_total_hours > item.planned_hours: + item.progress = 100 + else: + item.progress = round( + 100.0 * item.timesheet_total_hours / item.planned_hours, 2 + ) + item.remaining_hours = item.planned_hours - item.timesheet_total_hours + + def _add_followers(self): + """ + Members of maintenance team are included as followers to automatically + grant request visibility and timesheet permissions for this request + """ + res = super()._add_followers() + for request in self: + partner_ids = request.maintenance_team_id.member_ids.mapped( + "partner_id" + ).ids + request.message_subscribe(partner_ids=partner_ids) + return res + + @api.depends("timesheet_ids.unit_amount") + def _compute_timesheet_total_hours(self): + for request in self: + request.timesheet_total_hours = sum( + request.timesheet_ids.mapped("unit_amount") + ) + + def action_view_timesheet_ids(self): + """ + Access to the current timesheets for this maintenance request + The view will be restricted to the current request and only HR managers + could create timesheets for every employee + """ + self.ensure_one() + action = self.env["ir.actions.act_window"]._for_xml_id( + "maintenance_timesheet.timesheet_action_from_request" + ) + action["domain"] = [("maintenance_request_id", "=", self.id)] + action["context"] = { + "default_project_id": self.project_id.id, + "default_task_id": self.task_id.id, + "default_maintenance_request_id": self.id, + "readonly_employee_id": not self.env.user.has_group( + "hr_timesheet.group_timesheet_manager" + ), + } + return action diff --git a/maintenance_timesheet/readme/CONTRIBUTORS.rst b/maintenance_timesheet/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..53bacebc4 --- /dev/null +++ b/maintenance_timesheet/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* David Alonso +* Luisa Miguéns +* Christian Ramos diff --git a/maintenance_timesheet/readme/DESCRIPTION.rst b/maintenance_timesheet/readme/DESCRIPTION.rst new file mode 100644 index 000000000..6bfcb8a6c --- /dev/null +++ b/maintenance_timesheet/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds timesheets to a request. diff --git a/maintenance_timesheet/report/maintenance_request_report.xml b/maintenance_timesheet/report/maintenance_request_report.xml new file mode 100644 index 000000000..a9d079a57 --- /dev/null +++ b/maintenance_timesheet/report/maintenance_request_report.xml @@ -0,0 +1,97 @@ + + + + diff --git a/maintenance_timesheet/security/maintenance_timesheet_security.xml b/maintenance_timesheet/security/maintenance_timesheet_security.xml new file mode 100644 index 000000000..c18ab6ab5 --- /dev/null +++ b/maintenance_timesheet/security/maintenance_timesheet_security.xml @@ -0,0 +1,31 @@ + + + + Users are allowed to access timesheets related to a followed request + + [ + '|', + ('maintenance_request_id', '=', False), + '|', + ('maintenance_request_id.message_partner_ids', 'in', [user.partner_id.id]), + ('maintenance_request_id.user_id.id', '=', user.id) + ] + + + + + Managers are allowed to access timesheets related to any request + + + [('maintenance_request_id', '!=', False)] + + + + diff --git a/maintenance_timesheet/static/description/icon.png b/maintenance_timesheet/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/maintenance_timesheet/static/description/icon.png differ diff --git a/maintenance_timesheet/static/description/index.html b/maintenance_timesheet/static/description/index.html new file mode 100644 index 000000000..991d9a182 --- /dev/null +++ b/maintenance_timesheet/static/description/index.html @@ -0,0 +1,423 @@ + + + + + + +Maintenance Timesheets + + + +
+

Maintenance Timesheets

+ + +

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

+

This module adds timesheets to a request.

+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Solvos
  • +
+
+
+

Contributors

+ +
+
+

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.

+

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/tests/__init__.py b/maintenance_timesheet/tests/__init__.py new file mode 100644 index 000000000..2c3cdf5b4 --- /dev/null +++ b/maintenance_timesheet/tests/__init__.py @@ -0,0 +1 @@ +from . import test_maintenance_timesheet diff --git a/maintenance_timesheet/tests/test_maintenance_timesheet.py b/maintenance_timesheet/tests/test_maintenance_timesheet.py new file mode 100644 index 000000000..9760606ac --- /dev/null +++ b/maintenance_timesheet/tests/test_maintenance_timesheet.py @@ -0,0 +1,108 @@ +# Copyright 2019 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import fields +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + + +class TestMaintenanceTimesheet(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.stage_undone = cls.env.ref("maintenance.stage_0") + cls.stage_done = cls.env.ref("maintenance.stage_4") + + cls.request_demo1 = cls.env.ref("maintenance_timesheet.request_1") + cls.request2 = cls.env["maintenance.request"].create( + { + "name": "Corrective #2 for Generic Monitor", + "equipment_id": cls.env.ref("maintenance_project.equipment_1").id, + "user_id": cls.env.ref("base.user_admin").id, + "schedule_date": fields.Date.today(), + "stage_id": cls.stage_undone.id, + "maintenance_type": "corrective", + } + ) + cls.timesheet21_data = { + "name": "Some tasks done", + "project_id": cls.request2.project_id.id, + "user_id": cls.env.ref("base.user_admin").id, + "date": fields.Date.today(), + "unit_amount": 1.5, + } + cls.request2.timesheet_ids = [(0, 0, cls.timesheet21_data)] + + def test_request_timesheets(self): + self.assertEqual(self.request_demo1.timesheet_total_hours, 2) + self.assertEqual( + self.request2.timesheet_total_hours, self.timesheet21_data["unit_amount"] + ) + + def test_onchange_maintenance_request_id(self): + ts1 = self.env["account.analytic.line"].new( + { + "date": fields.Date.today(), + "name": "Timesheet without initial equipment", + "user_id": self.env.ref("base.user_admin").id, + } + ) + self.assertFalse(ts1.project_id) + ts1.maintenance_request_id = self.request2 + ts1.onchange_maintenance_request_id() + self.assertEqual(ts1.project_id, self.request2.project_id) + + def test_check_request_done(self): + self.request2.stage_id = self.stage_done + with self.assertRaises(ValidationError): + self.request2.timesheet_ids = [ + ( + 0, + 0, + { + "name": "Attempt to create a task for a done request", + "project_id": self.request2.project_id.id, + "user_id": self.env.ref("base.user_admin").id, + "date": fields.Date.today(), + "unit_amount": 2, + }, + ) + ] + with self.assertRaises(ValidationError): + self.env["account.analytic.line"].create( + { + "name": "Attepting to create a task 2", + "project_id": self.request2.project_id.id, + "user_id": self.env.ref("base.user_admin").id, + "maintenance_request_id": self.request2.id, + "date": fields.Date.today(), + "unit_amount": 1, + } + ) + with self.assertRaises(ValidationError): + # Attempt to modify a timesheet related a done request + for timesheet in self.request2.timesheet_ids: + timesheet.unit_amount += 1 + with self.assertRaises(ValidationError): + # Attempt to delete a timesheet related a done request + self.request2.timesheet_ids.unlink() + + self.request2.stage_id = self.stage_undone + # Deleting timesheets is enabled again + self.request2.timesheet_ids.unlink() + + def test_action_view_timesheet_ids(self): + act1 = self.request2.action_view_timesheet_ids() + self.assertEqual(act1["domain"][0][2], self.request2.id) + self.assertEqual( + act1["context"]["default_project_id"], self.request2.project_id.id + ) + self.assertFalse(act1["context"]["default_task_id"]) + self.assertFalse(act1["context"]["readonly_employee_id"]) + + def test_prepare_project_from_equipment_values(self): + data = self.env["maintenance.equipment"]._prepare_project_from_equipment_values( + {"name": "my name"} + ) + self.assertTrue(data["allow_timesheets"]) diff --git a/maintenance_timesheet/views/hr_timesheet_views.xml b/maintenance_timesheet/views/hr_timesheet_views.xml new file mode 100644 index 000000000..9f69490e7 --- /dev/null +++ b/maintenance_timesheet/views/hr_timesheet_views.xml @@ -0,0 +1,52 @@ + + + + account.analytic.line + + + + + + + + + + + + account.analytic.line + + + + + + + + + account.analytic.line + + + + context.get('readonly_employee_id', False) + + + + + account.analytic.line + + + + + + + + diff --git a/maintenance_timesheet/views/maintenance_request_views.xml b/maintenance_timesheet/views/maintenance_request_views.xml new file mode 100644 index 000000000..e46cb60c2 --- /dev/null +++ b/maintenance_timesheet/views/maintenance_request_views.xml @@ -0,0 +1,159 @@ + + + + Timesheets + account.analytic.line + + [('project_id', '!=', False), ('maintenance_request_id', '!=', False)] + + + + tree + + + + + + form + + + + + + maintenance.request + + + + + + + + + maintenance.request + + + + + + + +
+ + + + + Hours +
+
+
+
+
+ + maintenance.request + + + + + + + + + maintenance.request + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + +
+
+ + + + +
+
+
+
+
diff --git a/setup/maintenance_timesheet/odoo/addons/maintenance_timesheet b/setup/maintenance_timesheet/odoo/addons/maintenance_timesheet new file mode 120000 index 000000000..f3af04479 --- /dev/null +++ b/setup/maintenance_timesheet/odoo/addons/maintenance_timesheet @@ -0,0 +1 @@ +../../../../maintenance_timesheet \ No newline at end of file diff --git a/setup/maintenance_timesheet/setup.py b/setup/maintenance_timesheet/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/maintenance_timesheet/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)