From bd07b7d60a9701527af6cc23451dbc3ca83794c7 Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Sat, 11 Jan 2025 17:49:51 +0800 Subject: [PATCH 1/2] =?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 --- yuthon_property/__manifest__.py | 1 + .../models/property_meter_water.py | 8 +++ yuthon_property/security/ir.model.access.csv | 3 +- .../views/property_meter_water_views.xml | 7 +++ yuthon_property/wizard/__init__.py | 3 +- .../wizard/property_meter_wizard.py | 18 +++++- .../wizard/property_water_wizard.py | 61 +++++++++++++++++++ .../wizard/property_water_wizard_views.xml | 34 +++++++++++ .../models/property_lease_contract.py | 2 +- .../wizard/choose_property_wizard.py | 45 ++++++++++++++ 10 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 yuthon_property/wizard/property_water_wizard.py create mode 100644 yuthon_property/wizard/property_water_wizard_views.xml diff --git a/yuthon_property/__manifest__.py b/yuthon_property/__manifest__.py index f82bb4b52..5f25807ae 100644 --- a/yuthon_property/__manifest__.py +++ b/yuthon_property/__manifest__.py @@ -49,6 +49,7 @@ 'wizard/yuthon_property_wizard_views.xml', 'wizard/property_meter_wizard_views.xml', 'wizard/property_tenant_wizard_views.xml', + 'wizard/property_water_wizard_views.xml', 'views/menuitem.xml', ], 'assets': { diff --git a/yuthon_property/models/property_meter_water.py b/yuthon_property/models/property_meter_water.py index d46f1da2e..e37989362 100644 --- a/yuthon_property/models/property_meter_water.py +++ b/yuthon_property/models/property_meter_water.py @@ -52,3 +52,11 @@ class PropertyMeterWater(models.Model): property_id.water_meter_ids = meter_list + def action_property_water_wizard(self): + return { + "type": "ir.actions.act_window", + "name": "批量导入物业电表", + "res_model": "property.water.wizard", + "view_mode": "form", + "target": "new", + } \ No newline at end of file diff --git a/yuthon_property/security/ir.model.access.csv b/yuthon_property/security/ir.model.access.csv index 48fd9d205..375026dba 100644 --- a/yuthon_property/security/ir.model.access.csv +++ b/yuthon_property/security/ir.model.access.csv @@ -56,4 +56,5 @@ access_yuthon_property_wizard,yuthon_property_wizard,model_yuthon_property_wizar access_yuthon_property_company,yuthon_property_company,model_yuthon_property_company,base.group_user,1,1,1,1 access_property_meter_wizard,property_meter_wizard,model_property_meter_wizard,base.group_user,1,1,1,1 access_yuthon_industry_setting,yuthon_industry_setting,model_yuthon_industry_setting,base.group_user,1,1,1,1 -access_property_tenant_wizard,property_tenant_wizard,model_property_tenant_wizard,base.group_user,1,1,1,1 \ No newline at end of file +access_property_tenant_wizard,property_tenant_wizard,model_property_tenant_wizard,base.group_user,1,1,1,1 +access_property_water_wizard,property_water_wizard,model_property_water_wizard,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/yuthon_property/views/property_meter_water_views.xml b/yuthon_property/views/property_meter_water_views.xml index 2798bcfa2..d5a92df03 100644 --- a/yuthon_property/views/property_meter_water_views.xml +++ b/yuthon_property/views/property_meter_water_views.xml @@ -78,4 +78,11 @@ property.meter.water tree,form + + 导入水表 + + + code + action = model.action_property_water_wizard() + \ No newline at end of file diff --git a/yuthon_property/wizard/__init__.py b/yuthon_property/wizard/__init__.py index d05385e17..ef88acd72 100644 --- a/yuthon_property/wizard/__init__.py +++ b/yuthon_property/wizard/__init__.py @@ -1,3 +1,4 @@ from . import yuthon_property_wizard from . import property_meter_wizard -from . import property_tenant_wizard \ No newline at end of file +from . import property_tenant_wizard +from . import property_water_wizard diff --git a/yuthon_property/wizard/property_meter_wizard.py b/yuthon_property/wizard/property_meter_wizard.py index 774d8e8f9..4cff40255 100644 --- a/yuthon_property/wizard/property_meter_wizard.py +++ b/yuthon_property/wizard/property_meter_wizard.py @@ -29,14 +29,25 @@ class PropertyMeterWizard(models.Model): def property_meter_data(self,row): name = row[0].value unit_number = row[1].value - property_id = self.env['yuthon.property'].search([('name', '=', row[2].value)]) + installation_location = row[2].value + if row[4].value: + gauge_magnification = float(row[4].value) + else: + gauge_magnification = None + property_id = self.env['yuthon.property'].search([('name', '=', row[8].value)]) meter_list = [] type_dict = {'公共':'public', '收费':'fees', '':''} - type = type_dict.get(row[3].value) + type = type_dict.get(row[6].value) + state_dict = {'启用': 1, '停用': 0, '': ''} + is_state = state_dict.get(row[7].value) meter_data = { 'name': name, 'unit_number': unit_number, - 'type': type + 'installation_location': installation_location, + 'type': type, + 'gauge_magnification': gauge_magnification, + 'yuthon_property_id':property_id.id if property_id else None, + 'is_state':is_state } meter_id = self.env['property.meter.archives'].create(meter_data) if property_id: @@ -46,4 +57,5 @@ class PropertyMeterWizard(models.Model): property_id.write({ 'is_electricity_meter' : True, }) + property_id.energy_meter_ids = [(5, 0, 0)] property_id.energy_meter_ids = meter_list diff --git a/yuthon_property/wizard/property_water_wizard.py b/yuthon_property/wizard/property_water_wizard.py new file mode 100644 index 000000000..94b264313 --- /dev/null +++ b/yuthon_property/wizard/property_water_wizard.py @@ -0,0 +1,61 @@ +# -*- 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 PropertyWaterWizard(models.Model): + _name = 'property.water.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.property_water_data(row) + + def property_water_data(self,row): + name = row[0].value + unit_number = row[1].value + installation_location = row[2].value + if row[4].value: + gauge_magnification = float(row[4].value) + else: + gauge_magnification = None + property_id = self.env['yuthon.property'].search([('name', '=', row[8].value)]) + water_list = [] + type_dict = {'公共':'public', '收费':'fees', '':''} + type = type_dict.get(row[6].value) + state_dict = {'启用':1, '停用':0, '':''} + is_state = state_dict.get(row[7].value) + water_data = { + 'name': name, + 'unit_number': unit_number, + 'installation_location': installation_location, + 'type': type, + 'gauge_magnification': gauge_magnification, + 'yuthon_property_id':property_id.id if property_id else None, + 'is_state':is_state + } + water_id = self.env['property.meter.water'].create(water_data) + if property_id: + water_list.append((0, 0, { + 'property_meter_water_id': water_id.id, + })) + property_id.write({ + 'is_meter' : True, + }) + property_id.water_meter_ids = [(5, 0, 0)] + property_id.water_meter_ids = water_list diff --git a/yuthon_property/wizard/property_water_wizard_views.xml b/yuthon_property/wizard/property_water_wizard_views.xml new file mode 100644 index 000000000..2061d63ff --- /dev/null +++ b/yuthon_property/wizard/property_water_wizard_views.xml @@ -0,0 +1,34 @@ + + + + 电仪表模板 下载 + self + . + + + 审批意见弹窗 + property.water.wizard + +
+ +
+
+ + + + + + + + +
+ +
+
+
+
\ No newline at end of file diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py index 5532c7f9a..7e61bf8fc 100644 --- a/yuthon_property_approval/models/property_lease_contract.py +++ b/yuthon_property_approval/models/property_lease_contract.py @@ -868,7 +868,7 @@ class PropertyLeaseContract(models.Model): rec.is_electricity = True for electricity_id in property_id.energy_meter_ids: electricity_list.append([0, 0, { - 'fees_id': electricity_id.id, + 'fees_id': electricity_id.standard_id.id, 'proportional':electricity_id.rate, }]) else: diff --git a/yuthon_property_approval/wizard/choose_property_wizard.py b/yuthon_property_approval/wizard/choose_property_wizard.py index 7453e9c15..9d8b0f33c 100644 --- a/yuthon_property_approval/wizard/choose_property_wizard.py +++ b/yuthon_property_approval/wizard/choose_property_wizard.py @@ -8,12 +8,57 @@ class ChoosePropertyWizard(models.Model): property_ids = fields.Many2many('yuthon.property', string="物业信息") def confirm(self): + rec = self.lease_contract_id self.lease_contract_id.lease_ids.unlink() + lease_name = [] lease_ids_to_add = [] + electricity_list = [] + water_list = [] + fee_list = [] for record in self.property_ids: + lease_name.append(record.name) lease_ids_to_add.append((0, 0, { "lease_id": self.lease_contract_id.id, "address_id": record.id, })) + if record.is_electricity_meter: + rec.is_electricity = True + for electricity_id in record.energy_meter_ids: + electricity_list.append([0, 0, { + 'fees_id': electricity_id.standard_id.id, + 'proportional': electricity_id.rate, + }]) + else: + rec.is_electricity = False + if record.is_meter: + rec.is_water = True + for electricity_id in record.water_meter_ids: + water_list.append([0, 0, { + 'fees_id': electricity_id.standard_id.id, + 'proportional': electricity_id.rate, + }]) + else: + rec.is_water = False + if record.is_message_fee: + rec.is_mange = True + standard_id = record.message_standard_id + fee_list.append([0, 0, { + 'fees_id': standard_id.id, + 'proportional': standard_id.amount}]) + else: + rec.is_mange = False + + rec.electricity_fee_ids = [(5, 0, 0)] + rec.mange_fee_ids = [(5, 0, 0)] + rec.water_fee_ids = [(5, 0, 0)] + rec.admin_id = rec.lease_ids[0].admin_id.id if rec.lease_ids else '' + rec.company_id = rec.lease_ids[0].address_id.company_id.id if rec.lease_ids else '' + rec.precinct_id = rec.lease_ids[0].address_id.precinct_id.id if rec.lease_ids else '' + rec.electricity_fee_ids = electricity_list + rec.water_fee_ids = water_list + rec.mange_fee_ids = fee_list + self.lease_contract_id.write({'name': ','.join(lease_name), + 'use_address':','.join(lease_name), + 'address_for_delivery':','.join(lease_name)}) self.lease_contract_id.lease_ids = lease_ids_to_add From 8b351d135791606a1c1ccc72bba6ff7059902dc5 Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Sat, 11 Jan 2025 17:52:51 +0800 Subject: [PATCH 2/2] =?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 --- yuthon_property/views/yuthon_property_views.xml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/yuthon_property/views/yuthon_property_views.xml b/yuthon_property/views/yuthon_property_views.xml index f3a2dc87b..940af86bb 100644 --- a/yuthon_property/views/yuthon_property_views.xml +++ b/yuthon_property/views/yuthon_property_views.xml @@ -57,8 +57,6 @@ - - @@ -80,9 +78,19 @@ + + + + + + + + + +