[FIX] hr_holidays : Remove automatic notification if no responsible_ids is set
Currently in hr_leaves_type, if no responsible_ids are set, all members of group_hr_holidays_user would get notified, the new behavior changes that to : If no responsible_ids are set, no one is notified. Some unit tests had to be adapted to this new flow, since they were sometimes getting created with no responsible_id assigned, leading to no one being notified. task-3284318 closes odoo/odoo#125738 X-original-commit: fb1a6a8f0072398c57508b59724fcbde9a34b124 Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
@@ -1360,8 +1360,8 @@ msgstr ""
|
||||
#. module: hr_holidays
|
||||
#: model:ir.model.fields,help:hr_holidays.field_hr_leave_type__responsible_ids
|
||||
msgid ""
|
||||
"Choose the Time Off Officer who will be notified to approve allocation or "
|
||||
"Time Off request"
|
||||
"Choose the Time Off Officers who will be notified to approve allocation or "
|
||||
"Time Off Request. If empty, nobody will be notified"
|
||||
msgstr ""
|
||||
|
||||
#. module: hr_holidays
|
||||
@@ -3018,7 +3018,7 @@ msgstr ""
|
||||
|
||||
#. module: hr_holidays
|
||||
#: model:ir.model.fields,field_description:hr_holidays.field_hr_leave_type__responsible_ids
|
||||
msgid "Responsible Time Off Officer"
|
||||
msgid "Notified Time Off Officer"
|
||||
msgstr ""
|
||||
|
||||
#. module: hr_holidays
|
||||
|
||||
@@ -1588,8 +1588,7 @@ class HolidaysRequest(models.Model):
|
||||
elif self.validation_type == 'hr' or (self.validation_type == 'both' and self.state == 'validate1'):
|
||||
if self.holiday_status_id.responsible_ids:
|
||||
responsible = self.holiday_status_id.responsible_ids
|
||||
else:
|
||||
responsible = self.env.ref('hr_holidays.group_hr_holidays_user').users.filtered(lambda u: self.holiday_status_id.company_id in u.company_ids)
|
||||
|
||||
return responsible
|
||||
|
||||
def activity_update(self):
|
||||
@@ -1604,16 +1603,17 @@ class HolidaysRequest(models.Model):
|
||||
if holiday.state == 'draft':
|
||||
to_clean |= holiday
|
||||
elif holiday.state == 'confirm':
|
||||
user_ids = holiday.sudo()._get_responsible_for_approval().ids or self.env.user.ids
|
||||
for user_id in user_ids:
|
||||
activity_vals.append({
|
||||
'activity_type_id': self.env.ref('hr_holidays.mail_act_leave_approval').id,
|
||||
'automated': True,
|
||||
'note': note,
|
||||
'user_id': user_id,
|
||||
'res_id': holiday.id,
|
||||
'res_model_id': self.env.ref('hr_holidays.model_hr_leave').id,
|
||||
})
|
||||
if holiday.holiday_status_id.responsible_ids:
|
||||
user_ids = holiday.sudo()._get_responsible_for_approval().ids or self.env.user.ids
|
||||
for user_id in user_ids:
|
||||
activity_vals.append({
|
||||
'activity_type_id': self.env.ref('hr_holidays.mail_act_leave_approval').id,
|
||||
'automated': True,
|
||||
'note': note,
|
||||
'user_id': user_id,
|
||||
'res_id': holiday.id,
|
||||
'res_model_id': self.env.ref('hr_holidays.model_hr_leave').id,
|
||||
})
|
||||
elif holiday.state == 'validate':
|
||||
to_do |= holiday
|
||||
elif holiday.state == 'refuse':
|
||||
|
||||
@@ -757,9 +757,6 @@ class HolidaysAllocation(models.Model):
|
||||
if self.validation_type == 'officer' or self.validation_type == 'set':
|
||||
if self.holiday_status_id.responsible_ids:
|
||||
responsible = self.holiday_status_id.responsible_ids
|
||||
else:
|
||||
responsible = self.env.ref('hr_holidays.group_hr_holidays_user').users.filtered(lambda u: self.holiday_status_id.company_id in u.company_ids)
|
||||
|
||||
return responsible
|
||||
|
||||
def activity_update(self):
|
||||
@@ -776,16 +773,17 @@ class HolidaysAllocation(models.Model):
|
||||
if allocation.state == 'draft':
|
||||
to_clean |= allocation
|
||||
elif allocation.state == 'confirm':
|
||||
user_ids = allocation.sudo()._get_responsible_for_approval().ids or self.env.user.ids
|
||||
for user_id in user_ids:
|
||||
activity_vals.append({
|
||||
'activity_type_id': self.env.ref('hr_holidays.mail_act_leave_allocation_approval').id,
|
||||
'automated': True,
|
||||
'note': note,
|
||||
'user_id': user_id,
|
||||
'res_id': allocation.id,
|
||||
'res_model_id': self.env.ref('hr_holidays.model_hr_leave_allocation').id,
|
||||
})
|
||||
if allocation.holiday_status_id.responsible_ids:
|
||||
user_ids = allocation.sudo()._get_responsible_for_approval().ids
|
||||
for user_id in user_ids:
|
||||
activity_vals.append({
|
||||
'activity_type_id': self.env.ref('hr_holidays.mail_act_leave_allocation_approval').id,
|
||||
'automated': True,
|
||||
'note': note,
|
||||
'user_id': user_id,
|
||||
'res_id': allocation.id,
|
||||
'res_model_id': self.env.ref('hr_holidays.model_hr_leave_allocation').id,
|
||||
})
|
||||
elif allocation.state == 'validate':
|
||||
to_do |= allocation
|
||||
elif allocation.state == 'refuse':
|
||||
|
||||
@@ -59,12 +59,12 @@ class HolidaysType(models.Model):
|
||||
compute='_compute_group_days_leave', string='Group Time Off')
|
||||
company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company)
|
||||
responsible_ids = fields.Many2many(
|
||||
'res.users', 'hr_leave_type_res_users_rel', 'hr_leave_type_id', 'res_users_id', string='Responsible Time Off Officer',
|
||||
'res.users', 'hr_leave_type_res_users_rel', 'hr_leave_type_id', 'res_users_id', string='Notified Time Off Officer',
|
||||
domain=lambda self: [('groups_id', 'in', self.env.ref('hr_holidays.group_hr_holidays_user').id),
|
||||
('share', '=', False),
|
||||
('company_ids', 'in', self.env.company.id)],
|
||||
auto_join=True,
|
||||
help="Choose the Time Off Officer who will be notified to approve allocation or Time Off request")
|
||||
help="Choose the Time Off Officers who will be notified to approve allocation or Time Off Request. If empty, nobody will be notified")
|
||||
leave_validation_type = fields.Selection([
|
||||
('no_validation', 'No Validation'),
|
||||
('hr', 'By Time Off Officer'),
|
||||
|
||||
@@ -805,7 +805,7 @@ class TestAccrualAllocations(TestHrHolidaysCommon):
|
||||
# The second level could give 6 days but since the first level was already giving
|
||||
# 3 days, the second level gives 3 days to reach the second level's limit.
|
||||
# The third level gives 1 day since it only counts for one iteration.
|
||||
self.assertEqual(allocation.number_of_days, 7)
|
||||
self.assertAlmostEqual(allocation.number_of_days, 7, 2)
|
||||
|
||||
def test_accrual_lost_previous_days(self):
|
||||
# Test that when an allocation with two levels is made and that the first level has it's action
|
||||
@@ -876,7 +876,7 @@ class TestAccrualAllocations(TestHrHolidaysCommon):
|
||||
allocation.action_validate()
|
||||
with freeze_time('2022-4-1'):
|
||||
allocation._update_accrual()
|
||||
self.assertEqual(allocation.number_of_days, 3, "Invalid number of days")
|
||||
self.assertAlmostEqual(allocation.number_of_days, 3, 2, "Invalid number of days")
|
||||
|
||||
def test_accrual_maximum_leaves(self):
|
||||
accrual_plan = self.env['hr.leave.accrual.plan'].with_context(tracking_disable=True).create({
|
||||
|
||||
@@ -134,6 +134,7 @@ class TestHolidaysFlow(TestHrHolidaysCommon):
|
||||
'employee_requests': 'no',
|
||||
'allocation_validation_type': 'officer',
|
||||
'leave_validation_type': 'both',
|
||||
'responsible_ids': [Command.link(self.env.ref('base.user_admin').id)]
|
||||
})
|
||||
HolidaysEmployeeGroup = Requests.with_user(self.user_employee_id)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from dateutil.relativedelta import relativedelta
|
||||
from freezegun import freeze_time
|
||||
from pytz import timezone, UTC
|
||||
|
||||
from odoo import fields
|
||||
from odoo import fields, Command
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tools import mute_logger
|
||||
from odoo.tests.common import Form
|
||||
@@ -1069,6 +1069,7 @@ class TestLeaveRequests(TestHrHolidaysCommon):
|
||||
'name': leave_validation_type.capitalize(),
|
||||
'leave_validation_type': leave_validation_type,
|
||||
'requires_allocation': 'no',
|
||||
'responsible_ids': [Command.link(self.env.ref('base.user_admin').id)],
|
||||
})
|
||||
current_leave = self.env['hr.leave'].with_user(self.user_employee_id).create({
|
||||
'name': 'Holiday Request',
|
||||
|
||||
@@ -39,6 +39,7 @@ class TestPartner(TransactionCase):
|
||||
'requires_allocation': 'no',
|
||||
'name': 'Legal Leaves',
|
||||
'time_type': 'leave',
|
||||
'responsible_ids': cls.users.ids
|
||||
})
|
||||
cls.leaves = cls.env['hr.leave'].create([{
|
||||
'date_from': cls.today + relativedelta(days=-2),
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
<group name="allocation_validation" id="allocation_requests" string="Allocation Requests">
|
||||
<field name="requires_allocation" widget="radio" options="{'horizontal':true}"/>
|
||||
<field name="employee_requests" widget="radio" attrs="{'invisible': [('requires_allocation', '=', 'no')]}"/>
|
||||
<field name="allocation_validation_type" string="Approval" widget="radio" attrs="{'invisible': ['|', ('requires_allocation', '=', 'no'), ('employee_requests', '=', 'no')]}"/>
|
||||
<field name="allocation_validation_type" string="Approval" widget="radio" attrs="{'invisible': [('requires_allocation', '=', 'no')]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<group name="visual" id="visual" string="Display Option" class="mw-100 col-lg-12">
|
||||
@@ -114,13 +114,15 @@
|
||||
<field name="name">hr.leave.type.normal.tree</field>
|
||||
<field name="model">hr.leave.type</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Time Off Type">
|
||||
<tree string="Time Off Type" multi_edit="1">
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="display_name"/>
|
||||
<field name="allocation_validation_type"/>
|
||||
<field name="employee_requests" optional="hide"/>
|
||||
<field name="requires_allocation" optional="hide"/>
|
||||
<field name="leave_validation_type" optional="hide"/>
|
||||
<field name="responsible_ids" widget="many2many_tags" attrs="{
|
||||
'invisible': [('leave_validation_type', 'in', ['no_validation', 'manager']), '|', ('requires_allocation', '=', 'no'), ('allocation_validation_type', '!=', 'officer')]}" optional="hide"/>
|
||||
<field name="company_id" groups="base.group_multi_company" optional="hide"/>
|
||||
</tree>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user