Can anyone follow these steps to check if they experience the same?
In Odoo version 12 (I have not checked yet if this happens in other versions), modify any product, write for example 9700000175781 in the barcode field and save.
Print the product report label with the barcode.
Read the printed label with a barcode reader or any barcode reader simulator.
Well, I have tried with a real barcode reader and several simulators. I asked to my colleague workers to try the same at their home.
We all get 9700000175784. And it happens the same with the barcodes 9700000175782, 9700000175783...
However, other barcodes work OK. For example, 9700000175784 is rightly printed and read.
This is the Qweb line which calls the controller:
<img alt="Barcode" t-if="len(product.barcode) == 13" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('EAN13', quote_plus(product.barcode or ''), 600, 150)" style="width:100%;height:4rem;"/>
The controller calls the method barcode
of the ir.actions.report
model:
@http.route(['/report/barcode', '/report/barcode/<type>/<path:value>'], type='http', auth="public")
def report_barcode(self, type, value, width=600, height=100, humanreadable=0):
"""Contoller able to render barcode images thanks to reportlab.
Samples:
<img t-att-src="'/report/barcode/QR/%s' % o.name"/>
<img t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' %
('QR', o.name, 200, 200)"/>
:param type: Accepted types: 'Codabar', 'Code11', 'Code128', 'EAN13', 'EAN8', 'Extended39',
'Extended93', 'FIM', 'I2of5', 'MSI', 'POSTNET', 'QR', 'Standard39', 'Standard93',
'UPCA', 'USPS_4State'
:param humanreadable: Accepted values: 0 (default) or 1. 1 will insert the readable value
at the bottom of the output image
"""
try:
barcode = request.env['ir.actions.report'].barcode(type, value, width=width, height=height, humanreadable=humanreadable)
except (ValueError, AttributeError):
raise werkzeug.exceptions.HTTPException(description='Cannot convert into barcode.')
return request.make_response(barcode, headers=[('Content-Type', 'image/png')])
And the barcode
method uses reportlab library to draw the barcode:
from reportlab.graphics.barcode import createBarcodeDrawing
...
@api.model
def barcode(self, barcode_type='EAN13', value=quote_plus(product.barcode or ''), width=600, height=150, humanreadable=0):
if barcode_type == 'UPCA' and len(value) in (11, 12, 13):
barcode_type = 'EAN13'
if len(value) in (11, 12):
value = '0%s' % value
try:
width, height, humanreadable = int(width), int(height), bool(int(humanreadable))
barcode = createBarcodeDrawing(
barcode_type, value=value, format='png', width=width, height=height,
humanReadable=humanreadable
)
return barcode.asString('png')
except (ValueError, AttributeError):
if barcode_type == 'Code128':
raise ValueError("Cannot convert into barcode.")
else:
return self.barcode('Code128', value, width=width, height=height, humanreadable=humanreadable)
My conclusion
Since the parameters arrive OK to the line which uses reportlab, I think the problem is with the library reportlab. Does anyone experience the same and know what could be happening? It is really weird that this has not reported yet to Odoo or reportlab. Is there a problem with the version?
I have tried with 3.4.0 and the latest by now, 3.5.42.
Solved. No programming problems...
The EAN13 9700000175781 is wrong. The 13rd digit, named the control digit, must fulfill some operations depending on the rest of the numbers. And in this case, the first twelve digits, 970000017578 generate the control digit 4, not 1.
The library reportlab
just ignores the control digit you have sent for being drawn and prints the right one, so in this case, and the other ones (9700000175782, 9700000175783, etc), the control digit is replaced by 4.