Files
odoo_source/addons/report/models/ir_qweb.py
T
Christophe Matthieu 3407fb70e4 [IMP] qweb: add t-options on t-esc and t-raw who use 'ir.qweb.field' models
Remove 'field' from 'value_to_html' method attributes
't-esc' escape the result of the widget.
(Added 'remove_span' as option for monetary widget)

E.g.: <t t-esc="32" t-options='t-options='{"widget": "monetary", "display_currency": website.currency_id, "remove_span": True}'>
result: $ 365.00
2016-07-05 18:43:09 +02:00

26 lines
984 B
Python

from reportlab.graphics.barcode import createBarcodeDrawing
from openerp.osv import osv
from openerp.addons.base.ir.ir_qweb import unicodifier
class BarcodeConverter(osv.AbstractModel):
""" ``barcode`` widget rendering, inserts a data:uri-using image tag in the
document. May be overridden by e.g. the website module to generate links
instead.
"""
_name = 'ir.qweb.field.barcode'
_inherit = 'ir.qweb.field'
def value_to_html(self, cr, uid, value, options, context=None):
options = options or {}
barcode_type = options.get('type', 'Code128')
barcode = self.pool['report'].barcode(
barcode_type,
value,
**dict((key, value) for key, value in options.items() if key in ['width', 'height', 'humanreadable']))
return unicodifier('<img src="data:%s;base64,%s">' % ('png', barcode.encode('base64')))
def from_html(self, cr, uid, model, field, element, context=None):
return None