diff --git a/yuthon_property_approval/wizard/click_reconciliation_wizard.py b/yuthon_property_approval/wizard/click_reconciliation_wizard.py index 6b78f4cb3..93b986c04 100644 --- a/yuthon_property_approval/wizard/click_reconciliation_wizard.py +++ b/yuthon_property_approval/wizard/click_reconciliation_wizard.py @@ -9,77 +9,26 @@ class ClickReconciliationWizard(models.Model): message = fields.Text(string='确认信息', readonly=True) def action_confirm(self): - unreconciled_contract_ids = self.env["property.accounts.receivable"].search([ + receivable_ids = self.env["property.accounts.receivable"].search([ ('is_reconciliation', '=', False), - ]).mapped('contract_id') - # 直接查询符合条件的对账单 - statements_ids = self.env["property.bank.statements"].search([ - ('bank_state', '=', 'not_reconciled'), - ('contract_ids', 'in', unreconciled_contract_ids.ids if unreconciled_contract_ids else []) ]) - # 只处理合同ID存在于应收账款合同中的对账单记录 - for record in statements_ids: - all_vals, total_rent_month = record._get_reconciliation_vals(record) - - # 检查所有明细行的rent_month和rent是否相等 - all_lines_match = True - amount_been_reconciled = 0.0 - for val in all_vals: - if isinstance(val, tuple) and len(val) == 3 and isinstance(val[2], dict): - line_data = val[2] - # 检查金额是否匹配 - if line_data.get('rent_month') != line_data.get('rent'): - all_lines_match = False - # 累加已对账金额 - amount_been_reconciled += line_data.get('amount', 0.0) - amount_reconciled = max(record.original_amount - amount_been_reconciled, 0.0) - - # 更新对账状态(总金额相等且所有行金额匹配) - if total_rent_month == record.original_amount and all_lines_match: - record.bank_state = 'reconciled' - # 查找对应的银行行记录 - bank_lines = self.env['property.bank.line'].search([ - ('bank', '=', record.name) - ]) - - if bank_lines: - record.yes_amount = amount_reconciled - record.no_amount = amount_been_reconciled - first_line = bank_lines[0] - - # 直接使用all_vals中的数据更新应收账款 - for val in all_vals: - if isinstance(val, tuple) and len(val) == 3 and isinstance(val[2], dict): - line_data = val[2] - amount = line_data.get('rent', 0) # 使用rent作为实际金额 - - # 跳过金额为0的行 - if not amount: - continue - - # 构建查询条件 - domain = [ - ('lessee_id', '=', first_line.tenant_id.id), - ('is_reconciliation', '=', False), - ('is_suspend', '=', False), - ] - - # 添加物业和合同条件 - if line_data.get('property_id'): - domain.append(('property_id', '=', line_data['property_id'])) - if line_data.get('contract_id'): - domain.append(('contract_id', '=', line_data['contract_id'])) - - # 搜索对应的应收账款记录 - receivable_ids = self.env['property.accounts.receivable'].search(domain) - - # 更新应收账款记录状态 - for receivable in receivable_ids: - receivable.write({ - 'is_reconciliation': True, - 'delivered1': amount, - 'reconciliation_time': fields.Datetime.now(), - 'payout_date': record.start_time.date(), - 'remark': line_data.get('remark', ''), # 使用line_data中的备注 - 'receivable_log': f'当前登录人{record.env.user.name}于{fields.Datetime.now()}对户名为{record.name_account}进行对账操作' - }) \ No newline at end of file + # 直接查询符合条件的对账单 + for receivable in receivable_ids: + statements_ids = self.env["property.bank.statements"].search([ + ('bank_state', 'in', ['not_reconciled', 'registered']), + ('name_account', '=', receivable.lessee_id.name), + ('is_company', '=', True), + ('contract_ids', 'in', receivable.contract_id.id), + ('original_amount', '=', receivable.original_amount) + ], order='start_time asc') + record = statements_ids[0] + record.yes_amount = receivable.original_amount + record.bank_state = 'reconciled' + record.no_amount = 0 + receivable.write({ + 'is_reconciliation': True, + 'delivered1': receivable.original_amount, + 'reconciliation_time': fields.Datetime.now() - timedelta(hours=8), + 'payout_date': record.start_time.date(), + 'receivable_log': f'当前登录人{record.env.user.name}于{fields.Datetime.now()}对户名为{record.name_account}进行对账操作' + }) \ No newline at end of file