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 Payment Request → bank API → status polling workflow:
- payment_api.py: send transfers, poll status, cancel, sync bank codes
- Kapital Bank Payment doctype for tracking transfer status
- Kapital Bank Bank Code doctype for transfer routing
- Client-side buttons on Payment Request and Payment Order
- PaymentRequest.before_submit override to survive wkhtmltopdf failures
- Custom fields on Bank Account (kb_bank_code) and Payment Request
- Improved HTTP error handling in BIRBankClient
- Updated CLAUDE.md with full architecture documentation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
In "Both" mode, mapping_currency is empty and the frontend does not
pass currency in the txn dict, causing txn_currency to default to AZN.
Now falling back to bank_txn.kb_currency so the actual account currency
is always used regardless of which mode triggered the JE creation.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previously a JE/PE was left in the database even when reconcile_vouchers threw
an error. Now the whole transaction (document creation + failed reconciliation)
is rolled back so no orphaned document is created.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pass mapping_row.currency through the call chain so _create_journal_entry_for_brt
uses the mapping's currency (not the bank transaction document) as txn_currency.
This ensures correct exchange-rate calculation and proper multi-currency handling.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- _find_mapping_for_txn: kb_currency could be empty on bank transactions not
imported through KB; fall back to standard currency field so USD-specific
mappings are not skipped when matching in Documents & Reconcile mode
- _create_journal_entry_for_brt: JS does not pass currency in txn dict;
fall back to bank_txn.currency so exchange-rate calculations are correct
Co-Authored-By: Claude Sonnet 4.6 <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>
In "Both" mode, mappings were saved before documents were created,
so a failed document still produced a mapping entry.
Now for "Both" mode: document is created first, and the mapping row
is added only on success. Settings are saved once after all transactions.
"Mappings Only" and "Documents & Reconcile" modes are unaffected.
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>