Commit Graph

41 Commits

Author SHA1 Message Date
Ali f87db8e6de fix: don't use mapping_currency as txn_currency in JE creation
mapping_currency is a filter field (which transactions the rule matches),
not the denomination of the BT amount. Using it as txn_currency caused
700 AZN to be treated as 700 USD → 1190 AZN in the Journal Entry.

Now txn_currency comes from bank_txn.currency (= GL account currency),
which always matches the BT deposit/withdrawal amount.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 21:37:21 +04:00
Ali d8cf942792 fix: use lcyAmount for cross-currency transactions on AZN accounts
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>
2026-03-26 19:44:16 +04:00
Ali b76cdd355e feat: add outbound payment flow via Kapital Bank API
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>
2026-03-26 19:44:05 +04:00
Ali 197257d044 fix: use bank_txn.kb_currency as fallback for txn_currency in JE creation
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>
2026-03-16 18:41:53 +04:00
Ali 97b57c8572 fix: rollback document if reconciliation fails in Documents & Reconcile mode
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>
2026-03-16 18:31:58 +04:00
Ali 87d4578927 fix: use mapping currency for JE creation in Documents & Reconcile mode
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>
2026-03-16 18:12:26 +04:00
Ali cbcd06c83b fix: use bt.currency fallback in _find_mapping_for_txn + fix txn_currency in JE creation
- _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>
2026-03-16 18:05:47 +04:00
Ali 57c8cb0925 fix: filter transaction mappings by currency + hide notes from list view
- 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>
2026-03-16 17:39:12 +04:00
Ali 3fbb02a7fc refactor: use existing expense_income_type field from jey_erp
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>
2026-03-16 16:32:16 +04:00
Ali 2f10fb4aa0 fix: skip mapping creation if document creation fails in Both mode
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>
2026-03-16 16:16:20 +04:00
Ali 3b44f5a694 feat: add kb_account_type custom field to Journal Entry
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>
2026-03-16 15:31:28 +04:00
Ali 62bc550186 fix: correct multi-currency amounts in Journal Entry creation
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>
2026-03-16 15:10:27 +04:00
Ali f063c5cd0c fix: swap debit/credit for Receive type Journal Entry
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>
2026-03-16 14:57:05 +04:00
Ali 3202f5e1ac fixed bug 2026-03-14 00:51:16 +04:00
Ali d17982c81a fixed bug 2026-03-13 22:06:27 +04:00
Ali 3e90e872a1 added currency to mappings 2026-03-13 21:28:17 +04:00
Ali 68c3d7d8a9 bug fix 2026-03-13 21:04:16 +04:00
Ali 5b47d06eec removed filter for multi currency 2026-03-13 20:21:30 +04:00
Ali 42e5c42ab3 removed filter for multi currency 2026-03-13 20:12:36 +04:00
Ali e54d13ae22 removed filter for multi currency 2026-03-13 20:09:07 +04:00
Ali c563f494c3 fixed bug with multicurrency 2026-03-13 18:26:43 +04:00
Ali fc34e5104b added mapping without party 2026-03-13 17:20:08 +04:00
Ali 7ced7d18a5 fixed documents & reconcile option 2026-03-12 15:01:04 +04:00
Ali 2f05dfe8d3 hide same operations 2026-03-11 21:24:23 +04:00
Ali c674fed28b bug fix 2026-03-11 19:36:51 +04:00
Ali 5f440c1b66 changed the way that check works in brt 2026-03-11 18:38:46 +04:00
Ali d20435b587 bug fix] 2026-03-11 17:08:44 +04:00
Ali 1c002a5e87 Added create & reconcile to brt 2026-03-11 15:00:39 +04:00
Ali bced451359 reconsiliation tool modified 2026-03-10 19:47:52 +04:00
Ali 7be2112e2a added bulk edit 2026-03-05 22:41:19 +04:00
Ali 6779cf89ec added bulk edit to kb settings 2026-03-05 22:25:48 +04:00
Ali 126c455217 еуые 2026-03-05 19:48:11 +04:00
Ali 896140629c fixed bug with voen 2026-03-05 18:27:31 +04:00
Ali 717c1eb817 changed purpose mapping and more 2026-03-05 17:57:43 +04:00
Ali 6cd30ca4bb bug fixes 2026-03-04 21:50:37 +04:00
Ali fe3ab9a38f fixed small bugs 2026-03-03 22:09:00 +04:00
Ali 89a372c490 added bank transaction 2026-03-03 17:56:08 +04:00
Ali cc12c99608 app polished 2026-02-27 23:10:19 +04:00
Ali 4a560dbde5 payment entry import works 2026-02-26 22:04:10 +04:00
Ali 70c0f33d37 added kapital bank settings and app rework 2026-02-25 22:07:07 +04:00
Ali a0d4ce9f81 feat: Initialize App 2026-02-20 14:13:47 +04:00