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:
swaits committed 2026-10-27 12:23:32 -06:00
1 parent ed637f0e27
commit d5b9e5cf99
28 files changed
+2604 -190

No files matched your search

+57 -4
View File
@@ -63,6 +63,20 @@ fn party_out(ledger: &Ledger, p: &ledger_core::Party) -> PartyOut {
website: p.website.clone(),
address: p.address.clone(),
notes: p.notes.clone(),
email: p.email.clone(),
phone: p.phone.clone(),
contact: p.contact.clone(),
billing_address: p.billing_address.clone(),
shipping_address: p.shipping_address.clone(),
billing_email: p.billing_email.clone(),
default_terms_as_customer: p
.default_terms_as_customer
.as_ref()
.map(ledger_core::Terms::describe),
default_terms_as_vendor: p
.default_terms_as_vendor
.as_ref()
.map(ledger_core::Terms::describe),
archived: p.archived,
vendor_id: p.vendor,
customer_id: p.customer,
@@ -540,7 +554,7 @@ impl BooksServer {
#[tool(
name = "books.update_party",
title = "Update a party",
description = "Change a party's facts: name, display_name, website, address, notes, archived, creditor_of. Give only the fields to change; \"\" clears display_name, website, address or notes. creditor_of replaces the list of liabilities the company owes the party itself (its card, its loan, what the members advanced): a credit to one never counts as paying it. Every field is checked before any is written, so a bad one (a blank or taken name, a full TIN, over 500 characters, not a liability) changes nothing; each is journaled as party.updated or party.creditor_set. Archive a party you no longer deal with (its history stays; it then goes by id). Returns the party.",
description = "Change a party's facts: name, display_name, website, address, notes, email, default_terms_as_customer, default_terms_as_vendor, archived, creditor_of. Give only the fields to change; \"\" clears display_name, website, address, notes, email or the terms. email and the terms are copied onto each invoice or bill at issue (A-13); terms (\"Net 30\") set a due date when the document gives none. creditor_of replaces the list of liabilities the company owes the party itself. Every field is checked before any is written; each is journaled as party.updated. Returns the party.",
annotations(
read_only_hint = false,
destructive_hint = false,
@@ -571,6 +585,40 @@ impl BooksServer {
if let Some(v) = p.notes {
fields.push(F::Notes(optional_text(&v)));
}
if let Some(v) = p.email {
fields.push(F::Email(optional_text(&v)));
}
// "" clears the terms; any other text is trade terms this party
// grants or is granted (B-39).
let terms = |v: String| -> Result<Option<ledger_core::Terms>, String> {
if v.trim().is_empty() {
return Ok(None);
}
ledger_core::Terms::parse(&v)
.map(Some)
.map_err(|e| e.to_string())
};
if let Some(v) = p.default_terms_as_customer {
fields.push(F::DefaultTermsAsCustomer(terms(v)?));
}
if let Some(v) = p.default_terms_as_vendor {
fields.push(F::DefaultTermsAsVendor(terms(v)?));
}
if let Some(v) = p.phone {
fields.push(F::Phone(optional_text(&v)));
}
if let Some(v) = p.contact {
fields.push(F::Contact(optional_text(&v)));
}
if let Some(v) = p.billing_address {
fields.push(F::BillingAddress(optional_text(&v)));
}
if let Some(v) = p.shipping_address {
fields.push(F::ShippingAddress(optional_text(&v)));
}
if let Some(v) = p.billing_email {
fields.push(F::BillingEmail(optional_text(&v)));
}
if let Some(a) = p.archived {
fields.push(F::Archived(a));
}
@@ -588,7 +636,7 @@ impl BooksServer {
}
if fields.is_empty() && p.creditor_of.is_none() {
return Err(
"give at least one field to change: name, display_name, website, address, notes, archived, creditor_of"
"give at least one field to change: name, display_name, website, address, notes, email, default_terms_as_customer, default_terms_as_vendor, phone, contact, billing_address, shipping_address, billing_email, archived, creditor_of"
.into(),
);
}
@@ -604,10 +652,15 @@ impl BooksServer {
.set_party_creditor(id, *a, *on)
.map_err(|e| e.to_string())?;
}
// The creditor lines' journal feature, asked for before this
// The journal features these lines need, asked for before this
// command's first line, never between its lines (rules.md B-27:
// books waiting for their format upgrade must not be left with the
// name changed and the creditors not).
// name changed and the rest not).
if fields.iter().any(|f| f.needs_documents_v2()) {
store
.ensure_feature(ledger_store::format::DOCUMENTS_V2)
.map_err(|e| e.to_string())?;
}
if !creditor.is_empty() {
store
.ensure_feature(ledger_store::format::PARTY_CREDITORS)