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

How to create barcodes in webkit reports?

By
Yannick Vaucher
on 4/11/13, 6:29 AM 7,017 views

How to create EAN13 and code39 barcode in a custom webkit report?

5

Yannick Vaucher

--Yannick Vaucher--
1699
| 5 7 9
Lausanne, Switzerland
--Yannick Vaucher--
Yannick Vaucher
On 4/11/13, 6:47 AM

As my previous answer was very limited here is an better one

Installing barcode on document

Requirements: Julius modules needs rsvg-convert install it:

apt-get install librsvg2-bin

One way is to install the julius modules accessible in lp:stock-logistic-barcode.

Let's say we want a barcode on our sale_order_webkit report

Install the module tr_barcode_on_sale_order

Then go on openerp and apply the install of the field x_barcode_id. In menu Settings -> Configuration -> Barcode Click on Apply

Adding a barcode in a report

Now your field generating barcode is ready on your document

To use it in you mako template:

${helper.embed_image('png', order.x_barcode_id.image)}

(where order is your sale_order browse record.)



Older version, simpler but very limited:

You can simply use a barcode font like http://www.barcodesinc.com/free-barcode-font/

First, install it on your server:

  • Place the fonts in the following folder: /usr/share/fonts
  • Run: fc-cache -fv

Now, we need to add a style in your CSS of the report or of the header.

Something like:

.barcode39 {
    font-family: "Free 3 of 9";
    font-size: 36pt;
}

And finnally use it like this:

<p class="barcode39">*${object.ref}*</p>

Note: you will need the * character to tell the scanner where to start and end reading the code.

Hi Yannick, I can't find the librsvg2-bin for windows easy_install don't recognize it and I didn't find an installer neither... Any tip for windows users??

Skillteam, Houssine BAKKALI
on 5/17/13, 1:22 PM

ok i've just solved the depency problem. Avoiding using the svg to png convertion... by generating direclty the barcode to the png format.

Skillteam, Houssine BAKKALI
on 5/17/13, 3:08 PM

The link doesn't seem to have a tr_barcode_on_sale_order module. Am i missing something or did it disappear?

Nicholas Linn
on 9/19/13, 3:48 PM
2

Here's a slightly different approach, this should work for any barcode types which couldn't be generated using barcode fonts, including 2D barcode PDF417, QR Code, etc

<%
import commands
commands.getoutput('barcode -b ' + l.product_id.default_code + ' -o /tmp/barcode.ps -e ean13 -g 450x200 -u mm')
commands.getoutput('ps2png /tmp/barcode.ps /tmp/barcode.png')
data_uri = open("/tmp/barcode.png", "rb").read().encode("base64")
%>
${helper.embed_image('png',data_uri,0,32)|n}

This involves 2 external command which should be installed on your server (I'm using Linux Ubuntu Server):

  1. barcode -> generates binary postcript file
  2. ps2png -> converts PS file to PNG

Thanks for your answer, I came up with another solution, which shouldn't be plateform specific. I updated my answer.

Camptocamp SA
on 4/25/13, 1:54 PM

You are welcome, thanks for your idea too Yannick. Will try that someday.

Yohanes Iwan Sugiarto
on 4/25/13, 3:57 PM

Forget about the not plateform specific, it needs librsvg2-bin package as it uses rsvg-convert

Camptocamp SA
on 4/26/13, 12:52 PM
2
Vince Vinet
On 11/7/14, 5:45 PM

You can now use the report_webkit_barcode module, available in OCA at:

https://github.com/OCA/webkit-tools/tree/7.0/report_webkit_barcode

This allows you to use ${helper.barcode(value) | u} in a webkit template to get a barcode. It supports all the barcodes supported by the RML reports.

 

How can we apply the 'value'? ${helper.barcode(1234) | u}, is this code valid?

Abhishek H Menon
on 11/25/14, 5:48 AM

Yes, you can put ${helper.barcode(1234) | u} if that's the value you want. Depending on the barcode type, the value can be an integer, string or numeric string. It can also come from your objects (${helper.barcode(object.id) | u}).

Savoir-Faire Linux, Vince Vinet
on 11/25/14, 8:26 AM

if I use the module, the gererated barcode is not scanable. The generated Image has some grey elements.

do you have an idea how to fix it?

Christian Werner
on 11/7/16, 6:16 AM

Most likely if you cannot scan the images, it is because your barcode images were stretched from a small size. To fix this, you should pass in the appropriate width/height options.

Savoir-Faire Linux, Vince Vinet
on 11/8/16, 8:09 AM
1
Houssine BAKKALI
On 5/17/13, 3:10 PM

In the getImage function of the tr_barcode class replace the following code by this following.

if code not in ['QR','qrcode']:
        try:
            ret_val = createBarcodeDrawing(code, value=str(value), **options)
        except Exception, e:
            raise osv.except_osv('Error', e)
        ret_val.save(formats=['png'], fnRoot='barcode', outDir='/tmp/')
        return base64.encodestring(open("/tmp/barcode.png","rb").read())

Nice, could you create a patch to send to julius ? If we can avoid a useless conversion forcing us to install another dependency and furthermore executing shell command I think it would be better.

Camptocamp SA
on 5/21/13, 7:57 AM

Ok I will see how to do it

Skillteam, Houssine BAKKALI
on 5/21/13, 2:25 PM

as far as I see the tr_barcode module is from Tech-Receptives Solutions and not Julius, which developped modules with a dependency on tr_barcode

Skillteam, Houssine BAKKALI
on 5/22/13, 8:06 AM

Hi Yannick, I'm not used with making merge or patch proposale. Have you some tips or guidelines for this? thanks

Skillteam, Houssine BAKKALI
on 5/22/13, 8:11 AM

The branch you want to modify is lp:stock-logistic-barcode

You need to push your branch on launchpad with the commited changes: (to commit changes bzr ci -m [my message])

bzr push lp:~[username or group]/[project_name]/[whatever_you_want]

So in you case something like

bzr push lp:~houssine/stock-logistic-barcode/replace-svg-conversion

Then you go on launchpad on your registered branches. You will see your branch and in it a link Propose for merging. Just select the right branch and there you have your MP.

Camptocamp SA
on 5/23/13, 8:07 AM

thanks for you help!

I made a bug report yesterday and attached a patch file to it. Hoping it will be enough to be taken into account. Otherwise I'll do a merge proposal.

Skillteam, Houssine BAKKALI
on 5/23/13, 9:00 AM

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

4 follower(s)

Stats

Asked: 4/11/13, 6:29 AM
Seen: 7017 times
Last updated: 3/16/15, 8:10 AM