Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions hr_leave_has_attachment/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/solvosci/slv-hr/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 <https://github.com/solvosci/slv-hr/issues/new?body=module:%20hr_leave_has_attachment%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Solvos

Contributors
------------

- Iria Alonso <iria.alonso@solvos.es>
- Christian Santamaría <christian.santamaria@solvos.es>

Maintainers
-----------

This module is part of the `solvosci/slv-hr <https://github.com/solvosci/slv-hr/tree/17.0/hr_leave_has_attachment>`_ project on GitHub.

You are welcome to contribute.
2 changes: 2 additions & 0 deletions hr_leave_has_attachment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import pre_init_hook
19 changes: 19 additions & 0 deletions hr_leave_has_attachment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# © 2025 Solvos Consultoría Informática (<http://www.solvos.es>)
# 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'
}
21 changes: 21 additions & 0 deletions hr_leave_has_attachment/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# © 2025 Solvos Consultoría Informática (<http://www.solvos.es>)
# 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'
);
""")
37 changes: 37 additions & 0 deletions hr_leave_has_attachment/i18n/es.po
Original file line number Diff line number Diff line change
@@ -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."
37 changes: 37 additions & 0 deletions hr_leave_has_attachment/i18n/hr_leave_has_attachment.pot
Original file line number Diff line number Diff line change
@@ -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 ""
3 changes: 3 additions & 0 deletions hr_leave_has_attachment/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import hr_leave
from . import ir_attachment
from . import mail_message
10 changes: 10 additions & 0 deletions hr_leave_has_attachment/models/hr_leave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# © 2025 Solvos Consultoría Informática (<http://www.solvos.es>)
# 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()
25 changes: 25 additions & 0 deletions hr_leave_has_attachment/models/ir_attachment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# © 2025 Solvos Consultoría Informática (<http://www.solvos.es>)
# 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)
16 changes: 16 additions & 0 deletions hr_leave_has_attachment/models/mail_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# © 2025 Solvos Consultoría Informática (<http://www.solvos.es>)
# 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
2 changes: 2 additions & 0 deletions hr_leave_has_attachment/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Iria Alonso \<iria.alonso@solvos.es\>
* Christian Santamaría \<christian.santamaria@solvos.es\>
1 change: 1 addition & 0 deletions hr_leave_has_attachment/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds new field to hr.leave model to check if there are any attachments.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading