feat(bank-integration): name Customer/Supplier registry records after their text name
Bank Integration Customer/Supplier used generic BIC-####/BIS-#### ids. Switched to the Kapital Bank scheme: an autoname() controller method sets the record name to customer_name / supplier_name (truncated to 140, -N on collision since multiple Bank Integrations can hold the same counterparty). The after_migrate pass renames any existing BIC-/BIS-/ BIP-#### records to their readable names. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fcdfffbcf0
commit
751154efa8
|
|
@ -41,41 +41,45 @@ def link_kb_bank_accounts_to_bi():
|
||||||
print(f"BI: linked {updated} kb-mapped Bank Account(s) to Kapital Bank Settings")
|
print(f"BI: linked {updated} kb-mapped Bank Account(s) to Kapital Bank Settings")
|
||||||
|
|
||||||
|
|
||||||
def rename_bip_purposes():
|
def _rename_to_readable(doctype, old_prefix, name_field):
|
||||||
"""Rename Bank Integration Purpose records from the old BIP-#### scheme to
|
"""Rename `doctype` records still named `old_prefix`-#### to their `name_field`
|
||||||
their purpose_keyword text (matching Kapital Bank Purpose). Idempotent —
|
text (truncated to 140, -N on collision). Idempotent. Link refs update."""
|
||||||
only touches records still named BIP-*. Link references update automatically."""
|
if not frappe.db.exists("DocType", doctype):
|
||||||
if not frappe.db.exists("DocType", "Bank Integration Purpose"):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
rows = frappe.get_all(
|
rows = frappe.get_all(
|
||||||
"Bank Integration Purpose",
|
doctype,
|
||||||
filters={"name": ["like", "BIP-%"]},
|
filters={"name": ["like", f"{old_prefix}-%"]},
|
||||||
fields=["name", "purpose_keyword"],
|
fields=["name", name_field],
|
||||||
)
|
)
|
||||||
renamed = 0
|
renamed = 0
|
||||||
for r in rows:
|
for r in rows:
|
||||||
if not r.purpose_keyword:
|
text = r.get(name_field)
|
||||||
|
if not text:
|
||||||
continue
|
continue
|
||||||
target = str(r.purpose_keyword)
|
target = str(text)
|
||||||
if len(target) > 140:
|
if len(target) > 140:
|
||||||
target = target[:137] + "..."
|
target = target[:137] + "..."
|
||||||
|
|
||||||
base = target
|
base = target
|
||||||
counter = 1
|
counter = 1
|
||||||
while target != r.name and frappe.db.exists("Bank Integration Purpose", target):
|
while target != r.name and frappe.db.exists(doctype, target):
|
||||||
suffix = f"-{counter}"
|
suffix = f"-{counter}"
|
||||||
target = base[: 140 - len(suffix)] + suffix
|
target = base[: 140 - len(suffix)] + suffix
|
||||||
counter += 1
|
counter += 1
|
||||||
if target == r.name:
|
if target == r.name:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
frappe.rename_doc("Bank Integration Purpose", r.name, target, force=True, show_alert=False)
|
frappe.rename_doc(doctype, r.name, target, force=True, show_alert=False)
|
||||||
renamed += 1
|
renamed += 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"BI: failed to rename purpose {r.name}: {e}")
|
print(f"BI: failed to rename {doctype} {r.name}: {e}")
|
||||||
|
|
||||||
if renamed:
|
if renamed:
|
||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
print(f"BI: renamed {renamed} Bank Integration Purpose record(s) to readable names")
|
print(f"BI: renamed {renamed} {doctype} record(s) to readable names")
|
||||||
|
|
||||||
|
|
||||||
|
def rename_bip_purposes():
|
||||||
|
"""Migrate Bank Integration Purpose / Customer / Supplier records from the
|
||||||
|
old BIP-/BIC-/BIS-#### ids to their text names (matching Kapital Bank)."""
|
||||||
|
_rename_to_readable("Bank Integration Purpose", "BIP", "purpose_keyword")
|
||||||
|
_rename_to_readable("Bank Integration Customer", "BIC", "customer_name")
|
||||||
|
_rename_to_readable("Bank Integration Supplier", "BIS", "supplier_name")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"actions": [],
|
"actions": [],
|
||||||
"autoname": "format:BIC-{####}",
|
"autoname": "Prompt",
|
||||||
"creation": "2026-05-08 00:00:00.000000",
|
"creation": "2026-05-08 00:00:00.000000",
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
|
|
@ -104,7 +104,7 @@
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Jey Erp",
|
"module": "Jey Erp",
|
||||||
"name": "Bank Integration Customer",
|
"name": "Bank Integration Customer",
|
||||||
"naming_rule": "Expression",
|
"naming_rule": "By script",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,25 @@
|
||||||
# Copyright (c) 2026, JeyERP and contributors
|
# Copyright (c) 2026, JeyERP and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|
||||||
class BankIntegrationCustomer(Document):
|
class BankIntegrationCustomer(Document):
|
||||||
pass
|
def autoname(self):
|
||||||
|
# Name the record after the customer name itself (like Kapital Bank
|
||||||
|
# Customer), truncated to 140 chars, with a -N suffix on collision
|
||||||
|
# (collisions are possible since multiple Bank Integrations can hold
|
||||||
|
# the same counterparty).
|
||||||
|
if not self.customer_name:
|
||||||
|
return
|
||||||
|
name = str(self.customer_name)
|
||||||
|
if len(name) > 140:
|
||||||
|
name = name[:137] + "..."
|
||||||
|
original = name
|
||||||
|
counter = 1
|
||||||
|
while frappe.db.exists("Bank Integration Customer", name):
|
||||||
|
suffix = f"-{counter}"
|
||||||
|
name = original[: 140 - len(suffix)] + suffix
|
||||||
|
counter += 1
|
||||||
|
self.name = name
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"actions": [],
|
"actions": [],
|
||||||
"autoname": "format:BIS-{####}",
|
"autoname": "Prompt",
|
||||||
"creation": "2026-05-08 00:00:00.000000",
|
"creation": "2026-05-08 00:00:00.000000",
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
|
|
@ -96,7 +96,7 @@
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Jey Erp",
|
"module": "Jey Erp",
|
||||||
"name": "Bank Integration Supplier",
|
"name": "Bank Integration Supplier",
|
||||||
"naming_rule": "Expression",
|
"naming_rule": "By script",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,23 @@
|
||||||
# Copyright (c) 2026, JeyERP and contributors
|
# Copyright (c) 2026, JeyERP and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|
||||||
class BankIntegrationSupplier(Document):
|
class BankIntegrationSupplier(Document):
|
||||||
pass
|
def autoname(self):
|
||||||
|
# Name the record after the supplier name itself (like Kapital Bank
|
||||||
|
# Supplier), truncated to 140 chars, with a -N suffix on collision.
|
||||||
|
if not self.supplier_name:
|
||||||
|
return
|
||||||
|
name = str(self.supplier_name)
|
||||||
|
if len(name) > 140:
|
||||||
|
name = name[:137] + "..."
|
||||||
|
original = name
|
||||||
|
counter = 1
|
||||||
|
while frappe.db.exists("Bank Integration Supplier", name):
|
||||||
|
suffix = f"-{counter}"
|
||||||
|
name = original[: 140 - len(suffix)] + suffix
|
||||||
|
counter += 1
|
||||||
|
self.name = name
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue