feat: document engine with kinds, states, atomic numbering and fulfilment (#47)

One engine for sales, purchases and warehouse documents (ADR 0032). Each document
type now carries a kind that decides its family of tables, life cycle, effects,
accepted lines, the kinds it fulfils and its permissions, so company-defined types
work without code.

- Six families of header and line tables plus document_links; document_types gets
  document_kind (seeded types filled by the migration and the Italian template),
  document_numerators gets last_date.
- DocumentStateMachine with the order, invoice and simple life cycles and the
  actions each state admits; issued invoices are immutable and are cancelled with
  a reason only before the file reaches the exchange system.
- DocumentNumberingService numbers at confirmation inside the transaction under
  the numerator lock (advisory lock on PostgreSQL, write lock on SQLite): no
  duplicates, a rollback gives the number back, out-of-sequence dates refused on
  gap-free numerators, the new year's numerator created on first use, gap report.
- DocumentEngine, the generic DocumentService<THeader, TLine> and
  DocumentCopyService: save, confirm or issue, cancel, close, reopen, delete,
  duplicate and transform; links are recorded at confirmation and removed at
  cancellation, and FulfillmentCalculator recomputes quantities and states.
- Tests: rules in Core, concurrent numbering on SQLite and PostgreSQL (data tests,
  run on PostgreSQL 18 locally), order to delivery notes to deferred invoice on a
  real instance. Wiki (Vendite, Tabelle azienda), CHANGELOG, STATUS, DATA-MODEL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-12 15:30:24 +01:00
1 parent fa9304834a
commit ddd2273f7e
33 files changed
+4081 -37

No files matched your search

@@ -255,6 +255,7 @@
"IsDefault": "Predefinito",
"Symbol": "Simbolo",
"Decimals": "Decimali",
"DocumentKind": "Genere",
"NumeratorId": "Numeratore",
"InventoryReasonId": "Causale di magazzino",
"EInvoiceType": "Tipo TD",
@@ -266,6 +267,7 @@
"Prefix": "Prefisso",
"Format": "Formato",
"LastNumber": "Ultimo numero",
"LastDate": "Data dell'ultimo numero",
"GapsAllowed": "Ammessi buchi di numerazione",
"CurrencyCode": "Valuta",
"VatIncluded": "IVA inclusa",
@@ -353,6 +355,25 @@
"Journal": "Prima nota",
"Other": "Altro"
},
"DocumentKind": {
"Quotation": "Preventivo",
"SalesOrder": "Ordine cliente",
"DeliveryNote": "DDT di vendita",
"ImmediateInvoice": "Fattura immediata",
"AccompanyingInvoice": "Fattura accompagnatoria",
"DeferredInvoice": "Fattura differita",
"DownPaymentInvoice": "Fattura di acconto",
"CreditNote": "Nota di credito",
"DebitNote": "Nota di debito",
"Fee": "Parcella",
"ProForma": "Pro forma",
"SelfInvoice": "Autofattura o integrazione",
"PurchaseOrder": "Ordine fornitore",
"PurchaseDeliveryNote": "DDT fornitore",
"PurchaseInvoice": "Fattura fornitore",
"PurchaseCreditNote": "Nota di credito fornitore",
"InventoryEntry": "Movimento di magazzino"
},
"StockEffect": {
"None": "Nessuno",
"Load": "Carico",
@@ -446,6 +467,9 @@
"numerator": {
"format": "Il formato deve contenere il segnaposto del numero e solo segnaposto noti (anno, prefisso, sezionale)."
},
"document-type": {
"kind-required": "Scegli il genere: dice come si comportano i documenti di questo tipo."
},
"year": {
"range": "Anno fuori intervallo."
},