dodil/erp-brick-consolidation

DODIL ERP brick: consolidation

README.md

brick-consolidation — Group consolidation

Turn the books of every company in the group into one set of group accounts: translated into the group's currency, with what the companies sold, lent and charged each other taken out, the parent's investments replaced by the assets behind them, and the minority's share shown, signed off by a second person each period.

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

src/brick_consolidation/
  domain/          the rules, plain Python: Group, StructureChange, ConsJournal, Statement, AiFinding, MigrationRun, MigrationMap, ConsMigrationRun; 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 `cons_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_consolidation/schema.sql --brick cons=0.1.0
BUCKET=my-bucket DEV_ALLOW_ANON=1 DEV_USER_PERMISSIONS=TODO(permission):cons:ai_finding:write,TODO(permission):cons:cons_migration_run:write,TODO(permission):cons:group:write,TODO(permission):cons:migration_map:write,TODO(permission):cons:migration_run:write,TODO(permission):cons:structure_change:write,cons:journal:approve,cons:journal:post_auto,cons:journal:reverse,cons:journal:write,cons:period:open,cons:period:reopen,cons:period:signoff,cons:settings:write,cons:statement:materialise \
  uvicorn brick_consolidation.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.