import frappe


def after_install():
    cleanup_payment_entry_custom_fields()


def after_migrate():
    cleanup_payment_entry_custom_fields()


KB_FIELDS = [
    "kb_section", "kb_transfer_type", "kb_operation_name", "kb_bank_id",
    "kb_transfer_status", "kb_column_break", "kb_from_iban", "kb_to_iban",
    "kb_to_tax_no", "kb_ben_bank_code",
]


def cleanup_payment_entry_custom_fields():
    for fieldname in KB_FIELDS:
        if frappe.db.exists("Custom Field", {"dt": "Payment Entry", "fieldname": fieldname}):
            frappe.delete_doc("Custom Field", f"Payment Entry-{fieldname}", ignore_missing=True)
    frappe.db.commit()
