From 2f453796afec42d635dc9ff819ea95cf3b691f5c Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Tue, 31 Dec 2024 16:24:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wizard/property_contract_wizard.py | 89 +++++++++++++++++++ ...izard.xml => property_contract_wizard.xml} | 12 +-- .../wizard/property_inducts_wizard.py | 35 -------- 3 files changed, 95 insertions(+), 41 deletions(-) create mode 100644 yuthon_property_approval/wizard/property_contract_wizard.py rename yuthon_property_approval/wizard/{property_inducts_wizard.xml => property_contract_wizard.xml} (67%) delete mode 100644 yuthon_property_approval/wizard/property_inducts_wizard.py diff --git a/yuthon_property_approval/wizard/property_contract_wizard.py b/yuthon_property_approval/wizard/property_contract_wizard.py new file mode 100644 index 000000000..05f3f15ed --- /dev/null +++ b/yuthon_property_approval/wizard/property_contract_wizard.py @@ -0,0 +1,89 @@ +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 PropertyContractWizard(models.Model): + _name = 'property.contract.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.yuthon_contract_data(row) + + def yuthon_contract_data(self, row): + admin_id = self.env['res.users'].search([('name', '=', row[0].value)]) + contract_code = row[1].value + name = row[2].value + address_id = int(row[3].value) + lessee_id = int(row[5].value) + contact = row[6].value + invoicing_begins = row[7].value + invoicing_type_dict = {'专票': 'spot', '普票': 'cape', '': ''} + invoicing_type = invoicing_type_dict.get(row[8].value, '') + contract_time = row[11].value + term_start_time = row[12].value + term_end_time = row[13].value + total_area = row[14].value + deposit = row[15].value + increments_every_few_years = row[16].value + increment_percentage = row[17].value + unit_price = row[23].value + first_year_rent = row[25].value + tax_rate = row[26].value + # rent_company = row[27].value + # rent_account = row[28].value + contract_type_dict = {'续租': 'lease_renewal', '临租': 'interim', '补充协议': 'new', '首租': 'first'} + contract_type = contract_type_dict.get(row[29].value, '') + cycle_type_dict = {'月': 'monthly', '季度': 'quarter', '半年': 'half', '年度': 'year'} + cycle_dict = cycle_type_dict.get(row[35].value, '') + percentage_liquidated_damages = self.env['yuthon.penalty.setting'].search([('name', '=', row[36].value)]) + if not percentage_liquidated_damages: + percentage_liquidated_damages = self.env['yuthon.penalty.setting'].create({'name': row[36].value}) + + tax = row[40].value + performance_bonds = row[39].value + contract_date = { + 'name': name, + 'admin_id': admin_id.id, + 'contract_code': contract_code, + 'contact': contact, + 'phone': invoicing_begins, + 'invoicing_type': invoicing_type, + 'contract_time':datetime.strptime(contract_time, '%Y-%m-%d').date() if term_start_time else None, + 'term_start_time':datetime.strptime(term_start_time, '%Y-%m-%d').date() if term_start_time else None, + 'term_end_time':datetime.strptime(term_end_time, '%Y-%m-%d').date() if term_end_time else None, + 'total_area':total_area, + 'deposit':deposit, + 'tax':tax, + 'performance_bonds':performance_bonds, + 'increments_every_few_years':increments_every_few_years, + 'increment_percentage':increment_percentage, + 'unit_price':unit_price, + 'first_year_rent':first_year_rent, + 'tax_rate':tax_rate, + 'contract_type':contract_type, + 'cycle_dict':cycle_dict, + 'lessee_id':lessee_id if self.env['property.tenant.information'].search([('id', '=',lessee_id)]) else '', + 'percentage_liquidated_damages':percentage_liquidated_damages.id, + } + property_contract_id = self.env['property.lease.contract'].create(contract_date) + management_list = [] + management_list.append((0, 0, { + 'lease_id': property_contract_id.id, + 'address_id': address_id, + })) + property_contract_id.lease_ids = management_list \ No newline at end of file diff --git a/yuthon_property_approval/wizard/property_inducts_wizard.xml b/yuthon_property_approval/wizard/property_contract_wizard.xml similarity index 67% rename from yuthon_property_approval/wizard/property_inducts_wizard.xml rename to yuthon_property_approval/wizard/property_contract_wizard.xml index 83095c1a0..2139b1f72 100644 --- a/yuthon_property_approval/wizard/property_inducts_wizard.xml +++ b/yuthon_property_approval/wizard/property_contract_wizard.xml @@ -1,19 +1,19 @@ - - 物业信息模板下载 + + 物业合同模板 self ... - - 物业信息导入弹窗 - property.inducts.wizard + + 物业合同导入弹窗 + property.contract.wizard
-
diff --git a/yuthon_property_approval/wizard/property_inducts_wizard.py b/yuthon_property_approval/wizard/property_inducts_wizard.py deleted file mode 100644 index 120bd3f69..000000000 --- a/yuthon_property_approval/wizard/property_inducts_wizard.py +++ /dev/null @@ -1,35 +0,0 @@ -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 PropertyInductsWizard(models.Model): - _name = 'property.inducts.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(1, sh.nrows): - row = sh.row(rx) - self.employee_user_data(row) - return { - 'name': '批量更新新物业信息', - 'type': 'ir.actions.act_window', - 'view_mode': 'tree', - 'res_model': 'property.approval.line', - } - - def employee_user_data(self, row): - pass \ No newline at end of file