Skip to content
ERPForAll DocsDevelopment

    Demo data

    An addon can ship demo data: example records that make a fresh database look used, so lists, forms, reports and tests have something to show. Demo data is optional and is loaded only when the database is created with demo data.

    Put the files in the addon’s demo/ folder and list them in the manifest next to data:

    data = ["views/book_views.xml"]
    demo = ["demo/book_demo.xml", "demo/loans.csv"]

    Demo files use the same formats as data files (data-files.md): XML with <record> elements, or CSV. They load after all data files of the module, in the order listed. Two rules differ from data files:

    • noupdate by default. A demo file loads as if it were wrapped in <erp noupdate="1">, so an upgrade never rewrites demo records a user has edited.
    • All or nothing. The demo files of one module load inside one savepoint. If one fails on its data (a missing reference, a refused value), the module installs without demo data and the failure is reported as a DemoFailed notice; the rest of the install goes ahead.

    base takes the database’s demo flag, chosen once when the database is initialized: erp db init --with-demo (the default is --without-demo; InitOptions::with_demo(true) in code). The flag stays on the database; erp db init refuses to change it later, and erp module install --with-demo on a database without demo data loads the demo data of every installed addon first (cli.md). Every other module gets demo data only when each module it depends on has it. A module with no demo list passes the flag on, so an addon without demo files does not stop its dependents from loading theirs. Without the flag, no demo record exists in any addon.

    A demo file may refer to the external ids of the module’s dependencies, because those are loaded first: the product demo prices the vendor partners that the base demo creates (base.partner_demo_mitra_kayu).

    • Invent the content: company names, people, products, notes. Use example.com-style addresses and fictional phone numbers. Never copy real customers or another project’s demo records.
    • Give every record an external id (partner_demo_..., product_demo_...) so tests and other demo files can refer to it. Most demo ids carry a _demo_ infix; attribute values (pav_…) do not, so check a new id against the addon’s default data ids before you use it.
    • A company partner is a root partner with a tax ID (vat): is_company is computed from it. People are child partners with parent_id.
    • Do not create demo users with passwords. Demo data never ships credentials.
    • Default data (categories, units, currencies, the record sets an addon needs to work) belongs in data, not in demo.
    • Test it: initialise a test database with and without demo data and assert that the records exist, and that none exist without the flag (crates/erp-cli/tests/demo_data.rs).
    AddonDemo filesRecords
    baseres_currency_demo.xml, res_currency_rate_demo.xml, res_partner_demo.xmlEUR, IDR, SGD and GBP made active; 7 spot rates for them against the company currency; 6 company partners (4 vendors, 2 customers) with 9 contacts
    productproduct_attribute_demo.xml, product_category_demo.xml, product_demo.xml, product_supplierinfo_demo.xml, product_pricelist_demo.xml17 attribute values (some with a default extra price); 7 subcategories; 15 product templates (12 goods, 3 services; 28 variants after the attribute lines); 11 vendor price rows on the base demo vendors; 2 pricelists with 4 rules; 3 combos with 6 items
    contactscontacts_demo.xml2 companies with contacts and 2 tags
    accountaccount_account_demo.xml, account_journal_demo.xml3 reporting tags; a small generic chart of 20 accounts of the main company (one or more per account type group, codes 101100 to 691000), some tagged with the demo tags or the cash-flow tags of the default data; 1 extra ledger (Management Reporting); 6 journals on those accounts (sales, purchases, bank, cash, general, and a general journal in the extra ledger)
    sample_librarysample_library_demo.xmlauthors, genres, books and loans

    The account demo names the company of every account (company_ids) and journal (company_id): base.main_company. An account code is stored per company, so naming it keeps the records independent of the company the loader happens to work in. Fiscal periods have no demo records: they are created when a dated document needs them, and the record API refuses them. Taxes come later, with the fiscal country of the company: a tax needs a country, and the main company has none.

    Combo items point at single-variant products. A variant that an attribute line generates has no external id, so a demo file refers to it with search="[('product_tmpl_id', '=', ref('...'))]", which finds the first variant of the template.

    acceptance_notes ships no demo. Its notes need an owner user in the same company as the note, and demo data creates no users (no passwords), so the company-consistency check refuses a note owned by the system user.