Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
11672 มุมมอง

I want output a Code128 barcode without margins on a odoo8 qweb report.

Barcodes generated with http://127.0.0.1:8069/report/barcode/?type=Code128&value=10123&width=600&height=100

have a oversized white left and right marigin, together ca. 40% of the image.

 

 

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

/report/barcode/?type=%s&value=%s&quiet=0' % ('Code128', 'text')

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

I presume this is the default report you're using?
You could always write your own report or modify the existing one.

Code for default barcode:

<img t-att-src="'/report/barcode/QR/%s' % 'My text in qr code'"/>

Code for custom barcode:

<img t-att-src="'/report/barcode/? type=%s&value=%s&width=%s&height=%s'%('QR', 'text', 200, 200)"/>

With the custom version you can set extra parameters which sounds exactly like what you need. 
You can find more details about Odoo barcodes and reports here: https://github.com/odoo/odoodays-2014/blob/master/v8_reporting_engine/index.rst

Note: I haven't tested the white borders myself, but I'm pretty sure this'll help you a good way along.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You can do it by adding the following code to your py and xml

In report.py

from reportlab.graphics.barcode import createBarcodeDrawing

    def barcode(self, type, value, width=400, 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,quiet=False)
        return base64.encodestring(barcode_obj.asString('png'))

In XML

<img  t-att-src="'data:image/png;base64,%s' % barcode('Code128',o.name)"/>

Note:

Check whether you have installed report lab


Regards,

Leelapriskila

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

This is quite old but I have found a different solution.

Odoo uses a library to generate code128 images, and this library has an option to avoid this big white margins to the left and right of barcode. You are right, it uses about 30-40% of all space and when there is no much space, it's a problem.

The option is called "quiet" and by default it's values is "1". You can set it as "0" but not in Odoo, because it's not prepared to pass such parameter to librery.

 The only way I see is to edit code128.py file of library. You can find it in reportlab/graphics/barcode.

Or to inherit and modify the way Odoo calls this library.


Of course Herbert, If you found a different solution, I will appreciate to know about it.

Regards.

อวตาร
ละทิ้ง

/report/barcode/?type=%s&amp;value=%s&amp;quiet=0' % ('Code128', o.delivery_reference_id)

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ค. 19
6688
Odoo11 Custom Report แก้ไขแล้ว
1
ก.ย. 18
7639
1
พ.ค. 16
6698
1
มี.ค. 16
4445
1
เม.ย. 25
1090