From d340a931de5ecd8045d79973f6ae71c480e1ea4b Mon Sep 17 00:00:00 2001 From: Laetitia Da Costa Date: Fri, 24 Oct 2025 10:26:34 +0200 Subject: [PATCH] [WIP]allow_negative_leave_and_allocation --- .../__manifest__.py | 2 +- .../allow_negative_leave_and_allocation.pot | 39 +++++++++++-- .../i18n/fr.po | 39 +++++++++++-- .../models/hr_leave.py | 2 +- .../models/hr_leave_type.py | 56 +++++++++++++++++++ .../static/src/xml/time_off_card.xml | 8 ++- 6 files changed, 133 insertions(+), 13 deletions(-) diff --git a/allow_negative_leave_and_allocation/__manifest__.py b/allow_negative_leave_and_allocation/__manifest__.py index 8d7ac7b..96a1432 100644 --- a/allow_negative_leave_and_allocation/__manifest__.py +++ b/allow_negative_leave_and_allocation/__manifest__.py @@ -3,7 +3,7 @@ { "name": "allow_negative_leave_and_allocation", - "version": "16.0.1.1.0", + "version": "16.0.1.2.0", "author": "Elabore", "website": "https://elabore.coop", "maintainer": "Elabore", diff --git a/allow_negative_leave_and_allocation/i18n/allow_negative_leave_and_allocation.pot b/allow_negative_leave_and_allocation/i18n/allow_negative_leave_and_allocation.pot index 304690e..a2cecd2 100644 --- a/allow_negative_leave_and_allocation/i18n/allow_negative_leave_and_allocation.pot +++ b/allow_negative_leave_and_allocation/i18n/allow_negative_leave_and_allocation.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 16.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-01-02 12:11+0000\n" -"PO-Revision-Date: 2025-01-02 12:11+0000\n" +"POT-Creation-Date: 2025-10-24 07:50+0000\n" +"PO-Revision-Date: 2025-10-24 07:50+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -15,6 +15,30 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: allow_negative_leave_and_allocation +#. odoo-python +#: code:addons/allow_negative_leave_and_allocation/models/hr_leave_type.py:0 +#: code:addons/allow_negative_leave_and_allocation/models/hr_leave_type.py:0 +#, python-format +msgid " days" +msgstr "" + +#. module: allow_negative_leave_and_allocation +#. odoo-python +#: code:addons/allow_negative_leave_and_allocation/models/hr_leave_type.py:0 +#: code:addons/allow_negative_leave_and_allocation/models/hr_leave_type.py:0 +#, python-format +msgid " hours" +msgstr "" + +#. module: allow_negative_leave_and_allocation +#. odoo-python +#: code:addons/allow_negative_leave_and_allocation/models/hr_leave_type.py:0 +#: code:addons/allow_negative_leave_and_allocation/models/hr_leave_type.py:0 +#, python-format +msgid "%g remaining out of %g" +msgstr "" + #. module: allow_negative_leave_and_allocation #: model:ir.model.fields,field_description:allow_negative_leave_and_allocation.field_hr_leave_type__allows_negative msgid "Allow Negative Leaves" @@ -33,8 +57,15 @@ msgid "" msgstr "" #. module: allow_negative_leave_and_allocation -#: model:ir.model.constraint,message:allow_negative_leave_and_allocation.constraint_hr_leave_allocation_duration_check -msgid "The duration must be greater than 0." +#: model:ir.model.fields,field_description:allow_negative_leave_and_allocation.field_hr_leave_type__remaining_leaves_allowing_negative +msgid "Remaining Leaves when Negative Allowed" +msgstr "" + +#. module: allow_negative_leave_and_allocation +#: model:ir.model.fields,field_description:allow_negative_leave_and_allocation.field_hr_leave__smart_search +#: model:ir.model.fields,field_description:allow_negative_leave_and_allocation.field_hr_leave_allocation__smart_search +#: model:ir.model.fields,field_description:allow_negative_leave_and_allocation.field_hr_leave_type__smart_search +msgid "Smart Search" msgstr "" #. module: allow_negative_leave_and_allocation diff --git a/allow_negative_leave_and_allocation/i18n/fr.po b/allow_negative_leave_and_allocation/i18n/fr.po index d4331ed..cf6582a 100644 --- a/allow_negative_leave_and_allocation/i18n/fr.po +++ b/allow_negative_leave_and_allocation/i18n/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 16.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-01-02 12:11+0000\n" -"PO-Revision-Date: 2025-01-02 12:11+0000\n" +"POT-Creation-Date: 2025-10-24 07:49+0000\n" +"PO-Revision-Date: 2025-10-24 07:49+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -15,6 +15,30 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: allow_negative_leave_and_allocation +#. odoo-python +#: code:addons/allow_negative_leave_and_allocation/models/hr_leave_type.py:0 +#: code:addons/allow_negative_leave_and_allocation/models/hr_leave_type.py:0 +#, python-format +msgid " days" +msgstr "jours" + +#. module: allow_negative_leave_and_allocation +#. odoo-python +#: code:addons/allow_negative_leave_and_allocation/models/hr_leave_type.py:0 +#: code:addons/allow_negative_leave_and_allocation/models/hr_leave_type.py:0 +#, python-format +msgid " hours" +msgstr "heures" + +#. module: allow_negative_leave_and_allocation +#. odoo-python +#: code:addons/allow_negative_leave_and_allocation/models/hr_leave_type.py:0 +#: code:addons/allow_negative_leave_and_allocation/models/hr_leave_type.py:0 +#, python-format +msgid "%g remaining out of %g" +msgstr "%g restant sur %g" + #. module: allow_negative_leave_and_allocation #: model:ir.model.fields,field_description:allow_negative_leave_and_allocation.field_hr_leave_type__allows_negative msgid "Allow Negative Leaves" @@ -33,8 +57,15 @@ msgid "" msgstr "" #. module: allow_negative_leave_and_allocation -#: model:ir.model.constraint,message:allow_negative_leave_and_allocation.constraint_hr_leave_allocation_duration_check -msgid "The duration must be greater than 0." +#: model:ir.model.fields,field_description:allow_negative_leave_and_allocation.field_hr_leave_type__remaining_leaves_allowing_negative +msgid "Remaining Leaves when Negative Allowed" +msgstr "" + +#. module: allow_negative_leave_and_allocation +#: model:ir.model.fields,field_description:allow_negative_leave_and_allocation.field_hr_leave__smart_search +#: model:ir.model.fields,field_description:allow_negative_leave_and_allocation.field_hr_leave_allocation__smart_search +#: model:ir.model.fields,field_description:allow_negative_leave_and_allocation.field_hr_leave_type__smart_search +msgid "Smart Search" msgstr "" #. module: allow_negative_leave_and_allocation diff --git a/allow_negative_leave_and_allocation/models/hr_leave.py b/allow_negative_leave_and_allocation/models/hr_leave.py index 9c196bd..f7d1fb4 100644 --- a/allow_negative_leave_and_allocation/models/hr_leave.py +++ b/allow_negative_leave_and_allocation/models/hr_leave.py @@ -10,7 +10,7 @@ class HrLeave(models.Model): @api.constrains('state', 'number_of_days', 'holiday_status_id') def _check_holidays(self): - # On ne garde que les congés qui ne permettent pas le négatif + # Keep only leaves that do not allow negative balances to_check = self.filtered(lambda h: not h.holiday_status_id.allows_negative) if to_check: super(HrLeave, to_check)._check_holidays() \ No newline at end of file diff --git a/allow_negative_leave_and_allocation/models/hr_leave_type.py b/allow_negative_leave_and_allocation/models/hr_leave_type.py index e90d35c..dc0e2a9 100644 --- a/allow_negative_leave_and_allocation/models/hr_leave_type.py +++ b/allow_negative_leave_and_allocation/models/hr_leave_type.py @@ -2,7 +2,12 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from collections import defaultdict +from datetime import time, timedelta + from odoo import api, fields, models +from odoo.tools.translate import _ +from odoo.tools.float_utils import float_round class HolidaysType(models.Model): @@ -12,6 +17,23 @@ class HolidaysType(models.Model): allows_negative = fields.Boolean(string='Allow Negative Leaves', help="If checked, users request can exceed the allocated days and balance can go in negative.") + remaining_leaves_allowing_negative = fields.Float( + string="Remaining Leaves when Negative Allowed", + compute='_compute_remaining_leaves_allowing_negative', + ) + + def _compute_remaining_leaves_allowing_negative(self): + for holiday_type in self: + if holiday_type.allows_negative: + # if left != usable : remaining_leaves_allowing_negative = left + usable + if (holiday_type.max_leaves - holiday_type.virtual_leaves_taken) != holiday_type.virtual_remaining_leaves: + holiday_type.remaining_leaves_allowing_negative = holiday_type.max_leaves - holiday_type.virtual_leaves_taken + holiday_type.virtual_remaining_leaves + else: + # else : remaining_leaves_allowing_negative = left + holiday_type.remaining_leaves_allowing_negative = holiday_type.max_leaves - holiday_type.virtual_leaves_taken + else: + holiday_type.remaining_leaves_allowing_negative = None + @api.depends('requires_allocation') def _compute_valid(self): res = super()._compute_valid() @@ -21,5 +43,39 @@ class HolidaysType(models.Model): def _get_days_request(self): res = super()._get_days_request() + print('res=', res) res[1]['allows_negative'] = self.allows_negative + res[1]['remaining_leaves_negative'] = ('%.2f' % (self.remaining_leaves_allowing_negative)).rstrip('0').rstrip('.'), + # if left != usable : recalculate leaves_approved, virtual_remaining_leaves and usable_remaining_leaves + if self.allows_negative and ((self.max_leaves - self.virtual_leaves_taken) != self.virtual_remaining_leaves): + res[1]['virtual_remaining_leaves'] = ('%.2f' % (self.remaining_leaves_allowing_negative)).rstrip('0').rstrip('.'), + res[1]['usable_remaining_leaves'] = ('%.2f' % (self.remaining_leaves_allowing_negative)).rstrip('0').rstrip('.'), + res[1]['leaves_approved'] = ('%.2f' % (abs(self.virtual_remaining_leaves) - abs(self.leaves_taken))).rstrip('0').rstrip('.'), + return res + + def name_get(self): + '''Override name_get to display remaining leaves in the selection list.''' + if not self.requested_name_get(): + return super().name_get() + res = [] + for record in self: + name = record.name + if record.requires_allocation == "yes" and not self._context.get('from_manager_leave_form'): + if record.allows_negative: + name = "%(name)s (%(count)s)" % { + 'name': name, + 'count': _('%g remaining out of %g') % ( + float_round(record.remaining_leaves_allowing_negative, precision_digits=2) or 0.0, + float_round(record.max_leaves, precision_digits=2) or 0.0, + ) + (_(' hours') if record.request_unit == 'hour' else _(' days')) + } + else : + name = "%(name)s (%(count)s)" % { + 'name': name, + 'count': _('%g remaining out of %g') % ( + float_round(record.virtual_remaining_leaves, precision_digits=2) or 0.0, + float_round(record.max_leaves, precision_digits=2) or 0.0, + ) + (_(' hours') if record.request_unit == 'hour' else _(' days')) + } + res.append((record.id, name)) return res diff --git a/allow_negative_leave_and_allocation/static/src/xml/time_off_card.xml b/allow_negative_leave_and_allocation/static/src/xml/time_off_card.xml index f0bf77c..f9871ce 100644 --- a/allow_negative_leave_and_allocation/static/src/xml/time_off_card.xml +++ b/allow_negative_leave_and_allocation/static/src/xml/time_off_card.xml @@ -1,8 +1,10 @@