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.
parent
ff043631fa
commit
21b10c4ec1
14
src/main.rs
14
src/main.rs
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue