diff --git a/addons/purchase_product_matrix/static/src/js/product_matrix_configurator.js b/addons/purchase_product_matrix/static/src/js/product_matrix_configurator.js index 4f429f4fcc6..907b2d4b5f8 100644 --- a/addons/purchase_product_matrix/static/src/js/product_matrix_configurator.js +++ b/addons/purchase_product_matrix/static/src/js/product_matrix_configurator.js @@ -99,7 +99,7 @@ var MatrixConfiguratorWidget = relationalFields.FieldMany2One.extend({ */ reset: async function (record, ev) { await this._super(...arguments); - if (ev && ev.data.changes && ev.data.changes.product_template_id && record.data.product_template_id.data.id) { + if (ev && ev.target === this && ev.data.changes && ev.data.changes.product_template_id && record.data.product_template_id.data.id) { this._onTemplateChange(record.data.product_template_id.data.id, ev.data.dataPointID); } }, diff --git a/addons/purchase_product_matrix/static/tests/section_and_note_widget_tests.js b/addons/purchase_product_matrix/static/tests/section_and_note_widget_tests.js index 5c4108b1c89..7dfc29e642a 100644 --- a/addons/purchase_product_matrix/static/tests/section_and_note_widget_tests.js +++ b/addons/purchase_product_matrix/static/tests/section_and_note_widget_tests.js @@ -207,5 +207,54 @@ QUnit.module('section_and_note: purchase_product_matrix', { form.destroy(); }); + + QUnit.test('drag and drop rows containing matrix_configurator many2one', async function (assert) { + assert.expect(4); + + this.data.order_line.fields.sequence = {string: "Sequence", type: 'number'}; + this.data.order_line.fields.order_id.relation = 'purchase_order'; + this.data.purchase_order.records = [ + {id: 1, order_line_ids: [1, 2]} + ]; + this.data.order_line.records = [ + {id: 1, sequence: 4, product_template_id: 1, order_id: 1}, + {id: 2, sequence: 14, product_template_id: 2, order_id: 1}, + ]; + this.data.product.records.push( + {id: 1, name: "Chair"}, + {id: 2, name: "Table"} + ); + + const form = await createView({ + View: FormView, + model: 'purchase_order', + data: this.data, + arch: `
`, + res_id: 1, + viewOptions: { + mode: 'edit', + }, + }); + + assert.containsN(form, '.o_data_row', 2); + assert.strictEqual(form.$('.o_data_row').text(), 'ChairTable'); + assert.containsN(form, '.o_data_row .o_row_handle', 2); + + // move first row below second + const $firstHandle = form.$('.o_data_row:nth(0) .o_row_handle'); + const $secondHandle = form.$('.o_data_row:nth(1) .o_row_handle'); + await testUtils.dom.dragAndDrop($firstHandle, $secondHandle); + + assert.strictEqual(form.$('.o_data_row').text(), 'TableChair'); + + form.destroy(); + }); }); });