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
@@ -1236,7 +1236,7 @@ fn invoice_and_bill_lines_count_toward_their_projects() {
|
||||
{"description": "Hosting", "amount": "200.00", "class": harbor.to_string()},
|
||||
{"description": "Rush fee", "amount": "100.00"},
|
||||
{"description": "Revisions", "amount": "500.00", "class": " zeta SITE "},
|
||||
]}),
|
||||
], "confirmed": true}),
|
||||
);
|
||||
assert_eq!(inv["total"], "3800.00");
|
||||
assert!(inv.get("notes").is_none(), "{inv}");
|
||||
@@ -1256,19 +1256,27 @@ fn invoice_and_bill_lines_count_toward_their_projects() {
|
||||
m.entry_class_ids(inv_entry),
|
||||
vec![None, Some(zeta), Some(harbor), None]
|
||||
);
|
||||
let dana_invoice = m.wire.upload(
|
||||
b"Dana's invoice",
|
||||
"dana-invoice.pdf",
|
||||
"application/pdf",
|
||||
"receipt",
|
||||
);
|
||||
let bill = m.ok(
|
||||
"books.create_bill",
|
||||
json!({"party_id": dana_vendor, "date": "2026-03-09", "due_date": "2026-04-08", "lines": [
|
||||
{"description": "Illustration", "amount": "1200.00", "class": "Zeta site"},
|
||||
{"description": "Postage", "amount": "50.00"},
|
||||
]}),
|
||||
json!({"party_id": dana_vendor, "date": "2026-03-09", "due_date": "2026-04-08",
|
||||
"vendor_ref": "DANA-77",
|
||||
"lines": [
|
||||
{"description": "Illustration", "amount": "1200.00", "account": "6000", "class": "Zeta site"},
|
||||
{"description": "Postage", "amount": "50.00", "account": "6000"},
|
||||
], "upload_id": dana_invoice, "confirmed": true}),
|
||||
);
|
||||
let bill_entry = bill["entry_id"].as_u64().unwrap();
|
||||
assert_eq!(
|
||||
m.entry_lines(bill_entry),
|
||||
vec![
|
||||
l4("6999", "debit", "1200.00", Some("Zeta site")),
|
||||
l4("6999", "debit", "50.00", None),
|
||||
l4("6000", "debit", "1200.00", Some("Zeta site")),
|
||||
l4("6000", "debit", "50.00", None),
|
||||
l4("2000", "credit", "1250.00", None),
|
||||
]
|
||||
);
|
||||
@@ -1375,7 +1383,7 @@ fn a_document_for_a_finished_project_says_so() {
|
||||
{"description": "Final", "amount": "10.00", "class": "Harbor"},
|
||||
{"description": "Again", "amount": "10.00", "class": "harbor"},
|
||||
{"description": "Old", "amount": "10.00", "class": "Dock"},
|
||||
]}),
|
||||
], "confirmed": true}),
|
||||
);
|
||||
let notes: Vec<&str> = out["notes"]
|
||||
.as_array()
|
||||
@@ -1420,7 +1428,7 @@ fn an_invoice_for_an_on_spec_project_asks_about_an_agreement() {
|
||||
{"description": "Build", "amount": "10.00", "class": "Kestrel"},
|
||||
{"description": "More", "amount": "5.00", "class": "kestrel"},
|
||||
{"description": "Site", "amount": "7.00", "class": "Zeta"},
|
||||
]}),
|
||||
], "confirmed": true}),
|
||||
);
|
||||
let notes = out["notes"].as_array().unwrap();
|
||||
assert_eq!(notes.len(), 1, "{out}");
|
||||
@@ -1434,11 +1442,19 @@ fn an_invoice_for_an_on_spec_project_asks_about_an_agreement() {
|
||||
m.entry_lines(e)[1],
|
||||
l4("4000", "credit", "15.00", Some("Kestrel"))
|
||||
);
|
||||
let icons_invoice = m.wire.upload(
|
||||
b"icons invoice",
|
||||
"icons-invoice.pdf",
|
||||
"application/pdf",
|
||||
"receipt",
|
||||
);
|
||||
let bill = m.ok(
|
||||
"books.create_bill",
|
||||
json!({"party_id": v, "date": "2026-10-05", "due_date": "2026-11-04", "lines": [
|
||||
{"description": "Icons", "amount": "10.00", "class": "Kestrel"},
|
||||
]}),
|
||||
json!({"party_id": v, "date": "2026-10-05", "due_date": "2026-11-04",
|
||||
"vendor_ref": "V-512",
|
||||
"lines": [
|
||||
{"description": "Icons", "amount": "10.00", "account": "6000", "class": "Kestrel"},
|
||||
], "upload_id": icons_invoice, "confirmed": true}),
|
||||
);
|
||||
assert!(bill.get("notes").is_none(), "{bill}");
|
||||
}
|
||||
@@ -1473,7 +1489,7 @@ fn books_without_the_feature_refuse_a_tagged_document() {
|
||||
"books.create_invoice",
|
||||
json!({"party_id": cedar, "date": "2026-03-02", "due_date": "2026-04-01", "lines": [
|
||||
{"description": "a", "amount": "10.00"},
|
||||
]}),
|
||||
], "confirmed": true}),
|
||||
);
|
||||
let text = m.read_only("books.handbook", json!({"section": "projects"}))["section"]["text"]
|
||||
.as_str()
|
||||
|
||||
Reference in new issue
Block a user