From 751fe5282c4451c5d74a86112de2aeb60af47d57 Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Wed, 20 Mar 2024 14:40:47 +0100 Subject: [PATCH] [FIX] stock: fix zpl label for product without barcode Current behavior: When printing a ZPL label for a product without barcode, the label was printed with a barcode containing the "False" value Steps to reproduce: - Install the stock module - Create a product without barcode - Print a ZPL label for this product - The label contains a barcode with the "False" value (You can check the rendering on labelary.com) opw-3797462 closes odoo/odoo#158939 X-original-commit: e392027afa245a708a906b484250ed46200e13be Signed-off-by: Quentin Wolfs (quwo) Signed-off-by: Robin Engels (roen) --- addons/stock/report/product_label_report.py | 2 +- addons/stock/tests/test_report.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/stock/report/product_label_report.py b/addons/stock/report/product_label_report.py index 42c42449b15..9847bb6c8b1 100644 --- a/addons/stock/report/product_label_report.py +++ b/addons/stock/report/product_label_report.py @@ -25,7 +25,7 @@ class ReportProductLabel(models.AbstractModel): product = Product.browse(int(p)) default_code_markup = markupsafe.Markup(product.default_code) if product.default_code else '' product_info = { - 'barcode': markupsafe.Markup(product.barcode), + 'barcode': markupsafe.Markup(product.barcode) if product.barcode else '', 'quantity': q, 'display_name_markup': markupsafe.Markup(product.display_name), 'default_code': (default_code_markup[:15], default_code_markup[15:30]) diff --git a/addons/stock/tests/test_report.py b/addons/stock/tests/test_report.py index 415d5bf4203..a9d63eae01a 100644 --- a/addons/stock/tests/test_report.py +++ b/addons/stock/tests/test_report.py @@ -96,6 +96,16 @@ class TestReports(TestReportsCommon): self.assertEqual(target, rendering.replace(b' ', b''), 'The rendering is not good, make sure quotes are correctly escaped') self.assertEqual(qweb_type, 'text', 'the report type is not good') + def test_reports_product_no_barcode(self): + """ Test that product without barcode is correctly rendered without a barcode. + """ + report = self.env.ref('stock.label_product_product') + self.product1.barcode = False + target = b'\n\n^XA^CI28\n^FT100,80^A0N,40,30^FD[C4181234""154654654654]Mellohi"^FS\n^FT100,115^A0N,30,24^FDC4181234""15465^FS\n^FT100,150^A0N,30,24^FD4654654^FS\n^XZ\n' + rendering, qweb_type = report._render_qweb_text('stock.label_product_product', self.product1.product_tmpl_id.id, {'quantity_by_product': {self.product1.product_tmpl_id.id: 1}, 'active_model': 'product.template'}) + self.assertEqual(target, rendering.replace(b' ', b''), 'Product name, default code or barcode is not correctly rendered, make sure the quotes are escaped correctly') + self.assertEqual(qweb_type, 'text', 'the report type is not good') + def test_report_quantity_1(self): product_form = Form(self.env['product.product']) product_form.detailed_type = 'product'