From 73bec3d60feaced7d285ad062021f7703fc9e31a Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Tue, 19 Sep 2017 12:34:54 +0200 Subject: [PATCH] [FIX] account: reconciliation, error when changing partner Traceback by pressing enter when changing partner which should not occur as keyUp event is in place for other M2O fields and not for the partner. In some case, if the line is balanced (marked as reconciled) and we change the user for one that does not have any move lines, we removed the selected proposition but we did not changed the line balance, resulting in a widget that is marked as inactive and no way to do something with it. --- .../js/reconciliation/reconciliation_model.js | 1 + .../js/reconciliation/reconciliation_renderer.js | 4 ++++ .../account/static/tests/reconciliation_tests.js | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/addons/account/static/src/js/reconciliation/reconciliation_model.js b/addons/account/static/src/js/reconciliation/reconciliation_model.js index 9caea6d8712..1d86c058e09 100644 --- a/addons/account/static/src/js/reconciliation/reconciliation_model.js +++ b/addons/account/static/src/js/reconciliation/reconciliation_model.js @@ -235,6 +235,7 @@ var StatementModel = BasicModel.extend({ return $.when(partner && this._changePartner(handle, partner.id)) .then(function() { line.reconciliation_proposition = []; + self._computeLine(line); return self.changeMode(handle, 'match'); }) .then(function () { diff --git a/addons/account/static/src/js/reconciliation/reconciliation_renderer.js b/addons/account/static/src/js/reconciliation/reconciliation_renderer.js index ff0abf316ec..d9aa12967e1 100644 --- a/addons/account/static/src/js/reconciliation/reconciliation_renderer.js +++ b/addons/account/static/src/js/reconciliation/reconciliation_renderer.js @@ -600,6 +600,10 @@ var LineRenderer = Widget.extend(FieldManagerMixin, { * @param {keyup event} event */ _onInputKeyup: function (event) { + var target_partner_id = $(event.target).parents('[name="partner_id"]'); + if (target_partner_id.length === 1) { + return; + } if(event.keyCode === 13) { if (_.findWhere(this.model.lines, {mode: 'create'}).balance.amount) { this._onCreateProposition(); diff --git a/addons/account/static/tests/reconciliation_tests.js b/addons/account/static/tests/reconciliation_tests.js index 27f327febb1..88d9a7a0f78 100644 --- a/addons/account/static/tests/reconciliation_tests.js +++ b/addons/account/static/tests/reconciliation_tests.js @@ -741,7 +741,7 @@ QUnit.module('account', { }); QUnit.test('Reconciliation change partner', function (assert) { - assert.expect(13); + assert.expect(17); var clientAction = new ReconciliationClientAction.StatementAction(null, this.params.options); @@ -759,6 +759,20 @@ QUnit.module('account', { var widget = clientAction.widgets[0]; assert.strictEqual(widget.$('.o_input_dropdown input').val(), "Agrolait", "the partner many2one should display agrolait"); assert.strictEqual(widget.$('.match table tr').length, 2, "agrolait should have 2 propositions for reconciliation"); + + // Adding the two propositions + // This is in order to try that after changing partner the propositions are emptied + widget.$('.match .cell_account_code:first').trigger('click'); + widget.$('.match .cell_account_code:first').trigger('click'); + assert.strictEqual(widget.$('.accounting_view tbody tr').length, 2, "Both proposition should be selected"); + + // Similate changing partner to one that does not have propositions to see if create mode is open after + widget.$('.o_input_dropdown input').trigger('click'); + $('.ui-autocomplete .ui-menu-item a:contains(partner 1)').trigger('mouseenter').trigger('click'); + clientAction._onAction({target: widget, name: 'change_partner', data: {data: {display_name: 'partner 1', id: 1}}, stopped: false}); + assert.strictEqual(widget.$('.o_input_dropdown input').val(), "partner 1", "the partner many2one should display partner 1"); + assert.strictEqual(widget.$('.match table tr.mv_line').length, 0, "partner 1 should have 0 propositions for reconciliation"); + assert.strictEqual(widget.$el.data('mode'), 'create', "widget should be in create mode"); // Simulate changing partner widget.$('.o_input_dropdown input').trigger('click');