Skip to content

Commit

Permalink
fix: Validate if the config points to a deleted field
Browse files Browse the repository at this point in the history
  • Loading branch information
marination committed Nov 21, 2024
1 parent 2b5330e commit 903e59e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1327,11 +1327,34 @@ def get_description_match_condition(


def get_reference_field_map() -> dict:
"""Get the reference field map for the document types from Banking Settings."""

def _validate_and_get_field(row: dict) -> str:
is_df = frappe.db.exists(
"DocField", {"fieldname": row.field_name, "parent": row.document_type}
)
is_custom = frappe.db.exists(
"Custom Field", {"fieldname": row.field_name, "dt": row.document_type}
)
if not (is_df or is_custom):
frappe.throw(
title=_("Invalid Field"),
msg=_(
"Field {} does not exist in {}. Please check the configuration in Banking Settings."
).format(frappe.bold(row.field_name), frappe.bold(row.document_type)),
)

return row.field_name

reference_fields = frappe.get_all(
"Banking Reference Mapping",
filters={
"parent": "Banking Settings",
},
fields=["document_type", "field_name"],
)
return {frappe.scrub(row.document_type): row.field_name for row in reference_fields}

return {
frappe.scrub(row.document_type): _validate_and_get_field(row)
for row in reference_fields
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class TestBankReconciliationToolBeta(AccountsTestMixin, FrappeTestCase):
@classmethod
def setUpClass(cls):
def setUpClass(cls) -> None:
super().setUpClass()
create_bank()
cls.gl_account = create_gl_account("_Test Bank Reco Tool")
Expand All @@ -43,9 +43,11 @@ def setUpClass(cls):
cls.create_item(
cls, item_name="Reco Item", company="_Test Company", warehouse="Finished Goods - _TC"
)

def setUp(self) -> None:
frappe.db.savepoint("before_bank_reco_tool_beta_tests")

def tearDown(self):
def tearDown(self) -> None:
"""Runs after each test."""
# Make sure invoices are rolled back to not affect invoice count assertions
frappe.db.rollback(save_point="before_bank_reco_tool_beta_tests")
Expand Down
2 changes: 2 additions & 0 deletions banking/translations/de.csv
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@ Bank Account not found for IBAN {0},Bankkonto nicht gefunden für IBAN {0},
EBICS Host ID,EBICS-Host-ID,
EBICS URL,EBICS-URL,
Usage,Nutzung,
Invalid Field,Unzulässiges Feld,
Field {} does not exist in {}. Please check the configuration in Banking Settings.,"Feld {} existiert nicht in {}. Bitte überprüfen Sie die Konfiguration in den Bankeneinstellungen.",

0 comments on commit 903e59e

Please sign in to comment.