Skip to content

Commit

Permalink
fix: Reset last integration date on account relinking
Browse files Browse the repository at this point in the history
- This is to avoid out of scope dates comapred to the consent

(cherry picked from commit 6d208fc)
  • Loading branch information
marination authored and mergify[bot] committed Nov 6, 2024
1 parent dd6e9a6 commit b810316
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def add_bank_account(

existing_bank_account = frappe.db.exists("Bank Account", {"account": gl_account})
if existing_bank_account:
update_bank_account(account_data, existing_bank_account)
update_bank_account(account_data, existing_bank_account, relink=True)
else:
create_bank_account(account_data, bank_name, company, gl_account)

Expand Down
14 changes: 10 additions & 4 deletions banking/klarna_kosma_integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,17 @@ def create_bank_account(
)


def update_bank_account(account_data: dict, bank_account_name: str) -> None:
def update_bank_account(
account_data: dict, bank_account_name: str, relink=False
) -> None:
try:
frappe.db.set_value(
"Bank Account", bank_account_name, "kosma_account_id", account_data.get("id")
)
to_update = {"kosma_account_id": account_data.get("id")}
if relink:
# Reset last integration date if relinking
# It will be picked up from the new consent start date
to_update["last_integration_date"] = None

frappe.db.set_value("Bank Account", bank_account_name, to_update)
except Exception:
frappe.log_error(
title=_("Kosma Error - Bank Account Update"), message=frappe.get_traceback()
Expand Down

0 comments on commit b810316

Please sign in to comment.