From 0f93d0ecb52053a760f0fe94e100fd84ffacd0d8 Mon Sep 17 00:00:00 2001 From: mnovak Date: Thu, 5 Nov 2026 15:06:31 +0100 Subject: [PATCH] [ledger] Invoices: the print language, Czech or English per invoice (Czech when absent); v0.4.1 --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- crates/fiscus-ledger/src/invoice.rs | 12 ++++++++++++ crates/fiscus-ledger/tests/invoices.rs | 18 +++++++++++++++++- docs/03_invoices.md | 3 ++- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6701ff3..48f883f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,7 +139,7 @@ checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" [[package]] name = "fiscus-capture" -version = "0.4.0" +version = "0.4.1" dependencies = [ "fiscus-ledger", "proptest", @@ -150,7 +150,7 @@ dependencies = [ [[package]] name = "fiscus-insight" -version = "0.4.0" +version = "0.4.1" dependencies = [ "fiscus-ledger", "serde", @@ -159,7 +159,7 @@ dependencies = [ [[package]] name = "fiscus-ledger" -version = "0.4.0" +version = "0.4.1" dependencies = [ "proptest", "serde", @@ -169,7 +169,7 @@ dependencies = [ [[package]] name = "fiscus-statement" -version = "0.4.0" +version = "0.4.1" dependencies = [ "encoding_rs", "fiscus-ledger", diff --git a/Cargo.toml b/Cargo.toml index 659b6cb..7ebb779 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["crates/fiscus-ledger", "crates/fiscus-statement", "crates/fiscus-insight", "crates/fiscus-capture"] [workspace.package] -version = "0.4.0" +version = "0.4.1" edition = "2021" license = "MPL-2.0" repository = "https://gitea.marek-novak.cz/mnovak/FiscusPublic" diff --git a/crates/fiscus-ledger/src/invoice.rs b/crates/fiscus-ledger/src/invoice.rs index e14a502..5ab08a6 100644 --- a/crates/fiscus-ledger/src/invoice.rs +++ b/crates/fiscus-ledger/src/invoice.rs @@ -98,6 +98,15 @@ pub struct InvoiceLine { pub vat: Option, } +/// 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, /// The budget the payment goes into when it arrives; `None`: the default budget. pub budget: Option, + /// What the printed invoice is in. Absent in an event: Czech. + #[serde(default)] + pub language: Language, } /// What an invoice adds up to. diff --git a/crates/fiscus-ledger/tests/invoices.rs b/crates/fiscus-ledger/tests/invoices.rs index 5c88f38..77280b4 100644 --- a/crates/fiscus-ledger/tests/invoices.rs +++ b/crates/fiscus-ledger/tests/invoices.rs @@ -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, 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::(&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::(&older).unwrap().language, Language::Cs); + // Anything else is refused. + assert!(serde_json::from_str::(&json.replace("\"en\"", "\"de\"")).is_err()); +} diff --git a/docs/03_invoices.md b/docs/03_invoices.md index ffec4ad..4106988 100644 --- a/docs/03_invoices.md +++ b/docs/03_invoices.md @@ -15,7 +15,8 @@ IČO: 8 digits, the last the weighted mod-11 check of the first seven. DIČ: `CZ ## An invoice `invoice.issued` carries the whole invoice: id, number, issue and due dates, the taxable-supply date (DUZP, on a -VAT invoice only), the customer, 1–50 lines, and the budget its payment goes into (`None`: the default one). +VAT invoice only), the customer, 1–50 lines, the budget its payment goes into (`None`: the default one), and +the language it is printed in: `cs` or `en`, chosen per invoice (absent: Czech). - **Number = variable symbol.** `YYYYNNNN`: the year it was issued and its place in that year (`State::next_invoice_number(year)`). A number is used once. The payment is matched by it.