fix: clearing a mapping row's ERP/Bank Account link resets the registry record

The on_update reverse-sync only treated a row as "mapped" if its key
field was present, so clearing erp_customer / erp_supplier / bank_account
(without deleting the row) left the Kapital Bank Customer/Supplier/
Account/Card still marked Mapped. Now a row counts as mapped only when
both the key and the ERP/Bank Account link are set.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ali 2026-05-12 11:38:08 +00:00
parent d9d033bfe1
commit bb49b5915a
1 changed files with 12 additions and 8 deletions

View File

@ -10,8 +10,9 @@ class KapitalBankSettings(Document):
self._sync_card_statuses()
def _sync_account_statuses(self):
"""Reset Kapital Bank Account status to 'New' for accounts removed from account_mappings."""
mapped_ibans = {row.iban for row in self.account_mappings if row.iban}
"""Reset Kapital Bank Account status to 'New' when its mapping row is removed
from account_mappings, or when the row's Bank Account link is cleared."""
mapped_ibans = {row.iban for row in self.account_mappings if row.iban and row.bank_account}
orphaned = frappe.get_all(
"Kapital Bank Account",
@ -32,8 +33,9 @@ class KapitalBankSettings(Document):
)
def _sync_customer_statuses(self):
"""Reset Kapital Bank Customer status to 'New' for customers removed from customer_mappings."""
mapped_names = {row.kb_customer_name for row in self.customer_mappings if row.kb_customer_name}
"""Reset Kapital Bank Customer status to 'New' when its mapping row is removed
from customer_mappings, or when the row's ERP Customer link is cleared."""
mapped_names = {row.kb_customer_name for row in self.customer_mappings if row.kb_customer_name and row.erp_customer}
orphaned = frappe.get_all(
"Kapital Bank Customer",
@ -57,8 +59,9 @@ class KapitalBankSettings(Document):
)
def _sync_supplier_statuses(self):
"""Reset Kapital Bank Supplier status to 'New' for suppliers removed from supplier_mappings."""
mapped_names = {row.kb_supplier_name for row in self.supplier_mappings if row.kb_supplier_name}
"""Reset Kapital Bank Supplier status to 'New' when its mapping row is removed
from supplier_mappings, or when the row's ERP Supplier link is cleared."""
mapped_names = {row.kb_supplier_name for row in self.supplier_mappings if row.kb_supplier_name and row.erp_supplier}
orphaned = frappe.get_all(
"Kapital Bank Supplier",
@ -81,8 +84,9 @@ class KapitalBankSettings(Document):
)
def _sync_card_statuses(self):
"""Reset Kapital Bank Card status to 'New' for cards removed from card_mappings."""
mapped_accounts = {row.account_number for row in self.card_mappings if row.account_number}
"""Reset Kapital Bank Card status to 'New' when its mapping row is removed
from card_mappings, or when the row's Bank Account link is cleared."""
mapped_accounts = {row.account_number for row in self.card_mappings if row.account_number and row.bank_account}
orphaned = frappe.get_all(
"Kapital Bank Card",