Skip to content

[bug] bank reconciliation tool: api get_linked_payments called 2 times, first time click actions matched vouchers not shown in datatable in dialog #47589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
szufisher opened this issue May 17, 2025 · 0 comments
Labels
bug need-more-info Provide additional context, steps to reproduce this issue.

Comments

@szufisher
Copy link
Contributor

szufisher commented May 17, 2025

Information about bug

bank reconciliation tool: api get_linked_payments called 2 times, first time click actions matched vouchers not shown in datatable in dialog

Module

accounts

Version

ERPNext version 15

Installation method

None

Relevant log output / Stack trace / Full Error Message.

below are the changes proposed by deepseek, already verified and tested OKay

https://github.com/frappe/erpnext/blob/develop/erpnext/public/js/bank_reconciliation_tool/dialog_manager.js
need to be changed as below

	show_dialog(bank_transaction_name, update_dt_cards) {
		this.bank_transaction_name = bank_transaction_name;
		this.update_dt_cards = update_dt_cards;
		frappe.call({
			method: "frappe.client.get_value",
			args: {
				doctype: "Bank Transaction",
				filters: { name: this.bank_transaction_name },
				fieldname: [
					"date",
					"deposit",
					"withdrawal",
					"currency",
					"description",
					"name",
					"bank_account",
					"company",
					"reference_number",
					"party_type",
					"party",
					"unallocated_amount",
					"allocated_amount",
					"transaction_type",
				],
			},
			callback: (r) => {
				if (r.message) {
					this.bank_transaction = r.message;
					this.dialog.set_values(r.message);
					this.copy_data_to_voucher();
	
					// 关键修改 1: 禁用事件后设置默认勾选
					this.dialog.$wrapper.find('input[data-fieldname="payment_entry"]').prop("checked", true);
					this.dialog.$wrapper.find('input[data-fieldname="journal_entry"]').prop("checked", true);
	
					// 关键修改 2: 手动收集选中项并触发一次查询
					const selected = ["payment_entry", "journal_entry"];
					this.get_linked_vouchers(selected);
					
					this.dialog.show();
				}
			},
		});
	}

	// dialog_manager.js 修改 get_datatable 方法
	get_datatable(proposals_wrapper) {
		// 1. 确保容器可见并强制布局重绘
		proposals_wrapper.show();
		
		// 关键修改:强制触发浏览器重绘以计算布局
		const forceRedraw = proposals_wrapper[0].offsetHeight; // 无实际作用,但触发重绘

		// 2. 销毁旧实例避免残留
		if (this.datatable) {
			this.datatable.destroy();
			this.datatable = null;
		}

		// 3. 延迟初始化确保DOM就绪
		setTimeout(() => {
			const datatable_options = {
				columns: this.columns,
				data: this.data,
				dynamicRowHeight: true,
				checkboxColumn: true,
				inlineFilters: true,
			};
			
			// 4. 创建新DataTable实例
			this.datatable = new frappe.DataTable(proposals_wrapper.get(0), datatable_options);
			
			// 5. 显式调用内部调整方法
			this.datatable.adjustWidth(true); // 强制调整宽度
			this.datatable.refresh(); // 确保数据渲染
		}, 100); // 适当延迟100ms
	}

	make_dialog() {
		const me = this;
		me.selected_payment = null;

		const fields = [
			{
				label: __("Action"),
				fieldname: "action",
				fieldtype: "Select",
				options: `Match Against Voucher\nCreate Voucher\nUpdate Bank Transaction`,
				default: "Match Against Voucher",
			},
			{
				fieldname: "column_break_4",
				fieldtype: "Column Break",
			},
			{
				label: __("Document Type"),
				fieldname: "document_type",
				fieldtype: "Select",
				options: `Payment Entry\nJournal Entry`,
				default: "Payment Entry",
				depends_on: "eval:doc.action=='Create Voucher'",
			},
			{
				fieldtype: "Section Break",
				fieldname: "section_break_1",
				label: __("Filters"),
				depends_on: "eval:doc.action=='Match Against Voucher'",
			},
		];

		frappe.call({
			method: "erpnext.accounts.doctype.bank_transaction.bank_transaction.get_doctypes_for_bank_reconciliation",
			callback: (r) => {
				$.each(r.message, (_i, entry) => {
					if (_i % 3 == 0) {
						fields.push({
							fieldtype: "Column Break",
						});
					}
					fields.push({
						fieldtype: "Check",
						label: entry,
						fieldname: frappe.scrub(entry),
						// 关键修改 3: 使用事件委托统一处理复选框点击
						//onchange: () => this.update_options(),
					});
				});

				fields.push(...this.get_voucher_fields());

				me.dialog = new frappe.ui.Dialog({
					title: __("Reconcile the Bank Transaction"),
					fields: fields,
					size: "large",
					primary_action: (values) => this.reconciliation_dialog_primary_action(values),
				});
				// 关键修改 3: 使用事件委托统一处理复选框点击
				me.dialog.$wrapper.on('click', '[data-fieldtype="Check"] input', () => {
					const selected = this.get_selected_attributes();
					this.get_linked_vouchers(selected);
				});
			},
		});
	}
@szufisher szufisher added the bug label May 17, 2025
@DipenFrappe DipenFrappe added the need-more-info Provide additional context, steps to reproduce this issue. label May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug need-more-info Provide additional context, steps to reproduce this issue.
Projects
None yet
Development

No branches or pull requests

2 participants