Metadata-Version: 2.1
Name: odoo-addon-base_print_wizard
Version: 18.0.1.1.0
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:3bced2c086783f7b20d181c8f4e1b1928a4602b6d9809cb1c00ea57a8e7cf1dd
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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 every selected record matches the domain (e.g. only
  confirmed orders).
- **Access-aware and validated** - reports respect their configured
  groups, and the selected report is validated again on the server
  before printing.
- **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 ``_get_report_context()``
  to pass context to the report.
- **Optional copy options** - inherit ``base.print.copy.mixin`` when a
  specialized wizard needs copy quantity and Original/Copy type fields.

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. The copy mixin is
optional and does not add fields to the base wizard. 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
=====

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 every selected 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 every
active record matches the domain. Reports restricted to groups are only
shown to users in one of those groups. 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).

The fixed report must still have ``show_in_wizard = True``, use the same
model as the active records, and satisfy its ``domain_form`` when one is
configured.

**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 the default selection. The report must still be available for the records.
           return self.env.ref("my_module.action_report_my_document")

       def _get_report_context(self):
           res = super()._get_report_context()
           res["print_mode"] = self.print_mode
           return res

**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="mode">primary</field>
       <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"],

--------------

Optional copy options
---------------------

Add the copy fields only to wizards that need them by inheriting the
optional mixin:

.. code:: python

   from odoo import models


   class MyDocumentPrintWizard(models.TransientModel):
       _name = "my.document.print.wizard"
       _inherit = ["base.print.wizard", "base.print.copy.mixin"]

       def _get_report_context(self):
           res = super()._get_report_context()
           res.update(self._get_copy_report_context())
           return res

Add ``copy_qty`` and ``copy_type`` to the specialized wizard view. The
mixin validates that the copy quantity is greater than zero, but does
not add fields to the base wizard view.

.. 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="mode">primary</field>
       <field name="arch" type="xml">
           <xpath expr="//group[@name='criteria']/group[last()]" position="inside">
               <field name="copy_qty" />
               <field name="copy_type" />
           </xpath>
       </field>
   </record>

Validation behavior
-------------------

- A report must have ``show_in_wizard = True`` and its ``model`` must
  match the active model.
- Every selected record must match ``domain_form``; mixed selections do
  not expose a partially applicable report.
- Reports restricted with ``groups_id`` are only available to members of
  those groups.
- ``domain_form`` syntax is validated when the report action is saved.
- The selected report is validated again by ``action_print()`` to
  prevent bypassing the form-view domain through RPC or custom code.

--------------

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                         |
+---------------------------------+------------------------------------+
| ``_get_report_context()``       | Pass extra context to              |
|                                 | ``report_action()``                |
+---------------------------------+------------------------------------+
| ``_validate_report()``          | Add server-side report validation  |
|                                 | rules                              |
+---------------------------------+------------------------------------+

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.
