show holiday on employee dashboard

This commit is contained in:
pawan.sharma 2021-07-09 18:09:40 +05:30
parent 1ba6c451fd
commit c2147b80d1
2 changed files with 35 additions and 32 deletions

View File

@ -71,42 +71,42 @@ class CompanyResourceCalendar(models.Model):
Calendar = self.env['calendar.event']
for comp_global_leave in self.company_global_leave_ids:
public_holiday.append({
'name': "Holiday"+"/"+comp_global_leave.name,
'name': "Holiday" + "/" + comp_global_leave.name,
'start': comp_global_leave.date_from,
'stop': comp_global_leave.date_to,
'categ_ids': [(6, 0, [self.env.ref('company_public_holidays_kanak.categ_meet6').id])]
})
})
for holiday in public_holiday:
existing_calender = Calendar.search([('start', '=', holiday['start'])])
if not existing_calender:
Calendar.create(holiday)
# def action_holiday_update_timeoff_calendar(self):
# public_holiday = []
# holiday_id = self.env['hr.leave.type'].search([], limit=1)
# company = self.env['res.company'].search([], limit=1)
# employee = self.env['hr.employee'].search([('id', '=', 14)], limit=1)
# #leave_calendar = self.env['hr.leave']
# leave_calendar = self.env['hr.leave'].with_context(
# tracking_disable=True,
# mail_activity_automation_skip=True,
# leave_fast_create=True,
# leave_skip_state_check=True,
# )
# for comp_global_leave in self.company_global_leave_ids:
# public_holiday.append({
# 'name': "Holiday"+"/"+comp_global_leave.name,
# 'date_from': comp_global_leave.date_from,
# 'date_to': comp_global_leave.date_to,
# 'holiday_status_id': holiday_id.id,
# 'employee_id': employee.id,
# 'state': 'validate'
# })
# for holiday in public_holiday:
# existing_calender = leave_calendar.search([('date_from', '=', holiday['date_from'])])
# if not existing_calender:
# leave_calendar.create(holiday)
def action_holiday_update_timeoff_calendar(self):
public_holiday = []
holiday_id = self.env['hr.leave.type'].search([], limit=1)
employees = self.env['hr.employee'].search([])
# leave_calendar = self.env['hr.leave']
leave_calendar = self.env['hr.leave']
for comp_global_leave in self.company_global_leave_ids:
for employee in employees:
existing_calender = leave_calendar.search([('date_from', '=', comp_global_leave.date_from),('employee_id', '=', employee.id)])
if not existing_calender:
leave_calendar.with_context(
tracking_disable=True,
mail_activity_automation_skip=True,
leave_fast_create=True,
leave_skip_state_check=True,
).create({
'name': "Holiday" + "/" + comp_global_leave.name,
'date_from': comp_global_leave.date_from,
'date_to': comp_global_leave.date_to,
'holiday_status_id': holiday_id.id,
'employee_id': employee.id,
'state': 'validate'
})
self.action_holiday_update_calendar()
class CompanyResourceCalendarLeaves(models.Model):
@ -135,13 +135,15 @@ class CompanyResourceCalendarLeaves(models.Model):
return res
def write(self, values):
resource_calendar = self.env['resource.calendar.leaves'].search([('company_res_calendar_leaves_id', '=', self.id)])
resource_calendar = self.env['resource.calendar.leaves'].search(
[('company_res_calendar_leaves_id', '=', self.id)])
resource_calendar.write(values)
res = super(CompanyResourceCalendarLeaves, self).write(values)
return res
def unlink(self):
resource_calendar = self.env['resource.calendar.leaves'].search([('company_res_calendar_leaves_id', '=', self.id)])
resource_calendar = self.env['resource.calendar.leaves'].search(
[('company_res_calendar_leaves_id', '=', self.id)])
resource_calendar.unlink()
res = super(CompanyResourceCalendarLeaves, self).unlink()
return res
@ -150,7 +152,8 @@ class CompanyResourceCalendarLeaves(models.Model):
class ResourceCalendarLeaves(models.Model):
_inherit = "resource.calendar.leaves"
company_res_calendar_leaves_id = fields.Many2one('company.resource.calendar.leaves', string='Company Resouce Calendar')
company_res_calendar_leaves_id = fields.Many2one('company.resource.calendar.leaves',
string='Company Resouce Calendar')
class MailComposer(models.TransientModel):

View File

@ -28,8 +28,8 @@
<form string="Company Public Holiday">
<header>
<button name="action_public_holiday_send" string="Send by Email" type="object" class="btn-primary"/>
<button name="action_holiday_update_calendar" string="Update Holiday Calendar" type="object" class="btn-primary"/>
<!--<button name="action_holiday_update_timeoff_calendar" string="Update Holiday Calendar" type="object" class="btn-primary"/>-->
<!--<button name="action_holiday_update_calendar" string="Update Holiday Calendar" type="object" class="btn-primary"/>-->
<button name="action_holiday_update_timeoff_calendar" string="Update Holiday Calendar" type="object" class="btn-primary"/>
</header>
<sheet>
<group>