37 lines
1.3 KiB
Python
37 lines
1.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 PayrollLaborWizard(models.Model):
|
|
_name = 'payroll.labor.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):
|
|
employee_id = self.env['hr.employee'].search([('name', '=', row[0].value)])
|
|
current_year = row[1].value
|
|
current_month = str(int(row[2].value))
|
|
labor_amount = row[3].value
|
|
self.env['yuthon.payroll.labor'].create({
|
|
'employee_id': employee_id.id,
|
|
'current_year': current_year,
|
|
'current_month': current_month,
|
|
'labor_amount': labor_amount,
|
|
}) |