Files
gzth/yuthon_holiday/wizard/leave_allocation_wizard.py
T
2025-03-15 21:02:30 +08:00

48 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
from odoo import models, fields, api, _, SUPERUSER_ID
from odoo.exceptions import ValidationError, UserError
import xlrd
import base64
import datetime
from datetime import datetime
import pandas as pd
class LeaveAllocationWizard(models.Model):
_name = 'leave.allocation.wizard'
_description = '初始化假期弹窗'
excel_file = fields.Binary(string="上传Excel表")
excel_name = fields.Char(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.salary_import(row)
def salary_import(self, row):
employee_id = self.env['hr.employee'].search([('name', '=', row[0].value)], limit=1)
holiday_status_id = self.env['hr.leave.type'].search([('name', '=', '年假')], limit=1)
accrual_plan_id = self.env['hr.leave.accrual.plan'].search([('name', '=', '年假(集团本部)')], limit=1)
self.env['hr.leave.allocation'].create({
'employee_id': employee_id.id,
'name': '年假公司分配',
'number_of_days':row[2].value,
'holiday_status_id': holiday_status_id.id,
'accrual_plan_id': accrual_plan_id.id,
'allocation_type': 'accrual',
"number_of_days_display":row[2].value,
'notes':row[3].value
})