From f703271c0a79cc5bd989d83695a11f04d348f044 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Tue, 15 Oct 2019 12:06:49 +0000 Subject: [PATCH] [FIX] account: reconciliation widget fetch correct reconciliation models Have a reconciliation model that applies to some particular journals And that will match some of those journals' lines The field journal should be filled too (this field is only the default journal that a proposition will be filled with) Open the reconciliation widget on a given journal, within the list of possible journal (from the account dashboard) Before this commit there was a crashed. This was caused by the fact that one of the lines that should be displayed had a reconcile model that was not fetched beforehand After this commit, there is no crash as all relevant reconcile models are fetched Note that, on reconcile models, the field journal_id is just there to prefill the propositions it will create corrects commit e5c8071484c883bf78478a39ef2120bcd8f2442d OPW 2084942 closes odoo/odoo#38836 X-original-commit: c285d578cc497044e819c62d42373c29f87b1e93 Signed-off-by: Lucas Perais (lpe) --- .../js/reconciliation/reconciliation_model.js | 2 +- .../static/tests/reconciliation_tests.js | 31 +++++++++++++++++++ 2 files changed, 32 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 2854ac4760b..8adb4ec1c91 100644 --- a/addons/account/static/src/js/reconciliation/reconciliation_model.js +++ b/addons/account/static/src/js/reconciliation/reconciliation_model.js @@ -438,7 +438,7 @@ var StatementModel = BasicModel.extend({ domainReconcile.push(['company_id', 'in', self.context.company_ids]); } if (self.context && self.context.active_model === 'account.journal' && self.context.active_ids) { - domainReconcile.push(['journal_id', 'in', [false].concat(self.context.active_ids)]); + domainReconcile.push(['match_journal_ids', 'in', [false].concat(self.context.active_ids)]); } var def_reconcileModel = this._loadReconciliationModel({domainReconcile: domainReconcile}); var def_account = this._rpc({ diff --git a/addons/account/static/tests/reconciliation_tests.js b/addons/account/static/tests/reconciliation_tests.js index 853e7205f87..a1e2e215126 100644 --- a/addons/account/static/tests/reconciliation_tests.js +++ b/addons/account/static/tests/reconciliation_tests.js @@ -589,6 +589,7 @@ var demoData = require('account.reconciliation_tests.data'); var testUtils = require('web.test_utils'); var testUtilsDom = require('web.test_utils_dom'); +var testUtilsMock = require('web.test_utils_mock'); QUnit.module('account', { beforeEach: function () { @@ -1329,6 +1330,36 @@ QUnit.module('account', { clientAction.destroy(); }); + QUnit.test('Reconciliation fetch correct reconciliation models', async function (assert) { + assert.expect(1); + + testUtilsMock.patch(this.params.options.context, { + active_model: 'account.journal', // On account dashboard, click "Reconcile" on a journal + active_ids: [1,2], // Active journals + company_ids: [3,4], // Active companies + }); + + var clientAction = new ReconciliationClientAction.StatementAction(null, this.params.options); + + testUtils.addMockEnvironment(clientAction, { + data: this.params.data, + mockRPC: async function (route, args) { + if (args.model === 'account.reconcile.model' && args.method === 'search_read') { + assert.deepEqual( + args.kwargs.domain, + [['company_id', 'in', [3,4]], ['match_journal_ids', 'in', [false, 1, 2]]], + 'The domain to get reconcile models should contain the right fields and values' + ); + } + return this._super.apply(this, arguments); + } + }); + clientAction.appendTo($('#qunit-fixture')); + testUtilsMock.unpatch(this.params.options.context); + + clientAction.destroy(); + }); + QUnit.test('Reconciliation manual', async function (assert) { assert.expect(13);