diff --git a/hr_maintenance_workspace/README.rst b/hr_maintenance_workspace/README.rst new file mode 100644 index 000000000000..626042296b50 --- /dev/null +++ b/hr_maintenance_workspace/README.rst @@ -0,0 +1,101 @@ +======================== +Hr Maintenance Workspace +======================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fhr-lightgray.png?logo=github + :target: https://github.com/OCA/hr/tree/14.0/hr_maintenance_workspace + :alt: OCA/hr +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/hr-14-0/hr-14-0-hr_maintenance_workspace + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/hr&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Allows to associate employees and equipments to workspaces. + +**Table of contents** + +.. contents:: + :local: + +Implemented Uses +================ + +**Employees** + +* Employees can be assigned to workspaces. + +**Workspaces** + +* Each workspace has employees and equipment asigned to it. It represents a real workspace. + +**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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* SDi Digital Group + +Contributors +~~~~~~~~~~~~ + +* Valentín Georgian Castravete +* Jorge Luis Quinteros + +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-valentincastravete| image:: https://github.com/valentincastravete.png?size=40px + :target: https://github.com/valentincastravete + :alt: valentincastravete +.. |maintainer-JorgeQuinteros| image:: https://github.com/JorgeQuinteros.png?size=40px + :target: https://github.com/JorgeQuinteros + :alt: JorgeQuinteros + +Current `maintainers `__: + +|maintainer-valentincastravete| |maintainer-JorgeQuinteros| + +This module is part of the `OCA/hr `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_maintenance_workspace/__init__.py b/hr_maintenance_workspace/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/hr_maintenance_workspace/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_maintenance_workspace/__manifest__.py b/hr_maintenance_workspace/__manifest__.py new file mode 100644 index 000000000000..777b0092048a --- /dev/null +++ b/hr_maintenance_workspace/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2023 SDi Digital Group (https://www.sdi.es/odoo-cloud) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Hr Maintenance Workspace", + "summary": "Allows to assign equipments and employees to workspaces.", + "version": "14.0.1.0.0", + "category": "Human Resources", + "website": "https://github.com/OCA/hr", + "author": "SDi Digital Group, Odoo Community Association (OCA)", + "maintainers": ["valentincastravete", "JorgeQuinteros"], + "license": "AGPL-3", + "depends": ["hr_maintenance"], + "data": [ + "security/ir.model.access.csv", + "views/maintenance_views.xml", + "views/maintenance_workspace_views.xml", + "views/hr_maintenance_workspace_menu_views.xml", + "views/hr_employee_views.xml", + ], +} diff --git a/hr_maintenance_workspace/models/__init__.py b/hr_maintenance_workspace/models/__init__.py new file mode 100644 index 000000000000..11c9283f68a2 --- /dev/null +++ b/hr_maintenance_workspace/models/__init__.py @@ -0,0 +1,3 @@ +from . import equipment +from . import hr_employee +from . import workspace diff --git a/hr_maintenance_workspace/models/equipment.py b/hr_maintenance_workspace/models/equipment.py new file mode 100644 index 000000000000..20253818f0f3 --- /dev/null +++ b/hr_maintenance_workspace/models/equipment.py @@ -0,0 +1,34 @@ +# Copyright 2023 SDi Digital Group (https://www.sdi.es/odoo-cloud) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class MaintenanceEquipment(models.Model): + _inherit = "maintenance.equipment" + + workspace_id = fields.Many2one( + comodel_name="maintenance.workspace", + string="Workspace", + tracking=True, + ) + equipment_assign_to = fields.Selection( + selection_add=[("workspace", "Workspace"), ("other", "Other")], + ondelete={ + "workspace": "set default", + "other": "set default", + }, + ) + + @api.depends("equipment_assign_to") + def _compute_equipment_assign(self): + super()._compute_equipment_assign() + for equipment in self: + if equipment.equipment_assign_to in ["employee", "department"]: + equipment.workspace_id = False + elif equipment.equipment_assign_to == "workspace": + equipment.workspace_id = equipment.workspace_id + equipment.department_id = False + equipment.employee_id = False + else: + equipment.workspace_id = equipment.workspace_id diff --git a/hr_maintenance_workspace/models/hr_employee.py b/hr_maintenance_workspace/models/hr_employee.py new file mode 100644 index 000000000000..670589370548 --- /dev/null +++ b/hr_maintenance_workspace/models/hr_employee.py @@ -0,0 +1,31 @@ +# Copyright 2023 SDi Digital Group (https://www.sdi.es/odoo-cloud) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, fields, models + + +class HrEmployee(models.Model): + _inherit = "hr.employee" + + workspace_ids = fields.Many2many( + comodel_name="maintenance.workspace", + string="Workspaces", + ) + workspace_count = fields.Integer( + name="Workspaces", + compute="_compute_workspace_count", + ) + + @api.depends("workspace_ids") + def _compute_workspace_count(self): + for employee in self: + employee.workspace_count = len(employee.workspace_ids) + + def button_employee_workspaces(self): + return { + "name": _("Workspaces"), + "view_mode": "tree,form", + "res_model": "maintenance.workspace", + "type": "ir.actions.act_window", + "domain": [("employee_ids", "=", self.id)], + } diff --git a/hr_maintenance_workspace/models/workspace.py b/hr_maintenance_workspace/models/workspace.py new file mode 100644 index 000000000000..ae4d10151f4f --- /dev/null +++ b/hr_maintenance_workspace/models/workspace.py @@ -0,0 +1,74 @@ +# Copyright 2023 SDi Digital Group (https://www.sdi.es/odoo-cloud) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class Workspace(models.Model): + _name = "maintenance.workspace" + _inherit = "mail.thread" + _description = "Workspace" + + name = fields.Char( + string="Name", + required=True, + ) + description = fields.Char( + string="Description", + ) + location = fields.Char( + string="Location", + ) + equipment_ids = fields.One2many( + comodel_name="maintenance.equipment", + inverse_name="workspace_id", + ) + equipment_count = fields.Integer( + name="Equipments", + compute="_compute_equipment_count", + store=True, + ) + employee_ids = fields.Many2many( + comodel_name="hr.employee", + string="Employees", + ) + employee_count = fields.Integer( + string="Employee count", + compute="_compute_employee_count", + store=True, + ) + employee_equipment_count = fields.Integer( + string="Employee Equipment Count", + compute="_compute_employee_equipment_count", + store=True, + ) + + @api.depends("equipment_ids") + def _compute_equipment_count(self): + for workspace in self: + workspace.equipment_count = len(workspace.equipment_ids) + + @api.depends("employee_ids") + def _compute_employee_count(self): + for workspace in self: + workspace.employee_count = len(workspace.employee_ids) + + @api.depends("employee_ids", "employee_ids.equipment_ids") + def _compute_employee_equipment_count(self): + for workspace in self: + workspace_empl_equipment_count = 0 + if len(workspace.employee_ids) > 0: + for employee in workspace.employee_ids: + equipment_count = len(employee.equipment_ids) + workspace_empl_equipment_count += equipment_count + workspace.employee_equipment_count = workspace_empl_equipment_count + + def button_employee_equipment_count(self): + return { + "name": "Employee Equipments", + "view_type": "form", + "view_mode": "tree,form", + "res_model": "maintenance.equipment", + "type": "ir.actions.act_window", + "domain": [("employee_id", "in", self.employee_ids.ids)], + } diff --git a/hr_maintenance_workspace/readme/CONTRIBUTORS.rst b/hr_maintenance_workspace/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..56f61b50ae28 --- /dev/null +++ b/hr_maintenance_workspace/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Valentín Georgian Castravete +* Jorge Luis Quinteros diff --git a/hr_maintenance_workspace/readme/DESCRIPTION.rst b/hr_maintenance_workspace/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..07d3c1ad47a1 --- /dev/null +++ b/hr_maintenance_workspace/readme/DESCRIPTION.rst @@ -0,0 +1,17 @@ +Allows to associate employees and equipments to workspaces. + +**Table of contents** + +.. contents:: + :local: + +Implemented Uses +================ + +**Employees** + +* Employees can be assigned to workspaces. + +**Workspaces** + +* Each workspace has employees and equipment asigned to it. It represents a real workspace. diff --git a/hr_maintenance_workspace/security/ir.model.access.csv b/hr_maintenance_workspace/security/ir.model.access.csv new file mode 100644 index 000000000000..c4094d7c3cb6 --- /dev/null +++ b/hr_maintenance_workspace/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_workspace_user,workspace.user,model_maintenance_workspace,base.group_user,1,0,0,0 +access_workspace_admin_user,workspace.admin.user,model_maintenance_workspace,maintenance.group_equipment_manager,1,1,1,1 diff --git a/hr_maintenance_workspace/static/description/icon.png b/hr_maintenance_workspace/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/hr_maintenance_workspace/static/description/icon.png differ diff --git a/hr_maintenance_workspace/static/description/index.html b/hr_maintenance_workspace/static/description/index.html new file mode 100644 index 000000000000..ee38958b93ac --- /dev/null +++ b/hr_maintenance_workspace/static/description/index.html @@ -0,0 +1,435 @@ + + + + + + +Hr Maintenance Workspace + + + +
+

