diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index 9e5a6216fc1..dea73b09ef5 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -151,7 +151,9 @@ class HolidaysAllocation(models.Model): def _compute_is_officer(self): self.is_officer = self.env.user.has_group("hr_holidays.group_hr_holidays_user") + # Useless depends, so that name is computed on new, before saving the record @api.depends_context('uid') + @api.depends('holiday_status_id') def _compute_description(self): self.check_access_rights('read') self.check_access_rule('read') @@ -162,11 +164,14 @@ class HolidaysAllocation(models.Model): if is_officer or allocation.employee_id.user_id == self.env.user or allocation.employee_id.leave_manager_id == self.env.user: title = allocation.sudo().private_name if allocation.env.context.get('is_employee_allocation'): - allocation_duration = allocation.number_of_days_display if allocation.type_request_unit != 'hour' else allocation.number_of_hours_display - title = _(" %s Allocation Request ( %s %s)" % ( - allocation.holiday_status_id.name, - allocation_duration, - allocation.type_request_unit)) + if allocation.holiday_status_id: + allocation_duration = allocation.number_of_days_display if allocation.type_request_unit != 'hour' else allocation.number_of_hours_display + title = _(" %s Allocation Request ( %s %s)" % ( + allocation.holiday_status_id.name, + allocation_duration, + allocation.type_request_unit)) + else: + title = _("Allocation Request") allocation.name = title else: allocation.name = '*****' @@ -589,6 +594,7 @@ class HolidaysAllocation(models.Model): if 'lastcall' not in values: values['lastcall'] = fields.Date.today() holidays = super(HolidaysAllocation, self.with_context(mail_create_nosubscribe=True)).create(vals_list) + created_from_dashboard = self.env.context.get('created_from_dashboard') for holiday in holidays: partners_to_subscribe = set() if holiday.employee_id.user_id: @@ -601,6 +607,8 @@ class HolidaysAllocation(models.Model): holiday.activity_update() if holiday.validation_type == 'no' and holiday.state == 'draft': holiday.action_confirm() + if created_from_dashboard: + holiday.action_confirm() return holidays def write(self, values): diff --git a/addons/hr_holidays/models/hr_leave_type.py b/addons/hr_holidays/models/hr_leave_type.py index 0a18d997544..77812ad6bfe 100644 --- a/addons/hr_holidays/models/hr_leave_type.py +++ b/addons/hr_holidays/models/hr_leave_type.py @@ -457,6 +457,7 @@ class HolidaysType(models.Model): 'closest_allocation_expire': format_date(self.env, self.closest_allocation_to_expire.date_to) if self.closest_allocation_to_expire.date_to else False, 'request_unit': self.request_unit, 'icon': self.sudo().icon_id.url, + 'id': self.id, }, self.requires_allocation, self.id) def _get_contextual_employee_id(self): diff --git a/addons/hr_holidays/static/src/dashboard/time_off_card.js b/addons/hr_holidays/static/src/dashboard/time_off_card.js index 34afa2adca0..db68db0cf74 100644 --- a/addons/hr_holidays/static/src/dashboard/time_off_card.js +++ b/addons/hr_holidays/static/src/dashboard/time_off_card.js @@ -1,17 +1,19 @@ /* @odoo-module */ import { usePopover } from "@web/core/popover/popover_hook"; +import { useNewAllocationRequest } from '@hr_holidays/views/hooks'; const { Component } = owl; export class TimeOffCardPopover extends Component {} TimeOffCardPopover.template = 'hr_holidays.TimeOffCardPopover'; -TimeOffCardPopover.props = ['allocated', 'approved', 'planned', 'left', 'close?']; +TimeOffCardPopover.props = ['allocated', 'approved', 'planned', 'left', 'employeeId', 'holidayStatusId', 'close?', 'onClickNewAllocationRequest?']; export class TimeOffCard extends Component { setup() { this.popover = usePopover(TimeOffCardPopover, { position: "right", popoverClass: "bg-view" }); + this.newAllocationRequest = useNewAllocationRequest(); } onClickInfo(ev) { @@ -21,12 +23,20 @@ export class TimeOffCard extends Component { approved: data.leaves_approved, planned: data.leaves_requested, left: data.virtual_remaining_leaves, + employeeId: this.props.employeeId, + holidayStatusId: this.props.holidayStatusId, + onClickNewAllocationRequest: this.newAllocationRequestFrom.bind(this), }); } + + async newAllocationRequestFrom() { + this.popover.close(); + await this.newAllocationRequest(this.props.employeeId, this.props.holidayStatusId); + } } TimeOffCard.template = 'hr_holidays.TimeOffCard'; -TimeOffCard.props = ['name', 'id', 'data', 'requires_allocation']; +TimeOffCard.props = ['name', 'data', 'requires_allocation', 'employeeId', 'holidayStatusId']; export class TimeOffCardMobile extends TimeOffCard {} diff --git a/addons/hr_holidays/static/src/dashboard/time_off_card.xml b/addons/hr_holidays/static/src/dashboard/time_off_card.xml index a48d16e1903..b07cdf76386 100644 --- a/addons/hr_holidays/static/src/dashboard/time_off_card.xml +++ b/addons/hr_holidays/static/src/dashboard/time_off_card.xml @@ -54,7 +54,7 @@