diff --git a/hr_holidays_leave_auto_approve/README.rst b/hr_holidays_leave_auto_approve/README.rst index 627be07ae6a..6b51d78cab1 100644 --- a/hr_holidays_leave_auto_approve/README.rst +++ b/hr_holidays_leave_auto_approve/README.rst @@ -37,15 +37,16 @@ belonging to that leave type. Configuration ============= -Get sure that the administrative user belongs at least to the group -Leaves/Officer. - -If you wish that the system automatically validates all the leave requests +If you wish that the system automatically validates the leave requests belonging to a specific leave type, please follow the steps below. #. Go on the leave type configuration menu #. Select the leave type you wish to setup -#. Mark the flag 'Auto Validate'. +#. Select the auto approve policy for that leave type. + +The option 'Auto Validated by HR' will auto validate leave requests created by +HR Officers while option 'Auto Validated by Everyone' will auto validate all +leave requests of the selected type, no matter who requested it. Bug Tracker =========== @@ -70,6 +71,7 @@ Contributors * Andrea Stirpe * Antonio Esposito +* Jaime Arroyo Maintainers ~~~~~~~~~~~ diff --git a/hr_holidays_leave_auto_approve/__manifest__.py b/hr_holidays_leave_auto_approve/__manifest__.py index c912b844496..6140cfe5f11 100644 --- a/hr_holidays_leave_auto_approve/__manifest__.py +++ b/hr_holidays_leave_auto_approve/__manifest__.py @@ -3,7 +3,7 @@ { 'name': 'Auto Approve Leaves', - 'version': '12.0.1.0.0', + 'version': '12.0.2.0.0', 'license': 'AGPL-3', 'summary': 'Leave type for auto-validation of Leaves', 'author': 'Onestein, Odoo Community Association (OCA)', diff --git a/hr_holidays_leave_auto_approve/migrations/12.0.2.0.0/post-migration.py b/hr_holidays_leave_auto_approve/migrations/12.0.2.0.0/post-migration.py new file mode 100644 index 00000000000..74608764d45 --- /dev/null +++ b/hr_holidays_leave_auto_approve/migrations/12.0.2.0.0/post-migration.py @@ -0,0 +1,17 @@ +# Copyright 2019 Eficent +# Copyright 2019 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + cr = env.cr + if openupgrade.column_exists(cr, 'hr_leave_type', 'auto_approve'): + openupgrade.logged_query( + cr, """ + UPDATE hr_leave_type + SET auto_approve_policy = 'hr' + WHERE auto_approve + """ + ) diff --git a/hr_holidays_leave_auto_approve/models/hr_leave.py b/hr_holidays_leave_auto_approve/models/hr_leave.py index 30e17a4112d..3f1b033b9bf 100644 --- a/hr_holidays_leave_auto_approve/models/hr_leave.py +++ b/hr_holidays_leave_auto_approve/models/hr_leave.py @@ -12,6 +12,18 @@ def _check_approval_update(self, state): return return super()._check_approval_update(state) + @api.multi + def _should_auto_approve(self): + self.ensure_one() + policy = self.holiday_status_id.auto_approve_policy + return (self.can_approve and policy == 'hr') or policy == 'all' + + @api.multi + def _apply_auto_approve_policy(self): + self.filtered( + lambda r: r._should_auto_approve() + ).sudo().action_approve() + @api.model def create(self, values): auto_approve = self._get_auto_approve_on_creation(values) @@ -21,15 +33,15 @@ def create(self, values): HrLeave, self.with_context( tracking_disable=tracking_disable) ).create(values) - if res.can_approve and res.holiday_status_id.auto_approve: - res.action_approve() + res._apply_auto_approve_policy() return res @api.model def _get_auto_approve_on_creation(self, values): auto_approve = False if values.get('holiday_status_id'): - auto_approve = self.env['hr.leave.type'].browse( + leave_type = self.env['hr.leave.type'].browse( values.get('holiday_status_id') - ).auto_approve + ) + auto_approve = leave_type.auto_approve_policy != 'no' return auto_approve diff --git a/hr_holidays_leave_auto_approve/models/hr_leave_type.py b/hr_holidays_leave_auto_approve/models/hr_leave_type.py index 2dc2da46fde..1717d47cbf2 100644 --- a/hr_holidays_leave_auto_approve/models/hr_leave_type.py +++ b/hr_holidays_leave_auto_approve/models/hr_leave_type.py @@ -7,7 +7,10 @@ class HrLeaveType(models.Model): _inherit = "hr.leave.type" - auto_approve = fields.Boolean( - string='Auto Validate', - help="If True, leaves belonging to this leave type will be" - " automatically validated") + auto_approve_policy = fields.Selection( + selection=[ + ('no', 'No auto Validation'), + ('hr', 'Auto Validated by HR'), + ('all', 'Auto Validated by Everyone'), + ], default='no', required=True, + ) diff --git a/hr_holidays_leave_auto_approve/readme/CONFIGURE.rst b/hr_holidays_leave_auto_approve/readme/CONFIGURE.rst index 5022f4ee384..97c26a5bf03 100644 --- a/hr_holidays_leave_auto_approve/readme/CONFIGURE.rst +++ b/hr_holidays_leave_auto_approve/readme/CONFIGURE.rst @@ -1,9 +1,10 @@ -Get sure that the administrative user belongs at least to the group -Leaves/Officer. - -If you wish that the system automatically validates all the leave requests +If you wish that the system automatically validates the leave requests belonging to a specific leave type, please follow the steps below. #. Go on the leave type configuration menu #. Select the leave type you wish to setup -#. Mark the flag 'Auto Validate'. +#. Select the auto approve policy for that leave type. + +The option 'Auto Validated by HR' will auto validate leave requests created by +HR Officers while option 'Auto Validated by Everyone' will auto validate all +leave requests of the selected type, no matter who requested it. diff --git a/hr_holidays_leave_auto_approve/readme/CONTRIBUTORS.rst b/hr_holidays_leave_auto_approve/readme/CONTRIBUTORS.rst index 1da930f8f86..efd34e65976 100644 --- a/hr_holidays_leave_auto_approve/readme/CONTRIBUTORS.rst +++ b/hr_holidays_leave_auto_approve/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Andrea Stirpe * Antonio Esposito +* Jaime Arroyo diff --git a/hr_holidays_leave_auto_approve/static/description/index.html b/hr_holidays_leave_auto_approve/static/description/index.html index a1905a07137..801dae5bae1 100644 --- a/hr_holidays_leave_auto_approve/static/description/index.html +++ b/hr_holidays_leave_auto_approve/static/description/index.html @@ -3,7 +3,7 @@ - + Auto Approve Leaves