diff --git a/hr_employee_document/README.rst b/hr_employee_document/README.rst new file mode 100644 index 00000000000..78604b90627 --- /dev/null +++ b/hr_employee_document/README.rst @@ -0,0 +1,99 @@ +==================== +HR Employee Document +==================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f6160e17963c83b7fd651427c39dad6e70142869e22b8beafa34bedf0dbddf48 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/17.0/hr_employee_document + :alt: OCA/hr +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/hr-17-0/hr-17-0-hr_employee_document + :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/hr&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module displays a button on the employee's profile to view linked +attachments, both for HR officers/managers and the own employee, so you +can use it as employee document storage. + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +This module adds read permission to the employee model; the rest of the +model data will be available to the employee. If another module grants +permissions to the employee model (Pre-officer for example), I will need +to create a rule to extend the basic permissions. + +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 +------- + +* CorporateHub + +Contributors +------------ + +- `CorporateHub `__ + + - Alexey Pelykh + +- Tharathip Chaweewongphan + +- `Tecnativa `__: + + - Víctor Martínez + +- Alberto Nieto de Pablos + (https://braintec.com) + +- Manish Bohra + +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/hr `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_employee_document/__init__.py b/hr_employee_document/__init__.py new file mode 100644 index 00000000000..4b76c7b2d5c --- /dev/null +++ b/hr_employee_document/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/hr_employee_document/__manifest__.py b/hr_employee_document/__manifest__.py new file mode 100644 index 00000000000..34c2442d01e --- /dev/null +++ b/hr_employee_document/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2018 Brainbean Apps (https://brainbeanapps.com) +# Copyright 2020 CorporateHub (https://corporatehub.eu) +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "HR Employee Document", + "version": "17.0.1.0.0", + "category": "Human Resources", + "website": "https://github.com/OCA/hr", + "author": "CorporateHub, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "application": False, + "summary": "Documents attached to the employee profile", + "depends": ["hr"], + "data": [ + "views/hr_employee.xml", + "views/hr_employee_public.xml", + ], +} diff --git a/hr_employee_document/i18n/es.po b/hr_employee_document/i18n/es.po new file mode 100644 index 00000000000..a56766cc4d5 --- /dev/null +++ b/hr_employee_document/i18n/es.po @@ -0,0 +1,55 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_document +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-09-05 21:36+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\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: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_hr_employee_base +msgid "Basic Employee" +msgstr "Empleado Básico" + +#. module: hr_employee_document +#: model_terms:ir.ui.view,arch_db:hr_employee_document.ir_attachment_view_search +msgid "Content" +msgstr "Contenido" + +#. module: hr_employee_document +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee__document_count +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_base__document_count +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_public__document_count +msgid "Document Count" +msgstr "Recuento de Documentos" + +#. module: hr_employee_document +#: model_terms:ir.ui.view,arch_db:hr_employee_document.hr_employee_public_view_form +#: model_terms:ir.ui.view,arch_db:hr_employee_document.hr_employee_view_form +msgid "Documents" +msgstr "Documentos" + +#. module: hr_employee_document +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_public__is_logged +msgid "Is Logged" +msgstr "Está registrado/a" + +#. module: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_hr_employee_public +msgid "Public Employee" +msgstr "Empleado Público" + +#. module: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_ir_rule +msgid "Record Rule" +msgstr "Regla de Registro" diff --git a/hr_employee_document/i18n/fr.po b/hr_employee_document/i18n/fr.po new file mode 100644 index 00000000000..b3f03eb1bb2 --- /dev/null +++ b/hr_employee_document/i18n/fr.po @@ -0,0 +1,55 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_document +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-05-23 20:19+0000\n" +"Last-Translator: Kévin Allard \n" +"Language-Team: none\n" +"Language: fr\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 3.6.1\n" + +#. module: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_hr_employee_base +msgid "Basic Employee" +msgstr "" + +#. module: hr_employee_document +#: model_terms:ir.ui.view,arch_db:hr_employee_document.ir_attachment_view_search +msgid "Content" +msgstr "Contenu" + +#. module: hr_employee_document +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee__document_count +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_base__document_count +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_public__document_count +msgid "Document Count" +msgstr "Nombre de documents" + +#. module: hr_employee_document +#: model_terms:ir.ui.view,arch_db:hr_employee_document.hr_employee_public_view_form +#: model_terms:ir.ui.view,arch_db:hr_employee_document.hr_employee_view_form +msgid "Documents" +msgstr "Documents" + +#. module: hr_employee_document +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_public__is_logged +msgid "Is Logged" +msgstr "" + +#. module: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_hr_employee_public +msgid "Public Employee" +msgstr "" + +#. module: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_ir_rule +msgid "Record Rule" +msgstr "" diff --git a/hr_employee_document/i18n/hr.po b/hr_employee_document/i18n/hr.po new file mode 100644 index 00000000000..a83d8da7a55 --- /dev/null +++ b/hr_employee_document/i18n/hr.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_document +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-11-18 14:34+0000\n" +"Last-Translator: Bole \n" +"Language-Team: none\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" +"X-Generator: Weblate 3.8\n" + +#. module: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_hr_employee_base +msgid "Basic Employee" +msgstr "" + +#. module: hr_employee_document +#: model_terms:ir.ui.view,arch_db:hr_employee_document.ir_attachment_view_search +msgid "Content" +msgstr "Sadržaj" + +#. module: hr_employee_document +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee__document_count +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_base__document_count +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_public__document_count +msgid "Document Count" +msgstr "Broj dokumenata" + +#. module: hr_employee_document +#: model_terms:ir.ui.view,arch_db:hr_employee_document.hr_employee_public_view_form +#: model_terms:ir.ui.view,arch_db:hr_employee_document.hr_employee_view_form +msgid "Documents" +msgstr "Dokumenti" + +#. module: hr_employee_document +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_public__is_logged +msgid "Is Logged" +msgstr "" + +#. module: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_hr_employee_public +msgid "Public Employee" +msgstr "" + +#. module: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_ir_rule +msgid "Record Rule" +msgstr "" diff --git a/hr_employee_document/i18n/hr_employee_document.pot b/hr_employee_document/i18n/hr_employee_document.pot new file mode 100644 index 00000000000..a7b11982dca --- /dev/null +++ b/hr_employee_document/i18n/hr_employee_document.pot @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_document +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_hr_employee_base +msgid "Basic Employee" +msgstr "" + +#. module: hr_employee_document +#: model_terms:ir.ui.view,arch_db:hr_employee_document.ir_attachment_view_search +msgid "Content" +msgstr "" + +#. module: hr_employee_document +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee__document_count +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_base__document_count +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_public__document_count +msgid "Document Count" +msgstr "" + +#. module: hr_employee_document +#: model_terms:ir.ui.view,arch_db:hr_employee_document.hr_employee_public_view_form +#: model_terms:ir.ui.view,arch_db:hr_employee_document.hr_employee_view_form +msgid "Documents" +msgstr "" + +#. module: hr_employee_document +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_public__is_logged +msgid "Is Logged" +msgstr "" + +#. module: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_hr_employee_public +msgid "Public Employee" +msgstr "" + +#. module: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_ir_rule +msgid "Record Rule" +msgstr "" diff --git a/hr_employee_document/i18n/it.po b/hr_employee_document/i18n/it.po new file mode 100644 index 00000000000..cb8728ace19 --- /dev/null +++ b/hr_employee_document/i18n/it.po @@ -0,0 +1,55 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_document +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-09-04 18:38+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: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_hr_employee_base +msgid "Basic Employee" +msgstr "Dipendente base" + +#. module: hr_employee_document +#: model_terms:ir.ui.view,arch_db:hr_employee_document.ir_attachment_view_search +msgid "Content" +msgstr "Contenuto" + +#. module: hr_employee_document +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee__document_count +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_base__document_count +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_public__document_count +msgid "Document Count" +msgstr "Conteggio documenti" + +#. module: hr_employee_document +#: model_terms:ir.ui.view,arch_db:hr_employee_document.hr_employee_public_view_form +#: model_terms:ir.ui.view,arch_db:hr_employee_document.hr_employee_view_form +msgid "Documents" +msgstr "Documenti" + +#. module: hr_employee_document +#: model:ir.model.fields,field_description:hr_employee_document.field_hr_employee_public__is_logged +msgid "Is Logged" +msgstr "È collegato" + +#. module: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_hr_employee_public +msgid "Public Employee" +msgstr "Dipendente pubblico" + +#. module: hr_employee_document +#: model:ir.model,name:hr_employee_document.model_ir_rule +msgid "Record Rule" +msgstr "Regola su record" diff --git a/hr_employee_document/models/__init__.py b/hr_employee_document/models/__init__.py new file mode 100644 index 00000000000..9e792963e5a --- /dev/null +++ b/hr_employee_document/models/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import hr_employee +from . import hr_employee_public +from . import ir_rule diff --git a/hr_employee_document/models/hr_employee.py b/hr_employee_document/models/hr_employee.py new file mode 100644 index 00000000000..8c8b201117f --- /dev/null +++ b/hr_employee_document/models/hr_employee.py @@ -0,0 +1,56 @@ +# Copyright 2018 Brainbean Apps (https://brainbeanapps.com) +# Copyright 2023 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class HrEmployeeBase(models.AbstractModel): + _inherit = "hr.employee.base" + + document_count = fields.Integer( + compute="_compute_document_count", + ) + + def _compute_document_count(self): + self.document_count = 0 + attachment_groups = self.env["ir.attachment"].read_group( + [("res_model", "=", "hr.employee"), ("res_id", "in", self.ids)], + ["res_id"], + ["res_id"], + ) + count_dict = {x["res_id"]: x["res_id_count"] for x in attachment_groups} + for record in self: + record.document_count = count_dict.get(record.id, 0) + + @api.model + def check_access_rights(self, operation, raise_exception=True): + """Return access to the hr.employee model if we pass a specific context, + is a trick to list the attachments related to an employee.""" + if ( + not self.env.is_superuser() + and not self.env.user.has_group("hr.group_hr_user") + and operation == "read" + and self._name == "hr.employee" + ): + if ( + self.env.context.get("search_attachments_from_hr_employee") + or self == self.env.user.employee_ids + ): + return True + return super().check_access_rights( + operation=operation, raise_exception=raise_exception + ) + + def action_get_attachment_tree_view(self): + action = self.env["ir.actions.act_window"]._for_xml_id("base.action_attachment") + action["context"] = { + "default_res_model": self._name, + "default_res_id": self.ids[0], + "search_attachments_from_hr_employee": True, + } + action["domain"] = [("res_model", "=", self._name), ("res_id", "in", self.ids)] + action["search_view_id"] = ( + self.env.ref("hr_employee_document.ir_attachment_view_search").id, + ) + return action diff --git a/hr_employee_document/models/hr_employee_public.py b/hr_employee_document/models/hr_employee_public.py new file mode 100644 index 00000000000..c70f94ba1a0 --- /dev/null +++ b/hr_employee_document/models/hr_employee_public.py @@ -0,0 +1,32 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class HrEmployeePublic(models.Model): + _inherit = "hr.employee.public" + + is_logged = fields.Boolean(compute="_compute_is_logged", store=False) + + def _compute_is_logged(self): + self.is_logged = False + for record in self: + if self.env.user == record.user_id: + record.is_logged = True + + def action_get_attachment_tree_view(self): + action = self.env["ir.actions.act_window"]._for_xml_id("base.action_attachment") + action["context"] = { + "default_res_model": "hr.employee", + "default_res_id": self.env.user.employee_id.id, + "search_attachments_from_hr_employee": True, + } + action["domain"] = [ + ("res_model", "=", "hr.employee"), + ("res_id", "=", self.env.user.employee_id.id), + ] + action["search_view_id"] = ( + self.env.ref("hr_employee_document.ir_attachment_view_search").id, + ) + return action diff --git a/hr_employee_document/models/ir_rule.py b/hr_employee_document/models/ir_rule.py new file mode 100644 index 00000000000..a9b7b6bf066 --- /dev/null +++ b/hr_employee_document/models/ir_rule.py @@ -0,0 +1,36 @@ +# Copyright 2023 Tecnativa - Víctor Martínez +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import api, models, tools +from odoo.osv import expression +from odoo.tools import config + + +class IrRule(models.Model): + _inherit = "ir.rule" + + @api.model + @tools.conditional( + "xml" not in config["dev_mode"], + tools.ormcache( + "self.env.uid", + "self.env.su", + "model_name", + "mode", + "tuple(self._compute_domain_context_values())", + ), + ) + def _compute_domain(self, model_name, mode="read"): + """We need to add for security purposes an extra domain in the hr.employee + model to restrict only the user's employees when search employee attachments.""" + res = super()._compute_domain(model_name, mode=mode) + user = self.env.user + if ( + model_name == "hr.employee" + and not self.env.su + and not user.has_group("hr.group_hr_manager") + and self.env.context.get("search_attachments_from_hr_employee") + ): + extra_domain = [[("id", "in", user.employee_ids.ids)]] + res = expression.AND(extra_domain + [res]) + return res diff --git a/hr_employee_document/pyproject.toml b/hr_employee_document/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/hr_employee_document/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/hr_employee_document/readme/CONTRIBUTORS.md b/hr_employee_document/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..2f38535672c --- /dev/null +++ b/hr_employee_document/readme/CONTRIBUTORS.md @@ -0,0 +1,14 @@ +- [CorporateHub](https://corporatehub.eu/) + + - Alexey Pelykh \<\> + +- Tharathip Chaweewongphan \<\> + +- [Tecnativa](https://www.tecnativa.com): + + > - Víctor Martínez + +- Alberto Nieto de Pablos \<\> + () + +- Manish Bohra \<\> diff --git a/hr_employee_document/readme/DESCRIPTION.md b/hr_employee_document/readme/DESCRIPTION.md new file mode 100644 index 00000000000..7c3e055625c --- /dev/null +++ b/hr_employee_document/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module displays a button on the employee's profile to view linked +attachments, both for HR officers/managers and the own employee, so you +can use it as employee document storage. diff --git a/hr_employee_document/readme/ROADMAP.md b/hr_employee_document/readme/ROADMAP.md new file mode 100644 index 00000000000..c321b9db356 --- /dev/null +++ b/hr_employee_document/readme/ROADMAP.md @@ -0,0 +1,4 @@ +This module adds read permission to the employee model; the rest of the +model data will be available to the employee. If another module grants +permissions to the employee model (Pre-officer for example), I will need +to create a rule to extend the basic permissions. diff --git a/hr_employee_document/static/description/icon.png b/hr_employee_document/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/hr_employee_document/static/description/icon.png differ diff --git a/hr_employee_document/static/description/index.html b/hr_employee_document/static/description/index.html new file mode 100644 index 00000000000..c7cc274ecf2 --- /dev/null +++ b/hr_employee_document/static/description/index.html @@ -0,0 +1,449 @@ + + + + + + +HR Employee Document + + + +
+

HR Employee Document

+ + +

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

+

This module displays a button on the employee’s profile to view linked +attachments, both for HR officers/managers and the own employee, so you +can use it as employee document storage.

+

Table of contents

+ +
+

Known issues / Roadmap

+

This module adds read permission to the employee model; the rest of the +model data will be available to the employee. If another module grants +permissions to the employee model (Pre-officer for example), I will need +to create a rule to extend the basic permissions.

+
+
+

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

+
    +
  • CorporateHub
  • +
+
+
+

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/hr project on GitHub.

+

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

+
+
+
+ + diff --git a/hr_employee_document/tests/__init__.py b/hr_employee_document/tests/__init__.py new file mode 100644 index 00000000000..494f8efa6b3 --- /dev/null +++ b/hr_employee_document/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_hr_employee_document diff --git a/hr_employee_document/tests/test_hr_employee_document.py b/hr_employee_document/tests/test_hr_employee_document.py new file mode 100644 index 00000000000..e1730c044d8 --- /dev/null +++ b/hr_employee_document/tests/test_hr_employee_document.py @@ -0,0 +1,107 @@ +# Copyright 2018 Brainbean Apps (https://brainbeanapps.com) +# Copyright 2021-2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +import base64 + +from odoo.tests import common, new_test_user +from odoo.tests.common import users + + +class TestHrEmployeeDocument(common.TransactionCase): + def setUp(self): + super().setUp() + self.env = self.env( + context=dict( + self.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) + self.user_1 = new_test_user(self.env, login="test-user-1") + self.user_2 = new_test_user(self.env, login="test-user-2") + new_test_user(self.env, login="test-user-manager", groups="hr.group_hr_user") + self.employee_1 = self.env["hr.employee"].create( + {"name": "Employee #1", "user_id": self.user_1.id} + ) + self.employee_2 = self.env["hr.employee"].create( + {"name": "Employee #2", "user_id": self.user_2.id} + ) + + def _create_attachment(self, employee_id): + return ( + self.env["ir.attachment"] + .sudo() + .create( + { + "res_model": employee_id._name, + "res_id": employee_id.id, + "datas": base64.b64encode(b"My attachment"), + "name": "doc.txt", + } + ) + ) + + @users("test-user-1") + def test_employee_attachment(self): + employee = self.env.user.employee_id + self._create_attachment(employee) + self.assertEqual(employee.document_count, 1) + employee_public = self.env["hr.employee.public"].browse(employee.id) + self.assertEqual(employee_public.document_count, 1) + + def _get_attachments_from_employee(self, employee): + res = employee.action_get_attachment_tree_view() + return ( + self.env[res["res_model"]] + .with_context(**res["context"]) + .search(res["domain"]) + ) + + @users("test-user-2") + def test_employee_attachment_tree_view(self): + employee = self.env.user.employee_id + self.assertNotEqual(employee.action_get_attachment_tree_view(), None) + employee_public = self.env["hr.employee.public"].browse(employee.id) + items = self._get_attachments_from_employee(employee_public) + self.assertEqual(len(items), 0) + + @users("test-user-1") + def test_attachments_access_user_1(self): + # create attachments + attachment_1 = self._create_attachment(self.employee_1) + attachment_2 = self._create_attachment(self.employee_2) + records = self._get_attachments_from_employee(self.env.user.employee_id) + self.assertIn(attachment_1, records) + self.assertNotIn(attachment_2, records) + + @users("test-user-2") + def test_attachments_access_user_2(self): + # create attachments + attachment_1 = self._create_attachment(self.employee_1) + attachment_2 = self._create_attachment(self.employee_2) + records = self._get_attachments_from_employee(self.env.user.employee_id) + self.assertNotIn(attachment_1, records) + self.assertIn(attachment_2, records) + + @users("test-user-manager") + def test_attachments_access_user_manager(self): + # create attachments + attachment_1 = self._create_attachment(self.employee_1) + attachment_2 = self._create_attachment(self.employee_2) + records = self.env["ir.attachment"].search([]) + self.assertIn(attachment_1, records) + self.assertIn(attachment_2, records) + + @users("test-user-1") + def test_is_logged(self): + employee = self.env.user.employee_id + employee_public = self.env["hr.employee.public"].browse(employee.id) + self.assertTrue(employee_public.is_logged) + + employee = self.employee_2 + employee_public = self.env["hr.employee.public"].browse(employee.id) + self.assertFalse(employee_public.is_logged) diff --git a/hr_employee_document/views/hr_employee.xml b/hr_employee_document/views/hr_employee.xml new file mode 100644 index 00000000000..3e7cd42611e --- /dev/null +++ b/hr_employee_document/views/hr_employee.xml @@ -0,0 +1,48 @@ + + + + + hr.employee.view.form.inherit.document + hr.employee + + +
+ +
+ +
+ + + + + ir.attachment.search.inherit.employee + ir.attachment + primary + + + + + + + 1 + + + 1 + + + 1 + + + + diff --git a/hr_employee_document/views/hr_employee_public.xml b/hr_employee_document/views/hr_employee_public.xml new file mode 100644 index 00000000000..13c21cee604 --- /dev/null +++ b/hr_employee_document/views/hr_employee_public.xml @@ -0,0 +1,28 @@ + + + + + hr.employee.public.view.form.inherit.document + hr.employee.public + + + + + +
+ +
+
+
+