Files
gzth/yuthon_salary/wizard/payroll_retired_wizard.py
T
2025-04-01 15:46:21 +08:00

37 lines
1.2 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 PayrollLaborWizard(models.Model):
_name = 'payroll.retired.wizard'
_description = '退休人员费用导入弹窗'
excel_file = fields.Binary(string="上传Excel表")
excel_name = fields.Char(string="文件名")
def confirm(self):
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.yuthon_payroll_data(row)
def yuthon_payroll_data(self, row):
name = row[0].value
current_year = row[1].value
current_month = str(int(row[2].value))
retired_amount = row[3].value
self.env['yuthon.payroll.retired'].create({
'name': name,
'current_year': current_year,
'current_month': current_month,
'retired_amount': retired_amount,
})