feat(mcp): the create tools preview and confirm, and the party keeps its contact block (P4b S4.4)
An invoice is issued, not edited. Without `confirmed` the create tools now preview: the posting (with the accounts' codes, which the live chart may not hold yet), the number it will take, its due date, terms and early discount, warnings, and for an invoice the DRAFT copy of the PDF, handed over as a file. Nothing is written and no number is used up. With `confirmed` the invoice posts, takes the number the preview showed, and files the issued copy with itself in the same call: `receipt.attached` on its entry plus the link to the invoice, its SHA-256 in the event (A-1, A-7, B-40). The copy the customer received is therefore the copy in the books, and `books.document`'s re-created page can never be mistaken for it. The result also carries a `mailto` link for a human to send it; the books never send (A-4). A bill keeps what the plan says a bill is: the vendor's own invoice number, the vendor's invoice filed on its entry as its evidence, and, in books that have declared `documents_v2`, an account on every line, so no bill can land in General Expenses by default any more (A-9, A-10, A-13). A vendor number entered twice is refused unless the caller says why, and the reason is journaled with the second bill (B-40 item 4). Books that have not declared the feature keep recording bills exactly as before, so the owner's books keep working between units (D-39, 8.0.4). Terms are resolved in one place and in one order: the due date given, else the terms given, else the customer's or vendor's own default, else the books' `invoicing.default_terms`; a document given only a due date stores no terms, so an old-shape invoice is still written byte for byte as before (B-39, A-13). D-55: a party carries the owner's full contact block (phone, contact person, billing and shipping addresses, billing email). It rides the same `party.updated` event behind `documents_v2`, and an invoice's bill-to is snapshotted at issue with the billing address and billing email in place of the general ones when the party has them — `PartySnapshot::from_party` is the one place that rule lives, so a later edit cannot change what was sent, and the next invoice takes today's details. Tests: the wire tests are the new `crates/ledger-cli/tests/documents.rs` (preview writes nothing, the DRAFT copy, the issued copy's SHA-256 equals `books.get_receipt`'s, numbers run, a bill's file and terms, the duplicate refusal, the line-account rules, the terms fallback, the `party_id` alias and the ambiguity it refuses, the contact block's set and clear, and the bill-to at issue); `format_upgrade.rs` gains `documents_v2_refused_until_consent` and the cut-over test now refuses and then makes a document carrying a new field (8.0.6 item 3); the store tests are `the_contact_block_round_trips_and_replays` and `an_invoice_keeps_the_billing_details_it_was_issued_with`, and `books_written_under_older_rules_still_open` gains a hand-written contact-block event (8.0.6 item 1). Merge does not need the owner's go-ahead: the live books refuse a write that needs `documents_v2` until he gives it, and take every other write as before (8.0.6 item 6). No figure moved: S4 moves none.
This commit is contained in:
1 parent
ed637f0e27
commit
d5b9e5cf99
28 files changed
+2604
-190
No files matched your search
@@ -611,6 +611,63 @@ fn format_upgrade_waits_for_consent() {
|
||||
assert_eq!(format_lines(&dir), 1);
|
||||
}
|
||||
|
||||
/// plan P4b S4.4 (R-A step 4, 8.0.6 item 3): on books that haven't
|
||||
/// declared `documents_v2`, an invoice carrying a new field (terms) is
|
||||
/// refused with the upgrade remedy and journals nothing, while one
|
||||
/// carrying none posts as before; after the owner's go-ahead the same call
|
||||
/// is made, and takes the first number.
|
||||
#[test]
|
||||
fn documents_v2_refused_until_consent() {
|
||||
let home = Home::new("documents-v2");
|
||||
let dir = old_books(&home, "acme");
|
||||
let _held = serve(&home);
|
||||
let out = home
|
||||
.cmd("token")
|
||||
.args(["create", "--book", "acme"])
|
||||
.stdin(Stdio::null())
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(out.status.success(), "{out:?}");
|
||||
let mut a = Agent::start(&home, "acme");
|
||||
let customer = a
|
||||
.call("books.add_customer", json!({"name": "Harbor Coffee"}))
|
||||
.unwrap()["id"]
|
||||
.clone();
|
||||
let line = json!([{"description": "Design", "amount": "500.00"}]);
|
||||
let with_terms = json!({"customer": customer.to_string(), "date": "2026-02-10",
|
||||
"terms": "Net 30", "lines": line, "confirmed": true});
|
||||
let before = journal(&dir);
|
||||
let refused = a
|
||||
.call("books.create_invoice", with_terms.clone())
|
||||
.unwrap_err();
|
||||
assert!(refused.starts_with("format_upgrade_pending"), "{refused}");
|
||||
assert!(refused.contains("documents_v2"), "{refused}");
|
||||
assert_eq!(journal(&dir), before, "a refusal journals nothing");
|
||||
// A document carrying none of the new fields posts as before, and
|
||||
// files its copy; it takes no number (an older version reads it).
|
||||
let plain = a
|
||||
.call(
|
||||
"books.create_invoice",
|
||||
json!({"customer": customer.to_string(), "date": "2026-02-10", "due_date": "2026-03-12",
|
||||
"lines": line, "confirmed": true}),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(plain.get("number").is_none(), "{plain}");
|
||||
assert_eq!(plain["total"], "500.00");
|
||||
|
||||
// The go-ahead.
|
||||
let mut words = home.words("books");
|
||||
words.extend(["upgrade".into(), "acme".into()]);
|
||||
let (code, shown) = home.at_terminal(&words, &[PASS]);
|
||||
assert_eq!(code, 0, "{shown}");
|
||||
assert_eq!(format_lines(&dir), 1, "the format moved once");
|
||||
let made = a.call("books.create_invoice", with_terms).unwrap();
|
||||
assert_eq!(made["number"], "INV-0001", "{made}");
|
||||
assert_eq!(made["terms"], "Net 30", "{made}");
|
||||
assert_eq!(made["due_date"], "2026-03-12", "{made}");
|
||||
a.call("books.verify", json!({})).unwrap();
|
||||
}
|
||||
|
||||
/// Copy the tree `from` into `to`, private as the server keeps a book
|
||||
/// (folders 0700, files 0600).
|
||||
fn copy_private(from: &Path, to: &Path) {
|
||||
@@ -705,17 +762,24 @@ fn books_p2_served_cut_over_whole() {
|
||||
.unwrap();
|
||||
let waiting = journal(&dir);
|
||||
let refused: Vec<(&str, Value)> = vec![
|
||||
// An invoice's or bill's line naming its project
|
||||
// (document_line_projects, rules.md B-37 item 8).
|
||||
// An invoice carrying documents_v2's fields (terms: P4b S4.4) and
|
||||
// its line naming its project (document_line_projects, rules.md
|
||||
// B-37 item 8).
|
||||
(
|
||||
"books.create_invoice",
|
||||
json!({"party_id": 1, "date": "2026-02-10", "due_date": "2026-03-12",
|
||||
"lines": [{"description": "Design", "amount": "500.00", "class": "Lighthouse"}]}),
|
||||
json!({"customer": "1", "date": "2026-02-10", "terms": "Net 30",
|
||||
"lines": [{"description": "Design", "amount": "500.00", "class": "Lighthouse"}],
|
||||
"confirmed": true}),
|
||||
),
|
||||
// A bill carrying documents_v2's fields (the vendor's number, the
|
||||
// line's account, its invoice: A-10, A-13) and its line's project.
|
||||
(
|
||||
"books.create_bill",
|
||||
json!({"party_id": 1, "date": "2026-02-11", "due_date": "2026-03-13",
|
||||
"lines": [{"description": "Drafting", "amount": "120.00", "class": "Lighthouse"}]}),
|
||||
json!({"vendor": "1", "date": "2026-02-11", "due_date": "2026-03-13",
|
||||
"vendor_ref": "L-77",
|
||||
"lines": [{"description": "Drafting", "amount": "120.00",
|
||||
"account": "6600", "class": "Lighthouse"}],
|
||||
"existing_attachment_id": 1, "confirmed": true}),
|
||||
),
|
||||
(
|
||||
"books.set_setting",
|
||||
|
||||
Reference in new issue
Block a user