From 6148d9ee4ac77d3cb9d4ec95d3aa790ef50dbcb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Mon, 2 Mar 2026 21:33:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=8E=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/current_receivable_property_fee_report.py | 6 +++++- yuthon_report/models/current_receivable_rent_report.py | 6 +++++- yuthon_report/models/receivable_report.py | 10 +++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/yuthon_report/models/current_receivable_property_fee_report.py b/yuthon_report/models/current_receivable_property_fee_report.py index c34dbd582..adebda322 100644 --- a/yuthon_report/models/current_receivable_property_fee_report.py +++ b/yuthon_report/models/current_receivable_property_fee_report.py @@ -79,7 +79,11 @@ class CurrentReceivablePropertyFeeReport(models.Model): for idx, rec in enumerate(receivables, start=1): amt = rec.original_amount or 0.0 # 从合同获取税率 - tax_rate = float(rec.contract_id.tax_rate.name.replace('%', '')) if rec.contract_id and rec.contract_id.tax_rate else 0.0 + try: + tax_rate_str = str(rec.contract_id.tax_rate.name) if rec.contract_id and rec.contract_id.tax_rate else "0" + tax_rate = float(tax_rate_str.replace('%', '').strip()) if tax_rate_str else 0.0 + except (ValueError, TypeError): + tax_rate = 0.0 amt_nt = amt / (1 + tax_rate / 100) if tax_rate else amt total_amount += amt total_amount_nt += amt_nt diff --git a/yuthon_report/models/current_receivable_rent_report.py b/yuthon_report/models/current_receivable_rent_report.py index 85198c1e1..ea94a6661 100644 --- a/yuthon_report/models/current_receivable_rent_report.py +++ b/yuthon_report/models/current_receivable_rent_report.py @@ -64,7 +64,11 @@ class CurrentReceivableRentReport(models.Model): # 实际应收 = 原始金额 - 减免金额 actual_amt = amt - discount # 从合同获取税率 - tax_rate = float(rec.contract_id.tax_rate.name.replace('%', '')) if rec.contract_id and rec.contract_id.tax_rate else 0.0 + try: + tax_rate_str = str(rec.contract_id.tax_rate.name) if rec.contract_id and rec.contract_id.tax_rate else "0" + tax_rate = float(tax_rate_str.replace('%', '').strip()) if tax_rate_str else 0.0 + except (ValueError, TypeError): + tax_rate = 0.0 actual_amt_nt = actual_amt / (1 + tax_rate / 100) if tax_rate else actual_amt # 统计每个管理类型的合计 diff --git a/yuthon_report/models/receivable_report.py b/yuthon_report/models/receivable_report.py index 58f864eb9..cc3a63332 100644 --- a/yuthon_report/models/receivable_report.py +++ b/yuthon_report/models/receivable_report.py @@ -78,7 +78,15 @@ class YuthonProperty(models.Model): 'display_name': rec.contract_id.contract_code, } if rec.contract_id else "", "发票类型": invoice_type_map.get(rec.invoice_type, ""), - "税率": f"{float(rec.contract_id.tax_rate.name.replace('%', '')):.1f}%" if rec.contract_id and rec.contract_id.tax_rate else "0.0%" + "税率": ( + lambda tr: ( + lambda v: f"{v:.1f}%" if v is not None else "0.0%" + )( + float(str(tr).replace('%', '').strip()) + if tr and str(tr).replace('%', '').strip() + else None + ) + )(rec.contract_id.tax_rate.name if rec.contract_id and rec.contract_id.tax_rate else None) }) summary_stats = []