Skip to Content
Menu
This question has been flagged
1 Reply
4628 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**


Avatar
Discard
Best Answer
The problem is that the document has a different commercial than the person who is logged in, check if the commercial field is different from your login, it must be the same or at least be empty
Avatar
Discard
Related Posts Replies Views Activity
7
Apr 23
26600
2
Feb 16
8250
1
Jan 24
422
1
Jun 23
2188
1
Apr 22
8013