Files
2025-01-21 15:58:51 +08:00

52 lines
2.0 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 PropertyAddWizard(models.Model):
_name = 'property.add.wizard'
excel_file = fields.Binary(string="上传Excel表")
property_approval_id = fields.Many2one('property.approval', string="新增物业审批")
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.yuthon_property_add_data(row)
def yuthon_property_add_data(self, row):
name = row[0].value
is_affirmation = row[1].value
owner_id = self.env['yuthon.owner.message'].search([('name', '=', row[2].value)])
title_number = row[3].value
rent_area = row[4].value
condition_data = {'出租中': 'rental', '空置中': 'vacant', '待出租': 'rented'}
condition = condition_data.get(row[6].value)
registered_id = self.env['yuthon.purpose.evidence'].search([('name', '=', row[5].value)])
if not registered_id:
self.env['yuthon.purpose.evidence'].create({'name': row[5].value})
approval_list =[]
approval_list.append({
'property_approval_id': self.property_approval_id.id,
'name': name,
'is_affirmation': is_affirmation,
'owner': owner_id.id,
'title_number': title_number,
'area': rent_area,
'condition': condition,
'registered_id':registered_id.id,
})
self.env['yuthon.property.approval.line'].create(approval_list)