[IMP] hr_holidays,hr_work_entry_holidays: change responsible_id from ma2o to m2m
task - 3060720 closes odoo/odoo#107804 Related: odoo/upgrade#4128 Related: odoo/enterprise#34926 Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
@@ -260,7 +260,7 @@
|
||||
<field name="allocation_validation_type">officer</field>
|
||||
<field name="leave_notif_subtype_id" ref="mt_leave"/>
|
||||
<field name="allocation_notif_subtype_id" ref="mt_leave_allocation"/>
|
||||
<field name="responsible_id" ref="base.user_admin"/>
|
||||
<field name="responsible_ids" eval="[(4, ref('base.user_admin'))]"/>
|
||||
<field name="icon_id" ref="hr_holidays.icon_14"/>
|
||||
<field name="color">2</field>
|
||||
</record>
|
||||
@@ -270,7 +270,7 @@
|
||||
<field name="name">Sick Time Off</field>
|
||||
<field name="requires_allocation">no</field>
|
||||
<field name="leave_notif_subtype_id" ref="mt_leave_sick"/>
|
||||
<field name="responsible_id" ref="base.user_admin"/>
|
||||
<field name="responsible_ids" eval="[(4, ref('base.user_admin'))]"/>
|
||||
<field name="support_document">True</field>
|
||||
<field name="icon_id" ref="hr_holidays.icon_21"/>
|
||||
<field name="color">3</field>
|
||||
@@ -285,7 +285,7 @@
|
||||
<field name="allocation_validation_type">officer</field>
|
||||
<field name="request_unit">hour</field>
|
||||
<field name="leave_notif_subtype_id" ref="mt_leave"/>
|
||||
<field name="responsible_id" ref="base.user_admin"/>
|
||||
<field name="responsible_ids" eval="[(4, ref('base.user_admin'))]"/>
|
||||
<field name="icon_id" ref="hr_holidays.icon_4"/>
|
||||
<field name="color">4</field>
|
||||
</record>
|
||||
@@ -299,7 +299,7 @@
|
||||
<field name="request_unit">hour</field>
|
||||
<field name="unpaid" eval="True"/>
|
||||
<field name="leave_notif_subtype_id" ref="mt_leave_unpaid"/>
|
||||
<field name="responsible_id" ref="base.user_admin"/>
|
||||
<field name="responsible_ids" eval="[(4, ref('base.user_admin'))]"/>
|
||||
<field name="icon_id" ref="hr_holidays.icon_28"/>
|
||||
<field name="color">5</field>
|
||||
</record>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<field name="employee_requests">no</field>
|
||||
<field name="leave_validation_type">both</field>
|
||||
<field name="allocation_validation_type">officer</field>
|
||||
<field name="responsible_id" ref="base.user_admin"/>
|
||||
<field name="responsible_ids" eval="[(4, ref('base.user_admin'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="holiday_status_training" model="hr.leave.type">
|
||||
@@ -22,7 +22,7 @@
|
||||
<field name="employee_requests">no</field>
|
||||
<field name="leave_validation_type">both</field>
|
||||
<field name="allocation_validation_type">officer</field>
|
||||
<field name="responsible_id" ref="base.user_admin"/>
|
||||
<field name="responsible_ids" eval="[(4, ref('base.user_admin'))]"/>
|
||||
</record>
|
||||
|
||||
<!-- Accrual Plan -->
|
||||
|
||||
@@ -19,10 +19,5 @@
|
||||
<field name="icon">fa-sun-o</field>
|
||||
<field name="res_model">hr.leave.allocation</field>
|
||||
</record>
|
||||
<record id="mail_act_leave_allocation_second_approval" model="mail.activity.type">
|
||||
<field name="name">Allocation Second Approve</field>
|
||||
<field name="icon">fa-sun-o</field>
|
||||
<field name="res_model">hr.leave.allocation</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -987,7 +987,7 @@ class HolidaysRequest(models.Model):
|
||||
if holiday.validation_type == 'no_validation':
|
||||
# Automatic validation should be done in sudo, because user might not have the rights to do it by himself
|
||||
holiday_sudo.action_validate()
|
||||
holiday_sudo.message_subscribe(partner_ids=[holiday._get_responsible_for_approval().partner_id.id])
|
||||
holiday_sudo.message_subscribe(partner_ids=holiday._get_responsible_for_approval().partner_id.ids)
|
||||
holiday_sudo.message_post(body=_("The time off has been automatically approved"), subtype_xmlid="mail.mt_comment") # Message from OdooBot (sudo)
|
||||
elif not self._context.get('import_file'):
|
||||
holiday_sudo.activity_update()
|
||||
@@ -1425,11 +1425,11 @@ class HolidaysRequest(models.Model):
|
||||
responsibles = leave.employee_id.leave_manager_id.partner_id
|
||||
# officer
|
||||
elif leave.holiday_status_id.leave_validation_type == 'hr' and leave.state == 'validate':
|
||||
responsibles = leave.holiday_status_id.responsible_id.partner_id
|
||||
responsibles = leave.holiday_status_id.responsible_ids.partner_id
|
||||
# both
|
||||
elif leave.holiday_status_id.leave_validation_type == 'both' and leave.state == 'validate':
|
||||
responsibles = leave.employee_id.leave_manager_id.partner_id
|
||||
responsibles |= leave.holiday_status_id.responsible_id.partner_id
|
||||
responsibles |= leave.holiday_status_id.responsible_ids.partner_id
|
||||
|
||||
if responsibles:
|
||||
leave_name = list(filter(lambda h: leave.id in h, leave_names))[0][1]
|
||||
@@ -1572,13 +1572,15 @@ class HolidaysRequest(models.Model):
|
||||
elif self.employee_id.parent_id.user_id:
|
||||
responsible = self.employee_id.parent_id.user_id
|
||||
elif self.validation_type == 'hr' or (self.validation_type == 'both' and self.state == 'validate1'):
|
||||
if self.holiday_status_id.responsible_id:
|
||||
responsible = self.holiday_status_id.responsible_id
|
||||
|
||||
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):
|
||||
to_clean, to_do = self.env['hr.leave'], self.env['hr.leave']
|
||||
activity_vals = []
|
||||
for holiday in self:
|
||||
note = _(
|
||||
'New %(leave_type)s Request created by %(user)s',
|
||||
@@ -1588,16 +1590,16 @@ class HolidaysRequest(models.Model):
|
||||
if holiday.state == 'draft':
|
||||
to_clean |= holiday
|
||||
elif holiday.state == 'confirm':
|
||||
holiday.activity_schedule(
|
||||
'hr_holidays.mail_act_leave_approval',
|
||||
note=note,
|
||||
user_id=holiday.sudo()._get_responsible_for_approval().id or self.env.user.id)
|
||||
elif holiday.state == 'validate1':
|
||||
holiday.activity_feedback(['hr_holidays.mail_act_leave_approval'])
|
||||
holiday.activity_schedule(
|
||||
'hr_holidays.mail_act_leave_second_approval',
|
||||
note=note,
|
||||
user_id=holiday.sudo()._get_responsible_for_approval().id or self.env.user.id)
|
||||
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':
|
||||
@@ -1606,6 +1608,7 @@ class HolidaysRequest(models.Model):
|
||||
to_clean.activity_unlink(['hr_holidays.mail_act_leave_approval', 'hr_holidays.mail_act_leave_second_approval'])
|
||||
if to_do:
|
||||
to_do.activity_feedback(['hr_holidays.mail_act_leave_approval', 'hr_holidays.mail_act_leave_second_approval'])
|
||||
self.env['mail.activity'].create(activity_vals)
|
||||
|
||||
####################################################
|
||||
# Messaging methods
|
||||
|
||||
@@ -737,13 +737,16 @@ class HolidaysAllocation(models.Model):
|
||||
responsible = self.env.user
|
||||
|
||||
if self.validation_type == 'officer' or self.validation_type == 'set':
|
||||
if self.holiday_status_id.responsible_id:
|
||||
responsible = self.holiday_status_id.responsible_id
|
||||
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):
|
||||
to_clean, to_do = self.env['hr.leave.allocation'], self.env['hr.leave.allocation']
|
||||
activity_vals = []
|
||||
for allocation in self:
|
||||
if allocation.validation_type != 'no':
|
||||
note = _(
|
||||
@@ -755,24 +758,25 @@ class HolidaysAllocation(models.Model):
|
||||
if allocation.state == 'draft':
|
||||
to_clean |= allocation
|
||||
elif allocation.state == 'confirm':
|
||||
allocation.activity_schedule(
|
||||
'hr_holidays.mail_act_leave_allocation_approval',
|
||||
note=note,
|
||||
user_id=allocation.sudo()._get_responsible_for_approval().id or self.env.user.id)
|
||||
elif allocation.state == 'validate1':
|
||||
allocation.activity_feedback(['hr_holidays.mail_act_leave_allocation_approval'])
|
||||
allocation.activity_schedule(
|
||||
'hr_holidays.mail_act_leave_allocation_second_approval',
|
||||
note=note,
|
||||
user_id=allocation.sudo()._get_responsible_for_approval().id or self.env.user.id)
|
||||
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,
|
||||
})
|
||||
elif allocation.state == 'validate':
|
||||
to_do |= allocation
|
||||
elif allocation.state == 'refuse':
|
||||
to_clean |= allocation
|
||||
self.env['mail.activity'].create(activity_vals)
|
||||
if to_clean:
|
||||
to_clean.activity_unlink(['hr_holidays.mail_act_leave_allocation_approval', 'hr_holidays.mail_act_leave_allocation_second_approval'])
|
||||
to_clean.activity_unlink(['hr_holidays.mail_act_leave_allocation_approval'])
|
||||
if to_do:
|
||||
to_do.activity_feedback(['hr_holidays.mail_act_leave_allocation_approval', 'hr_holidays.mail_act_leave_allocation_second_approval'])
|
||||
to_do.activity_feedback(['hr_holidays.mail_act_leave_allocation_approval'])
|
||||
|
||||
####################################################
|
||||
# Messaging methods
|
||||
@@ -813,7 +817,7 @@ class HolidaysAllocation(models.Model):
|
||||
|
||||
def message_subscribe(self, partner_ids=None, subtype_ids=None):
|
||||
# due to record rule can not allow to add follower and mention on validated leave so subscribe through sudo
|
||||
if self.state in ['validate', 'validate1']:
|
||||
if any(state in ['validate', 'validate1'] for state in self.mapped('state')):
|
||||
self.check_access_rights('read')
|
||||
self.check_access_rule('read')
|
||||
return super(HolidaysAllocation, self.sudo()).message_subscribe(partner_ids=partner_ids, subtype_ids=subtype_ids)
|
||||
|
||||
@@ -58,11 +58,12 @@ class HolidaysType(models.Model):
|
||||
group_days_leave = fields.Float(
|
||||
compute='_compute_group_days_leave', string='Group Time Off')
|
||||
company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company)
|
||||
responsible_id = fields.Many2one(
|
||||
'res.users', 'Responsible Time Off Officer',
|
||||
responsible_ids = fields.Many2many(
|
||||
'res.users', 'hr_leave_type_res_users_rel', 'hr_leave_type_id', 'res_users_id', string='Responsible 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")
|
||||
leave_validation_type = fields.Selection([
|
||||
('no_validation', 'No Validation'),
|
||||
|
||||
@@ -4,6 +4,7 @@ import datetime
|
||||
from freezegun import freeze_time
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import Command
|
||||
from odoo.tests import tagged
|
||||
|
||||
from odoo.addons.hr_holidays.tests.common import TestHrHolidaysCommon
|
||||
@@ -354,7 +355,7 @@ class TestAccrualAllocations(TestHrHolidaysCommon):
|
||||
holiday_type = self.env['hr.leave.type'].create({
|
||||
'name': 'Paid Time Off',
|
||||
'requires_allocation': 'no',
|
||||
'responsible_id': self.user_hrmanager_id,
|
||||
'responsible_ids': [Command.link(self.user_hrmanager_id)],
|
||||
'time_type': 'leave',
|
||||
})
|
||||
leave = self.env['hr.leave'].create({
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
from datetime import date, datetime
|
||||
|
||||
from odoo import Command
|
||||
from odoo.tests import tagged
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
@@ -18,7 +19,7 @@ class TestCompanyLeave(TransactionCase):
|
||||
|
||||
cls.bank_holiday = cls.env['hr.leave.type'].create({
|
||||
'name': 'Bank Holiday',
|
||||
'responsible_id': cls.env.user.id,
|
||||
'responsible_ids': [Command.link(cls.env.ref('base.user_admin').id)],
|
||||
'company_id': cls.company.id,
|
||||
'requires_allocation': 'no',
|
||||
})
|
||||
|
||||
@@ -7,7 +7,7 @@ from dateutil.relativedelta import relativedelta
|
||||
from freezegun import freeze_time
|
||||
from psycopg2 import IntegrityError
|
||||
|
||||
from odoo import fields
|
||||
from odoo import Command
|
||||
from odoo.exceptions import AccessError, ValidationError, UserError
|
||||
from odoo.tools import mute_logger, test_reports
|
||||
|
||||
@@ -90,7 +90,7 @@ class TestHolidaysFlow(TestHrHolidaysCommon):
|
||||
'employee_requests': 'no',
|
||||
'allocation_validation_type': 'officer',
|
||||
'leave_validation_type': 'both',
|
||||
'responsible_id': self.env.ref('base.user_admin').id,
|
||||
'responsible_ids': [Command.link(self.env.ref('base.user_admin').id)],
|
||||
})
|
||||
|
||||
self.env['hr.leave.allocation'].create([
|
||||
@@ -244,7 +244,7 @@ class TestHolidaysFlow(TestHrHolidaysCommon):
|
||||
'employee_requests': 'no',
|
||||
'allocation_validation_type': 'officer',
|
||||
'leave_validation_type': 'both',
|
||||
'responsible_id': self.env.ref('base.user_admin').id,
|
||||
'responsible_ids': [Command.link(self.env.ref('base.user_admin').id)],
|
||||
})
|
||||
|
||||
self.env['hr.leave.allocation'].create({
|
||||
|
||||
@@ -63,10 +63,10 @@
|
||||
<group name="leave_validation" id="time_off_requests" string="Time Off Requests">
|
||||
<field name="active" invisible="1"/>
|
||||
<field name="leave_validation_type" string="Approval" widget="radio"/>
|
||||
<field name="responsible_id"
|
||||
<field name="responsible_ids"
|
||||
widget="many2many_tags"
|
||||
attrs="{
|
||||
'invisible': [('leave_validation_type', 'in', ['no_validation', 'manager']), '|', ('requires_allocation', '=', 'no'), ('allocation_validation_type', '!=', 'officer')],
|
||||
'required': ['|',('leave_validation_type', 'in', ['both', 'hr']), ('requires_allocation', '=', 'yes'), ('allocation_validation_type', '=', 'officer')]}"/>
|
||||
'invisible': [('leave_validation_type', 'in', ['no_validation', 'manager']), '|', ('requires_allocation', '=', 'no'), ('allocation_validation_type', '!=', 'officer')]}"/>
|
||||
<field name="request_unit"/>
|
||||
<field name="support_document" string="Allow To Attach Supporting Document" />
|
||||
<field name="time_type" required="1"/>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import Command
|
||||
from odoo.fields import Datetime
|
||||
from odoo.addons.hr_work_entry_contract.tests.common import TestWorkEntryBase
|
||||
|
||||
@@ -17,8 +18,10 @@ class TestWorkEntryHolidaysBase(TestWorkEntryBase):
|
||||
'name': 'Legal Leaves',
|
||||
'time_type': 'leave',
|
||||
'requires_allocation': 'no',
|
||||
'responsible_ids': [Command.link(cls.env.ref('base.user_admin').id)],
|
||||
'work_entry_type_id': cls.work_entry_type_leave.id
|
||||
})
|
||||
cls.env.ref('base.user_admin').notification_type = 'inbox'
|
||||
|
||||
# I create a new employee "Jules"
|
||||
cls.jules_emp = cls.env['hr.employee'].create({
|
||||
|
||||
@@ -32,7 +32,7 @@ class TestWorkEntryHolidaysPerformance(TestWorkEntryHolidaysBase):
|
||||
self.richard_emp.generate_work_entries(date(2018, 1, 1), date(2018, 1, 2))
|
||||
leave = self.create_leave(datetime(2018, 1, 1, 7, 0), datetime(2018, 1, 1, 18, 0))
|
||||
|
||||
with self.assertQueryCount(__system__=79, admin=81):
|
||||
with self.assertQueryCount(__system__=91, admin=93):
|
||||
leave.action_validate()
|
||||
leave.action_refuse()
|
||||
|
||||
@@ -48,7 +48,7 @@ class TestWorkEntryHolidaysPerformance(TestWorkEntryHolidaysBase):
|
||||
@users('__system__', 'admin')
|
||||
@warmup
|
||||
def test_performance_leave_create(self):
|
||||
with self.assertQueryCount(__system__=29, admin=30):
|
||||
with self.assertQueryCount(__system__=44, admin=44):
|
||||
leave = self.create_leave(datetime(2018, 1, 1, 7, 0), datetime(2018, 1, 1, 18, 0))
|
||||
leave.action_refuse()
|
||||
|
||||
@@ -57,7 +57,7 @@ class TestWorkEntryHolidaysPerformance(TestWorkEntryHolidaysBase):
|
||||
def test_performance_leave_confirm(self):
|
||||
leave = self.create_leave(datetime(2018, 1, 1, 7, 0), datetime(2018, 1, 1, 18, 0))
|
||||
leave.action_draft()
|
||||
with self.assertQueryCount(__system__=25, admin=26):
|
||||
with self.assertQueryCount(__system__=40, admin=40):
|
||||
leave.action_confirm()
|
||||
leave.state = 'refuse'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user