Metadata-Version: 2.1
Name: odoo-addon-base_print_wizard
Version: 18.0.1.0.0.2
Requires-Python: >=3.10
Requires-Dist: odoo==18.0.*
Summary: Add wizard when use print action
Home-page: https://github.com/ecosoft-odoo/ecosoft-addons
License: AGPL-3
Author: Ecosoft, Odoo Community Association (OCA)
Author-email: support@odoo-community.org
Classifier: Programming Language :: Python
Classifier: Framework :: Odoo
Classifier: Framework :: Odoo :: 18.0
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Classifier: Development Status :: 3 - Alpha
Description-Content-Type: text/x-rst

.. image:: https://odoo-community.org/readme-banner-image
   :target: https://odoo-community.org/get-involved?utm_source=readme
   :alt: Odoo Community Association

=================
Base Print Wizard
=================

.. 
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! This file is generated by oca-gen-addon-readme !!
   !! changes will be overwritten.                   !!
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! source digest: sha256:88883aae54d28af4af45593590619345315dbc9fd20e362653e0faeaf4124233
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
    :target: https://odoo-community.org/page/development-status
    :alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
    :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
    :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-ecosoft--odoo%2Fecosoft--addons-lightgray.png?logo=github
    :target: https://github.com/ecosoft-odoo/ecosoft-addons/tree/18.0/base_print_wizard
    :alt: ecosoft-odoo/ecosoft-addons

|badge1| |badge2| |badge3|

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.

.. IMPORTANT::
   This is an alpha version, the data model and design can change at any time without warning.
   Only for development or testing purpose, do not use in production.
   `More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
   :local:

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)*

.. code:: xml

   <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

.. code:: xml

   <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

.. code:: python

   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

.. code:: xml

   <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

.. code:: xml

   <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:

.. code:: python

   "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 <https://github.com/ecosoft-odoo/ecosoft-addons/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 <https://github.com/ecosoft-odoo/ecosoft-addons/issues/new?body=module:%20base_print_wizard%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Ecosoft

Contributors
------------

- Saran Lim. <saranl@ecosoft.co.th>

Maintainers
-----------

.. |maintainer-Saran440| image:: https://github.com/Saran440.png?size=40px
    :target: https://github.com/Saran440
    :alt: Saran440

Current maintainer:

|maintainer-Saran440| 

This module is part of the `ecosoft-odoo/ecosoft-addons <https://github.com/ecosoft-odoo/ecosoft-addons/tree/18.0/base_print_wizard>`_ project on GitHub.

You are welcome to contribute.
