From b8103166b2f3791f288703fe15a3152e81b3049e Mon Sep 17 00:00:00 2001 From: marination Date: Mon, 4 Nov 2024 17:40:54 +0100 Subject: [PATCH] fix: Reset last integration date on account relinking - This is to avoid out of scope dates comapred to the consent (cherry picked from commit 6d208fcbadf7149cd300ab00470ada1f08c27773) --- .../doctype/banking_settings/banking_settings.py | 2 +- banking/klarna_kosma_integration/utils.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/banking/klarna_kosma_integration/doctype/banking_settings/banking_settings.py b/banking/klarna_kosma_integration/doctype/banking_settings/banking_settings.py index 3c61e67a..e78ed408 100644 --- a/banking/klarna_kosma_integration/doctype/banking_settings/banking_settings.py +++ b/banking/klarna_kosma_integration/doctype/banking_settings/banking_settings.py @@ -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) diff --git a/banking/klarna_kosma_integration/utils.py b/banking/klarna_kosma_integration/utils.py index 9a027036..dd6b4f2e 100644 --- a/banking/klarna_kosma_integration/utils.py +++ b/banking/klarna_kosma_integration/utils.py @@ -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()