49 lines
2.1 KiB
Python
49 lines
2.1 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
|
|
|
|
|
|
class YuthonContractWizard(models.Model):
|
|
_name = 'yuthon.contract.wizard'
|
|
|
|
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(4, sh.nrows):
|
|
row = sh.row(rx)
|
|
self.employee_contract_data(row)
|
|
|
|
def employee_contract_data(self,row):
|
|
employee_id = self.env['hr.employee'].search([('name', '=', row[1].value)])
|
|
structure_type_id = self.env['hr.payroll.structure.type'].search([('name', '=', row[11].value), ('yuthon_company', '=', 'thlc')])
|
|
party_id = self.env['yuthon.party.setting'].search([('party', '=', '广州天河粮食储备管理有限公司')])
|
|
contract_type_id = self.env['hr.contract.type'].search([('name', '=', '正式合同(一签)')])
|
|
wage_id = self.env['hr.salary.rule'].search([('struct_id.name', '=', structure_type_id.name),
|
|
('yuthon_company', '=', 'thlc'),
|
|
('name', '=', '基本工资')])
|
|
resource_calendar_id = self.env['resource.calendar'].search([('name', '=', '行政考勤')], limit=1)
|
|
wage = wage_id.amount_fix
|
|
self.env['hr.contract'].create({
|
|
'employee_id': employee_id.id,
|
|
'structure_type_id':structure_type_id.id,
|
|
'party_id':party_id.id,
|
|
'contract_type_id':contract_type_id.id,
|
|
'wage':wage,
|
|
'state':'open',
|
|
'resource_calendar_id':resource_calendar_id.id
|
|
})
|
|
|