[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) <vfe@odoo.com>
This commit is contained in:
Manushi Shah (mash)
2023-09-08 09:47:01 +00:00
committed by Victor Feyens
parent 39401c7928
commit cd2e6ea534
2 changed files with 14 additions and 3 deletions
@@ -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. # configurable products are only configured through the matrix in purchase, so no need to check product_add_mode.
for template in grid_configured_templates: for template in grid_configured_templates:
if len(self.order_line.filtered(lambda line: line.product_template_id == template)) > 1: 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 return matrixes
@@ -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') 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: for template in grid_configured_templates:
if len(self.order_line.filtered(lambda line: line.product_template_id == template)) > 1: 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 ?? matrix = self._get_matrix(template)
matrixes.append(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 return matrixes