summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorVictor Feyens <vfe@odoo.com>2020-07-28 15:46:23 +0000
committerVictor Feyens <vfe@odoo.com>2020-07-29 13:46:46 +0000
commit42fc0f491001041b6001ed5a9eab2b7e79cbb75b (patch)
tree09b4a738f5af3a18ff09b00ed6e4b5fa269c0ff1 /addons
parentd3f0632f4977cd1f7d7099fb2688722bcd451d27 (diff)
[FIX] product_matrix: matrix edition on a new record.
Probably since recent js framework changes, when trying to modify the matrix of a product on a new SO (not saved), a js error was raised (wrong qweb template rendering). This is due to a wrong check when loading the matrix data, in the case of a new record, the data wasn't correctly updated on all widgets, resulting in an opening of the matrix with the results of the last matrix changes (since the information is transferred in the same field). This commit: * Ensures that the correct data is taken to open the matrix (solving the main problem of matrix update on new records) * Improves test coverage to cover untested buggy situation * Fixes another error found while improving test coverage: The edition of existing quantities was wrongly creating new lines, instead of updating existing ones. Simplify lines comparison to ensure the matrix won't generate two lines for the same variant combination. closes odoo/odoo#54917 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/product_matrix/static/src/js/section_and_note_widget.js7
-rw-r--r--addons/sale_product_matrix/models/sale_order.py5
-rw-r--r--addons/sale_product_matrix/static/tests/tours/sale_product_matrix_tour.js32
3 files changed, 42 insertions, 2 deletions
diff --git a/addons/product_matrix/static/src/js/section_and_note_widget.js b/addons/product_matrix/static/src/js/section_and_note_widget.js
index 5cbc318ed76..3cdddf0f596 100644
--- a/addons/product_matrix/static/src/js/section_and_note_widget.js
+++ b/addons/product_matrix/static/src/js/section_and_note_widget.js
@@ -76,7 +76,12 @@ SectionAndNoteFieldOne2Many.include({
// find one of the SO widget
// (not so lines because the grid values are computed on the SO)
// and get the grid information from its recordData.
- var gridInfo = result.find(r => r.recordData.grid).recordData.grid;
+ var gridInfo = result.find(
+ r => r.recordData.grid && r.recordData.grid.includes("header")
+ ).recordData.grid;
+ // includes "header" is necessary to ensure the correct data is taken
+ // because the grid data isn't correctly updated in all widgets
+ // when in an new record environment.
self._openMatrixConfigurator(gridInfo, productTemplateId, editedCellAttributes);
}
});
diff --git a/addons/sale_product_matrix/models/sale_order.py b/addons/sale_product_matrix/models/sale_order.py
index 814093e3bdc..f5d5469e78f 100644
--- a/addons/sale_product_matrix/models/sale_order.py
+++ b/addons/sale_product_matrix/models/sale_order.py
@@ -55,7 +55,10 @@ class SaleOrder(models.Model):
# create or find product variant from combination
product = product_template._create_product_variant(combination)
- order_lines = self.order_line.filtered(lambda line: (line._origin or line).product_id == product and (line._origin or line).product_no_variant_attribute_value_ids == no_variant_attribute_values)
+ order_lines = self.order_line.filtered(
+ lambda line: line.product_id.id == product.id
+ and line.product_no_variant_attribute_value_ids.ids == no_variant_attribute_values.ids
+ )
# if product variant already exist in order lines
old_qty = sum(order_lines.mapped('product_uom_qty'))
diff --git a/addons/sale_product_matrix/static/tests/tours/sale_product_matrix_tour.js b/addons/sale_product_matrix/static/tests/tours/sale_product_matrix_tour.js
index 622784b115f..10259a98176 100644
--- a/addons/sale_product_matrix/static/tests/tours/sale_product_matrix_tour.js
+++ b/addons/sale_product_matrix/static/tests/tours/sale_product_matrix_tour.js
@@ -36,6 +36,38 @@ tour.register('sale_matrix_tour', {
trigger: 'span:contains("Confirm")',
run: 'click'
}, {
+ trigger: 'span:contains("Matrix (PAV11, PAV22, PAV31)\n\nPA4: PAV41")',
+ extra_trigger: '.o_form_editable',
+ run: 'click'
+}, {
+ trigger: '.o_edit_product_configuration',
+ run: 'click' // edit the matrix
+}, {
+ trigger: '.o_product_variant_matrix',
+ run: function () {
+ // set all qties to 3
+ $('.o_matrix_input').val(3);
+ }
+}, {
+ trigger: 'span:contains("Confirm")',
+ run: 'click' // apply the matrix
+}, {
+ trigger: 'span:contains("Matrix (PAV11, PAV22, PAV31)\n\nPA4: PAV41")',
+ extra_trigger: '.o_form_editable',
+ run: 'click'
+}, {
+ trigger: '.o_edit_product_configuration',
+ run: 'click' // edit the matrix
+}, {
+ trigger: '.o_product_variant_matrix',
+ run: function () {
+ // reset all qties to 1
+ $('.o_matrix_input').val(1);
+ }
+}, {
+ trigger: 'span:contains("Confirm")',
+ run: 'click' // apply the matrix
+}, {
trigger: ".o_form_editable .o_field_many2one[name='partner_id'] input",
extra_trigger: ".o_sale_order",
run: 'text Agrolait'