Odoo Custom Module Development Part 6 - Reports, Demo Data, and Tests
This is the sixth article in the Odoo custom module development series.
In Part 5, we added business logic to the estate module. In this final article, we will make the module easier to demonstrate and maintain by adding demo data, a PDF report, and automated tests.
These are the pieces that turn a learning project into something closer to a production-ready module.
What we will add
We will create:
- demo data records
- a simple sequence
- a QWeb PDF report
- test cases for model behavior
1. Create directories for data, reports, and tests
Inside the estate module:
mkdir -p data report tests |
Create these files:
touch data/estate_demo.xml |
2. Add demo data
Open data/estate_demo.xml:
<odoo> |
Demo data is useful when you want an immediately usable database for local development or training.
3. Add a sequence for property references
Update the property model to include a reference field:
reference = fields.Char(required=True, copy=False, readonly=True, default='New') |
Then override create() in models/property.py:
|
Now create data/estate_sequence.xml:
<odoo noupdate="1"> |
4. Show the reference in views
Add reference near the top of the list and form views.
Example list view field:
<field name="reference"/> |
Example form view field:
<field name="reference" readonly="1"/> |
5. Create a simple PDF report action
Open report/estate_property_report.xml:
<odoo> |
Now create the template in report/estate_property_templates.xml:
<odoo> |
With this, users can print a property report from the record action menu.
6. Add tests for model behavior
Open tests/__init__.py:
from . import test_estate_property |
Now add this to tests/test_estate_property.py:
from odoo.exceptions import ValidationError |
These tests check both validation and computed behavior.
7. Load files from the manifest
Update __manifest__.py to include the new files:
{ |
Why add web to depends? Because the report template uses web.external_layout.
8. Upgrade the module and test the report
Run:
cd ~/odoo-dev/odoo |
Then:
- open a property record
- click the print menu
- choose
Property Report
If wkhtmltopdf is installed correctly, Odoo should generate a PDF.
9. Run automated tests
Run module tests with:
python3 odoo-bin -c ~/odoo-dev/odoo.conf -d odoo_test --test-enable -i estate --stop-after-init |
Using a dedicated test database is better than reusing your normal development database.
10. Best practices for maintainable modules
- keep XML IDs stable once other data references them
- use
noupdate="1"for sequences and technical records that should not reset on upgrade - keep demo data separate from required data
- write tests for business rules that must never silently break
- add reports only after your model and UI are already stable
11. Common mistakes
The report action exists but PDF generation fails
This often means wkhtmltopdf is missing or incompatible.
Tests do not run
Check:
tests/__init__.pyimports the test file- the module is installed during the test run
- you are using a clean database for tests
Demo records fail during install
This usually means the referenced model or XML ID is not loaded yet. Verify file order in the manifest.
Final words
You now have a small but complete custom Odoo module with models, security, views, business logic, demo data, reporting, and tests.
That is a strong base for building real Odoo business applications.
Previous article: Part 5 - Relations, Computed Fields, and Business Logic
Related posts
- /article/odoo-custom-module-development-part-2-models-and-fields/
- /article/odoo-custom-module-development-part-1-create-your-first-module/
- /article/odoo-custom-module-development-part-4-menus-actions-and-views/
- /article/odoo-custom-module-development-part-3-security-and-access-rights/
- /article/odoo-custom-module-development-part-5-relations-computed-fields-and-business-logic/