Merge pull request !10146 from 李鹏宇/dev
This commit is contained in:
李鹏宇
2026-03-24 07:18:38 +00:00
committed by Gitee
2 changed files with 34 additions and 14 deletions
+34 -13
View File
@@ -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,
})
})
@@ -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: