Files
gzth/yuthon_salary/wizard/payroll_labor_wizard.py
T
2025-10-16 19:32:56 +08:00

85 lines
3.7 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))
basic_salary = row[3].value
rank_salary = row[4].value
meal_allowance = row[5].value
total_payable = row[6].value
social_security_personal = row[7].value
provident_fund_personal = row[8].value
individual_tax = row[9].value
dispatched_actual_salary = row[10].value
social_security_company = row[11].value
provident_fund_company = row[12].value
disability_insurance = row[13].value
service_fee = row[14].value
tiantou_payable = row[15].value
company = row[16].value
payroll_id = self.env['yuthon.payroll.labor'].search([('employee_id', '=', employee_id.id),
('current_year', '=', current_year),
('current_month', '=', current_month),
])
if not payroll_id:
self.env['yuthon.payroll.labor'].create({
'employee_id': employee_id.id,
'current_year': current_year,
'current_month': current_month,
'basic_salary': basic_salary,
'rank_salary': rank_salary,
'meal_allowance': meal_allowance,
'total_payable': total_payable,
'social_security_personal': social_security_personal,
'provident_fund_personal': provident_fund_personal,
'individual_tax': individual_tax,
'dispatched_actual_salary': dispatched_actual_salary,
'social_security_company': social_security_company,
'provident_fund_company': provident_fund_company,
'disability_insurance': disability_insurance,
'service_fee': service_fee,
'tiantou_payable': tiantou_payable,
'company': company,
})
else:
payroll_id.write({
'basic_salary': basic_salary,
'rank_salary': rank_salary,
'meal_allowance': meal_allowance,
'total_payable': total_payable,
'social_security_personal': social_security_personal,
'provident_fund_personal': provident_fund_personal,
'individual_tax': individual_tax,
'dispatched_actual_salary': dispatched_actual_salary,
'social_security_company': social_security_company,
'provident_fund_company': provident_fund_company,
'disability_insurance': disability_insurance,
'service_fee': service_fee,
'tiantou_payable': tiantou_payable,
'company': company,
})