Files
gzth/yuthon_salary/wizard/rank_log_wizard.py
T
2025-07-24 20:37:19 +08:00

45 lines
1.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 RankLogWizard(models.Model):
_name = 'rank.log.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.payroll_rank_log(row)
def payroll_rank_log(self, row):
structure_id = self.env['hr.payroll.structure'].search([('name', '=', row[1].value)])
base_salary = row[2].value
rank_salary = row[3].value
advance_performance_bonuses = row[4].value
communication_subsidy = row[5].value
position_salary = row[6].value
log_data = {
'structure_id': structure_id.id,
'base_salary': float(base_salary) if base_salary else 0.0,
'rank_salary': float(rank_salary) if rank_salary else 0.0,
'advance_performance_bonuses': float(advance_performance_bonuses) if advance_performance_bonuses else 0.0,
'communication_subsidy': float(communication_subsidy) if communication_subsidy else 0.0,
'position_salary': float(position_salary) if position_salary else 0.0,
'effective_date': fields.Date.today(),
'is_enable': True
}
self.env['rank.log.line'].create(log_data)