backend: Attach photo to Journal ID

Firefly attachments are related to transaction journal entries rather
than the transactions themselves.  In other words, they're attached to
splits.
bugfix/ci-buildah
Dustin 2025-03-08 20:13:10 -06:00
parent 2050ebf088
commit 6701579ee8
1 changed files with 11 additions and 3 deletions

View File

@ -178,14 +178,18 @@ async fn update_transaction(
notes: s.notes, notes: s.notes,
}) })
.collect(); .collect();
if let Some(split) = splits.last_mut() { let jrnl_id = if let Some(split) = splits.last_mut() {
if form.amount != amount { if form.amount != amount {
split.amount = form.amount.to_string(); split.amount = form.amount.to_string();
} }
if !form.notes.is_empty() { if !form.notes.is_empty() {
split.notes = Some(form.notes.clone()); split.notes = Some(form.notes.clone());
} }
} split.transaction_journal_id.clone()
} else {
error!("Somehow, transaction {} has no splits!", id);
return (Status::BadRequest, "Invalid transaction: no splits".into());
};
let update = TransactionUpdate { let update = TransactionUpdate {
transactions: splits, transactions: splits,
}; };
@ -209,7 +213,11 @@ async fn update_transaction(
} }
if let Err(e) = ctx if let Err(e) = ctx
.firefly .firefly
.attach_receipt(id, content, file.name().unwrap_or("receipt.jpg")) .attach_receipt(
&jrnl_id,
content,
file.name().unwrap_or("receipt.jpg"),
)
.await .await
{ {
error!("Failed to attach receipt to transaction: {}", e); error!("Failed to attach receipt to transaction: {}", e);