[FIX] base: barcode qweb field correct API

Before this commit, the barcode Qweb Field had a
option called "type", which meant what is the mapping between
numbers and barcode, that mapping is called a symbology
https://www.barcoding.com/resources/barcoding-basics/barcode-symbologies/

This option "type" collided with what the qweb engine does
at
```
qweb > _compile_directive_field
that calls
ir_qweb > _get_field
```
It resulted in a crash where type = "barcode" was not a valid symbology
to pass to the barcode lib

It is safe to say that this barcode widget was never user, otherwise it would have crashed

This commit changes that non-functioning API, and the barcode renders well

OPW 2066870

forward-port of #36499 (330d862513dba5bbc4716fe9c8694fd0db696934)
closes odoo/odoo#36499

closes odoo/odoo#36658

Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
Lucas Perais (lpe)
2019-09-11 08:05:34 +00:00
parent 5032fc16b4
commit 6ebbea1681
2 changed files with 9 additions and 3 deletions
+6
View File
@@ -6938,6 +6938,12 @@ msgstr ""
#. module: base
#: code:addons/base/models/ir_qweb_fields.py:610
#, python-format
msgid "Barcode symbology"
msgstr ""
#. module: base
#: code:addons/base/models/ir_qweb_fields.py:603
#, python-format
msgid "Barcode type"
msgstr ""
+3 -3
View File
@@ -607,7 +607,7 @@ class BarcodeConverter(models.AbstractModel):
def get_available_options(self):
options = super(BarcodeConverter, self).get_available_options()
options.update(
type=dict(type='string', string=_('Barcode type'), description=_('Barcode type, eg: UPCA, EAN13, Code128'), default_value='Code128'),
symbology=dict(type='string', string=_('Barcode symbology'), description=_('Barcode type, eg: UPCA, EAN13, Code128'), default_value='Code128'),
width=dict(type='integer', string=_('Width'), default_value=600),
height=dict(type='integer', string=_('Height'), default_value=100),
humanreadable=dict(type='integer', string=_('Human Readable'), default_value=0),
@@ -616,9 +616,9 @@ class BarcodeConverter(models.AbstractModel):
@api.model
def value_to_html(self, value, options=None):
barcode_type = options.get('type', 'Code128')
barcode_symbology = options.get('symbology', 'Code128')
barcode = self.env['ir.actions.report'].barcode(
barcode_type,
barcode_symbology,
value,
**{key: value for key, value in options.items() if key in ['width', 'height', 'humanreadable']})
return u'<img src="data:png;base64,%s">' % base64.b64encode(barcode).decode('ascii')