From aae3f7d6da3ebd42bec6e6e17bb8216461004426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= <9664676+pengyuthon@user.noreply.gitee.com> Date: Sat, 13 Sep 2025 19:18:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_hr_attendance/models/hr_attendance.py | 53 ++++++++++++------- .../models/property_lease_contract.py | 8 ++- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py index 4c55ac0e0..dfc801cfc 100644 --- a/yuthon_hr_attendance/models/hr_attendance.py +++ b/yuthon_hr_attendance/models/hr_attendance.py @@ -991,42 +991,45 @@ class HrAttendance(models.Model): attendance.absenteeism_card = True attendance.is_abnormal = True + def _set_shift_name(self): + """抽取的统一班次名称设置逻辑""" + for record in self: + if record.shift_id: + continue # 已有班次记录,无需自动设置 - @api.model - def create(self, vals): - record = super(HrAttendance, self).create(vals) - if 'current_data' in vals: - current_data = fields.Date.to_date(vals['current_data']) - today = fields.Date.today() - if current_data > today: - return record - if not record.shift_id: shift_days_list = [] is_shift_replacement = False is_leave_day = False is_weekend = False + if record.current_data: - # 查询休假记录 - leave_records = self.env['resource.calendar.leaves'].search([("calendar_id", "=", "行政考勤工作日")]) - # 检查是否存在匹配的休假日期 + # 查询休假记录(假设"行政考勤工作日"是calendar_id的name) + leave_records = self.env['resource.calendar.leaves'].search([ + ("calendar_id.name", "=", "行政考勤工作日") + ]) + + # 检查是否为休假日期 for leave in leave_records: if leave.date_from and leave.date_to: - # 提取休假记录的月日范围 - from_date = fields.Date.to_date(leave.date_from)+ timedelta(days=1) - to_date = fields.Date.to_date(leave.date_to)+ timedelta(days=1) + from_date = fields.Date.to_date(leave.date_from) + timedelta(days=1) + to_date = fields.Date.to_date(leave.date_to) + timedelta(days=1) if from_date <= record.current_data <= to_date: is_leave_day = True + # 收集调班补班日期 if leave.shift_replacement_day: - shift_days_list.extend(leave.shift_replacement_day.split(',')) # 调班补班 + shift_days_list.extend(leave.shift_replacement_day.split(',')) + # 检查是否为调班补班日 target_day_str = f"{record.current_data.month}月{record.current_data.day}日" if target_day_str in shift_days_list: is_shift_replacement = True + # 检查是否为周末 weekday = record.current_data.isoweekday() - if weekday in [6, 7]: + if weekday in [6, 7]: # 6=周六,7=周日 is_weekend = True + # 设置班次名称 if is_leave_day: record.shift_name = '' elif is_shift_replacement: @@ -1036,14 +1039,26 @@ class HrAttendance(models.Model): else: record.shift_name = '行政班次' - self._update_vacation_report(record) + @api.model + def create(self, vals): + record = super(HrAttendance, self).create(vals) + # 未来日期不处理班次(保持原逻辑) + if 'current_data' in vals: + current_data = fields.Date.to_date(vals['current_data']) + today = fields.Date.today() + if current_data > today: + return record + record._set_shift_name() return record def write(self, vals): result = super(HrAttendance, self).write(vals) + # 当更新考勤日期或班次时,重新计算班次名称 + if 'current_data' in vals or 'shift_id' in vals: + self._set_shift_name() for record in self: self._update_vacation_report(record) - return result + return result def unlink(self): for record in self: diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py index 19f7c72f0..73c4997ab 100644 --- a/yuthon_property_approval/models/property_lease_contract.py +++ b/yuthon_property_approval/models/property_lease_contract.py @@ -1477,9 +1477,7 @@ class PropertyLeaseContract(models.Model): def get_property_contract_time(self): - records_only_in_tree1 = self.env['property.lease.contract'].search([ - ('condition', 'not in', ['new', 'approval', 'cancel']) - ]) + records_only_in_tree1 = self.env['property.lease.contract'].search([]) today = fields.Date.today() for contract in records_only_in_tree1: # 获取时间字段 @@ -1509,12 +1507,12 @@ class PropertyLeaseContract(models.Model): elif effective_month and today >= effective_month < term_end: contract.contact_state = 'terminate' - @api.onchange('actual_start', 'actual_end') + @api.onchange('actual_start_time', 'actual_end_time') def _onchange_contact_state(self): for contract in self: today = fields.Date.today() term_end = contract.term_start_time - actual_start = contract.actual_start + actual_start = contract.actual_start_time actual_end = contract.actual_end effective_month = None