dodil/erp-brick-ar

DODIL ERP brick: accounts receivable

README.md

erp-brick-ar — Invoicing

Send invoices for what you sold (from an order, a repeating schedule, delivered work, or by hand), correct them with credit notes, and keep the books in step, without re-typing anything the sales side already captured.

A brick on erp-platform, scaffolded by erp-compose scaffold from the ar module spec. The shape is templates/brick-example's; the business rules are not written yet — see AGENTS.md.

src/brick_ar/
  domain/          the rules, plain Python: Invoice, Writeoff, Schedule, Customer, ExportBatch, NumberSeries, MigrationRun, CreditNote; values.py, events.py, errors.py
  application/     the use cases — each declared once, served as an API route AND an MCP tool
  infrastructure/  the tables, and one repository per aggregate that loads/saves it whole
  app.py           the ASGI app: routes, /mcp, the sign-in metadata for agents
  schema.sql       the tables (generated from the same model as infrastructure/tables.py)
  migrations/      00001_init/{up,down}.sql, journal `ar_schema_migrations`
tests/             rules (xfail per story), both doors on SQLite, schema, composition, scenarios

Run it.

pip install -e '.[test]'
pytest -q                                  # no bucket needed
BUCKET=my-bucket erp-migrate --schema src/brick_ar/schema.sql --brick ar=0.1.0
BUCKET=my-bucket DEV_ALLOW_ANON=1 DEV_USER_PERMISSIONS=TODO(permission):ar:migration_run:write,ar:credit_note:approve,ar:credit_note:write,ar:customer:write,ar:export_batch:run,ar:invoice:check,ar:invoice:collect,ar:invoice:issue,ar:invoice:post,ar:invoice:raise,ar:invoice:send,ar:invoice:void,ar:invoice:write,ar:number_series:claim,ar:schedule:finish,ar:schedule:plan,ar:schedule:stop,ar:settings:write,ar:writeoff:approve,ar:writeoff:write \
  uvicorn brick_ar.app:app                 # API at /docs, agents at /mcp

Migrations. migrations/00001_init/{up,down}.sql is the versioned layout with a per-brick journal; erp-platform has no migrator for it yet, so erp-migrate --schema schema.sql is what applies the tables today.

Re-scaffolding. erp-compose scaffold never overwrites a file that differs without --force, and there is no scaffold --update: once the rules are written, this code is the brick's own.