-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] hr_holidays_length_validation: check for outdated amount of tim…
…e taken
- Loading branch information
1 parent
73bb981
commit e5808d9
Showing
12 changed files
with
795 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
========================= | ||
Leaves: length validation | ||
========================= | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! 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/12.0/hr_holidays_length_validation | ||
:alt: OCA/hr | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/hr-12-0/hr-12-0-hr_holidays_length_validation | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/116/12.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows leave's amount of time validation to handle cases when | ||
changes to Resource Calendar (e.g. Global Leaves or Timezone) may change | ||
computed length. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
To validate length of requested leaves: | ||
#. Go to *Leaves > Managers > All > Leaves*. | ||
#. Select leaves of interest and perform *Action > Validate Length*. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/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 <https://github.com/OCA/hr/issues/new?body=module:%20hr_holidays_length_validation%0Aversion:%2012.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 | ||
~~~~~~~ | ||
|
||
* Brainbean Apps | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Alexey Pelykh <alexey.pelykh@brainbeanapps.com> | ||
|
||
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 <https://github.com/OCA/hr/tree/12.0/hr_holidays_length_validation>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
'name': 'Leaves: length validation', | ||
'version': '12.0.1.0.0', | ||
'category': 'Human Resources', | ||
'website': 'https://github.com/OCA/hr', | ||
'author': | ||
'Brainbean Apps, ' | ||
'Odoo Community Association (OCA)', | ||
'license': 'AGPL-3', | ||
'installable': True, | ||
'application': False, | ||
'summary': 'Leave\'s length validation', | ||
'depends': [ | ||
'hr_holidays', | ||
], | ||
'data': [ | ||
'views/hr_leave.xml', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import hr_leave |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models, api, _ | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class HrLeave(models.Model): | ||
_inherit = 'hr.leave' | ||
|
||
@api.multi | ||
def _validate_length(self): | ||
self.ensure_one() | ||
|
||
if not self.employee_id: # pragma: no cover | ||
return False | ||
|
||
recomputed_number_of_days = self.employee_id.get_work_days_data( | ||
self.date_from, | ||
self.date_to, | ||
domain=[ | ||
('time_type', '=', 'leave'), | ||
'|', | ||
('holiday_id', '!=', self.id), | ||
('holiday_id', '=', False), | ||
], | ||
)['days'] | ||
|
||
return self.number_of_days != recomputed_number_of_days | ||
|
||
@api.multi | ||
def action_validate_length(self): | ||
outdated = self.filtered(lambda x: x._validate_length()) | ||
if outdated: | ||
raise UserError(_( | ||
'Following leaves have outdated length:\n\t %s' | ||
) % ( | ||
_('\n\t').join(list(map( | ||
lambda leave: _('%s%s of %s for %.2f day(s)') % ( | ||
leave.holiday_status_id.name, | ||
_(' (%s)') % (leave.name) if leave.name else '', | ||
leave.employee_id.name, | ||
leave.number_of_days, | ||
), | ||
outdated | ||
))), | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Alexey Pelykh <alexey.pelykh@brainbeanapps.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This module allows leave's amount of time validation to handle cases when | ||
changes to Resource Calendar (e.g. Global Leaves or Timezone) may change | ||
computed length. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
To validate length of requested leaves: | ||
#. Go to *Leaves > Managers > All > Leaves*. | ||
#. Select leaves of interest and perform *Action > Validate Length*. |
Oops, something went wrong.