From 710496a95564e6962be16faea370ad4aa1fae368 Mon Sep 17 00:00:00 2001
From: LauraCForgeFlow
Date: Tue, 8 Oct 2024 13:47:44 +0200
Subject: [PATCH] [MIG] hr_holidays_credit: Migration to 16.0
---
hr_holidays_credit/README.rst | 10 +-
hr_holidays_credit/__manifest__.py | 7 +-
hr_holidays_credit/i18n/es.po | 65 +++---
.../i18n/hr_holidays_credit.pot | 51 +++--
hr_holidays_credit/models/__init__.py | 1 +
hr_holidays_credit/models/hr_leave.py | 44 ++--
.../models/hr_leave_allocation.py | 17 ++
hr_holidays_credit/models/hr_leave_type.py | 42 ++--
.../static/description/index.html | 7 +-
.../tests/test_hr_holidays_credit.py | 209 +++++++++++++-----
hr_holidays_credit/views/hr_leave_type.xml | 10 +-
hr_holidays_credit/views/hr_leave_views.xml | 20 ++
.../odoo/addons/hr_holidays_credit | 1 +
setup/hr_holidays_credit/setup.py | 6 +
14 files changed, 343 insertions(+), 147 deletions(-)
create mode 100644 hr_holidays_credit/models/hr_leave_allocation.py
create mode 100644 hr_holidays_credit/views/hr_leave_views.xml
create mode 120000 setup/hr_holidays_credit/odoo/addons/hr_holidays_credit
create mode 100644 setup/hr_holidays_credit/setup.py
diff --git a/hr_holidays_credit/README.rst b/hr_holidays_credit/README.rst
index 9f62550f..fe3cefc2 100644
--- a/hr_holidays_credit/README.rst
+++ b/hr_holidays_credit/README.rst
@@ -17,13 +17,13 @@ Leave Credit
: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--holidays-lightgray.png?logo=github
- :target: https://github.com/OCA/hr-holidays/tree/14.0/hr_holidays_credit
+ :target: https://github.com/OCA/hr-holidays/tree/16.0/hr_holidays_credit
:alt: OCA/hr-holidays
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/hr-holidays-14-0/hr-holidays-14-0-hr_holidays_credit
+ :target: https://translation.odoo-community.org/projects/hr-holidays-16-0/hr-holidays-16-0-hr_holidays_credit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
- :target: https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&target_branch=14.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&target_branch=16.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -42,7 +42,7 @@ Bug Tracker
Bugs are tracked on `GitHub 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 `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -79,6 +79,6 @@ 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-holidays `_ project on GitHub.
+This module is part of the `OCA/hr-holidays `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/hr_holidays_credit/__manifest__.py b/hr_holidays_credit/__manifest__.py
index b50bdc0b..c41b23d3 100644
--- a/hr_holidays_credit/__manifest__.py
+++ b/hr_holidays_credit/__manifest__.py
@@ -4,7 +4,7 @@
{
"name": "Leave Credit",
- "version": "14.0.1.0.0",
+ "version": "16.0.1.0.0",
"category": "Human Resources",
"website": "https://github.com/OCA/hr-holidays",
"author": "CorporateHub, Odoo Community Association (OCA)",
@@ -13,5 +13,8 @@
"application": False,
"summary": "Enable negative leave balance for employees",
"depends": ["hr_holidays"],
- "data": ["views/hr_leave_type.xml"],
+ "data": [
+ "views/hr_leave_type.xml",
+ "views/hr_leave_views.xml",
+ ],
}
diff --git a/hr_holidays_credit/i18n/es.po b/hr_holidays_credit/i18n/es.po
index dde83d0b..75cfca0b 100644
--- a/hr_holidays_credit/i18n/es.po
+++ b/hr_holidays_credit/i18n/es.po
@@ -17,28 +17,48 @@ msgstr ""
"X-Generator: Weblate 4.17\n"
#. module: hr_holidays_credit
+#. odoo-python
#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
#, python-format
-msgid "%(name)s (%(extra)s)"
-msgstr "%(name)s (%(extra)s)"
+msgid " + credit"
+msgstr " + crédito"
+
+#. module: hr_holidays_credit
+#. odoo-python
+#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
+#, python-format
+msgid " available"
+msgstr " disponibles"
+
+#. module: hr_holidays_credit
+#. odoo-python
+#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
+#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
+#, python-format
+msgid " days"
+msgstr " días"
#. module: hr_holidays_credit
+#. odoo-python
+#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
#, python-format
-msgid "%g available"
-msgstr "%g disponible"
+msgid " hours"
+msgstr " horas"
#. module: hr_holidays_credit
+#. odoo-python
#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
#, python-format
-msgid "%g available + credit"
-msgstr "%g disponible + crédito"
+msgid " used in credit"
+msgstr " utilizados en crédito"
#. module: hr_holidays_credit
+#. odoo-python
#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
#, python-format
-msgid "%g used in credit"
-msgstr "%g utilizado en el crédito"
+msgid "%(name)s (%(extra)s)"
+msgstr "%(name)s (%(extra)s)"
#. module: hr_holidays_credit
#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave_type__allow_credit
@@ -60,26 +80,14 @@ msgstr "Etiquetas de Empleado Acreditable"
msgid "Creditable Employees"
msgstr "Empleados Acreditados"
-#. module: hr_holidays_credit
-#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave__display_name
-#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave_type__display_name
-msgid "Display Name"
-msgstr "Mostrar Nombre"
-
-#. module: hr_holidays_credit
-#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave__id
-#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave_type__id
-msgid "ID"
-msgstr "ID"
-
#. module: hr_holidays_credit
#: model:ir.model.fields,help:hr_holidays_credit.field_hr_leave_type__allow_credit
msgid ""
"If set to true, employees would be able to make requests for this leave type"
" even if allocated amount is insufficient."
msgstr ""
-"Si se establece en true, los empleados podrán solicitar este tipo de permiso "
-"aunque la cantidad asignada sea insuficiente."
+"Si se establece en true, los empleados podrán solicitar este tipo de permiso"
+" aunque la cantidad asignada sea insuficiente."
#. module: hr_holidays_credit
#: model:ir.model.fields,help:hr_holidays_credit.field_hr_leave_type__creditable_department_ids
@@ -102,18 +110,19 @@ msgstr ""
msgid "If set, limits credit allowance to specified employees"
msgstr "Si se fija, limita la concesión de créditos a determinados empleados"
-#. module: hr_holidays_credit
-#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave____last_update
-#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave_type____last_update
-msgid "Last Modified on"
-msgstr "Última Modificación el"
-
#. module: hr_holidays_credit
#: model:ir.model,name:hr_holidays_credit.model_hr_leave
msgid "Time Off"
msgstr "Tiempo Libre"
+#. module: hr_holidays_credit
+#: model:ir.model,name:hr_holidays_credit.model_hr_leave_allocation
+msgid "Time Off Allocation"
+msgstr "Asignación de ausencias"
+
#. module: hr_holidays_credit
#: model:ir.model,name:hr_holidays_credit.model_hr_leave_type
+#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave__holiday_status_id
+#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave_allocation__holiday_status_id
msgid "Time Off Type"
msgstr "Tipo de Tiempo Libre"
diff --git a/hr_holidays_credit/i18n/hr_holidays_credit.pot b/hr_holidays_credit/i18n/hr_holidays_credit.pot
index 27c6af7f..6ef75a73 100644
--- a/hr_holidays_credit/i18n/hr_holidays_credit.pot
+++ b/hr_holidays_credit/i18n/hr_holidays_credit.pot
@@ -14,27 +14,47 @@ msgstr ""
"Plural-Forms: \n"
#. module: hr_holidays_credit
+#. odoo-python
#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
#, python-format
-msgid "%(name)s (%(extra)s)"
+msgid " + credit"
+msgstr ""
+
+#. module: hr_holidays_credit
+#. odoo-python
+#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
+#, python-format
+msgid " available"
+msgstr ""
+
+#. module: hr_holidays_credit
+#. odoo-python
+#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
+#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
+#, python-format
+msgid " days"
msgstr ""
#. module: hr_holidays_credit
+#. odoo-python
+#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
#, python-format
-msgid "%g available"
+msgid " hours"
msgstr ""
#. module: hr_holidays_credit
+#. odoo-python
#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
#, python-format
-msgid "%g available + credit"
+msgid " used in credit"
msgstr ""
#. module: hr_holidays_credit
+#. odoo-python
#: code:addons/hr_holidays_credit/models/hr_leave_type.py:0
#, python-format
-msgid "%g used in credit"
+msgid "%(name)s (%(extra)s)"
msgstr ""
#. module: hr_holidays_credit
@@ -57,18 +77,6 @@ msgstr ""
msgid "Creditable Employees"
msgstr ""
-#. module: hr_holidays_credit
-#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave__display_name
-#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave_type__display_name
-msgid "Display Name"
-msgstr ""
-
-#. module: hr_holidays_credit
-#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave__id
-#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave_type__id
-msgid "ID"
-msgstr ""
-
#. module: hr_holidays_credit
#: model:ir.model.fields,help:hr_holidays_credit.field_hr_leave_type__allow_credit
msgid ""
@@ -94,17 +102,18 @@ msgid "If set, limits credit allowance to specified employees"
msgstr ""
#. module: hr_holidays_credit
-#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave____last_update
-#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave_type____last_update
-msgid "Last Modified on"
+#: model:ir.model,name:hr_holidays_credit.model_hr_leave
+msgid "Time Off"
msgstr ""
#. module: hr_holidays_credit
-#: model:ir.model,name:hr_holidays_credit.model_hr_leave
-msgid "Time Off"
+#: model:ir.model,name:hr_holidays_credit.model_hr_leave_allocation
+msgid "Time Off Allocation"
msgstr ""
#. module: hr_holidays_credit
#: model:ir.model,name:hr_holidays_credit.model_hr_leave_type
+#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave__holiday_status_id
+#: model:ir.model.fields,field_description:hr_holidays_credit.field_hr_leave_allocation__holiday_status_id
msgid "Time Off Type"
msgstr ""
diff --git a/hr_holidays_credit/models/__init__.py b/hr_holidays_credit/models/__init__.py
index 5501fafd..8ce91fe6 100644
--- a/hr_holidays_credit/models/__init__.py
+++ b/hr_holidays_credit/models/__init__.py
@@ -1,4 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import hr_leave_type
+from . import hr_leave_allocation
from . import hr_leave
diff --git a/hr_holidays_credit/models/hr_leave.py b/hr_holidays_credit/models/hr_leave.py
index f727a919..38387f7b 100644
--- a/hr_holidays_credit/models/hr_leave.py
+++ b/hr_holidays_credit/models/hr_leave.py
@@ -1,39 +1,57 @@
# Copyright (C) 2018 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import api, models
+from odoo import api, fields, models
class HrLeave(models.Model):
_inherit = "hr.leave"
+ holiday_status_id = fields.Many2one(
+ domain=[
+ "|",
+ ("has_valid_allocation", "=", True),
+ "|",
+ ("requires_allocation", "=", "no"),
+ ("allow_credit", "=", True),
+ ]
+ )
+
@api.constrains("state", "number_of_days", "holiday_status_id")
def _check_holidays(self):
uncreditable_requests = self.filtered(
lambda holiday: not holiday._is_holiday_credit_allowed()
)
+ return super(HrLeave, uncreditable_requests)._check_holidays()
- super(HrLeave, uncreditable_requests)._check_holidays()
+ def _check_overtime_deductible(self, leaves):
+ uncreditable_leaves = leaves.filtered(
+ lambda holiday: not holiday._is_holiday_credit_allowed()
+ )
+ return super()._check_overtime_deductible(uncreditable_leaves)
def _is_holiday_credit_allowed(self):
self.ensure_one()
-
leave_type = self.holiday_status_id
-
if not leave_type.allow_credit:
return False
- if self.employee_id in leave_type.creditable_employee_ids:
+ hr_leave_employees = set(self.employee_ids.ids)
+ hr_leave_type_employees = set(leave_type.creditable_employee_ids.ids)
+ same_employees = hr_leave_employees.issubset(hr_leave_type_employees)
+ if same_employees:
return True
-
- if self.employee_id in (
- leave_type.creditable_employee_category_ids.mapped("employee_ids")
- ):
+ hr_leave_type_cat_employees = set(
+ leave_type.creditable_employee_category_ids.mapped("employee_ids").ids
+ )
+ same_employees_cat = hr_leave_employees.issubset(hr_leave_type_cat_employees)
+ if same_employees_cat:
return True
-
- if self.employee_id in (
- leave_type.creditable_department_ids.mapped("member_ids")
- ):
+ hr_leave_type_dpt_employees = set(
+ leave_type.creditable_department_ids.mapped("member_ids").ids
+ )
+ same_employees_dpt = hr_leave_employees.issubset(hr_leave_type_dpt_employees)
+ if same_employees_dpt:
return True
return (
diff --git a/hr_holidays_credit/models/hr_leave_allocation.py b/hr_holidays_credit/models/hr_leave_allocation.py
new file mode 100644
index 00000000..a71b0ef9
--- /dev/null
+++ b/hr_holidays_credit/models/hr_leave_allocation.py
@@ -0,0 +1,17 @@
+# Copyright (C) 2018 Brainbean Apps (https://brainbeanapps.com)
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import fields, models
+from odoo.osv import expression
+
+
+class HolidaysAllocation(models.Model):
+ _inherit = "hr.leave.allocation"
+
+ def _domain_holiday_status_id(self):
+ res = super(HolidaysAllocation, self)._domain_holiday_status_id()
+ return expression.OR([[("allow_credit", "=", True)], res])
+
+ holiday_status_id = fields.Many2one(
+ "hr.leave.type", domain=_domain_holiday_status_id
+ )
diff --git a/hr_holidays_credit/models/hr_leave_type.py b/hr_holidays_credit/models/hr_leave_type.py
index 8063ce23..ca30fc24 100644
--- a/hr_holidays_credit/models/hr_leave_type.py
+++ b/hr_holidays_credit/models/hr_leave_type.py
@@ -1,7 +1,7 @@
# Copyright (C) 2018 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import _, fields, models
+from odoo import _, api, fields, models
from odoo.tools.float_utils import float_round
@@ -9,7 +9,6 @@ class HrLeaveType(models.Model):
_inherit = "hr.leave.type"
allow_credit = fields.Boolean(
- string="Allow Credit",
help=(
"If set to true, employees would be able to make requests for this"
" leave type even if allocated amount is insufficient."
@@ -31,41 +30,50 @@ class HrLeaveType(models.Model):
creditable_department_ids = fields.Many2many(
string="Creditable Departments",
comodel_name="hr.department",
- help=("If set, limits credit allowance to employees of specified departments"),
+ help="If set, limits credit allowance to employees of specified departments",
)
- def name_get(self):
- context_employee_id = self._context.get("employee_id")
+ @api.onchange("requires_allocation", "allocation_validation_type")
+ def _onchange_allow_credit(self):
+ if self.requires_allocation == "no" or self.allocation_validation_type == "no":
+ self.allow_credit = False
+ def name_get(self):
+ if not self.requested_name_get():
+ return super().name_get()
res = []
for record in self:
record_name = record.name
-
- extra = None
- if record.allocation_type != "no" and context_employee_id:
+ extra = False
+ if record.requires_allocation == "yes":
if record.virtual_remaining_leaves >= 0:
+ extra = _("%g")
+ extra += (
+ _(" hours") if record.request_unit == "hour" else _(" days")
+ )
+ extra += _(" available")
if record.allow_credit:
- extra = _("%g available + credit")
- else:
- extra = _("%g available")
+ extra += _(" + credit")
extra = extra % (
float_round(record.virtual_remaining_leaves, precision_digits=2)
- or 0.0,
+ or 0.0
)
elif record.allow_credit:
- extra = _("%g used in credit") % (
+ extra = _("%g")
+ extra += (
+ _(" hours") if record.request_unit == "hour" else _(" days")
+ )
+ extra += _(" used in credit")
+ extra = extra % (
float_round(
-record.virtual_remaining_leaves, precision_digits=2
)
- or 0.0,
+ or 0.0
)
-
if extra:
record_name = _("%(name)s (%(extra)s)") % {
"name": record_name,
"extra": extra,
}
-
res.append((record.id, record_name))
-
return res
diff --git a/hr_holidays_credit/static/description/index.html b/hr_holidays_credit/static/description/index.html
index b07ed766..25da82f1 100644
--- a/hr_holidays_credit/static/description/index.html
+++ b/hr_holidays_credit/static/description/index.html
@@ -1,4 +1,3 @@
-
@@ -369,7 +368,7 @@ Leave Credit
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:938aee0bf51e9b55127b2f4f5981ae659ebde9ab8d55a1af3b0463f1e28e4bd4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
With this module installed, HR Officer can configure specific leave types to
allow negative balance, or allow employees take leave credit.
Table of contents
@@ -389,7 +388,7 @@
Bugs are tracked on GitHub 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.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -421,7 +420,7 @@
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-holidays project on GitHub.
+
This module is part of the OCA/hr-holidays project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/hr_holidays_credit/tests/test_hr_holidays_credit.py b/hr_holidays_credit/tests/test_hr_holidays_credit.py
index b2b4b134..d2c06438 100644
--- a/hr_holidays_credit/tests/test_hr_holidays_credit.py
+++ b/hr_holidays_credit/tests/test_hr_holidays_credit.py
@@ -10,68 +10,109 @@
class TestHrHolidaysCredit(common.TransactionCase):
- def setUp(self):
- super().setUp()
-
- self.Employee = self.env["hr.employee"]
- self.SudoEmployee = self.Employee.sudo()
- self.Department = self.env["hr.department"]
- self.SudoDepartment = self.Department.sudo()
- self.LeaveType = self.env["hr.leave.type"]
- self.SudoLeaveType = self.LeaveType.sudo()
- self.Leave = self.env["hr.leave"]
- self.SudoLeave = self.Leave.sudo()
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ cls.Employee = cls.env["hr.employee"]
+ cls.SudoEmployee = cls.Employee.sudo()
+ cls.Department = cls.env["hr.department"]
+ cls.SudoDepartment = cls.Department.sudo()
+
+ cls.LeaveType = cls.env["hr.leave.type"]
+ cls.SudoLeaveType = cls.LeaveType.sudo()
+ cls.Leave = cls.env["hr.leave"]
+ cls.SudoLeave = cls.Leave.sudo()
+ cls.Allocation = cls.env["hr.leave.allocation"]
+ cls.SudoAllocation = cls.Allocation.sudo()
def test_1(self):
employee = self.SudoEmployee.create({"name": "Employee #1"})
leave_type = self.SudoLeaveType.create(
{
"name": "Leave Type #1",
- "allocation_type": "fixed",
+ "requires_allocation": "yes",
+ "allocation_validation_type": "officer",
"allow_credit": False,
}
)
+ allocation = self.SudoAllocation.create(
+ {
+ "holiday_status_id": leave_type.id,
+ "number_of_days": 5,
+ "employee_id": employee.id,
+ "date_from": "2020-01-01",
+ "date_to": "2020-12-31",
+ }
+ )
+ allocation.action_confirm()
+ allocation.action_validate()
+
with self.assertRaises(ValidationError):
self.SudoLeave.create(
{
"holiday_status_id": leave_type.id,
"holiday_type": "employee",
"employee_id": employee.id,
- "number_of_days": 1,
+ "date_from": "2020-01-01",
+ "date_to": "2020-01-10",
}
)
- def test_2(self):
- employee = self.SudoEmployee.create({"name": "Employee #2"})
- leave_type = self.SudoLeaveType.create(
- {"name": "Leave Type #2", "allocation_type": "fixed", "allow_credit": True}
- )
-
+ leave_type.write({"allow_credit": True})
self.SudoLeave.create(
{
"holiday_status_id": leave_type.id,
"holiday_type": "employee",
"employee_id": employee.id,
- "number_of_days": 1,
+ "date_from": "2020-01-01",
+ "date_to": "2020-01-10",
}
)
- def test_3(self):
- department = self.SudoDepartment.create({"name": "Department #3"})
+ def test_2(self):
+ department = self.SudoDepartment.create({"name": "Department #2"})
employee_1 = self.SudoEmployee.create(
- {"name": "Employee #3-1", "department_id": department.id}
+ {"name": "Employee #2-1", "department_id": department.id}
)
- employee_2 = self.SudoEmployee.create({"name": "Employee #3-2"})
+ employee_2 = self.SudoEmployee.create(
+ {"name": "Employee #2-2", "department_id": False}
+ )
+
leave_type = self.SudoLeaveType.create(
{
- "name": "Leave Type #3",
- "allocation_type": "fixed",
+ "name": "Leave Type #2",
+ "requires_allocation": "yes",
+ "allocation_validation_type": "officer",
"allow_credit": True,
"creditable_department_ids": [(6, False, [department.id])],
}
)
+ allocation_1 = self.SudoAllocation.create(
+ {
+ "holiday_status_id": leave_type.id,
+ "number_of_days": 5,
+ "employee_id": employee_1.id,
+ "date_from": "2020-01-01",
+ "date_to": "2020-12-31",
+ }
+ )
+ allocation_2 = self.SudoAllocation.create(
+ {
+ "holiday_status_id": leave_type.id,
+ "number_of_days": 5,
+ "employee_id": employee_2.id,
+ "date_from": "2020-01-01",
+ "date_to": "2020-12-31",
+ }
+ )
+
+ allocation_1.action_confirm()
+ allocation_1.action_validate()
+ allocation_2.action_confirm()
+ allocation_2.action_validate()
+
self.SudoLeave.create(
{
"holiday_status_id": leave_type.id,
@@ -80,7 +121,6 @@ def test_3(self):
"number_of_days": 1,
}
)
-
with self.assertRaises(ValidationError):
self.SudoLeave.create(
{
@@ -91,18 +131,43 @@ def test_3(self):
}
)
- def test_4(self):
- employee_1 = self.SudoEmployee.create({"name": "Employee #4-1"})
- employee_2 = self.SudoEmployee.create({"name": "Employee #4-2"})
+ def test_3(self):
+ employee_1 = self.SudoEmployee.create({"name": "Employee #3-1"})
+ employee_2 = self.SudoEmployee.create({"name": "Employee #3-2"})
leave_type = self.SudoLeaveType.create(
{
- "name": "Leave Type #4",
- "allocation_type": "fixed",
+ "name": "Leave Type #3",
+ "requires_allocation": "yes",
+ "allocation_validation_type": "officer",
"allow_credit": True,
"creditable_employee_ids": [(6, False, [employee_1.id])],
}
)
+ allocation_1 = self.SudoAllocation.create(
+ {
+ "holiday_status_id": leave_type.id,
+ "number_of_days": 5,
+ "employee_id": employee_1.id,
+ "date_from": "2020-01-01",
+ "date_to": "2020-12-31",
+ }
+ )
+ allocation_2 = self.SudoAllocation.create(
+ {
+ "holiday_status_id": leave_type.id,
+ "number_of_days": 5,
+ "employee_id": employee_2.id,
+ "date_from": "2020-01-01",
+ "date_to": "2020-12-31",
+ }
+ )
+
+ allocation_1.action_confirm()
+ allocation_1.action_validate()
+ allocation_2.action_confirm()
+ allocation_2.action_validate()
+
self.SudoLeave.create(
{
"holiday_status_id": leave_type.id,
@@ -111,7 +176,6 @@ def test_4(self):
"number_of_days": 1,
}
)
-
with self.assertRaises(ValidationError):
self.SudoLeave.create(
{
@@ -122,37 +186,68 @@ def test_4(self):
}
)
- def test_5(self):
- employee = self.SudoEmployee.create({"name": "Employee #5"})
+ def test_4(self):
+ employee = self.SudoEmployee.create({"name": "Employee #4"})
leave_type = self.SudoLeaveType.create(
{
- "name": "Leave Type #5",
- "allocation_type": "fixed",
+ "name": "Leave Type #4",
+ "requires_allocation": "yes",
+ "allocation_validation_type": "officer",
"allow_credit": False,
}
)
- name = leave_type.with_context(employee_id=employee.id,).name_get()[
- 0
- ][1]
+ allocation = self.SudoAllocation.create(
+ {
+ "holiday_status_id": leave_type.id,
+ "number_of_days": 5,
+ "employee_id": employee.id,
+ "date_from": "2020-01-01",
+ "date_to": "2020-12-31",
+ }
+ )
+ allocation.action_confirm()
+ allocation.action_validate()
+
+ name = leave_type.with_context(employee_id=employee.id).name_get()[0][1]
self.assertTrue("available" in name)
self.assertTrue("credit" not in name)
- def test_6(self):
- employee = self.SudoEmployee.create({"name": "Employee #6"})
+ def test_5(self):
+ employee = self.SudoEmployee.create({"name": "Employee #5"})
leave_type = self.SudoLeaveType.create(
- {"name": "Leave Type #6", "allocation_type": "fixed", "allow_credit": True}
+ {
+ "name": "Leave Type #5",
+ "requires_allocation": "yes",
+ "allocation_validation_type": "officer",
+ "allow_credit": True,
+ }
)
- name = leave_type.with_context(employee_id=employee.id,).name_get()[
- 0
- ][1]
+ allocation = self.SudoAllocation.create(
+ {
+ "holiday_status_id": leave_type.id,
+ "number_of_days": 5,
+ "employee_id": employee.id,
+ "date_from": "2020-01-01",
+ "date_to": "2020-12-31",
+ }
+ )
+ allocation.action_confirm()
+ allocation.action_validate()
+
+ name = leave_type.with_context(employee_id=employee.id).name_get()[0][1]
self.assertTrue("available + credit" in name)
- def test_7(self):
- employee = self.SudoEmployee.create({"name": "Employee #7"})
+ def test_6(self):
+ employee = self.SudoEmployee.create({"name": "Employee #6"})
leave_type = self.SudoLeaveType.create(
- {"name": "Leave Type #7", "allocation_type": "fixed", "allow_credit": True}
+ {
+ "name": "Leave Type #6",
+ "requires_allocation": "yes",
+ "allocation_validation_type": "officer",
+ "allow_credit": True,
+ }
)
self.SudoLeave.create(
{
@@ -163,7 +258,17 @@ def test_7(self):
}
)
- name = leave_type.with_context(employee_id=employee.id,).name_get()[
- 0
- ][1]
+ allocation = self.SudoAllocation.create(
+ {
+ "holiday_status_id": leave_type.id,
+ "number_of_days": 5,
+ "employee_id": employee.id,
+ "date_from": "2020-01-01",
+ "date_to": "2020-12-31",
+ }
+ )
+ allocation.action_confirm()
+ allocation.action_validate()
+
+ name = leave_type.with_context(employee_id=employee.id).name_get()[0][1]
self.assertTrue("used in credit" in name)
diff --git a/hr_holidays_credit/views/hr_leave_type.xml b/hr_holidays_credit/views/hr_leave_type.xml
index 466d26c5..bd93e9e1 100644
--- a/hr_holidays_credit/views/hr_leave_type.xml
+++ b/hr_holidays_credit/views/hr_leave_type.xml
@@ -9,25 +9,25 @@
hr.leave.type
-
+
diff --git a/hr_holidays_credit/views/hr_leave_views.xml b/hr_holidays_credit/views/hr_leave_views.xml
new file mode 100644
index 00000000..d0a957ea
--- /dev/null
+++ b/hr_holidays_credit/views/hr_leave_views.xml
@@ -0,0 +1,20 @@
+
+
+
+
+ hr.leave.view.form
+ hr.leave
+
+
+
+ ['|', ('requires_allocation', '=', 'no'), '|', ("allow_credit", "=", True), '&', ('has_valid_allocation', '=', True), '&', ('max_leaves', '>', '0'), ('virtual_remaining_leaves', '>', 0)]
+
+
+
+
+
diff --git a/setup/hr_holidays_credit/odoo/addons/hr_holidays_credit b/setup/hr_holidays_credit/odoo/addons/hr_holidays_credit
new file mode 120000
index 00000000..98f6887a
--- /dev/null
+++ b/setup/hr_holidays_credit/odoo/addons/hr_holidays_credit
@@ -0,0 +1 @@
+../../../../hr_holidays_credit
\ No newline at end of file
diff --git a/setup/hr_holidays_credit/setup.py b/setup/hr_holidays_credit/setup.py
new file mode 100644
index 00000000..28c57bb6
--- /dev/null
+++ b/setup/hr_holidays_credit/setup.py
@@ -0,0 +1,6 @@
+import setuptools
+
+setuptools.setup(
+ setup_requires=['setuptools-odoo'],
+ odoo_addon=True,
+)