Accounting: auto-create record-only bills for no-bill vendor payments (import mode)

Buildium often records vendor payments as direct checks (Dr Expense/Cr Bank)
with no bill. For import-mode companies post_bill_gl no-ops, so a bill is a
record only. New fn accounting.autocreate_nobill_vendor_bills() creates a paid
record-only bill for each such buildium_gl payment (vendor resolved by payee,
idempotent by external_id); buildium-gl-sync calls it per import-mode company
after each pull. No GL impact, no double-count.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-16 12:57:28 -04:00
parent 73f04017f5
commit a65c135122
2 changed files with 78 additions and 0 deletions
@@ -526,6 +526,17 @@ Deno.serve(async (req) => {
} else if (unmappedGl.size > 0) {
companyResult.watermark_held = true;
}
// Import-mode: surface no-bill vendor payments (Buildium direct checks that
// hit an expense account with no A/P leg) as record-only bills. post_bill_gl
// no-ops for gl_auto_post=false companies, so this never touches the GL.
if (!dryRun && company.gl_auto_post === false) {
const { data: madeBills, error: billErr } =
await supabase.schema("accounting").rpc("autocreate_nobill_vendor_bills", { _company_id: company.id });
if (billErr) companyResult.errors.push(`autocreate bills: ${billErr.message}`);
else if (madeBills) companyResult.autobills_created = madeBills;
}
companyResult.window = { since, until };
} catch (e: any) {
companyResult.errors.push(e?.message || String(e));