From 6701579ee8aebef94294d7594dec19657848893b Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 8 Mar 2025 20:13:10 -0600 Subject: [PATCH] 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. --- src/main.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3de0027..9ca96b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -178,14 +178,18 @@ async fn update_transaction( notes: s.notes, }) .collect(); - if let Some(split) = splits.last_mut() { + let jrnl_id = if let Some(split) = splits.last_mut() { if form.amount != amount { split.amount = form.amount.to_string(); } if !form.notes.is_empty() { 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 { transactions: splits, }; @@ -209,7 +213,11 @@ async fn update_transaction( } if let Err(e) = ctx .firefly - .attach_receipt(id, content, file.name().unwrap_or("receipt.jpg")) + .attach_receipt( + &jrnl_id, + content, + file.name().unwrap_or("receipt.jpg"), + ) .await { error!("Failed to attach receipt to transaction: {}", e);