Odoo Help

0

Problem with wizard qweb report and base_report_to_printer

By
Gabriel Caceres Cabriza
on 5/3/18, 11:54 PM 203 views

Hello,
We are currently using the base_report_to_printer module and  its just almost perfect for the needs of our customers. We have one problem printing a qweb wizard based report. If the report its configured with the "Send to client" behaviour it works fine, but, when we try to sent to printer, it give us the following error:
```

  File "/home/gcc/PycharmProjects/gigigogo/addons/base_report_to_printer/models/ir_actions_report.py", line 106, in print_document
    record_ids, data=data)
  File "/home/gcc/PycharmProjects/gigigogo/addons/base_report_to_printer/models/ir_actions_report.py", line 139, in render_qweb_pdf
    docids, data=data)
  File "/home/gcc/PycharmProjects/gigigogo/addons/base/ir/ir_actions_report.py", line 596, in render_qweb_pdf
    Model = self.env[self.model]
  File "/home/gcc/odoo/odoo11/odoo/api.py", line 760, in __getitem__
    return self.registry[model_name]._browse((), self)
  File "/home/gcc/odoo/odoo11/odoo/modules/registry.py", line 181, in __getitem__
    return self.models[model_name]
KeyError: False
```

All the reports are sending fine to the printer, except for this one.

**Wizard python code:**
```python

# -*- coding: utf-8 -*-
from odoo import fields, models, exceptions, api
from datetime import datetime, timedelta
from lxml import etree
from odoo.exceptions import ValidationError

class BarcodeWizard(models.Model):
    _name='barcode.wizard'

    product_id = fields.Many2one('product.template','Producto',required=True)
    copias = fields.Integer(string="Cantidad de copias",default=1,required=True)
    name=fields.Char(related="product_id.name")
    # product_name = fields.Char(related="product_id.name")
    # product_barcode = fields.Char(related="product_id.barcode")


    @api.multi
    def imprimir_reporte(self):
        if self.product_id.barcode:

            return self.env.ref('gigigogo.report_product_etiqueta_wizard_action').report_action(self)
        else:
            raise ValidationError('Favor registrar código de barras del producto')
```
**Xml wizard code:**


```xml
<odoo>
    <data>
        <record id="barcode_wizard_report_view" model="ir.ui.view">
            <field name="name">barcode.wizard</field>
            <field name="model">barcode.wizard</field>
            <field name="arch" type="xml">
               <form>
                   <group>
                       <field name="product_id"/>
                       <field name="copias"/>
                   </group>
                   <footer>
                       <button name="imprimir_reporte" string="Imprimir etiquetas" type="object" class="oe_highlight"/>
                       <button string="Cancelar" class="oe_link" special="cancel"/>
                   </footer>
               </form>
            </field>
        </record>


        <act_window
            name="Imprimir etiquetas"
            res_model="barcode.wizard"
            src_model="product.template"
            view_mode="form"
            target="new"
            context="{'default_product_id':active_id}"
            key2="client_action_multi"
            id="action_imprimir_etiquetas"/>



    </data>
</odoo>
```
**Barcode wizard report xml**

```xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <report
            id="report_product_etiqueta_wizard_action"
            string="Etiqueta"
            model="barcode.wizard"
            report_type="qweb-pdf"
            name="gigigogo.product_etiqueta_report_wizard"
            file="gigigogo.product_etiqueta_report_wizard"
            print_report_name="'Etiqueta - %s' % (object.name)"
            paperformat="gigigogo.paperformat_etiqueta"

        />
    </data>

    <template id="report_simple_etiqueta_wizard">
    <div class="col-xs-6" style="padding:0;" >
        <table style="border-spacing:0;margin-bottom:0;margin-top:10px;height:110px;" class="table">
            <thead>
                <tr style="width: 3in;">
                    <td style="border: 2px solid black;width: 2.63in;" colspan="2" class="col-xs-8 danger">
                        <t t-if="product.product_id.default_code">
                            [<strong t-field="product.product_id.default_code"/>]
                        </t>
                        <strong t-field="product.product_id.name"/>
                    </td>
                </tr>
            </thead>
            <tbody>
                <tr style="width: 1in;">
                    <td style="border: 2px solid black;text-align: center; vertical-align: middle;" class="col-xs-5">
                        <img t-if="product.product_id.barcode" t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', product.product_id.barcode, 600, 150)" style="width:100%;height:20%;"/>
                        <span t-field="product.product_id.barcode"/>
                    </td>
                    <td style="border: 2px solid black; text-align: center;" class="col-xs-7">
                        <h4>
                            <strong t-field="product.product_id.company_id.currency_id.symbol"/>
                            <strong t-field="product.product_id.list_price"/>
                        </h4>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="col-xs-6" style="padding:0;">
        <table style="border-spacing:0;margin-bottom:0;margin-top:10px;height:110px;" class="table">
            <thead>
                <tr style="width: 3in;">
                    <td style="border: 2px solid black;width: 2.63in;" colspan="2" class="col-xs-8 danger">
                        <t t-if="product.product_id.default_code">
                            [<strong t-field="product.product_id.default_code"/>]
                        </t>
                        <strong t-field="product.product_id.name"/>
                    </td>
                </tr>
            </thead>
            <tbody>
                <tr style="width: 1in;">
                    <td style="border: 2px solid black;text-align: center; vertical-align: middle;" class="col-xs-5">
                        <img t-if="product.product_id.barcode" t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', product.product_id.barcode, 600, 150)" style="width:100%;height:20%;"/>
                        <span t-field="product.product_id.barcode"/>
                    </td>
                    <td style="border: 2px solid black; text-align: center;" class="col-xs-7">
                        <h4>
                            <strong t-field="product.product_id.company_id.currency_id.symbol"/>
                            <strong t-field="product.product_id.list_price"/>
                        </h4>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div>
        <p style="page-break-after: always;"/>
    </div>

</template>

<template id="product_etiqueta_report_wizard">
    <t t-call="web.basic_layout">
        <div class="page">
            <t t-foreach="docs" t-as="product">
                <t t-foreach="range(product.copias)" t-as="n">
                    <t t-call="gigigogo.report_simple_etiqueta_wizard">
                        <t t-set="product" t-value="product"/>
                    </t>
                </t>
            </t>
        </div>
    </t>
</template>


</odoo>
```
Any solution for the problem? The problem its only with wizards. If we use the report outside the wizard it works perfect.

Thanks in advance.

Best regards.

**Gabriel Cáceres Cabriza**


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 5/3/18, 11:54 PM
Seen: 203 times
Last updated: 5/4/18, 12:15 AM