This question has been flagged
3 Replies
18138 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 -
Avatar
Discard

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.

Best Answer

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"/>
Avatar
Discard

check the answer update

Author

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

Best Answer

best answer helpful
i have upgrade reportlab libs
>> python3 -m pip install --upgrade reportlab
work fine

Avatar
Discard

For me, an extra step was that the solution was only applied after rebooting the entire server system.

Hope it helps!

I used: pip3 install reportlab --upgrade

Best Answer

where can I find the module report?

is it OCa module?

Avatar
Discard

the report module has been integrated with the web module