!9276 添加功能

Merge pull request !9276 from 李鹏宇/dev_zhou
This commit is contained in:
李鹏宇
2026-03-05 03:36:11 +00:00
committed by Gitee
5 changed files with 46 additions and 97 deletions
@@ -30,7 +30,6 @@ class OvertimeActiveLine(models.Model):
validity = fields.Char(string="有效期")
is_void = fields.Boolean(string="作废", default=False)
def all_unlink(self):
active_ids = self.env["overtime.active.line"].browse(
self._context.get('active_ids', self._context.get('active_id')))
@@ -31,6 +31,22 @@ class VacationOvertimeActive(models.Model):
remaining_quantity = fields.Float(string="剩余数")
select_revoke = fields.Selection([('to_do', '待撤销'), ('done', '已撤销')], string='状态')
def update_vacation(self):
active_ids = self.env["vacation.overtime.active"].browse(
self._context.get('active_ids', self._context.get('active_id', []))
)
for record in active_ids:
overtime_lines = self.env['vacation.over.line'].search([
('employee_id', '=', record.employee_id.id),
('overtime_methods', '=', 'fee')
])
overtime_lines.write({
'workday': record.carry_forward_quantity,
'update_date': record.carry_forward_date
})
def all_unlink(self):
active_ids = self.env["vacation.overtime.active"].browse(
self._context.get('active_ids', self._context.get('active_id')))
@@ -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')
@@ -41,4 +41,11 @@
<field name="view_mode">tree,search</field>
<field name="view_id" ref="view_vacation_overtime_active_tree"/>
</record>
<record id="update_vacation" model="ir.actions.server">
<field name="name">一次性</field>
<field name="model_id" ref="yuthon_hr_attendance.model_vacation_overtime_active"/>
<field name="binding_model_id" ref="yuthon_hr_attendance.model_vacation_overtime_active"/>
<field name="state">code</field>
<field name="code">action = model.update_vacation()</field>
</record>
</odoo>
@@ -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()