Execute a report from a wizard?

I want to make a wizard “return” a report. How can I achieve this?

The idea is to use the wizard to ask parameters of what to be reported and on transition (or however) create the report and make the GUI client and SAO “display” it. (“display” depending on the file-type/extension like any other report.)

Hi Harmut,

I recently did such wizard to print a label for a package with some custom fields.
Here’s my code. Hope this helps.

class ShippingPalletLabelReport(Report):
    'Shipping Pallet Label Report'
    __name__ = 'shipping.pallet.label.report'

    def get_context(cls, records, header, data):
        pool = Pool()
        Date = pool.get('ir.date')
        context = super().get_context(records, header, data)
        context['today'] = Date.today()
        return context

class PrintShippingPalletLabelAskDetails(ModelView):
    'Print Shipping Pallet Label Ask Details'
    __name__ = 'shipping.pallet.label.ask_details'

    shipment_number = fields.Char("Shipment Number", readonly=True,
        help="The main identifier for the shipment.")
    marking = fields.Text("Marking", readonly=True)
    package = fields.Many2One('stock.package', "Package", required=True,
        domain=[('id', 'in', Eval('shipment_packages'))],
        help="The package to print.")
    primary_package_number = fields.Function(
        fields.Char("Primary Package Number"),
    box_quantity = fields.Function(
        fields.Integer("Box Quantity"), 'on_change_with_box_quantity')
    primary_package_id = fields.Integer("Primary Package Id", required=True)
    primary_packages_quantity = fields.Integer("Primary Packages Quantity")
    display_logo = fields.Boolean("Display Logo")
    shipping_date = fields.Date("Shipping Date")
    shipment_packages = fields.Many2Many(
        'stock.package', None, None, "Shipment Packages")

    def on_change_with_primary_package_number(self, name=None):
        if self.package and self.package.number:
            return self.package.number

    def on_change_with_box_quantity(self, name=None):
        if self.package and self.package.box_quantity:
            return self.package.box_quantity

    def default_primary_package_id(cls):
        return 1

    def default_display_logo(cls):
        return True

    def set_primary_packages_quantity(cls):

class PrintShippingPalletLabel(Wizard):
    'Print Shipping Pallet Label'
    __name__ = 'shipping.pallet.label.print'

    start = StateTransition()
    show = StateView(
        'stock_shipping_pallet_label_print_ask_details', [
            Button("Cancel", 'end', 'tryton-cancel'),
            Button("Print Label", 'print_label', 'tryton-ok', default=True),
    print_label = StateReport('shipping.pallet.label.report')

    def transition_start(self):
        if self.record.packages:
            return 'show'
        return 'end'

    def default_show(self, fields):
        Date = Pool().get('ir.date')
        packages = self.record.packages
        shipping_date = (self.record.effective_date
            if self.record.effective_date else Date.today())
        package_ids = [p.id for p in packages]
        return {
            'package': package_ids[0] if len(package_ids) == 1 else None,
            'shipment_number': self.record.number,
            'marking': self.record.reference,    # en attendant marking
            'primary_packages_quantity': len(packages),
            'shipment_packages': package_ids,
            'shipping_date': shipping_date,

    def do_print_label(self, action):
        pool = Pool()
        StockPackage = pool.get('stock.package')
        data = {
            'ids': [self.show.package.id],
            'model': StockPackage.__name__,
            'display_logo': self.show.display_logo,
            'shipping_date': self.show.shipping_date,
            'primary_package_id': self.show.primary_package_id,
            'primary_packages_quantity': self.show.primary_packages_quantity,
            'box_quantity': self.show.box_quantity,
        return action, data
1 Like