61 lines
2.3 KiB
Python
61 lines
2.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import models, fields, api, _, SUPERUSER_ID
|
|
from odoo.exceptions import ValidationError, UserError
|
|
from pypinyin import pinyin, Style
|
|
import xlrd
|
|
import base64
|
|
import datetime
|
|
from datetime import datetime
|
|
|
|
|
|
class VacationReportsWizard(models.TransientModel):
|
|
_name = 'vacation.reports.wizard'
|
|
_description = '考勤报表导入'
|
|
|
|
excel_file = fields.Binary(string="上传Excel表")
|
|
excel_name = fields.Char(string="文件名")
|
|
report_ids = fields.Many2many('yuthon.vacation.reports', string='报表')
|
|
|
|
def confirm(self):
|
|
"""
|
|
导入excel文件,按行读取数据并处理
|
|
:return: 导入员工信息表并更新
|
|
"""
|
|
if not self.excel_file:
|
|
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.over_import(row)
|
|
|
|
def leave_import(self, row):
|
|
employee_id = self.env['hr.employee'].search([('name', '=', row[0].value)])
|
|
year_distribution = row[1].value
|
|
start_date = fields.Date.from_string("2025-12-1")
|
|
report_id = self.env['yuthon.vacation.reports'].search([('employee_id', '=', employee_id.id),
|
|
('vacation_date', '=', start_date)
|
|
])
|
|
if report_id:
|
|
report_id.write({'year_distribution': year_distribution})
|
|
|
|
|
|
def over_import(self, row):
|
|
employee_id = self.env['hr.employee'].search([('name', '=', row[0].value)])
|
|
year_holiday = float(row[12].value)
|
|
year_workday = float(row[11].value)
|
|
if not year_workday and not year_holiday:
|
|
year_workday = float(row[10].value)
|
|
start_date = fields.Date.from_string("2025-12-1")
|
|
report_id = self.env['yuthon.vacation.reports'].search([('employee_id', '=', employee_id.id),
|
|
('vacation_date', '=', start_date)
|
|
])
|
|
if report_id:
|
|
report_id.write(
|
|
{'year_holiday': year_holiday / 8
|
|
,'year_workday': year_workday / 8
|
|
})
|
|
|
|
|
|
|