43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
from odoo import models, fields, api, _, SUPERUSER_ID
|
|
from odoo.exceptions import ValidationError, UserError
|
|
import xlrd
|
|
import base64
|
|
import datetime
|
|
from datetime import datetime
|
|
import pandas as pd
|
|
|
|
|
|
class PropertyPhysicalWizard(models.Model):
|
|
_name = 'property.physical.wizard'
|
|
|
|
excel_file = fields.Binary(string="上传Excel表")
|
|
excel_name = fields.Char(string="文件名")
|
|
reimbursement_id = fields.Many2one('property.reimbursement.form', string="关联报销单")
|
|
|
|
def confirm(self):
|
|
"""
|
|
导入excel文件,按行读取数据并处理
|
|
"""
|
|
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_physical_update(row)
|
|
|
|
def yuthon_physical_update(self, row):
|
|
package_grouping = row[1].value
|
|
package_fee = row[4].value
|
|
examination_fee = row[5].value
|
|
fees = row[6].value
|
|
employee_id = self.env['hr.employee'].search([('name', '=', row[2].value)])
|
|
physical_date = {
|
|
'reimbursement_id': self.reimbursement_id.id,
|
|
'package_grouping': package_grouping,
|
|
'package_fee': package_fee,
|
|
'examination_fee': examination_fee,
|
|
'fees': fees,
|
|
'employee_id': employee_id.id,
|
|
}
|
|
self.env['property.physical.line'].create(physical_date) |