添加功能
This commit is contained in:
@@ -202,7 +202,7 @@ class YuthonVacationReports(models.Model):
|
||||
rec.update_line()
|
||||
|
||||
def update_line(self):
|
||||
if self.vacation_date == fields.Date.from_string('2026-01-01'):
|
||||
if self.vacation_date == fields.Date.from_string('2026-01-01') or (self.vacation_date == fields.Date.from_string('2026-03-01') and self.employee_id.name == '天河物管'):
|
||||
return
|
||||
self.manage_reject()
|
||||
# ========== 第一步:处理年假逻辑 ==========
|
||||
|
||||
@@ -14,6 +14,7 @@ class YuthonVacationImportWizard(models.TransientModel):
|
||||
|
||||
excel_file = fields.Binary(string="上传Excel表")
|
||||
excel_name = fields.Char(string="文件名")
|
||||
company_id = fields.Many2one('res.company', string='公司')
|
||||
|
||||
def confirm(self):
|
||||
"""
|
||||
@@ -24,14 +25,18 @@ class YuthonVacationImportWizard(models.TransientModel):
|
||||
raise ValidationError('请上传文件。')
|
||||
book = xlrd.open_workbook(file_contents=base64.decodebytes(self.excel_file))
|
||||
sh = book.sheet_by_index(0)
|
||||
for rx in range(1, sh.nrows):
|
||||
row = sh.row(rx)
|
||||
self.leave_import(row)
|
||||
if self.company_id.name in ['集团本部', '天河粮储']:
|
||||
for rx in range(1, sh.nrows):
|
||||
row = sh.row(rx)
|
||||
self.leave_import(row)
|
||||
else:
|
||||
for rx in range(1, sh.nrows):
|
||||
row = sh.row(rx)
|
||||
self.leave_import1(row)
|
||||
|
||||
def leave_import(self, row):
|
||||
employee_id = self.env['hr.employee'].search([('name', '=', row[0].value)], limit=1)
|
||||
if not employee_id:
|
||||
self.env.user.notify_warning(f"员工 {row[0].value} 不存在,跳过处理")
|
||||
return
|
||||
|
||||
date = datetime(2026, 1, 1)
|
||||
@@ -39,24 +44,97 @@ class YuthonVacationImportWizard(models.TransientModel):
|
||||
[('employee_id', '=', employee_id.id), ('vacation_date', '=', date)],
|
||||
limit=1
|
||||
)
|
||||
|
||||
if vacation_id:
|
||||
target_leaves = vacation_id.leave_ids.filtered(lambda l: l.text == '上月额度继承')
|
||||
for leave in target_leaves:
|
||||
update_value = int(row[1].value) * 8
|
||||
if update_value == 0:
|
||||
leave.unlink()
|
||||
else:
|
||||
leave.write({'update_lines': update_value})
|
||||
if employee_id.company_id.name == '天河粮储':
|
||||
target_leaves = vacation_id.leave_ids.filtered(lambda l: l.text == '年假分配')
|
||||
for leave in target_leaves:
|
||||
update_value = float(row[1].value) * 8
|
||||
if update_value == 0:
|
||||
leave.unlink()
|
||||
else:
|
||||
leave.write({'update_lines': update_value})
|
||||
target_leaves1 = vacation_id.leave_ids.filtered(lambda l: l.text == '上月额度继承')
|
||||
for leave in target_leaves1:
|
||||
update_value = float(row[2].value) * 8
|
||||
if update_value == 0:
|
||||
leave.unlink()
|
||||
else:
|
||||
leave.write({'update_lines': update_value})
|
||||
|
||||
|
||||
target_overtimes = vacation_id.overtime_ids.filtered(lambda o: o.text == '上月额度继承')
|
||||
for overtime in target_overtimes:
|
||||
workday_value = int(row[2].value) * 8
|
||||
if workday_value == 0:
|
||||
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 = float(row[4].value) * 8
|
||||
if workday_value == 0 and public_holidays == 0:
|
||||
overtime.unlink()
|
||||
else:
|
||||
overtime.write({'workday': workday_value})
|
||||
overtime.write({'workday': workday_value,
|
||||
'public_holidays': public_holidays})
|
||||
vacation_id.update_vacation1()
|
||||
vacation_id._compute_leave()
|
||||
vacation_id._compute_working_overtime()
|
||||
|
||||
def leave_import1(self, row):
|
||||
employee_id = self.env['hr.employee'].search([('name', '=', row[0].value)], limit=1)
|
||||
if not employee_id:
|
||||
self.env.user.notify_warning(f"员工 {row[0].value} 不存在,跳过处理")
|
||||
return
|
||||
|
||||
date = datetime(2026, 3, 1)
|
||||
vacation_id = self.env['yuthon.vacation.reports'].search(
|
||||
[('employee_id', '=', employee_id.id), ('vacation_date', '=', date)],
|
||||
limit=1
|
||||
)
|
||||
if vacation_id:
|
||||
target_leaves = vacation_id.leave_ids.filtered(lambda l: l.text == '上月额度继承')
|
||||
update_value = float(row[1].value) * 8
|
||||
if target_leaves:
|
||||
for leave in target_leaves:
|
||||
if update_value == 0:
|
||||
leave.unlink()
|
||||
else:
|
||||
leave.write({
|
||||
'update_lines': update_value,
|
||||
})
|
||||
vacation_id.dynamic_previous_year = update_value / 8
|
||||
else:
|
||||
if update_value != 0:
|
||||
self.env[vacation_id.leave_ids._name].create({
|
||||
'text': '上月额度继承',
|
||||
'update_type': 'add',
|
||||
'update_date': date,
|
||||
'valid_date': datetime(2027, 2, 28),
|
||||
'update_lines': update_value,
|
||||
'vacation_id': vacation_id.id,
|
||||
})
|
||||
vacation_id.dynamic_previous_year = update_value / 8
|
||||
|
||||
|
||||
target_overtimes = vacation_id.overtime_ids.filtered(lambda o: o.text == '上月额度继承')
|
||||
workday_value = float(row[2].value) * 8
|
||||
if target_overtimes:
|
||||
for overtime in target_overtimes:
|
||||
if workday_value == 0:
|
||||
overtime.unlink()
|
||||
else:
|
||||
overtime.write({'workday': workday_value})
|
||||
vacation_id.dynamic_previous_year1 = workday_value / 8
|
||||
else:
|
||||
if workday_value != 0:
|
||||
self.env[vacation_id.overtime_ids._name].create({
|
||||
'text': '上月额度继承',
|
||||
'update_type': 'add',
|
||||
'update_date': date,
|
||||
'overtime_methods': 'leave',
|
||||
'valid_date': datetime(2027, 2, 28),
|
||||
'workday': workday_value,
|
||||
'vacation_id': vacation_id.id,
|
||||
})
|
||||
vacation_id.dynamic_previous_year1 = workday_value / 8
|
||||
vacation_id._compute_leave()
|
||||
vacation_id._compute_working_overtime()
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<sheet>
|
||||
<group>
|
||||
<group>
|
||||
<field name="company_id"/>
|
||||
<field name="excel_file" filename="excel_name"/>
|
||||
<field name="excel_name" invisible="1"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user