Dev/E2E Accounting Rules Seeding
This system provides convenient ways to seed development and testing organizations with standard fallback rules for posting matrices, eliminating the need to manually configure accounting rules during testing.Overview
The seeding system configures fallback rules for posting matrices. Fallback rules are used when no specific posting rules match transaction criteria, ensuring transactions always have a default GL account to post to.Current Standard Dev Fallback Rules
Matrix | Trigger Event | Dimension | Fallback Account | Account Nr | Description |
---|---|---|---|---|---|
Sales Invoice Posting | sales-invoice | Credit | Revenue Germany | 8000 | Default revenue account for Sales Invoice credit side |
DEV_FALLBACK_RULES
array in the CLI script.
Usage Methods
1. UI Button (Recommended for Manual Testing)
Navigate to/setup/accounting-logic
in your dev environment and click the “⚙️ Seed Dev Accounting Rules” button at the top of the page.
- Only visible in development environment (NODE_ENV === “development”)
- Uses the
warning
button variant for dev/testing purposes - Shows loading state during seeding
- Displays success/error toasts with detailed information
- Creates or updates fallback rules as needed
2. CLI Script (Recommended for Automation)
Use the CLI script for automated testing or CI/CD pipelines:DATABASE_URL
must be set (uses organization’s database)
3. Server Action (Programmatic Use)
For programmatic usage in tests or other server-side code:How It Works
The seeding system:- Finds Posting Matrices: Locates the specified posting matrices by label and trigger event
- Validates GL Dimensions: Ensures the matrix has the correct GL dimension type (Credit/Debit)
- Locates Chart Accounts: Finds the target chart accounts by account number
- Creates/Updates Fallback Rules:
- Creates new fallback rules with
is_fallback: true
and high order numbers (9999) - Updates existing fallback rules to point to the correct chart account
- Links the rule to the appropriate posting matrix and GL account
- Creates new fallback rules with
Features
- Upsert Logic: Rules are created or updated, so running the seed multiple times is safe
- Validation: Validates that posting matrices and chart accounts exist before creating rules
- Error Handling: Continues processing even if individual rules fail
- Comprehensive Logging: Detailed logging for debugging and audit trails
- Interactive CLI: Prompts for required parameters with validation
- Single Source of Truth: Fallback rules defined once in CLI script, imported by UI
Prerequisites
Before using the accounting rules seeding:-
Posting Matrices Must Exist: Run the standard posting matrix seeding first:
-
Chart of Accounts Must Exist: Ensure the target chart accounts are seeded:
E2E Testing Integration
Playwright/E2E Tests
Add this to your test setup:CI/CD Integration
Add to your CI pipeline after creating test organization and seeding prerequisites:Important Notes
⚠️ This is for development/testing only!- This seeding is NOT part of production organization setup
- It’s separate from the standard posting matrix seeding
- The UI button only appears in development environment
- Rules are created for testing purposes, not production-ready configurations
- Requires prerequisite seeding (posting matrices and chart accounts)
Modifying Fallback Rules
To add, remove, or modify the standard dev fallback rules:- Edit only
apps/webapp/scripts/seed-dev-accounting-rules.mjs
- Update the
DEV_FALLBACK_RULES
array - Both UI button and CLI will automatically use the updated data
Fallback Rule Configuration Format
File Structure
Troubleshooting
“Posting matrix not found” warnings:- Ensure posting matrices have been seeded first using
seedPostingMatrix
- Verify the matrix label and trigger event slug are correct
- Check that matrices are active (
is_active: true
)
- Run chart of accounts seeding first:
pnpm seed:dev-chart <orgId>
- Verify the account number exists in the dev chart seeding data
- Ensure accounts are current and not deleted
- Verify the posting matrix has the correct GL dimension type (Credit/Debit)
- Check the posting matrix configuration in the database
- Ensure you’re in a development environment (
NODE_ENV === "development"
) - Check that you’re authenticated and have access to the organization
- Verify
DATABASE_URL
environment variable is set - Check database connectivity
Related Systems
- Chart of Accounts Seeding:
apps/internal-docs/guides/dev-chart-seeding.mdx
- Posting Matrix System: Core business logic for GL account determination
- GL Dimensions: Credit and Debit dimension configuration