fix(import): the IIF export refuses an entry on two A/R or A/P accounts

BS-format-2 item 7: QuickBooks Desktop records at most one A/R or A/P
account in a transaction (Intuit's own warning, sources/intuit-iif.md
and rules/format/BS-format-2.toml), so an entry with lines on two
receivable accounts, two payable accounts, or one of each cannot be
written as one IIF transaction. journal_to_iif used to write it and
merely list it in Iif::receivable_payable.

Now the export collects every entry whose lines touch more than one
distinct A/R/A/P account and returns
IifError::SeveralReceivablePayableAccounts, naming the entries and
saying why and what to do (reverse and post as two entries through a
clearing account; splitting one would change what it says). It never
splits an entry itself. ledger_package::export_iif and build_package
pass the refusal through, so books.export and books.export_cpa_package
return it before a file is handed over.

The README test's entry on both controls moved to its own refusal test;
the valid books it covers (one A/R entry, one A/P entry) are unchanged,
as are every IIF golden and every test of the file's bytes.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
This commit is contained in:
swaitsandDeepSeek V4.1 Flash committed 2026-11-08 14:32:23 -07:00
1 parent 4b295ee224
commit 45ea103283
5 files changed
+280 -26

No files matched your search

+37
View File
@@ -1546,6 +1546,43 @@ fn iif_declares_accounts_by_role_and_balances_every_transaction() {
);
}
/// BS-format-2 item 7 through the server: an entry with lines on both the
/// receivables and payables control accounts makes `books.export` iif and
/// `books.export_cpa_package` refuse, naming the entry, rather than hand
/// over a file QuickBooks Desktop will not import.
#[test]
fn iif_and_the_package_refuse_an_entry_on_two_receivable_or_payable_accounts() {
let dir = test_dir("iif-two-receivable-payable");
let mut s = new_store(&dir);
let netted = ledger_core::parties::replaying(|| {
post(
&mut s,
"2025-04-05",
"Netted",
&[("2000", Dr, "80.00"), ("1200", Cr, "80.00")],
)
});
drop(s);
let mut m = Mcp::start(&dir, "1000000.00");
for (tool, args) in [
(
"books.export",
json!({"format": "iif", "report": "journal", "as_of": END}),
),
(
"books.export_cpa_package",
json!({"as_of": END, "cash_accounts": ["1000"], "include_receipts": false, "include_tins": false}),
),
] {
let why = m.refuse(tool, args);
assert!(why.contains(&format!("entry {netted}: ")), "{tool}: {why}");
assert!(
why.contains("more than one accounts receivable or accounts payable account"),
"{tool}: {why}"
);
}
}
/// P3 review R5: books.export iif without as_of is as of today, like the
/// trial balance: an entry dated later is left out, and the two exports
/// made with no dates tie, account by account.