From 13fc58bd334a66bc27928522420651fa031a30a3 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: Tue, 24 Mar 2026 15:17:51 +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/electric_water_wizard.py | 47 ++++++++++++++----- .../models/inherit_yuthon_property.py | 1 - 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/yuthon_property/wizard/electric_water_wizard.py b/yuthon_property/wizard/electric_water_wizard.py index cd5df762f..f1fef19b6 100644 --- a/yuthon_property/wizard/electric_water_wizard.py +++ b/yuthon_property/wizard/electric_water_wizard.py @@ -14,14 +14,12 @@ class ElectricWaterWizard(models.TransientModel): def confirm(self): push_date = self.push_date - # 当月第一天 month_start = push_date.replace(day=1) - # 当月最后一天(处理12月边界) if push_date.month == 12: month_end = push_date.replace(year=push_date.year + 1, month=1, day=1) - timedelta(days=1) else: month_end = push_date.replace(month=push_date.month + 1, day=1) - timedelta(days=1) - # 处理电表推送 + push_date_minus_1month = (self.push_date - relativedelta(months=1)) if self.meter_ids: is_acc = False for meter in self.meter_ids: @@ -31,9 +29,21 @@ class ElectricWaterWizard(models.TransientModel): if meter.end_time: if meter.end_time and meter.end_time < self.push_date: continue + first_property = False if meter.yuthon_property_ids: - push_date_minus_1month = (self.push_date - relativedelta(months=1)) - first_property = meter.yuthon_property_ids[0] + for prop in meter.yuthon_property_ids: + # 检查这个房产是否存在合同 + contract_line = self.env['property.lease.contract.line'].search([ + ('address_id', '=', prop.id), + ('lease_id.actual_start_time', '<', push_date_minus_1month), + ('lease_id.actual_end_time', '>=', push_date_minus_1month), + ], limit=1) + if contract_line: + first_property = prop + break + # ====================================================================== + + if first_property: contract_line = self.env['property.lease.contract.line'].search([ ('address_id', '=', first_property.id), ('lease_id.actual_start_time', '<', push_date_minus_1month), @@ -57,9 +67,7 @@ class ElectricWaterWizard(models.TransientModel): is_fix_price = 'no' # 查找上个月的记录 - # 查找上个月的记录,上次用量,上次读数,上次抄表日期 last_month_line = meter.line_ids.search([('meter_date', '<', self.push_date)]).sorted('meter_date')[-1] - # 如果当前数据不存在,则新建任务,按照天的纬度 self_month_line = meter.line_ids.search([ ('meter_date', '>=', month_start), ('meter_date', '<=', month_end), @@ -69,8 +77,8 @@ class ElectricWaterWizard(models.TransientModel): meter.line_ids.create({ 'archives_id': meter.id, 'is_acc': is_acc, - 'is_fix_loss':is_fix_loss, - 'is_fix_price':is_fix_price, + 'is_fix_loss': is_fix_loss, + 'is_fix_price': is_fix_price, 'last_meter': last_month_line.last_meter, 'last_read': last_month_line.last_read, 'last_dosage': last_month_line.last_dosage, @@ -98,9 +106,24 @@ class ElectricWaterWizard(models.TransientModel): if water.end_time: if water.end_time and water.end_time < self.push_date: continue + + # ====================== 水表:找到第一个有合同的房产 ====================== + first_property = False if water.yuthon_property_ids: + for prop in water.yuthon_property_ids: + # 检查这个房产是否存在合同 + contract_line = self.env['property.lease.contract.line'].search([ + ('address_id', '=', prop.id), + ('lease_id.actual_start_time', '<', push_date_minus_1month), + ('lease_id.actual_end_time', '>=', push_date_minus_1month), + ], limit=1) + if contract_line: + first_property = prop + break + # ====================================================================== + + if first_property: push_date_minus_1month = (self.push_date - relativedelta(months=1)) - first_property = water.yuthon_property_ids[0] contract_line = self.env['property.lease.contract.line'].search([ ('address_id', '=', first_property.id), ('lease_id.actual_start_time', '<', push_date_minus_1month), @@ -122,9 +145,7 @@ class ElectricWaterWizard(models.TransientModel): is_fix_loss = 'yes' is_fix_price = 'no' - # 查找上个月的记录,上次用量,上次读数,上次抄表日期 last_month_line = water.line_ids.search([('meter_date', '<', self.push_date)]).sorted('meter_date')[-1] - # 如果当前数据不存在,则新建任务,按照天的纬度 self_month_line = water.line_ids.search([ ('meter_date', '>=', month_start), ('meter_date', '<=', month_end), @@ -151,4 +172,4 @@ class ElectricWaterWizard(models.TransientModel): 'is_acc': is_acc, 'maximum_count': water.maximum_count, 'contract_id': contract_line.lease_id.id if contract_line and contract_line.lease_id else False, - }) + }) \ No newline at end of file diff --git a/yuthon_property_approval/models/inherit_yuthon_property.py b/yuthon_property_approval/models/inherit_yuthon_property.py index 046905ad5..552d051f0 100644 --- a/yuthon_property_approval/models/inherit_yuthon_property.py +++ b/yuthon_property_approval/models/inherit_yuthon_property.py @@ -52,7 +52,6 @@ class MeterArchivesLine(models.Model): contract_name = fields.Char(string='合同编号', store=True, index=True, compute="_compute_name") lessee_name = fields.Char(string='承租方名称', store=True, index=True, compute="_compute_name") - @api.depends('yuthon_property_ids', 'archives_id', 'contract_id', 'lessee_id') def _compute_name(self): for name in self: