fix(bank-statement-importer): drop premature File Format validation

The validate() hook threw "Amount Mode 'X' requires these Standard
Fields: Reference Number, Debit, Credit" as soon as the user uploaded a
sample file — auto-detect made the form dirty, and any later save
ran into a setup the user hadn't finished yet. The dialog interrupted
the very flow it was supposed to support.

Removed the entire _validate_file_format hook. The same check already
lives in excel_parser.parse_excel — it fires only when the user actually
tries to import a statement, which is the right moment to demand that
the format be complete. Saving a half-configured form is fine: users
can come back and finish later.
This commit is contained in:
Ali 2026-05-18 13:03:13 +00:00
parent 0e52ec16b6
commit d87da25417
1 changed files with 0 additions and 40 deletions

View File

@ -2,23 +2,10 @@
# For license information, please see license.txt
import frappe
from frappe import _
from frappe.model.document import Document
# Standard fields the parser needs depending on the chosen amount_mode.
# Date + Reference Number are always required.
_REQUIRED_BY_MODE = {
"Single column with sign": ("Date", "Reference Number", "Amount"),
"Separate debit/credit columns": ("Date", "Reference Number", "Debit", "Credit"),
"Single column + direction column": ("Date", "Reference Number", "Amount", "Direction"),
}
class BankStatementImporter(Document):
def validate(self):
self._validate_file_format()
def on_update(self):
# Keep the registry records in sync with the mapping child tables:
# removing a row OR clearing its erp_customer / erp_supplier flips the
@ -26,33 +13,6 @@ class BankStatementImporter(Document):
self._sync_customer_statuses()
self._sync_supplier_statuses()
def _validate_file_format(self):
# Only validate when the user has started filling in the File Format tab.
# An empty Bank Integration is allowed (e.g. just created, before any setup).
if not (self.column_mappings or self.amount_mode or self.header_row):
return
mode = self.amount_mode or "Separate debit/credit columns"
mapped = {
(row.standard_field or "").strip()
for row in (self.column_mappings or [])
if row.excel_column and row.standard_field
}
required = _REQUIRED_BY_MODE.get(mode, ())
missing = [f for f in required if f not in mapped]
if mapped and missing:
frappe.throw(_(
"Amount Mode '{0}' requires these Standard Fields in the Column Mappings table: {1}. "
"Add a row for each missing field."
).format(mode, ", ".join(missing)))
if mode == "Single column + direction column":
if not (self.direction_debit_values or "").strip() and not (self.direction_credit_values or "").strip():
frappe.throw(_(
"Mode 'Single column + direction column' requires at least one of "
"'Debit Values' or 'Credit Values' to be filled (comma-separated)."
))
def _sync_customer_statuses(self):
mapped_names = {
row.bi_customer_name