Feat/Complete Sales Summaries #5
Reference in New Issue
Block a user
Delete Branch "feat/complete-sales-summaries"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Completes the automatic sales summary pipeline end-to-end: the
sales-summaries-v2job now calculates aggregate totals, preserves manual adjustments, and automatically posts balanced journal entries to the ledger.What Changed
New Datomic transaction function (
upsert-sales-summary-ledger)sales-summary-items into aggregatedjournal-entrylines grouped by account and ledger sideEnhanced
sales-summaries-v2jobmanual? true) during recalculation — only auto-calculated items are replacedLedger reconciliation
reconcile-ledgernow queries for sales summaries missing journal entries and repairs them via:upsert-sales-summary-ledger, alongside existing invoice and transaction repairsSchema
total-*attributes onsales-summary(alldb.type/double, no history)tx.cljanddatomic.cljAdmin UI cleanup
client-idTODOs in the sales summaries admin pagenew-summary-itemnow correctly passesclient-idviahx-valsFiles Changed (8)
iol_ion/.../upsert_sales_summary_ledger.cljiol_ion/.../tx.cljresources/schema.edntotal-*attributessrc/.../datomic.cljsrc/.../jobs/sales_summaries.cljsrc/.../ledger.cljreconcile-ledgersrc/.../ssr/admin/sales_summaries.cljdocs/plans/...plan.mdCode Review
Scope:
feat/complete-sales-summaries→master(1 commit, 8 files, +529/-105)Review team: correctness, testing, maintainability, project-standards, agent-native, learnings-researcher, data-migrations, adversarial
P0 -- Critical
upsert_sales_summary_ledger.clj:76:db/retractEntitysyntax — passes vector instead of entity ID. Crashes whenever summary has no mapped accounts.upsert_sales_summary_ledger.clj:66nilclient-id crashes entire reconciliation. Hard-deleted client with orphaned summaries aborts ALL pending ledger repairs.P1 -- High
sales_summaries.clj:279summary->journal-entry— dead code identical to tx function version. Will diverge.upsert_sales_summary_ledger.clj:51total-amountonly sums debits, ignoring credits. Downstream balance invariant expects amount == debits == credits.sales_summaries.clj:337calc-aggregate-totals:elseclause silently absorbs all unmatched categories intototal-net. Zero visibility.ledger.clj:58reconcile-ledgercan't retract stale journal entries when ALL accounts are cleared — query requires at least one mapped account.resources/schema.edn:1973:sales-summary/total-gift-card-refunds. SSR reads it, job never computes it. Always $0.00.resources/schema.edn:1985total-card-fees,total-food-app-fees,total-gift-card-fees).resources/schema.edn:2005total-unknown-payments, SSR readstotal-unknown-processor-payments. Always $0.00.P2 -- Moderate
upsert_sales_summary_ledger.clj:5-25-random-tempid,extant-read,calc-client+account+location+date, unusedDateimportupsert_sales_summary_ledger.clj:75current-datecalled with originaldbinstead of:db-after— potentially stale transaction timestampsales_summaries.clj:397total-unknown-processor-payments— not in schema.ednsales_summaries.clj:350P3 -- Low
tx.clj:40,datomic.clj:8upsert_sales_summary_ledger.clj:73client/ledger-last-changeupdate (already set byupsert-ledger)Requirements Completeness
total-amountonly sums debits; no balance assertionreconcile-ledger+:upsert-sales-summary-ledgertx fnclient-id, stale TODOs cleaned upResidual Risks & Testing Gaps
upsert-sales-summary-ledger,calc-aggregate-totals, andreconcile-ledgersales summary pathsummary->journal-entrywill diverge over timedc/withsimulation may not faithfully reproduceupsert-entitybehaviorVerdict: Not ready
Two P0 blockers must be fixed before merge: the
:db/retractEntitycrash (#1) and the nil client-id reconciliation abort (#2). Three P1 schema mismatches (#7-9) cause silent $0.00 display for gift card refunds, per-type fees, and unknown payments.5a49ad777cto5a39a0c762