[IMP] base, web: barcode drawer remove margins

The purpose of quiet parameter is to return a barcode image
without left and right margins.
It could be usefull on report where the barcode size should be
minize or align to another element.

closes odoo/odoo#29209

Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
Arnold Moyaux
2019-07-31 08:04:38 +00:00
committed by William Henrotin
parent bdb61d2c2f
commit caf6cb929b
2 changed files with 10 additions and 6 deletions
+5 -2
View File
@@ -1784,7 +1784,7 @@ class ReportController(http.Controller):
# Misc. route utils
#------------------------------------------------------
@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):
def report_barcode(self, type, value, width=600, height=100, humanreadable=0, quiet=1):
"""Contoller able to render barcode images thanks to reportlab.
Samples:
<img t-att-src="'/report/barcode/QR/%s' % o.name"/>
@@ -1796,9 +1796,12 @@ class ReportController(http.Controller):
'UPCA', 'USPS_4State'
:param humanreadable: Accepted values: 0 (default) or 1. 1 will insert the readable value
at the bottom of the output image
:param quiet: Accepted values: 0 (default) or 1. 1 will display white
margins on left and right.
"""
try:
barcode = request.env['ir.actions.report'].barcode(type, value, width=width, height=height, humanreadable=humanreadable)
barcode = request.env['ir.actions.report'].barcode(type, value, width=width,
height=height, humanreadable=humanreadable, quiet=quiet)
except (ValueError, AttributeError):
raise werkzeug.exceptions.HTTPException(description='Cannot convert into barcode.')
+5 -4
View File
@@ -490,23 +490,24 @@ class IrActionsReport(models.Model):
return report_obj.with_context(context).search(conditions, limit=1)
@api.model
def barcode(self, barcode_type, value, width=600, height=100, humanreadable=0):
def barcode(self, barcode_type, value, width=600, height=100, humanreadable=0, quiet=1):
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))
width, height, humanreadable, quiet = int(width), int(height), bool(int(humanreadable)), bool(int(quiet))
barcode = createBarcodeDrawing(
barcode_type, value=value, format='png', width=width, height=height,
humanReadable=humanreadable
humanReadable=humanreadable, quiet=quiet
)
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)
return self.barcode('Code128', value, width=width, height=height,
humanreadable=humanreadable, quiet=quiet)
def render_template(self, template, values=None):
"""Allow to render a QWeb template python-side. This function returns the 'ir.ui.view'