添加功能

This commit is contained in:
李鹏宇
2026-03-05 11:26:23 +08:00
parent 0ae543d19e
commit 33facc52e6
2 changed files with 23 additions and 96 deletions
@@ -523,95 +523,6 @@ class YuthonVacationReports(models.Model):
# 扣减本年剩余
rec.this_year1 = max(0.0, rec.this_year1 - remaining_over_decrease)
def update_overtime(self):
today = date.today()
over_line_domain = [
('vacation_id', '!=', False),
('update_type', '=', 'add'),
('is_void', '=', False)
]
over_lines = self.env['vacation.over.line'].search(over_line_domain)
void_lines = self.env['vacation.over.line']
for line in over_lines:
# 确定判断超期的基准日期:有adjust_date则用adjust_date,否则用valid_date
check_date = line.adjust_date if line.adjust_date else line.valid_date
if check_date and today > check_date:
void_lines |= line
# 批量标记作废
if void_lines:
void_lines.write({'is_void': True})
for void_line in void_lines:
# 跳过vacation_id为空的情况
if not void_line.vacation_id:
continue
main_vacation = void_line.vacation_id
vacation_date = main_vacation.vacation_date
# 查找vacation_date之后的加班记录中,text='上月额度继承'的行
inherit_domain = [
('vacation_id', '=', main_vacation.id),
('create_date', '>=', fields.Datetime.to_datetime(vacation_date)),
('text', '=', '上月额度继承'),
]
inherit_lines = self.env['vacation.over.line'].search(inherit_domain)
if not inherit_lines:
continue
deduct_value = void_line.update_lines or 0.0
for inherit_line in inherit_lines:
new_lines = inherit_line.update_lines - deduct_value
inherit_line.write({'update_lines': new_lines})
def update_leave(self):
today = date.today()
leave_line_domain = [
('vacation_id', '!=', False),
('update_type', '=', 'add'),
('is_void', '=', False)
]
leave_lines = self.env['vacation.leave.line'].search(leave_line_domain)
void_lines = self.env['vacation.leave.line']
for line in leave_lines:
check_date = line.adjust_date if line.adjust_date else line.valid_date
if check_date and today > check_date:
void_lines |= line
if void_lines:
void_lines.write({'is_void': True})
# 3. 扣减update_lines中「上月额度继承」的workday
for void_line in void_lines:
if not void_line.vacation_id:
continue
main_vacation = void_line.vacation_id
vacation_date = main_vacation.vacation_date
if not vacation_date:
continue
# 查找vacation_date之后的年假继承记录(关联update_lines)
inherit_domain = [
('vacation_id', '=', main_vacation.id),
('create_date', '>=', fields.Datetime.to_datetime(vacation_date)),
('text', '=', '上月额度继承'),
('is_void', '=', False)
]
inherit_lines = self.env['vacation.leave.line'].search(inherit_domain)
if not inherit_lines:
continue
# 扣减年假workday
deduct_value = void_line.workday or 0.0
for inherit_line in inherit_lines:
new_workday = inherit_line.workday - deduct_value
inherit_line.write({'workday': new_workday})
@api.depends('other_fee_ids', 'other_fee_ids.holiday_type', 'other_fee_ids.lines',
'other_fee_ids.is_void', 'other_fee_ids.update_type', 'parenting_line_ids',
'parenting_line_ids.update_date', 'parenting_line_ids.end_date', 'parenting_line_ids.lines')
@@ -55,8 +55,8 @@ class YuthonVacationImportWizard(models.TransientModel):
else:
leave.write({'update_lines': update_value})
target_leaves1 = vacation_id.leave_ids.filtered(lambda l: l.text == '上月额度继承')
update_value = float(row[2].value) * 8
for leave in target_leaves1:
update_value = float(row[2].value) * 8
if update_value == 0:
leave.unlink()
else:
@@ -64,18 +64,34 @@ class YuthonVacationImportWizard(models.TransientModel):
target_overtimes = vacation_id.overtime_ids.filtered(lambda o: o.text == '上月额度继承')
if employee_id.company_id.name == '集团本部':
workday_value = float(row[3].value)
public_holidays = float(row[4].value)
else:
workday_value = float(row[3].value) * 8
public_holidays = 0
if employee_id.company_id.name == '天河粮储':
valid_date = datetime(2027, 6, 30)
else:
valid_date = None
if not target_overtimes:
self.env['vacation.over.line'].create({
'text': '上月额度继承',
'update_type': 'add',
'update_date': date,
'valid_date': valid_date,
'workday': workday_value,
'public_holidays': public_holidays,
'vacation_id': vacation_id.id,
})
for overtime in target_overtimes:
if employee_id.company_id.name == '集团本部':
workday_value = float(row[3].value)
public_holidays = float(row[4].value)
else:
workday_value = float(row[3].value) * 8
public_holidays = 0
if workday_value == 0 and public_holidays == 0:
overtime.unlink()
else:
overtime.write({'workday': workday_value,
'public_holidays': public_holidays})
vacation_id.update_vacation1()
vacation_id._compute_leave()
vacation_id._compute_working_overtime()