74 lines
2.6 KiB
Python
74 lines
2.6 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 PropertyTenantWizard(models.Model):
|
|
_name = 'property.tenant.wizard'
|
|
|
|
|
|
excel_file = fields.Binary(string="上传Excel表")
|
|
excel_name = fields.Char(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.update_account(row)
|
|
|
|
def property_tenant_data(self, row):
|
|
tenant_id = self.env['property.tenant.information'].search([('name', '=', row[0].value)])
|
|
tax_number = row[1].value
|
|
invoicing_begins = row[2].value
|
|
invoicing_type_dict = {'专票': 'spot', '普票': 'cape'}
|
|
invoicing_type = invoicing_type_dict.get(row[3].value)
|
|
entity_type_dict = {'个人': 'person', '企业': 'company'}
|
|
entity_type = entity_type_dict.get(row[4].value)
|
|
legal = row[6].value
|
|
email = row[7].value
|
|
contact = row[8].value
|
|
phone = int(row[9].value) if row[9].value else False
|
|
industry_id = self.env['yuthon.industry.setting'].search([('name', '=', row[10].value)])
|
|
if not industry_id:
|
|
industry_id = self.env['yuthon.industry.setting'].create({'name': row[10].value})
|
|
tenant_data = {
|
|
'name': row[0].value,
|
|
'tax_number': tax_number,
|
|
'invoicing_begins': invoicing_begins,
|
|
'invoicing_type': invoicing_type,
|
|
'entity_type': entity_type,
|
|
'legal': legal,
|
|
'email': email,
|
|
'contact': contact,
|
|
'phone': phone,
|
|
'industry_id': industry_id.id,
|
|
}
|
|
|
|
if not tenant_id:
|
|
self.env['property.tenant.information'].create(tenant_data)
|
|
else:
|
|
tenant_id.write(tenant_data)
|
|
|
|
def update_account(self, row):
|
|
account_id = self.env['property.tenant.information'].search([('name', '=', row[0].value)], limit=1)
|
|
if account_id:
|
|
account_id.bank_ids = [(5, 0, 0)]
|
|
account_id.bank_ids = [(0, 0, {
|
|
'tenant_id': account_id.id,
|
|
'bank': row[1].value,
|
|
'user': row[3].value,
|
|
'name': row[2].value,
|
|
})]
|
|
|