Hr Maintenance Workspace

+ + +

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

+

Allows to associate employees and equipments to workspaces.

+

Table of contents

+ +
+

Implemented Uses

+

Employees

+
    +
  • Employees can be assigned to workspaces.
  • +
+

Workspaces

+
    +
  • Each workspace has employees and equipment asigned to it. It represents a real workspace.
  • +
+

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

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • SDi Digital Group
  • +
+
+
+

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.

+

Current maintainers:

+

valentincastravete JorgeQuinteros

+

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

+

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

+
+
+
+ + diff --git a/hr_maintenance_workspace/tests/__init__.py b/hr_maintenance_workspace/tests/__init__.py new file mode 100644 index 000000000000..cc7845d3c93b --- /dev/null +++ b/hr_maintenance_workspace/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import test_hr_maitenance_workspace diff --git a/hr_maintenance_workspace/tests/test_hr_maitenance_workspace.py b/hr_maintenance_workspace/tests/test_hr_maitenance_workspace.py new file mode 100644 index 000000000000..132b581da260 --- /dev/null +++ b/hr_maintenance_workspace/tests/test_hr_maitenance_workspace.py @@ -0,0 +1,105 @@ +# Copyright 2022 SDi Digital Group (https://www.sdi.es/odoo-cloud) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tests import TransactionCase + + +class TestHRMaintenanceWorkspace(TransactionCase): + def setUp(self): + super().setUp() + self.employee_test = self.env["hr.employee"].create( + { + "name": "Employee Test", + } + ) + self.equipment_test = self.env["maintenance.equipment"].create( + { + "name": "Equipment Test", + "employee_id": self.employee_test.id, + } + ) + self.workspace_test = self.env["maintenance.workspace"].create( + { + "name": "Workspace Test", + "description": "Description", + "location": "Office 1", + "employee_ids": [(6, 0, [self.employee_test.id])], + "equipment_ids": [(6, 0, [self.equipment_test.id])], + } + ) + + def test_workspace_compute_employee_count(self): + self.workspace_test._compute_employee_count() + self.assertEqual(self.workspace_test.employee_count, 1) + + def test_workspace_compute_equipment_count(self): + self.workspace_test._compute_equipment_count() + self.assertEqual(self.workspace_test.equipment_count, 1) + + def test_workspace_compute_employee_equipment_count(self): + self.workspace_test._compute_employee_equipment_count() + self.assertEqual(self.workspace_test.employee_equipment_count, 1) + self.workspace_test.write( + { + "employee_ids": False, + } + ) + self.assertEqual(self.workspace_test.employee_equipment_count, 0) + + def test_workspace_button_employee_count(self): + action = self.workspace_test.button_employee_equipment_count() + self.assertEqual( + action["domain"], [("employee_id", "in", [self.employee_test.id])] + ) + + def test_employee_workspace_count(self): + self.employee_test._compute_workspace_count() + self.assertEqual(self.employee_test.workspace_count, 1) + + def test_employee_button_employee_workspaces(self): + action = self.employee_test.button_employee_workspaces() + self.assertEqual( + action["domain"], [("employee_ids", "=", self.employee_test.id)] + ) + + def test_equipment_assign_to_employee(self): + self.equipment_test.write( + { + "equipment_assign_to": "employee", + } + ) + self.equipment_test._compute_equipment_assign() + self.assertEqual(self.equipment_test.workspace_id.id, False) + + def test_equipment_assign_to_department(self): + self.equipment_test.write( + { + "equipment_assign_to": "department", + } + ) + self.equipment_test._compute_equipment_assign() + self.assertEqual(self.equipment_test.workspace_id.id, False) + + def test_equipment_assign_to_workspace(self): + self.equipment_test.write( + { + "equipment_assign_to": "workspace", + } + ) + self.equipment_test._compute_equipment_assign() + self.assertEqual( + self.equipment_test.workspace_id, self.equipment_test.workspace_id + ) + self.assertEqual(self.equipment_test.department_id.id, False) + self.assertEqual(self.equipment_test.employee_id.id, False) + + def test_equipment_assign_to_other(self): + self.equipment_test.write( + { + "equipment_assign_to": "other", + } + ) + self.equipment_test._compute_equipment_assign() + self.assertEqual( + self.equipment_test.workspace_id, self.equipment_test.workspace_id + ) diff --git a/hr_maintenance_workspace/views/hr_employee_views.xml b/hr_maintenance_workspace/views/hr_employee_views.xml new file mode 100644 index 000000000000..9f7effdb5fca --- /dev/null +++ b/hr_maintenance_workspace/views/hr_employee_views.xml @@ -0,0 +1,20 @@ + + + + hr.employee + + form + +
+ +
+
+
+
diff --git a/hr_maintenance_workspace/views/hr_maintenance_workspace_menu_views.xml b/hr_maintenance_workspace/views/hr_maintenance_workspace_menu_views.xml new file mode 100644 index 000000000000..7c37b5982d4a --- /dev/null +++ b/hr_maintenance_workspace/views/hr_maintenance_workspace_menu_views.xml @@ -0,0 +1,16 @@ + + + + Workspaces + maintenance.workspace + kanban,tree,form + + + diff --git a/hr_maintenance_workspace/views/maintenance_views.xml b/hr_maintenance_workspace/views/maintenance_views.xml new file mode 100644 index 000000000000..0a09d34f000f --- /dev/null +++ b/hr_maintenance_workspace/views/maintenance_views.xml @@ -0,0 +1,86 @@ + + + + + maintenance.equipment + + + + ['|', '|', ('employee_id', '!=', False), ('department_id', '!=', False), ('workspace_id', '=', False)] + + + [('employee_id', '=', False), ('department_id', '=', False), ('workspace_id', '=', False)] + + + + + + + + + + + + maintenance.equipment.view.form.inherit.hr + maintenance.equipment + + + + Employee + {'invisible': ['|', '|', ('equipment_assign_to', '=', 'department'), ('equipment_assign_to', '=', 'workspace'), ('equipment_assign_to', '=', False)]} + + + Department + {'invisible': ['|', '|', ('equipment_assign_to', '=', 'employee'), ('equipment_assign_to', '=', 'workspace'), ('equipment_assign_to', '=', False)]} + + + + + + + + + maintenance.equipment + + + + + +
+
+ +
+
+
+
+ + + maintenance.equipment + + + + 1 + + + + + + + +
diff --git a/hr_maintenance_workspace/views/maintenance_workspace_views.xml b/hr_maintenance_workspace/views/maintenance_workspace_views.xml new file mode 100644 index 000000000000..22435bf64607 --- /dev/null +++ b/hr_maintenance_workspace/views/maintenance_workspace_views.xml @@ -0,0 +1,138 @@ + + + + maintenance.workspace + + + + + + + + + + + + + maintenance.workspace + +
+ +
+ +
+

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+
+
+
+ + maintenance.workspace + + + + + + + + +
+
+

+ +

+
+ Equipments: + +
+
+

+ Employees: + +

+
+ Employee Equipment Count: + +
+
+
+
+
+
+
+
+ + maintenance.workspace + + + + + + + + + +
diff --git a/setup/hr_maintenance_workspace/odoo/addons/hr_maintenance_workspace b/setup/hr_maintenance_workspace/odoo/addons/hr_maintenance_workspace new file mode 120000 index 000000000000..757183915a73 --- /dev/null +++ b/setup/hr_maintenance_workspace/odoo/addons/hr_maintenance_workspace @@ -0,0 +1 @@ +../../../../hr_maintenance_workspace \ No newline at end of file diff --git a/setup/hr_maintenance_workspace/setup.py b/setup/hr_maintenance_workspace/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/hr_maintenance_workspace/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)