Skip to content
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

fix: don't fetch C54 if batch splitting is disabled (backport #161) #162

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions banking/ebics/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,22 @@ def get_permitted_order_types(self, level: str = "T") -> list[str]:
return level_perms

def download_bank_statements(
self, start_date: str | None = None, end_date: str | None = None
self,
start_date: str | None = None,
end_date: str | None = None,
with_c54: bool = False,
) -> "Iterator[CAMTDocument]":
"""Yield an iterator over CAMTDocument objects for the given date range."""
from fintech.sepa import CAMTDocument

client = self.get_client()
permitted_types = self.get_permitted_order_types()

try:
camt53 = client.C53(start_date, end_date)
except fintech.ebics.EbicsNoDataAvailable:
return

camt54 = client.C54(start_date, end_date) if "C54" in permitted_types else None
camt54 = client.C54(start_date, end_date) if with_c54 else None

for name in sorted(camt53):
yield CAMTDocument(xml=camt53[name], camt54=camt54)
Expand Down
16 changes: 15 additions & 1 deletion banking/ebics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,25 @@ def sync_ebics_transactions(
reference_name=ebics_user,
)

if not intraday and user.split_batch_transactions and "C54" not in permitted_types:
frappe.log_error(
title=_("Banking Error"),
message=_(
"EBICS User {0} lacks permission 'C54' for splitting batch transactions. The permitted types are: {1}."
).format(ebics_user, ", ".join(permitted_types)),
reference_doctype="EBICS User",
reference_name=ebics_user,
)

try:
camt_documents = (
manager.download_intraday_transactions()
if intraday
else manager.download_bank_statements(start_date, end_date)
else manager.download_bank_statements(
start_date,
end_date,
with_c54=user.split_batch_transactions and "C54" in permitted_types,
)
)
except Exception:
frappe.log_error(
Expand Down
Loading