Skip to main content

Add wizard when use print action

Project description

Odoo Community Association

Base Print Wizard

Alpha License: AGPL-3 ecosoft-odoo/ecosoft-addons

Provides a reusable base wizard for printing reports from any Odoo model.

Key features:

  • Dynamic report list - wizard auto-discovers all ir.actions.report records flagged show_in_wizard = True for the active model.

  • Domain filtering - each report can define a domain_form so it only appears when the selected records match the domain (e.g. only confirmed orders).

  • Auto-select - when exactly one report qualifies, it is pre-selected and the user can print immediately without choosing.

  • Extensible - subclass base.print.wizard to add extra fields (print mode, date range, etc.) and override action_print() to pass context to the report.

Use Pattern 1 (direct binding) when you only need to choose among multiple reports. Use Pattern 2 (subclass) when the wizard itself needs extra options that influence how the report renders. See USAGE.md for step-by-step instructions.

Table of contents

Usage

Usage

Pattern 1 - Use wizard directly (no Python subclass)

Best for: multiple reports on one model, wizard just picks which to print.

Step 1: Mark reports with show_in_wizard = True (Technical menu → Reporting → Reports, or via XML data)

<record id="action_report_my_document" model="ir.actions.report">
    <field name="show_in_wizard" eval="True" />
    <!-- optional: only show when record matches this domain -->
    <field name="domain_form">[('state', '=', 'confirm')]</field>
</record>

Step 2: Bind a window action to the source model

<record id="action_open_my_print_wizard" model="ir.actions.act_window">
    <field name="name">Print Report</field>
    <field name="res_model">base.print.wizard</field>
    <field name="view_mode">form</field>
    <field name="view_id" ref="base_print_wizard.view_print_wizard_base" />
    <field name="binding_model_id" ref="my_module.model_my_document" />
    <field name="binding_view_types">list,form</field>
    <field name="binding_type">report</field>
    <field name="target">new</field>
</record>

The wizard lists all reports flagged show_in_wizard = True for that model. If domain_form is set, the report only appears when active records match the domain. When only one report qualifies, it is auto-selected and the user can click Print immediately.


Pattern 2 - Subclass for extra wizard fields

Best for: single fixed report with extra options (e.g. print mode, date range).

Step 1: Create a child TransientModel

from odoo import api, fields, models

class MyDocumentPrintWizard(models.TransientModel):
    _name = "my.document.print.wizard"
    _inherit = "base.print.wizard"
    _description = "My Document Print Wizard"

    print_mode = fields.Selection(
        selection=[("summary", "Summary"), ("detail", "Detail")],
        default="summary",
        required=True,
    )

    @api.model
    def _get_doctype_default(self):
        # Pin to a specific report - skip the dynamic selection logic
        return self.env.ref("my_module.action_report_my_document")

    def action_print(self):
        self.ensure_one()
        objs = self._get_action_report()
        return self.doctype.with_context(print_mode=self.print_mode).report_action(objs)

Step 2: Extend the base view to show the extra field

<record id="view_my_document_print_wizard_form" model="ir.ui.view">
    <field name="name">my.document.print.wizard.form</field>
    <field name="model">my.document.print.wizard</field>
    <field name="inherit_id" ref="base_print_wizard.view_print_wizard_base" />
    <field name="arch" type="xml">
        <!-- Replace doctype field with your custom field -->
        <field name="doctype" position="replace">
            <field name="doctype" invisible="1" />
            <field name="print_mode" widget="radio" />
        </field>
    </field>
</record>

Step 3: Bind the window action to the child wizard

<record id="action_my_document_print_wizard" model="ir.actions.act_window">
    <field name="name">Print Report</field>
    <field name="res_model">my.document.print.wizard</field>
    <field name="view_mode">form</field>
    <field name="view_id" ref="view_my_document_print_wizard_form" />
    <field name="binding_model_id" ref="my_module.model_my_document" />
    <field name="binding_view_types">list,form</field>
    <field name="binding_type">report</field>
    <field name="target">new</field>
</record>

Module dependency

Add base_print_wizard to your module’s depends list:

"depends": ["base_print_wizard"],

Override reference

Method

When to override

_get_doctype_default()

Fix a single default report instead of auto-select

_get_available_report_ids()

Custom report filtering logic

_get_action_report()

Change which records are passed to the report

action_print()

Pass extra context to report_action()

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits

Authors

  • Ecosoft

Contributors

Maintainers

Current maintainer:

Saran440

This module is part of the ecosoft-odoo/ecosoft-addons project on GitHub.

You are welcome to contribute.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file odoo_addon_base_print_wizard-18.0.1.0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for odoo_addon_base_print_wizard-18.0.1.0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 01ee87eaa6a3cbc86dbdc09db9dac0885fb163ea15cc10eb0433f8e1659688a2
MD5 675a9219ab97c70009ec6c5f75baaa86
BLAKE2b-256 887b4c794e5902db5425a995d064823c75e89df24c72774b096fdf45d59cbefa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page