From cd2e6ea534725c0f6c144ff9a317fa30cfca40a7 Mon Sep 17 00:00:00 2001 From: "Manushi Shah (mash)" Date: Wed, 16 Aug 2023 14:39:10 +0530 Subject: [PATCH] [FIX] sale_product_matrix: remove unnecessary matrix rows Prior to this commit: When generating a sale order/purchase order report, all rows, including those with entirely null values included in the report i.e. the entire matrix is displayed. Post this commit: The sale order/purchase order report is generated with only the rows with at least one quantity is added, rather than including the entire matrix. closes odoo/odoo#132045 Task: 2860388 Signed-off-by: Victor Feyens (vfe) --- addons/purchase_product_matrix/models/purchase.py | 8 +++++++- addons/sale_product_matrix/models/sale_order.py | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/addons/purchase_product_matrix/models/purchase.py b/addons/purchase_product_matrix/models/purchase.py index 5af1a298d57..27d3941a59d 100644 --- a/addons/purchase_product_matrix/models/purchase.py +++ b/addons/purchase_product_matrix/models/purchase.py @@ -150,7 +150,13 @@ class PurchaseOrder(models.Model): # configurable products are only configured through the matrix in purchase, so no need to check product_add_mode. for template in grid_configured_templates: if len(self.order_line.filtered(lambda line: line.product_template_id == template)) > 1: - matrixes.append(self._get_matrix(template)) + matrix = self._get_matrix(template) + matrix_data = [] + for row in matrix['matrix']: + if any(column['qty'] != 0 for column in row[1:]): + matrix_data.append(row) + matrix['matrix'] = matrix_data + matrixes.append(matrix) return matrixes diff --git a/addons/sale_product_matrix/models/sale_order.py b/addons/sale_product_matrix/models/sale_order.py index ba37a17a66c..e7f3d6e4053 100644 --- a/addons/sale_product_matrix/models/sale_order.py +++ b/addons/sale_product_matrix/models/sale_order.py @@ -158,6 +158,11 @@ class SaleOrder(models.Model): grid_configured_templates = self.order_line.filtered('is_configurable_product').product_template_id.filtered(lambda ptmpl: ptmpl.product_add_mode == 'matrix') for template in grid_configured_templates: if len(self.order_line.filtered(lambda line: line.product_template_id == template)) > 1: - # TODO do we really want the whole matrix even if there isn't a lot of lines ?? - matrixes.append(self._get_matrix(template)) + matrix = self._get_matrix(template) + matrix_data = [] + for row in matrix['matrix']: + if any(column['qty'] != 0 for column in row[1:]): + matrix_data.append(row) + matrix['matrix'] = matrix_data + matrixes.append(matrix) return matrixes