summaryrefslogtreecommitdiff
path: root/addons/purchase_product_matrix
diff options
context:
space:
mode:
authorAchraf (abz) <abz@odoo.com>2021-04-22 10:41:45 +0000
committerAchraf (abz) <abz@odoo.com>2021-04-26 10:51:06 +0000
commit25312bc576b9e0330eb316e77d8a177ee0434832 (patch)
tree28485f5b99a1ef139692191d7a1e7449ce7ccbe2 /addons/purchase_product_matrix
parent94849f6545e96d0823bd29cef7fa111b82ed3b28 (diff)
[FIX] purchase_product_matrix: Allow to change PO lines order
What are the steps to reproduce your issue ? 1. Install 'purchase_product_matrix' 2. try to edit a PO with more than one line 3. try to change the order of a product line What is currently happening ? Traceback: TypeError: Cannot read property 'data' of undefined What are you expecting to happen ? Change order lines without traceback Why is this happening ? There is a function 'reset' that checkes if 'ev' exists: https://github.com/odoo/odoo/blob/e0af10ccc92cb3b07f0eea6fa44ebf5a1bdc86aa/addons/sale/static/src/js/product_configurator_widget.js#L119 And in 'purchase_product_matrix' there is a override of this same function that calls it and then tries to use an 'ev' attribute without checking it before How to fix the bug ? Check 'ev' before accessing it opw-2513061 closes odoo/odoo#69666 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons/purchase_product_matrix')
-rw-r--r--addons/purchase_product_matrix/static/src/js/product_matrix_configurator.js2
-rw-r--r--addons/purchase_product_matrix/static/tests/section_and_note_widget_tests.js49
2 files changed, 50 insertions, 1 deletions
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: `<form>
+ <field name="order_line_ids" widget="section_and_note_one2many">
+ <tree editable="bottom">
+ <field name="sequence" widget="handle"/>
+ <field name="product_template_id" widget="matrix_configurator"/>
+ </tree>
+ </field>
+ </form>`,
+ 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();
+ });
});
});