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()