[WIP]allow_negative_leave_and_allocation

This commit is contained in:
2025-10-24 10:26:34 +02:00
parent f7c7496492
commit d340a931de
6 changed files with 133 additions and 13 deletions

View File

@@ -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",

View File

@@ -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

View File

@@ -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

View File

@@ -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()

View File

@@ -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

View File

@@ -1,8 +1,10 @@
<template>
<t t-name="allow_negative_leave_and_allocation.TimeOffCard" t-inherit="hr_holidays.TimeOffCard" t-inherit-mode="extension" owl="1">
<t t-name="allow_negative_leave_and_allocation.TimeOffCard" t-inherit="hr_holidays.TimeOffCard"
t-inherit-mode="extension" owl="1">
<xpath expr="//t[@t-set='duration']" position="replace">
<t t-set="duration" t-value="props.requires_allocation
? (props.data['allows_negative'] ? data.usable_remaining_leaves : data.virtual_remaining_leaves)
<t t-set="duration"
t-value="props.requires_allocation
? (props.data['allows_negative'] ? data.remaining_leaves_negative : data.virtual_remaining_leaves)
: data.virtual_leaves_taken" />
</xpath>
</t>