From c8e92fcdbc6c032afc11d6de1cdf5da559b22d39 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, 16 Sep 2025 18:38:48 +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/property_reconciliation_wizard.py | 57 +++++++++++-------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/yuthon_property_approval/wizard/property_reconciliation_wizard.py b/yuthon_property_approval/wizard/property_reconciliation_wizard.py index 2da8edda6..4da8177ec 100644 --- a/yuthon_property_approval/wizard/property_reconciliation_wizard.py +++ b/yuthon_property_approval/wizard/property_reconciliation_wizard.py @@ -92,14 +92,8 @@ class PropertyReconciliationWizard(models.Model): # 计算违约天数和违约金 late_days = (fields.Date.from_string(self.actual_date) - next_month_first).days + 1 # 找到符合月份的租金 - matching_breakdown = next(( - breakdown for breakdown in contract_id.breakdown_ids - if breakdown.start_data <= self.actual_date <= breakdown.end_data - ), - None - ) penalty_amount = late_days * round( - matching_breakdown.monthly_amount * float(contract_id.percentage_liquidated_damages.name), 2 + contract_receivables.submitted * float(contract_id.percentage_liquidated_damages.name), 2 ) start_date_str = fields.Date.to_string(next_month_first) end_date_str = self.actual_date @@ -133,22 +127,23 @@ class PropertyReconciliationWizard(models.Model): ('payout_date', '!=', None), ]) if unpaid_rent_recs: - first_day = (unpaid_rent_recs.payout_date + timedelta(days=1)) - last_month_rent = unpaid_rent_recs.submitted - penalty_days = self.actual_date - first_day - penalty_amount = (penalty_days.days + 1) * round( - last_month_rent * float(contract_id.percentage_liquidated_damages.name), 2 - ) if contract_id else 0.0 - if penalty_amount > 0: - new_lines.append((0, 0, { - 'contract_id': contract_id.id if contract_id else None, - 'rent_month': 0, - 'due_date': fields.Date.to_string(first_day), - 'rent': penalty_amount, - 'amount': 0, - 'collection_type': 'penalty', - 'remake': f'违约金({fields.Date.to_string(first_day)}至{fields.Date.to_string(self.actual_date)},共{penalty_days.days + 1}天)', - })) + if (unpaid_rent_recs.payout_date + relativedelta(months=1)).month != self.actual_date.month: + first_day = (unpaid_rent_recs.payout_date + timedelta(days=1)) + last_month_rent = unpaid_rent_recs.submitted + penalty_days = self.actual_date - first_day + penalty_amount = (penalty_days.days + 1) * round( + last_month_rent * float(contract_id.percentage_liquidated_damages.name), 2 + ) if contract_id else 0.0 + if penalty_amount > 0: + new_lines.append((0, 0, { + 'contract_id': contract_id.id if contract_id else None, + 'rent_month': 0, + 'due_date': fields.Date.to_string(first_day), + 'rent': penalty_amount, + 'amount': 0, + 'collection_type': 'penalty', + 'remake': f'违约金({fields.Date.to_string(first_day)}至{fields.Date.to_string(self.actual_date)},共{penalty_days.days + 1}天)', + })) # 3. 添加到总列表 for vals in contract_penalties: @@ -386,6 +381,11 @@ class PropertyReconciliationWizard(models.Model): 'reconciliation_time': fields.Datetime.now(), 'receivable_log': f'当前登录人{rec.env.user.name}于{fields.Datetime.now()}对户名为{rec.bank_id.name_account}进行对账操作,对账应收金额为{rec.receivable_total},实际金额为{rec.actual_total}' }) + self.env['receivable.modify.line'].create({ + 'bank_id': rec.bank_id.id, + 'receivable_id': receivable.id, + 'amount': line.amount, + }) management_type_id = self.env['yuthon.management.type'].search([('name', '=', '违约金')]) if line.collection_type == 'penalty': # 用备注的的开始日期和结束日期 @@ -424,7 +424,11 @@ class PropertyReconciliationWizard(models.Model): 'remark': line.remake, 'reconciliation_time': fields.Datetime.now(), }) - + self.env['receivable.modify.line'].create({ + 'bank_id': rec.bank_id.id, + 'receivable_id': receivable_id.id, + 'amount': 0, + }) else: existing_record.write({ 'delivered1': existing_record.delivered1 + line.amount, @@ -436,6 +440,11 @@ class PropertyReconciliationWizard(models.Model): 'is_write': True if line.amount != 0 else None, 'reconciliation_time': fields.Datetime.now(), }) + self.env['receivable.modify.line'].create({ + 'bank_id': rec.bank_id.id, + 'receivable_id': existing_record.id, + 'amount': existing_record.delivered1 + line.amount, + }) # 计算已对账和未对账金额 rec.amount_been_reconciled += line.amount