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'