[ledger] Invoices: the print language, Czech or English per invoice (Czech when absent); v0.4.1

This commit is contained in:
2026-11-05 15:06:31 +01:00
parent 95a8a8965b
commit 0f93d0ecb5
5 changed files with 36 additions and 7 deletions
+12
View File
@@ -98,6 +98,15 @@ pub struct InvoiceLine {
pub vat: Option<u8>,
}
/// The language an invoice is printed in, chosen per invoice.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Language {
#[default]
Cs,
En,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Invoice {
pub id: InvoiceId,
@@ -111,6 +120,9 @@ pub struct Invoice {
pub lines: Vec<InvoiceLine>,
/// The budget the payment goes into when it arrives; `None`: the default budget.
pub budget: Option<String>,
/// What the printed invoice is in. Absent in an event: Czech.
#[serde(default)]
pub language: Language,
}
/// What an invoice adds up to.
+17 -1
View File
@@ -3,7 +3,7 @@
//! inconsistent refused.
use fiscus_ledger::import::StatementLine;
use fiscus_ledger::invoice::{dic_ok, ico_ok, invoice_number, line_amount, plan_invoice_payments, same_vs, totals, Invoice, InvoiceError, InvoiceLine, Party, Supplier};
use fiscus_ledger::invoice::{dic_ok, ico_ok, invoice_number, line_amount, plan_invoice_payments, same_vs, totals, Invoice, InvoiceError, InvoiceLine, Language, Party, Supplier};
use fiscus_ledger::{Date, Event, EventBody, Haler, State, Timestamp};
fn d(s: &str) -> Date {
@@ -47,6 +47,7 @@ fn invoice(id: &str, number: &str, issued: &str, lines: Vec<InvoiceLine>, vat: b
customer: party("Odběratel s.r.o."),
lines,
budget: None,
language: Language::Cs,
}
}
@@ -347,3 +348,18 @@ fn the_events_round_trip_and_keep_their_names() {
// Replaying the log twice gives the same state.
assert_eq!(State::replay(&events), State::replay(&back));
}
#[test]
fn an_invoice_is_printed_in_czech_or_english_and_czech_when_unsaid() {
let mut i = invoice("i1", "20260001", "2026-03-01", vec![line("Work", 1_000, 100_000, None)], false);
i.language = Language::En;
let json = serde_json::to_string(&i).unwrap();
assert!(json.contains("\"language\":\"en\""), "{json}");
assert_eq!(serde_json::from_str::<Invoice>(&json).unwrap(), i);
// An event written without the field reads as Czech.
let older = json.replace(",\"language\":\"en\"", "");
assert!(!older.contains("language"));
assert_eq!(serde_json::from_str::<Invoice>(&older).unwrap().language, Language::Cs);
// Anything else is refused.
assert!(serde_json::from_str::<Invoice>(&json.replace("\"en\"", "\"de\"")).is_err());
}