Odoo Help

Welcome!

This community 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.

0

The barcode is not displayed in Qweb report (Odoo)

By
Adnier Rosello
on 10/15/15, 4:34 PM 2,533 views

I have a Qweb report that should display a barcode, but what is shown is the blank where it should be the barcode, below the full code of the report, and the displayed error when the controller /report/barcode is called, any idea?


report definition:

<report
id="roll_label_report"
string="Product label"
model="mrp.production.product"
report_type="qweb-pdf"
file="mrp.product_label_document"
name="mrp.product_label_document" />

report template

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="product_label_document">
    <t t-call="report.html_container">
       <t t-foreach="docs" t-as="o">
         <t t-call="report.external_layout">
         <div class="page">
         <table style="width:50%;">
        <tbody>
        <tr><td colspan="2"><b>O/T:</b> <span t-field="o.production_id.name"/></td></tr>
        <tr><td colspan="2"><img t-att-src="'/report/barcode/Code128/%s' % 'test-0001'" style="width:100%;height:25px"/>          </td></tr>
         </tbody>
        </table>
        </div>
       </t>
    </t>
</t>
</template>
</data>
</openerp>

call report:
def get_label(self, cr, uid, ids, context=None):
    if ids:
       if not isinstance(ids, list):
           ids = [ids]
       context = dict(context or {}, active_ids=ids, active_model=self._name)
   return {
      'type': 'ir.actions.report.xml',
      'report_name': 'mrp.product_label_document',
      'context': context,
   }
404 error:
2015-10-15 20:09:16,239 24721 INFO None werkzeug: 127.0.0.1 - - [15/Oct/2015 20:09:16] "GET /report/barcode/Code128/test-0001 HTTP/1.1" 404 -

I tried http://localhost:8069/report/barcode/Code128/test-0001 and the barcode is returned without problem, I have another report which also shows one barcode and it works perfectly, but with this example I get a 404 Error, the unique difference is the way of calling the report, the report that show me the barcode is called from Print option at page header, and this report is called from method.

Adnier Rosello
on 10/17/15, 4:17 AM
2

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 10/15/15, 5:03 PM

To generate a barcode using that way you need to have installed reportlab dependency and the module 'report' that it's auto-installed when base and web modules are installed, check those prerequisites and if they are ok you could always test in the browser your barcode image using this url in your case:

http://localhost:8069/report/barcode/Code128/test-0001

that will return you the barcode image generated, If some other error shows in the logs post it here. If the barcode not get generated and the logs doesn't show anything, then you need to debug what happens at /openerp/addons/report/controllers/main.py on the report_barcode method.

===========================================================================================

I test it and debug it and seems that you cannot do that because the request to the controller came with no session_id and also no database to use and get dropped with a 404. Your alternative could be to directly generate the barcode image using the same code of the barcode controller but used from a report parser. Define a function in a parser like:

import base64
from openerp.report import report_sxw
from reportlab.graphics.barcode import createBarcodeDrawing

class barcode_report_parser(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(barcode_report_parser, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'barcode': self.barcode,
})
def barcode(self, type, value, width=600, height=100, humanreadable=0):
width, height, humanreadable = int(width), int(height), bool(humanreadable)
barcode_obj = createBarcodeDrawing(
type, value=value, format='png', width=width, height=height,
humanReadable = humanreadable
)
return base64.encodestring(barcode_obj.asString('png'))

In the report template define your image like this:

<img t-att-src="'data:image/png;base64,%s' % barcode('Code128','test-0001')" style="width:100%;height:25px"/>

check the answer update

Axel Mendoza
on 10/17/15, 4:17 AM

That's right, now the barcode shown in the report

Adnier Rosello
on 10/17/15, 5:11 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 10/15/15, 4:34 PM
Seen: 2533 times
Last updated: 10/17/15, 5:10 PM