fix(transactions): use the resolved cash account name as bank line description (#899)
The booking dialog's bank line description was always the generic "bank_line_description" translation regardless of which cash account was actually resolved via resolveAccount(). This was accurate while the bank line was hardcoded to 1930, but now that the dialog resolves the real cash_account_id (#769) it can pick a different account whose own name should show up on the line instead. Signed-off-by: Jonas Flodén <jonas@floden.nu>
This commit is contained in:
@@ -117,10 +117,12 @@ export default function TransactionBookingDialog({
|
||||
const [pickedInboxDocs, setPickedInboxDocs] = useState<AvailableInboxDoc[]>([])
|
||||
const [inboxPickerOpen, setInboxPickerOpen] = useState(false)
|
||||
const [bankAccount, setBankAccount] = useState<string | null>(null)
|
||||
const [bankAccountName, setBankAccountName] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || !transaction) return
|
||||
setBankAccount(null)
|
||||
setBankAccountName(null)
|
||||
let cancelled = false
|
||||
fetch('/api/cash-accounts')
|
||||
.then((r) => {
|
||||
@@ -135,7 +137,12 @@ export default function TransactionBookingDialog({
|
||||
transaction.cash_account_id ?? null,
|
||||
transaction.currency ?? 'SEK',
|
||||
)
|
||||
// Use the matched account's own name instead of a generic label.
|
||||
const matched =
|
||||
accounts.find((a) => a.id === transaction.cash_account_id) ??
|
||||
accounts.find((a) => a.ledger_account === account)
|
||||
setBankAccount(account)
|
||||
setBankAccountName(matched?.name ?? null)
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setBankAccount('1930')
|
||||
@@ -362,7 +369,7 @@ export default function TransactionBookingDialog({
|
||||
initialLines={
|
||||
preselectedTemplate
|
||||
? buildInitialLinesFromTemplate(transaction, preselectedTemplate, bankAccount)
|
||||
: buildInitialLines(transaction, t('bank_line_description'), bankAccount)
|
||||
: buildInitialLines(transaction, bankAccountName ?? t('bank_line_description'), bankAccount)
|
||||
}
|
||||
initialDate={transaction.date}
|
||||
initialDescription={transaction.description}
|
||||
|
||||
Reference in New Issue
Block a user