Mirrors the same correctness fixes now in jey_erp.bank_integration:
- Party-name lookup at Create & Reconcile + fuzzy purpose matcher now apply
Azerbaijani transliteration when settings.consider_azeri_chars is on, with
per-row override via the new Azeri Translit Select on Customer/Supplier
Mappings (same pattern as case sensitivity).
- create_unmapped_customers / create_unmapped_suppliers now look up existing
parties by tax_id first, then by name; when found, the mapping row is
linked to the existing party instead of silently skipping it. Response
reports linked_count alongside created_count.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The first-leaf fallback meant customers always landed in "Individual"
even when no Customer Group was chosen. Customer/Supplier/Territory
aren't actually mandatory in ERPNext, so now: a configured value is
validated (exists + leaf) and used; nothing configured -> the party is
created with an empty customer_group / supplier_group / territory.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Creating customers/suppliers no longer requires a default Customer/
Supplier Group or Territory on Kapital Bank Settings — when none is set,
the first leaf (non-group) node of the tree is used. A configured value
is still validated (must exist and be a leaf), with a clear message.
Also: the default-group / default-territory Link fields (and the
matching mapping child-table fields) now filter to is_group=0 so a group
node can't be selected.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Customer/Supplier require a leaf node for customer_group/supplier_group/
territory; selecting a group node makes ERPNext throw "Cannot select a
Group type ...". Creation now checks is_group during the upfront
validation and returns a clear message before touching any record.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Creating customers/suppliers/bank accounts from unmapped rows fell back
to "All Customer Groups" / "All Territories" / "All Supplier Groups",
which don't exist on localized sites, producing ERPNext's cryptic
"Could not find Customer Group: All Customer Groups". Creation now
validates upfront and returns a clear message ("Set a Default Customer
Group on Kapital Bank Settings ...") before touching any records — also
for Territory, Supplier Group, and Company/Bank when creating Bank
Accounts from account/card mappings.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Build full description from operationName, fullRemark, shortRemark, and
description fields for card statement transactions. Show a warning banner
when card transactions are present since duplicate detection across card
and account statements is not possible due to different reference numbers.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Root cause: get_statement_transactions() used fcyAmount (foreign currency
amount) but tagged it with account_currency. For AZN-to-USD exchanges on
AZN accounts, this picked the USD amount (e.g. 400) but labelled it as
AZN, causing wrong BT amounts and cascading JE errors.
Fix: parse acCcy from API and use lcyAmount (always AZN per API docs)
when acCcy differs from account_currency. Also revert txn_currency
fallback in JE creation from kb_currency back to bank_txn.currency so
the amount and currency stay consistent throughout the pipeline.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add currency field to purpose_rules tuple in _build_import_lookups
- Filter rules by txn currency in _match_purpose_rules (empty = match all)
- Remove in_list_view from notes field so currency column is visible in grid
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace custom kb_account_type field with the existing
expense_income_type field (label: Expense/Income) defined
in jey_erp. Remove the now-unnecessary ensure_journal_entry_custom_fields()
function from setup.py.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a hidden, read-only 'KB Account Type' (Income/Expense) field
to Journal Entry via Custom Field, visible only in list view.
Populated automatically when a JE is created from a KB transaction:
- Pay (drcr=D) → Expense
- Receive (drcr=C) → Income
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace ad-hoc if/elif branches with a unified approach:
1. Read txn_currency from the transaction data
2. Convert amount → company currency via txn_rate
3. Derive each account's amount in its own currency
4. Recompute exact exchange rates from rounded amounts
to keep Frappe's debit == credit in company currency
Fixes the bug where a $40 debit was recorded as ~$25 debit
and 40 AZN credit due to dividing instead of multiplying
when the transaction currency matched the foreign account.
Applies to both bank_api.py (_import_one_transaction JE path)
and mapping.py (_create_journal_entry_for_brt).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
For Receive transactions, paid_to (bank account) should be debited
and paid_from (income/receivable account) should be credited.
The logic was inverted in both bank_api.py and mapping.py.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>