From fc692e5f9c3f56534e75268a3d796488bfe91ea4 Mon Sep 17 00:00:00 2001 From: "Ahmed Khalaf(ahkh)" Date: Wed, 11 May 2022 14:27:53 +0000 Subject: [PATCH] [FIX] product: Ordered printing product labels Product labels are now printed by name order Task: 2764771 Part-of: odoo/odoo#91640 --- addons/product/report/product_label_report.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/product/report/product_label_report.py b/addons/product/report/product_label_report.py index 35c9eb5b4e7..f2c0b3bcb61 100644 --- a/addons/product/report/product_label_report.py +++ b/addons/product/report/product_label_report.py @@ -17,9 +17,13 @@ def _prepare_data(env, data): raise UserError(_('Product model not defined, Please contact your administrator.')) total = 0 + qty_by_product_in = data.get('quantity_by_product') + # search for products all at once, ordered by name desc since popitem() used in xml to print the labels + # is LIFO, which results in ordering by product name in the report + products = Product.search([('id', 'in', [int(p) for p in qty_by_product_in.keys()])], order='name desc') quantity_by_product = defaultdict(list) - for p, q in data.get('quantity_by_product').items(): - product = Product.browse(int(p)) + for product in products: + q = qty_by_product_in[str(product.id)] quantity_by_product[product].append((product.barcode, q)) total += q if data.get('custom_barcodes'):