| docs | ||
| models | ||
| security | ||
| services | ||
| static/description | ||
| tests | ||
| views | ||
| wizards | ||
| __init__.py | ||
| __manifest__.py | ||
| .gitignore | ||
| README.md | ||
| requirements.txt | ||
Survey Custom Certificate Template
Overview
The Survey Custom Certificate Template module extends Odoo 19's Survey application to support custom DOCX-based certificate templates with dynamic placeholders. This allows survey administrators to create personalized, branded certificates without requiring XML/QWeb development or coding knowledge.
Features
- Custom DOCX Templates: Upload your own Microsoft Word certificate designs
- Dynamic Placeholders: Use
{key.field_name}syntax for automatic data insertion - Intelligent Mapping: Automatic field mapping for common placeholder names
- Live Preview: Generate sample certificates before going live
- Multi-Survey Support: Each survey can have its own unique template
- Easy Updates: Update templates while preserving existing mappings
- Comprehensive Error Handling: Graceful handling of missing data and conversion errors
- Security: Built-in validation and sanitization of all user inputs
Quick Start
For Users
- Navigate to Surveys in Odoo
- Open or create a survey
- Go to the Options tab
- Select Custom Template from the Certification Template dropdown
- Click Upload Custom Certificate
- Upload your DOCX template with placeholders
- Configure placeholder mappings
- Generate a preview
- Click Save
For Administrators
- Install LibreOffice on the server
- Install python-docx:
pip install python-docx - Install the module from Odoo Apps
- Grant Survey Manager access to users who need to configure templates
Documentation
- User Guide: Complete guide for creating and configuring certificate templates
- Administrator Guide: Installation, configuration, and troubleshooting for system administrators
- Troubleshooting Guide: Common issues and solutions
Requirements
System Requirements
- Odoo 19.0 or later
- Python 3.8 or later
- LibreOffice 6.0 or later (for PDF conversion)
Python Dependencies
python-docx >= 0.8.11
Odoo Module Dependencies
survey(Odoo Survey module)base(Odoo Base module)mail(Odoo Mail module)
Installation
1. Install System Dependencies
Ubuntu/Debian
sudo apt-get update
sudo apt-get install libreoffice
CentOS/RHEL
sudo yum install libreoffice
2. Install Python Dependencies
# Activate your Odoo virtual environment
source /path/to/odoo/venv/bin/activate
# Install python-docx
pip install python-docx
3. Install the Module
- Copy the module to your Odoo addons directory
- Update the apps list in Odoo
- Search for "Survey Custom Certificate Template"
- Click Install
4. Verify Installation
- Open a survey in Odoo
- Check that "Custom Template" appears in the Certification Template dropdown
- Try uploading a test template
Usage
Creating a Certificate Template
- Design your certificate in Microsoft Word (.docx format)
- Add placeholders where you want dynamic data:
{key.name} {key.course_name} {key.date} {key.score} - Save the file as .docx format
Placeholder Syntax
Placeholders must follow this exact format:
{key.field_name}
Examples:
{key.name}- Participant's name{key.course_name}- Survey title{key.completion_date}- Completion date{key.score}- Score percentage
Recognized Placeholder Names
The system automatically maps these common placeholders:
| Placeholder | Maps To | Description |
|---|---|---|
{key.name} |
partner_name | Participant's full name |
{key.email} |
partner_email | Participant's email |
{key.course_name} |
survey_title | Survey title |
{key.date} |
completion_date | Completion date |
{key.score} |
scoring_percentage | Score percentage |
See the User Guide for a complete list.
Configuring Mappings
For each placeholder, choose how it should be filled:
- Survey Field: Data from the survey (title, description)
- Participant Field: Data from the participant (name, email, date, score)
- Custom Text: Static text that's the same for all certificates
Architecture
Components
- Template Parser: Extracts placeholders from DOCX files using python-docx
- Certificate Generator: Replaces placeholders and converts to PDF using LibreOffice
- Configuration Wizard: User interface for uploading and configuring templates
- Survey Model Extension: Stores templates and mappings in the database
Data Flow
- Administrator uploads DOCX template
- Parser extracts placeholders
- Administrator configures mappings
- Configuration saved to database
- On survey completion, generator creates personalized certificate
- LibreOffice converts DOCX to PDF
- Certificate delivered to participant
Security
Access Control
- Only users with Survey Manager role can upload and configure templates
- Template data is restricted to appropriate user groups
- All user inputs are validated and sanitized
Data Validation
- File type validation (DOCX only)
- File size limits (10 MB maximum)
- Placeholder format validation
- Field name validation (alphanumeric only)
- Custom text length limits (1000 characters)
Sanitization
- HTML escaping for all placeholder values
- Control character removal
- Special character filtering
- Length limits to prevent DoS attacks
Troubleshooting
Common Issues
"Invalid file format" error
- Ensure file is .docx format (not .doc)
- Re-save the file in Microsoft Word or LibreOffice
"No placeholders found" warning
- Check placeholder syntax: must be
{key.field_name} - Common mistakes:
{{key.name}},{name},{ key.name }
"PDF conversion failed" error
- Ensure LibreOffice is installed on the server
- Contact your system administrator
Placeholders not replaced
- Verify mapping configuration is complete
- Check field names are correct (case-sensitive)
- Generate a preview to test
See the Troubleshooting Guide for more solutions.
Performance
Optimization Tips
- Template Size: Keep templates under 5 MB for best performance
- Image Compression: Compress images in templates
- Simple Formatting: Avoid complex Word features
- Batch Generation: Generate certificates during off-peak hours for high volumes
Resource Usage
- Memory: ~50-100 MB per certificate generation
- CPU: Moderate usage during PDF conversion
- Disk: Templates stored in database, certificates as attachments
- Time: 5-10 seconds per certificate (including PDF conversion)
Development
Module Structure
survey_custom_certificate_template/
├── __init__.py
├── __manifest__.py
├── models/
│ ├── __init__.py
│ ├── survey_survey.py
│ └── survey_user_input.py
├── wizards/
│ ├── __init__.py
│ ├── survey_custom_certificate_wizard.py
│ └── survey_custom_certificate_wizard_views.xml
├── services/
│ ├── __init__.py
│ ├── certificate_template_parser.py
│ ├── certificate_generator.py
│ ├── certificate_logger.py
│ └── admin_notifier.py
├── views/
│ └── survey_survey_views.xml
├── security/
│ └── ir.model.access.csv
├── tests/
│ ├── __init__.py
│ ├── hypothesis_strategies.py
│ ├── test_property_*.py
│ └── test_*.py
└── docs/
├── README.md
├── USER_GUIDE.md
├── ADMIN_GUIDE.md
└── TROUBLESHOOTING.md
Testing
The module includes comprehensive tests:
- Unit Tests: Test individual components
- Property-Based Tests: Test universal properties using Hypothesis
- Integration Tests: Test complete workflows
Run tests:
# Run all tests
python -m pytest customaddons/survey_custom_certificate_template/tests/
# Run specific test file
python -m pytest customaddons/survey_custom_certificate_template/tests/test_property_placeholder_extraction_standalone.py
# Run with coverage
python -m pytest --cov=customaddons/survey_custom_certificate_template
Contributing
When contributing to this module:
- Follow Odoo coding guidelines
- Add tests for new features
- Update documentation
- Ensure all tests pass
- Test with various template formats
License
This module is licensed under LGPL-3.
Support
For support:
- Documentation: Check the User Guide and Admin Guide
- Issues: Review the Troubleshooting Guide
- Logs: Check Odoo server logs for detailed error messages
- Community: Search Odoo community forums for similar issues
Changelog
Version 1.0.0 (2024)
Initial Release
- Custom DOCX template upload
- Dynamic placeholder system
- Automatic field mapping
- Live preview generation
- Multi-survey support
- Template update and deletion
- Comprehensive error handling
- Security validation and sanitization
- Property-based testing
- Complete documentation
Credits
Author: Survey Custom Certificate Template Team
Maintainer: Your Organization
Contributors: See CONTRIBUTORS.md
Technical Details
Database Schema
survey.survey (Extended)
custom_cert_template(Binary): Template filecustom_cert_template_filename(Char): Filenamecustom_cert_mappings(Text): JSON mappingshas_custom_certificate(Boolean): Configuration flag
survey.custom.certificate.wizard (Transient)
- Template upload and configuration wizard
survey.certificate.placeholder (Transient)
- Placeholder mapping configuration
API
Public Methods
survey.survey
action_open_custom_certificate_wizard(): Opens configuration wizard_generate_custom_certificate(user_input_id): Generates certificate for participant_get_certificate_data(user_input_id): Retrieves data for certificateaction_delete_custom_certificate(): Deletes custom template
CertificateTemplateParser
parse_template(docx_binary): Extracts placeholdersvalidate_template(docx_binary): Validates DOCX structure
CertificateGenerator
generate_certificate(template_binary, mappings, data): Generates PDF certificate
Configuration
No additional configuration required. The module works out of the box after installation.
Compatibility
- Odoo Version: 19.0
- Python Version: 3.8+
- Database: PostgreSQL 12+
- Operating System: Linux (Ubuntu, Debian, CentOS, RHEL)
FAQ
Q: Can I use .doc files instead of .docx?
A: No, only .docx format is supported. Convert .doc files to .docx first.
Q: What's the maximum template file size?
A: 10 MB. Compress images if your file exceeds this limit.
Q: Can I use custom fonts?
A: Yes, but use standard fonts for best compatibility. Custom fonts may not render correctly in PDF.
Q: How do I add a logo to my certificate?
A: Insert the logo as an image in your Word template. It will be preserved in generated certificates.
Q: Can I have different templates for different surveys?
A: Yes, each survey can have its own unique template.
Q: What happens if a participant's data is missing?
A: The system uses empty strings for missing data to prevent generation failures.
Q: Can I update a template after it's been configured?
A: Yes, upload a new template and existing mappings will be preserved where placeholders match.
Q: Is there a limit to the number of placeholders?
A: No hard limit, but keep it reasonable for performance (< 50 placeholders recommended).
Q: Can I use special characters in placeholders?
A: Placeholder names can only contain letters, numbers, and underscores.
Q: How are certificates delivered to participants?
A: Certificates can be emailed or made available for download through the participant portal.
For detailed information, please refer to the complete documentation in the docs/ directory.