feat(bank-integration): name purposes after the purpose text (like Kapital Bank)

Bank Integration Purpose used a generic BIP-#### id. Switched to the
Kapital Bank Purpose scheme: an autoname() controller method sets the
record name to the purpose_keyword text (truncated to 140, -N on
collision). A migration in after_migrate renames any existing BIP-####
records to their readable names (Link references update automatically).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ali 2026-05-12 11:45:57 +00:00
parent 8043b43875
commit cd162c1f89
4 changed files with 64 additions and 5 deletions

View File

@ -39,3 +39,43 @@ def link_kb_bank_accounts_to_bi():
if updated:
frappe.db.commit()
print(f"BI: linked {updated} kb-mapped Bank Account(s) to Kapital Bank Settings")
def rename_bip_purposes():
"""Rename Bank Integration Purpose records from the old BIP-#### scheme to
their purpose_keyword text (matching Kapital Bank Purpose). Idempotent
only touches records still named BIP-*. Link references update automatically."""
if not frappe.db.exists("DocType", "Bank Integration Purpose"):
return
rows = frappe.get_all(
"Bank Integration Purpose",
filters={"name": ["like", "BIP-%"]},
fields=["name", "purpose_keyword"],
)
renamed = 0
for r in rows:
if not r.purpose_keyword:
continue
target = str(r.purpose_keyword)
if len(target) > 140:
target = target[:137] + "..."
base = target
counter = 1
while target != r.name and frappe.db.exists("Bank Integration Purpose", target):
suffix = f"-{counter}"
target = base[: 140 - len(suffix)] + suffix
counter += 1
if target == r.name:
continue
try:
frappe.rename_doc("Bank Integration Purpose", r.name, target, force=True, show_alert=False)
renamed += 1
except Exception as e:
print(f"BI: failed to rename purpose {r.name}: {e}")
if renamed:
frappe.db.commit()
print(f"BI: renamed {renamed} Bank Integration Purpose record(s) to readable names")

View File

@ -143,10 +143,11 @@ def after_migrate_combined():
# Link kb-mapped Bank Accounts to Kapital Bank Settings via the
# Dynamic Link fields used by the universal Create & Reconcile resolver.
try:
from jey_erp.bank_integration.migrations import link_kb_bank_accounts_to_bi
from jey_erp.bank_integration.migrations import link_kb_bank_accounts_to_bi, rename_bip_purposes
link_kb_bank_accounts_to_bi()
rename_bip_purposes()
except Exception as e:
print(f"BI: link_kb_bank_accounts_to_bi failed: {e}")
print(f"BI: post-migrate sync failed: {e}")
# REMOVED: Asset categories creation moved to setup_wizard_complete hook
# from jey_erp.custom.create_asset_categories import create_asset_categories
# create_asset_categories()

View File

@ -1,6 +1,6 @@
{
"actions": [],
"autoname": "format:BIP-{####}",
"autoname": "Prompt",
"creation": "2026-05-08 00:00:00.000000",
"doctype": "DocType",
"engine": "InnoDB",
@ -54,7 +54,7 @@
"modified_by": "Administrator",
"module": "Jey Erp",
"name": "Bank Integration Purpose",
"naming_rule": "Expression",
"naming_rule": "By script",
"owner": "Administrator",
"permissions": [
{

View File

@ -1,8 +1,26 @@
# Copyright (c) 2026, JeyERP and contributors
# For license information, please see license.txt
import frappe
from frappe.model.document import Document
class BankIntegrationPurpose(Document):
pass
def autoname(self):
# Name the record after the purpose text itself (like Kapital Bank Purpose),
# truncated to 140 chars, with a -N suffix on collision.
if not self.purpose_keyword:
return
name = str(self.purpose_keyword)
if len(name) > 140:
name = name[:137] + "..."
original = name
counter = 1
while frappe.db.exists("Bank Integration Purpose", name):
suffix = f"-{counter}"
name = original[: 140 - len(suffix)] + suffix
counter += 1
self.name = name