How to create barcode image correctly using EAN

I have a function field with this code (trytond 7.0, python-barcode 0.15.1):

    from import barcode
except ImportError:
    barcode = None

def get_barcode_image(self, name=None):
        if not barcode or not self.code:

        image = barcode.generate_png('upc', self.code, width=2, height=80)
        return image

It generate the code but sometimes doesn’t display the code correctly.

For example, with this code 033123223010 I got this image

Also I’m not sure why but tryton was printing the code correctly

But for this 272082554843 it works fine

After reading the first code doesn’t fit the EAN standard, so, it converts to the fit the standard but doesn’t work for us because the provider gives us 12 digits code.

How to display the code correctly?


barcode recompute the checksum of UPC so it seems that your first UPC code is not valid.

Yes, barcode recompute the code, how to avoid it?

You can not. You must use valid code.

1 Like

Thanks, I tried and it works fine.
image = barcode.generate_png('code128', self.code, width=2, height=80)

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.