diff --git a/hr_leave_has_attachment/README.rst b/hr_leave_has_attachment/README.rst new file mode 100644 index 0000000..29f2723 --- /dev/null +++ b/hr_leave_has_attachment/README.rst @@ -0,0 +1,61 @@ +======================= +Hr Leave Has Attachment +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1a797231763d5e72b6e5caafcf1a953018568c64587370b3d80068e0321530cc + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-solvosci%2Fslv--hr-lightgray.png?logo=github + :target: https://github.com/solvosci/slv-hr/tree/17.0/hr_leave_has_attachment + :alt: solvosci/slv-hr + +|badge1| |badge2| |badge3| + +Adds new field to hr.leave model to check if there are any attachments. + +**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 +------------ + +- Iria Alonso +- Christian Santamaría + +Maintainers +----------- + +This module is part of the `solvosci/slv-hr `_ project on GitHub. + +You are welcome to contribute. diff --git a/hr_leave_has_attachment/__init__.py b/hr_leave_has_attachment/__init__.py new file mode 100644 index 0000000..6d58305 --- /dev/null +++ b/hr_leave_has_attachment/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import pre_init_hook diff --git a/hr_leave_has_attachment/__manifest__.py b/hr_leave_has_attachment/__manifest__.py new file mode 100644 index 0000000..a67ec33 --- /dev/null +++ b/hr_leave_has_attachment/__manifest__.py @@ -0,0 +1,19 @@ +# © 2025 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +{ + "name": "Hr Leave Has Attachment", + "summary": """ + Adds new field to hr.leave model to check if there are any attachments. + """, + "author": "Solvos", + "license": "AGPL-3", + "version": "17.0.1.0.0", + "category": "Human Resources", + "website": "https://github.com/solvosci/slv-hr", + "depends": ['hr_holidays'], + "data": [ + "views/hr_leave_views.xml", + ], + 'installable': True, + 'pre_init_hook': 'pre_init_hook' +} diff --git a/hr_leave_has_attachment/hooks.py b/hr_leave_has_attachment/hooks.py new file mode 100644 index 0000000..1da609d --- /dev/null +++ b/hr_leave_has_attachment/hooks.py @@ -0,0 +1,21 @@ +# © 2025 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +import logging + +logger = logging.getLogger(__name__) + +def pre_init_hook(env): + logger.info("Creating field has_attachment on hr_leave") + env.cr.execute(""" + ALTER TABLE hr_leave ADD COLUMN IF NOT EXISTS has_attachment boolean; + """) + + logger.info("Computing field has_attachment on hr.leave") + env.cr.execute(""" + UPDATE hr_leave SET has_attachment = TRUE + WHERE id IN ( + SELECT res_id FROM ir_attachment + WHERE res_model = 'hr.leave' + ); + """) diff --git a/hr_leave_has_attachment/i18n/es.po b/hr_leave_has_attachment/i18n/es.po new file mode 100644 index 0000000..d0e426c --- /dev/null +++ b/hr_leave_has_attachment/i18n/es.po @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_leave_has_attachment +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-03-14 08:24+0000\n" +"PO-Revision-Date: 2025-03-14 08:24+0000\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_leave_has_attachment +#: model:ir.model,name:hr_leave_has_attachment.model_ir_attachment +#: model_terms:ir.ui.view,arch_db:hr_leave_has_attachment.view_hr_leave_search_inherit +msgid "Attachment" +msgstr "Con archivos adjuntos" + +#. module: hr_leave_has_attachment +#: model:ir.model.fields,field_description:hr_leave_has_attachment.field_hr_leave__has_attachment +msgid "Has Attachment" +msgstr "Tiene archivos adjuntos" + +#. module: hr_leave_has_attachment +#: model:ir.model,name:hr_leave_has_attachment.model_hr_leave +msgid "Time Off" +msgstr "Ausencias" + +#. module: hr_leave_has_attachment +#: model_terms:ir.ui.view,arch_db:hr_leave_has_attachment.view_hr_leave_tree_inherit +msgid "With Atch." +msgstr "Con Adj." diff --git a/hr_leave_has_attachment/i18n/hr_leave_has_attachment.pot b/hr_leave_has_attachment/i18n/hr_leave_has_attachment.pot new file mode 100644 index 0000000..0d4c186 --- /dev/null +++ b/hr_leave_has_attachment/i18n/hr_leave_has_attachment.pot @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_leave_has_attachment +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-03-14 08:24+0000\n" +"PO-Revision-Date: 2025-03-14 08:24+0000\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_leave_has_attachment +#: model:ir.model,name:hr_leave_has_attachment.model_ir_attachment +#: model_terms:ir.ui.view,arch_db:hr_leave_has_attachment.view_hr_leave_search_inherit +msgid "Attachment" +msgstr "" + +#. module: hr_leave_has_attachment +#: model:ir.model.fields,field_description:hr_leave_has_attachment.field_hr_leave__has_attachment +msgid "Has Attachment" +msgstr "" + +#. module: hr_leave_has_attachment +#: model:ir.model,name:hr_leave_has_attachment.model_hr_leave +msgid "Time Off" +msgstr "" + +#. module: hr_leave_has_attachment +#: model_terms:ir.ui.view,arch_db:hr_leave_has_attachment.view_hr_leave_tree_inherit +msgid "With Atch." +msgstr "" diff --git a/hr_leave_has_attachment/models/__init__.py b/hr_leave_has_attachment/models/__init__.py new file mode 100644 index 0000000..a0a3866 --- /dev/null +++ b/hr_leave_has_attachment/models/__init__.py @@ -0,0 +1,3 @@ +from . import hr_leave +from . import ir_attachment +from . import mail_message diff --git a/hr_leave_has_attachment/models/hr_leave.py b/hr_leave_has_attachment/models/hr_leave.py new file mode 100644 index 0000000..ee609f9 --- /dev/null +++ b/hr_leave_has_attachment/models/hr_leave.py @@ -0,0 +1,10 @@ +# © 2025 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import models, fields + + +class HrLeave(models.Model): + _inherit = 'hr.leave' + + has_attachment = fields.Boolean() diff --git a/hr_leave_has_attachment/models/ir_attachment.py b/hr_leave_has_attachment/models/ir_attachment.py new file mode 100644 index 0000000..4f62239 --- /dev/null +++ b/hr_leave_has_attachment/models/ir_attachment.py @@ -0,0 +1,25 @@ +# © 2025 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import models, api + + +class IrAttachment(models.Model): + _inherit = 'ir.attachment' + + @api.model_create_multi + def create(self, vals_list): + res = super(IrAttachment, self).create(vals_list) + leave_ids = res.filtered(lambda x: x.res_model == 'hr.leave').mapped("res_id") + if leave_ids: + leave_ids = self.env["hr.leave"].browse(leave_ids) + leave_ids.filtered(lambda x: not x.has_attachment).sudo().write({"has_attachment": True}) + return res + + @api.ondelete(at_uninstall=False) + def _update_hr_leave_has_attachment(self): + hr_leave_ids = self.env['hr.leave'] + for attach in self.filtered(lambda x: x.res_model == 'hr.leave'): + hr_leave_ids |= self.env['hr.leave'].browse(attach.res_id).exists() + for leave in hr_leave_ids: + leave.sudo().has_attachment = bool(leave.message_attachment_count) diff --git a/hr_leave_has_attachment/models/mail_message.py b/hr_leave_has_attachment/models/mail_message.py new file mode 100644 index 0000000..361b76d --- /dev/null +++ b/hr_leave_has_attachment/models/mail_message.py @@ -0,0 +1,16 @@ +# © 2025 Solvos Consultoría Informática () +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import models + + +class Message(models.Model): + _inherit = 'mail.message' + + def create(self, vals_list): + res = super(Message, self).create(vals_list) + leave_ids = res.filtered(lambda x: x.model == 'hr.leave' and x.attachment_ids).mapped("res_id") + if leave_ids: + leave_ids = self.env["hr.leave"].browse(leave_ids) + leave_ids.filtered(lambda x: not x.has_attachment).sudo().write({"has_attachment": True}) + return res diff --git a/hr_leave_has_attachment/readme/CONTRIBUTORS.md b/hr_leave_has_attachment/readme/CONTRIBUTORS.md new file mode 100644 index 0000000..33c5376 --- /dev/null +++ b/hr_leave_has_attachment/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +* Iria Alonso \ +* Christian Santamaría \ diff --git a/hr_leave_has_attachment/readme/DESCRIPTION.md b/hr_leave_has_attachment/readme/DESCRIPTION.md new file mode 100644 index 0000000..2ab49eb --- /dev/null +++ b/hr_leave_has_attachment/readme/DESCRIPTION.md @@ -0,0 +1 @@ +Adds new field to hr.leave model to check if there are any attachments. diff --git a/hr_leave_has_attachment/static/description/icon.png b/hr_leave_has_attachment/static/description/icon.png new file mode 100644 index 0000000..daa2a02 Binary files /dev/null and b/hr_leave_has_attachment/static/description/icon.png differ diff --git a/hr_leave_has_attachment/static/description/index.html b/hr_leave_has_attachment/static/description/index.html new file mode 100644 index 0000000..5754ab5 --- /dev/null +++ b/hr_leave_has_attachment/static/description/index.html @@ -0,0 +1,417 @@ + + + + + +Hr Leave Has Attachment + + + +
+

Hr Leave Has Attachment

+ + +

Beta License: AGPL-3 solvosci/slv-hr

+

Adds new field to hr.leave model to check if there are any attachments.

+

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 part of the solvosci/slv-hr project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/hr_leave_has_attachment/views/hr_leave_views.xml b/hr_leave_has_attachment/views/hr_leave_views.xml new file mode 100644 index 0000000..6a9b6cc --- /dev/null +++ b/hr_leave_has_attachment/views/hr_leave_views.xml @@ -0,0 +1,26 @@ + + + hr.leave.tree (in hr_leave_has_attachment) + hr.leave + + + + + + + + + hr.leave.search (in hr_leave_has_attachment) + hr.leave + + + + + + + + + + + +