From caf6cb929b852209e84fa23efd10f58651d18d8e Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Wed, 12 Jun 2019 15:39:49 +0000 Subject: [PATCH] [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) --- addons/web/controllers/main.py | 7 +++++-- odoo/addons/base/models/ir_actions_report.py | 9 +++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 0a178431f2a..befdc0a2c8b 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1784,7 +1784,7 @@ class ReportController(http.Controller): # Misc. route utils #------------------------------------------------------ @http.route(['/report/barcode', '/report/barcode//'], 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: @@ -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.') diff --git a/odoo/addons/base/models/ir_actions_report.py b/odoo/addons/base/models/ir_actions_report.py index 820d852e6b5..49a53270894 100644 --- a/odoo/addons/base/models/ir_actions_report.py +++ b/odoo/addons/base/models/ir_actions_report.py @@ -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'