From 3298ff6102d62f1fae665726e3b0f510e0aa3a93 Mon Sep 17 00:00:00 2001 From: ljmwkx <1340053001@qq.com> Date: Mon, 3 Mar 2025 18:23:10 +0800 Subject: [PATCH] 1 --- yuthon_holiday/i18n/zh_CN.po | 15 ++ yuthon_holiday/models/inherit_hr_leave.py | 158 +++++++++++++++------- 2 files changed, 125 insertions(+), 48 deletions(-) diff --git a/yuthon_holiday/i18n/zh_CN.po b/yuthon_holiday/i18n/zh_CN.po index 8831bcbb6..70be46235 100644 --- a/yuthon_holiday/i18n/zh_CN.po +++ b/yuthon_holiday/i18n/zh_CN.po @@ -62,3 +62,18 @@ msgstr "日" #: model_terms:ir.ui.view,arch_db:yuthon_holiday.hr_accrual_plan_view_form_inherit msgid "number of holiday days:" msgstr "假期天数:" + + + +#. module: hr_holidays +#. odoo-python +#: code:addons/hr_holidays/models/hr_leave.py:0 +#, python-format +msgid "" +"You've already booked time off which overlaps with this period:\n" +"%s\n" +"Attempting to double-book your time off won't magically make your vacation 2x better!\n" +msgstr "" +"您已有:\n" +"「%s」\n" +"的假期申请待审批,请勿重复提交。如需调整,请先联系审批人或撤回原申请。\n" diff --git a/yuthon_holiday/models/inherit_hr_leave.py b/yuthon_holiday/models/inherit_hr_leave.py index 499978de7..1c87a8345 100644 --- a/yuthon_holiday/models/inherit_hr_leave.py +++ b/yuthon_holiday/models/inherit_hr_leave.py @@ -4,11 +4,13 @@ from email.policy import default from odoo import models, fields, api, _ from odoo.exceptions import ValidationError +from odoo.tools.misc import format_date class HrLeave(models.Model): _inherit = 'hr.leave' + @api.model def default_get(self, fields_list): default = super().default_get(fields_list) @@ -58,60 +60,120 @@ class HrLeave(models.Model): column2='attachment_id' ) request_hour_from = fields.Selection([ - ('0', '00:00 上午'), ('0.5', '00:30 上午'), - ('1', '1:00 上午'), ('1.5', '1:30 上午'), - ('2', '2:00 上午'), ('2.5', '2:30 上午'), - ('3', '3:00 上午'), ('3.5', '3:30 上午'), - ('4', '4:00 上午'), ('4.5', '4:30 上午'), - ('5', '5:00 上午'), ('5.5', '5:30 上午'), - ('6', '6:00 上午'), ('6.5', '6:30 上午'), - ('7', '7:00 上午'), ('7.5', '7:30 上午'), - ('8', '8:00 上午'), ('8.5', '8:30 上午'), - ('9', '9:00 上午'), ('9.5', '9:30 上午'), - ('10', '10:00 上午'), ('10.5', '10:30 上午'), - ('11', '11:00 上午'), ('11.5', '11:30 上午'), - ('12', '12:00 下午'), ('12.5', '12:30 下午'), - ('13', '1:00 下午'), ('13.5', '1:30 下午'), - ('14', '2:00 下午'), ('14.5', '2:30 下午'), - ('15', '3:00 下午'), ('15.5', '3:30 下午'), - ('16', '4:00 下午'), ('16.5', '4:30 下午'), - ('17', '5:00 下午'), ('17.5', '5:30 下午'), - ('18', '6:00 下午'), ('18.5', '6:30 下午'), - ('19', '7:00 下午'), ('19.5', '7:30 下午'), - ('20', '8:00 下午'), ('20.5', '8:30 下午'), - ('21', '9:00 下午'), ('21.5', '9:30 下午'), - ('22', '10:00 下午'), ('22.5', '10:30 下午'), - ('23', '11:00 下午'), ('23.5', '11:30 下午')], string='开始时间') + ('0', '00:00'), ('0.5', '00:30'), + ('1', '1:00'), ('1.5', '1:30'), + ('2', '2:00'), ('2.5', '2:30'), + ('3', '3:00'), ('3.5', '3:30'), + ('4', '4:00'), ('4.5', '4:30'), + ('5', '5:00'), ('5.5', '5:30'), + ('6', '6:00'), ('6.5', '6:30'), + ('7', '7:00'), ('7.5', '7:30'), + ('8', '8:00'), ('8.5', '8:30'), + ('9', '9:00'), ('9.5', '9:30'), + ('10', '10:00'), ('10.5', '10:30'), + ('11', '11:00'), ('11.5', '11:30'), + ('12', '12:00'), ('12.5', '12:30'), + ('13', '13:00'), ('13.5', '13:30'), + ('14', '14:00'), ('14.5', '14:30'), + ('15', '15:00'), ('15.5', '15:30'), + ('16', '16:00'), ('16.5', '16:30'), + ('17', '17:00'), ('17.5', '17:30'), + ('18', '18:00'), ('18.5', '18:30'), + ('19', '19:00'), ('19.5', '19:30'), + ('20', '20:00'), ('20.5', '20:30'), + ('21', '21:00'), ('21.5', '21:30'), + ('22', '22:00'), ('22.5', '22:30'), + ('23', '23:00'), ('23.5', '23:30')], string='开始时间') + request_hour_to = fields.Selection([ - ('0', '00:00 上午'), ('0.5', '00:30 上午'), - ('1', '1:00 上午'), ('1.5', '1:30 上午'), - ('2', '2:00 上午'), ('2.5', '2:30 上午'), - ('3', '3:00 上午'), ('3.5', '3:30 上午'), - ('4', '4:00 上午'), ('4.5', '4:30 上午'), - ('5', '5:00 上午'), ('5.5', '5:30 上午'), - ('6', '6:00 上午'), ('6.5', '6:30 上午'), - ('7', '7:00 上午'), ('7.5', '7:30 上午'), - ('8', '8:00 上午'), ('8.5', '8:30 上午'), - ('9', '9:00 上午'), ('9.5', '9:30 上午'), - ('10', '10:00 上午'), ('10.5', '10:30 上午'), - ('11', '11:00 上午'), ('11.5', '11:30 上午'), - ('12', '12:00 下午'), ('12.5', '12:30 下午'), - ('13', '1:00 下午'), ('13.5', '1:30 下午'), - ('14', '2:00 下午'), ('14.5', '2:30 下午'), - ('15', '3:00 下午'), ('15.5', '3:30 下午'), - ('16', '4:00 下午'), ('16.5', '4:30 下午'), - ('17', '5:00 下午'), ('17.5', '5:30 下午'), - ('18', '6:00 下午'), ('18.5', '6:30 下午'), - ('19', '7:00 下午'), ('19.5', '7:30 下午'), - ('20', '8:00 下午'), ('20.5', '8:30 下午'), - ('21', '9:00 下午'), ('21.5', '9:30 下午'), - ('22', '10:00 下午'), ('22.5', '10:30 下午'), - ('23', '11:00 下午'), ('23.5', '11:30 下午')], string='结束时间') + ('0', '12:00'), ('0.5', '12:30'), + ('1', '1:00'), ('1.5', '1:30'), + ('2', '2:00'), ('2.5', '2:30'), + ('3', '3:00'), ('3.5', '3:30'), + ('4', '4:00'), ('4.5', '4:30'), + ('5', '5:00'), ('5.5', '5:30'), + ('6', '6:00'), ('6.5', '6:30'), + ('7', '7:00'), ('7.5', '7:30'), + ('8', '8:00'), ('8.5', '8:30'), + ('9', '9:00'), ('9.5', '9:30'), + ('10', '10:00'), ('10.5', '10:30'), + ('11', '11:00'), ('11.5', '11:30'), + ('12', '12:00'), ('12.5', '12:30'), + ('13', '13:00'), ('13.5', '13:30'), + ('14', '14:00'), ('14.5', '14:30'), + ('15', '15:00'), ('15.5', '15:30'), + ('16', '16:00'), ('16.5', '16:30'), + ('17', '17:00'), ('17.5', '17:30'), + ('18', '18:00'), ('18.5', '18:30'), + ('19', '19:00'), ('19.5', '19:30'), + ('20', '20:00'), ('20.5', '20:30'), + ('21', '21:00'), ('21.5', '21:30'), + ('22', '22:00'), ('22.5', '22:30'), + ('23', '23:00'), ('23.5', '23:30')], string='结束时间') def _compute_request_unit_hours(self): if not self.env.context.get('no_change_request_unit_hours'): super()._compute_request_unit_hours() + @api.constrains('date_from', 'date_to', 'employee_id') + def _check_date(self): + + if self.env.context.get('leave_skip_date_check', False): + return + + all_employees = self.all_employee_ids + all_leaves = self.search([ + ('date_from', '<', max(self.mapped('date_to'))), + ('date_to', '>', min(self.mapped('date_from'))), + ('employee_id', 'in', all_employees.ids), + ('id', 'not in', self.ids), + ('state', 'not in', ['cancel', 'refuse']), + ]) + for holiday in self: + domain = [ + ('date_from', '<', holiday.date_to), + ('date_to', '>', holiday.date_from), + ('id', '!=', holiday.id), + ('state', 'not in', ['cancel', 'refuse']), + ] + + employee_ids = (holiday.employee_id | holiday.employee_ids).ids + search_domain = domain + [('employee_id', 'in', employee_ids)] + conflicting_holidays = all_leaves.filtered_domain(search_domain) + + if conflicting_holidays: + conflicting_holidays_list = [] + # Do not display the name of the employee if the conflicting holidays have an employee_id.user_id equivalent to the user id + holidays_only_have_uid = bool(holiday.employee_id) + holiday_states = dict(conflicting_holidays.fields_get(allfields=['state'])['state']['selection']) + for conflicting_holiday in conflicting_holidays: + conflicting_holiday_data = {} + conflicting_holiday_data['employee_name'] = conflicting_holiday.employee_id.name + conflicting_holiday_data['date_from'] = format_date(self.env, + min(conflicting_holiday.mapped('date_from'))) + conflicting_holiday_data['date_to'] = format_date(self.env, + min(conflicting_holiday.mapped('date_to'))) + conflicting_holiday_data['state'] = holiday_states[conflicting_holiday.state] + if conflicting_holiday.employee_id.user_id.id != self.env.uid: + holidays_only_have_uid = False + if conflicting_holiday_data not in conflicting_holidays_list: + conflicting_holidays_list.append(conflicting_holiday_data) + if not conflicting_holidays_list: + return + conflicting_holidays_strings = [] + if holidays_only_have_uid: + for conflicting_holiday_data in conflicting_holidays_list: + conflicting_holidays_string = _('%(date_from)s - %(date_to)s', + date_from=conflicting_holiday_data['date_from'], + date_to=conflicting_holiday_data['date_to']) + conflicting_holidays_strings.append(conflicting_holidays_string) + raise ValidationError(_("""\ + 您已有:「%s」 的假期申请待审批,请勿重复提交。如需调整,请先联系审批人或撤回原申请。 + """, + "\n".join(conflicting_holidays_strings))) + + super()._check_date() + class HolidaysRequestBatch(models.Model): _name = 'hr.leave.batch' _description = '请假审批'