From 1b10ed59f393aa423abb80f4c0528047481c69e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= <9664676+pengyuthon@user.noreply.gitee.com> Date: Wed, 29 Oct 2025 16:16:27 +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 --- .../models/property_meter_archives.py | 10 +++++----- .../wizard/property_meter_wizard.py | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/yuthon_property/models/property_meter_archives.py b/yuthon_property/models/property_meter_archives.py index 521c2dd49..60ceea0a5 100644 --- a/yuthon_property/models/property_meter_archives.py +++ b/yuthon_property/models/property_meter_archives.py @@ -36,12 +36,11 @@ class PropertyMeterArchives(models.Model): fixed_receivables = fields.Float(string="固定应收", digits=(16, 4)) state = fields.Selection([("reading", "已抄"), ("unreading", "未抄")], string="抄表状态", default="unreading") - # 一次性更改仪表位置 def change_floor_address(self): archives_ids = self.env["property.meter.archives"].browse(self._context.get("active_ids", self._context.get("active_id"))) - for i in archives_ids: - if i.epitope_values_id.type == 'watermeter': - i.epitope_values_id = self.env['yuthon.epitope.values'].search([('type', '=', 'ammeter'), ('name', '=', i.epitope_values_id.name)]) + for meter_id in archives_ids: + if meter_id.unit_number.endswith('.0'): + meter_id.unit_number = meter_id.unit_number[:-2] # @api.model_create_multi 多条创建 @@ -337,7 +336,8 @@ class MeterArchivesLine(models.Model): self._context.get("active_ids", self._context.get("active_id")) ) for meter_id in meter_ids: - meter_id.is_acc = False + if meter_id.unit_number.endswith('.0'): + meter_id.unit_number = meter_id.unit_number[:-2] def push_task_push_wizard(self): meter_ids = self.env["meter.archives.line"].browse( diff --git a/yuthon_property/wizard/property_meter_wizard.py b/yuthon_property/wizard/property_meter_wizard.py index fc4f721bf..35c51f5ee 100644 --- a/yuthon_property/wizard/property_meter_wizard.py +++ b/yuthon_property/wizard/property_meter_wizard.py @@ -31,11 +31,17 @@ class PropertyMeterWizard(models.Model): sh = book.sheet_by_index(0) except Exception as e: raise ValidationError(f'文件解析错误: {str(e)}') - + not_found_unit_numbers = [] # 按行处理数据 for rx in range(1, sh.nrows): # 跳过表头行 row = sh.row(rx) - self.property_meter_data1(row) + self.property_meter_data1(row, not_found_unit_numbers) + + if not_found_unit_numbers: + print("\n===== 未找到电表库的单元编号汇总 =====") + for unit in not_found_unit_numbers: + print(unit) # 每行打印一个单元编号 + print(f"\n共 {len(not_found_unit_numbers)} 个单元编号未匹配到电表库") # # 处理1-9月份数据 # for month in range(1, 10): # self.property_meter_data(row, month) @@ -152,15 +158,16 @@ class PropertyMeterWizard(models.Model): } self.env['meter.archives.line'].sudo().create(line_vals) - def property_meter_data1(self, row): + def property_meter_data1(self, row, not_found_list): + unit_number = int(row[0].value) if isinstance(row[0].value, float) else row[0].value # 1. 根据单元编号找到电表库记录 archives_id = self.env['property.meter.archives'].sudo().search( - [('unit_number', '=', row[0].value)], + [('unit_number', '=', unit_number)], limit=1 ) if not archives_id: - _logger.info(f"未找到单元编号为 {row[0].value} 的电表库记录") - return # 未找到电表库,直接返回 + not_found_list.append(unit_number) + return # 2. 从电表任务明细(line_ids)中筛选出2025年1月的记录,并找到last_reading_time最早的那条 target_year = 2025