添加功能
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user