From 67a89e88c98c1fd354277f4bc5a40c9299ec2ea8 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, 1 Apr 2026 18:30:17 +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_bank_statements.py | 4 +-
.../views/property_bank_statements_views.xml | 5 +-
.../wizard/click_reconciliation_wizard.py | 68 +++++++++++--------
.../wizard/property_reconciliation_wizard.py | 2 +
4 files changed, 48 insertions(+), 31 deletions(-)
diff --git a/yuthon_property/models/property_bank_statements.py b/yuthon_property/models/property_bank_statements.py
index 301cee6ed..d706e5e2c 100644
--- a/yuthon_property/models/property_bank_statements.py
+++ b/yuthon_property/models/property_bank_statements.py
@@ -37,6 +37,7 @@ class PropertyBankStatements(models.Model):
reconciliation_time = fields.Datetime('对账时间')
voucher_type = fields.Selection([('electronic_transfer', '电子转账凭证'), ('telegraphic_transfer', '电汇凭证')], string='凭证种类')
remake = fields.Text('备注')
+ marking = fields.Text(string='标注')
registered = fields.Float('挂账')
is_reconciliation = fields.Boolean('是否对账')
workflow_record_id = fields.Many2one('soong.workflow.record', string="流程")
@@ -281,7 +282,8 @@ class ReceivableModifyLine(models.Model):
- reconciliation_date = fields.Date(string='对账日期')
+ reconciliation_date = fields.Date(string='收款日期')
+ operation_date = fields.Date(string='操作日期')
is_penalty = fields.Boolean(string='是否为违约金')
not_collected = fields.Float(related='receivable_id.submitted', string='未收', store=False)
amount = fields.Float(string='已对金额')
diff --git a/yuthon_property/views/property_bank_statements_views.xml b/yuthon_property/views/property_bank_statements_views.xml
index 8e760fb12..6a67acaf6 100644
--- a/yuthon_property/views/property_bank_statements_views.xml
+++ b/yuthon_property/views/property_bank_statements_views.xml
@@ -46,6 +46,7 @@
+
@@ -136,7 +137,8 @@
-
+
+
@@ -157,6 +159,7 @@
+
diff --git a/yuthon_property_approval/wizard/click_reconciliation_wizard.py b/yuthon_property_approval/wizard/click_reconciliation_wizard.py
index d980a96a1..e64e6d450 100644
--- a/yuthon_property_approval/wizard/click_reconciliation_wizard.py
+++ b/yuthon_property_approval/wizard/click_reconciliation_wizard.py
@@ -10,74 +10,82 @@ class ClickReconciliationWizard(models.Model):
def action_confirm(self):
unreconciled_states = ['not_reconciled', 'registered']
-
bank_statements = self.env["property.bank.statements"].search([
('bank_state', 'in', unreconciled_states),
- ('is_company', '=', True),
+ ('company_id', '=', self.env.company.id),
], order='start_time asc')
- # 3. 按“月份+合同组”分组汇总流水金额(同一月同一批合同的流水合并)
stmt_groups = {}
for stmt in bank_statements:
stmt_datetime = fields.Datetime.from_string(stmt.start_time)
stmt_date = (stmt_datetime - timedelta(hours=8)).date()
- month_key = (stmt_date.year, stmt_date.month) # 月份标识(年,月)
+ month_key = (stmt_date.year, stmt_date.month)
contract_ids = tuple(stmt.contract_ids.ids)
if not contract_ids:
continue
- # 3.3 按“月份+合同组”汇总金额
- group_key = (month_key, contract_ids)
+ # 关键:加stmt.id → 每一笔流水独立分组,绝不合并多流水
+ group_key = (month_key, contract_ids, stmt.id)
if group_key not in stmt_groups:
stmt_groups[group_key] = {
- 'total_stmt_amount': 0.0,
- 'statements': self.env["property.bank.statements"], # 存储该组所有流水
+ 'total_stmt_amount': stmt.original_amount,
+ 'statements': self.env["property.bank.statements"] + stmt,
}
- # 累加流水金额并收集流水记录
- stmt_groups[group_key]['total_stmt_amount'] += stmt.original_amount
- stmt_groups[group_key]['statements'] |= stmt
- # 4. 遍历每个分组,匹配应收单
+ # 外层大循环
for group_key, group_data in stmt_groups.items():
- (month_key, contract_ids) = group_key
+ month_key, contract_ids, stmt_id = group_key
total_stmt_amount = group_data['total_stmt_amount']
statements = group_data['statements']
year, month = month_key
- # 4.1 计算该月份的时间范围
month_start = datetime(year, month, 1).date()
month_end = datetime(year + 1, 1, 1).date() if month == 12 else datetime(year, month + 1, 1).date()
- # 4.2 查找该月份、该合同组的未对账应收单
+ # 匹配当月该合同所有未对账应收
receivables = self.env["property.accounts.receivable"].search([
('is_reconciliation', '=', False),
- ('contract_id', 'in', contract_ids),
+ ('contract_id', 'in', list(contract_ids)),
('due_date', '>=', month_start),
('due_date', '<', month_end),
])
if not receivables:
- continue # 无匹配应收单,跳过
+ continue
- # 4.3 计算应收总金额
total_receivable = sum(rec.original_amount for rec in receivables)
- # 4.4 检查该合同组是否有前期未对账记录
+ # 判断有无前期未对账
has_prev_unreconciled = self.env["property.accounts.receivable"].search([
- ('contract_id', 'in', contract_ids),
+ ('contract_id', 'in', list(contract_ids)),
('is_reconciliation', '=', False),
('due_date', '<', month_start),
], limit=1)
-
- # 4.5 核心条件:多笔流水总和 == 应收总和,且无前期未对账
if total_stmt_amount == total_receivable and not has_prev_unreconciled:
- # 4.6 更新该组所有流水为“已对账”
+ # # 打印所有符合条件数据
+ # print("\n========================================")
+ # print("✅ 满足对账条件(单流水可对多应收)")
+ # print(f"年月:{year}年{month}月 | 流水总金额:{total_stmt_amount} | 应收总金额:{total_receivable}")
+ #
+ # print("\n【当前独立单条流水】")
+ # for st in statements:
+ # print(f"→ 流水ID: {st.id} | 金额: {st.original_amount} | 户名: {st.name_account}")
+ #
+ # print("\n【匹配的多笔应收单】")
+ # for rec in receivables:
+ # print(f"→ 应收ID: {rec.id} | 金额: {rec.original_amount} | 合同: {rec.contract_id.name}")
+ # print("========================================\n")
+ #
+ # # # 测试版:直接跳过写入,不修改任何数据
+ # # continue
+ # # # 下面是你原来的逻辑,完全不动
for stmt in statements:
stmt.write({
'change_amount': stmt.original_amount,
'bank_state': 'reconciled',
'reconciliation_time': fields.Datetime.now() - timedelta(hours=8),
'no_amount': 0,
- 'yes_amount': stmt.original_amount
+ 'yes_amount': stmt.original_amount,
+ 'marking': '系统一键对账'
})
for rec in receivables:
@@ -85,8 +93,7 @@ class ClickReconciliationWizard(models.Model):
'is_reconciliation': True,
'delivered1': rec.original_amount,
'reconciliation_time': fields.Datetime.now() - timedelta(hours=8),
- 'payout_date': statements[0].start_time.date() if statements else False, # 取第一笔流水日期
- 'receivable_log': f'当前登录人{self.env.user.name}于{fields.Datetime.now()}对户名为{statements[0].name_account}进行对账操作(多笔流水合并)'
+ 'payout_date': statements[0].start_time.date() if statements else False,
})
modify = self.env['receivable.modify.line'].search([
@@ -94,15 +101,18 @@ class ClickReconciliationWizard(models.Model):
('bank_id', '=', statements[0].id),
('is_write', '=', True),
('is_penalty', '=', False),
- ('reconciliation_date', '=', (fields.Datetime.from_string(statements[0].start_time) - timedelta(hours=8)).date()),
+ ('reconciliation_date', '=',
+ (fields.Datetime.from_string(statements[0].start_time) - timedelta(hours=8)).date()),
('amount', '=', rec.original_amount)
- ])
+ ])
if not modify:
self.env['receivable.modify.line'].create({
'is_write': True,
'is_penalty': False,
'bank_id': statements[0].id,
- 'reconciliation_date': (fields.Datetime.from_string(statements[0].start_time) - timedelta(hours=8)).date(),
+ 'reconciliation_date': (fields.Datetime.from_string(statements[0].start_time) - timedelta(
+ hours=8)).date(),
+ 'operation_date': fields.Date.today(),
'receivable_id': rec.id,
'amount': rec.original_amount,
})
\ No newline at end of file
diff --git a/yuthon_property_approval/wizard/property_reconciliation_wizard.py b/yuthon_property_approval/wizard/property_reconciliation_wizard.py
index 76628b652..9e21cd161 100644
--- a/yuthon_property_approval/wizard/property_reconciliation_wizard.py
+++ b/yuthon_property_approval/wizard/property_reconciliation_wizard.py
@@ -406,6 +406,7 @@ class PropertyReconciliationWizard(models.Model):
'reconciliation_date': rec.actual_date if line.amount != 0 else None,
'receivable_id': receivable.id,
'is_write': True if line.amount != 0 else False,
+ 'operation_date': fields.Date.today(),
'is_penalty': False,
'remake1': line.remake,
'amount': line.amount,
@@ -489,6 +490,7 @@ class PropertyReconciliationWizard(models.Model):
'is_write': True if line.amount != 0 else False,
'is_penalty': True,
'reconciliation_date': rec.actual_date if line.amount != 0 else None,
+ 'operation_date': fields.Date.today(),
'receivable_id': receivable_id.id,
'amount': line.amount,
})