From 43076cdd26418fec8cfa612657638d539f4c61da Mon Sep 17 00:00:00 2001 From: Brice bib Bartoletti Date: Fri, 20 Jan 2023 09:07:36 +0000 Subject: [PATCH] [FIX] account: adapt AccountMoveFormCompiler hack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The aim of this commit is to get rid of a traceback preventing the user to switch tabs in Invoice and Bill Context: AccountMoveFormCompiler is a hack that allows to save the record automatically when the user switch between tabs. With commit 264f313012aa99449d1576ae1110252c13755142 the way to call the compiler changed a bit but the hack wasn't. Before the commit: The `this` was leading nowhere in the compiler frame leading to a traceback in OWL. After the commit: `this` is defined and the traceback is gone closes odoo/odoo#110635 Community-pr: https://github.com/odoo/odoo/pull/110506 Task-id: no task X-original-commit: a926071fc6944d5cd720a8849b2f31a5dd8ff4dc Signed-off-by: William André (wan) Signed-off-by: Brice Bartoletti (bib) --- addons/account/__manifest__.py | 1 + .../account_move_form/account_move_form.js | 2 +- .../static/tests/account_move_form_tests.js | 46 +++++++++++++++++++ .../tests/helpers/model_definitions_setup.js | 5 ++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 addons/account/static/tests/account_move_form_tests.js create mode 100644 addons/account/static/tests/helpers/model_definitions_setup.js diff --git a/addons/account/__manifest__.py b/addons/account/__manifest__.py index 7ae6fa1558d..aeab46c4328 100644 --- a/addons/account/__manifest__.py +++ b/addons/account/__manifest__.py @@ -108,6 +108,7 @@ You could use this simplified accounting in case you work with an (external) acc 'account/static/tests/tours/**/*', ], 'web.qunit_suite_tests': [ + 'account/static/tests/helpers/*.js', 'account/static/tests/*.js', ], }, diff --git a/addons/account/static/src/components/account_move_form/account_move_form.js b/addons/account/static/src/components/account_move_form/account_move_form.js index 2fa1ba3aeef..56f84e23195 100644 --- a/addons/account/static/src/components/account_move_form/account_move_form.js +++ b/addons/account/static/src/components/account_move_form/account_move_form.js @@ -45,7 +45,7 @@ export class AccountMoveFormCompiler extends FormCompiler { for (const attr of originalNoteBook.attributes) { noteBook.setAttribute(attr.name, attr.value); } - noteBook.setAttribute("onBeforeTabSwitch", "() => this.saveBeforeTabChange()"); + noteBook.setAttribute("onBeforeTabSwitch", "() => __comp__.saveBeforeTabChange()"); const slots = originalNoteBook.childNodes; append(noteBook, [...slots]); return noteBook; diff --git a/addons/account/static/tests/account_move_form_tests.js b/addons/account/static/tests/account_move_form_tests.js new file mode 100644 index 00000000000..e83e3f180c1 --- /dev/null +++ b/addons/account/static/tests/account_move_form_tests.js @@ -0,0 +1,46 @@ +/** @odoo-module **/ +"use strict"; + +import { start, startServer } from "@mail/../tests/helpers/test_utils"; +import { patchWithCleanup } from "@web/../tests/helpers/utils"; +import { AccountMoveFormRenderer } from "@account/components/account_move_form/account_move_form"; + +QUnit.module("Views", {}, function (hooks) { + QUnit.module('MoveFormView'); + + QUnit.test("When I switch tabs, it saves", async (assert) => { + const pyEnv = await startServer(); + const accountMove = pyEnv['account.move'].create([{ name: "move0" }]); + + const views = { + 'account.move,false,form': + `
+ + + + + + +
`, + }; + const { click, openView } = await start({ + serverData: { views }, + }); + patchWithCleanup(AccountMoveFormRenderer.prototype, { + saveBeforeTabChange() { + this._super(); + assert.step("tab saved"); + }, + }); + await openView({ + res_id: accountMove, + res_model: 'account.move', + views: [[false, 'form']], + }); + + click('a[name="aml_tab"]'); + assert.verifySteps(["tab saved"], + "When clicking on a tab, the saving method should be called and succeed"); + }); + +}); diff --git a/addons/account/static/tests/helpers/model_definitions_setup.js b/addons/account/static/tests/helpers/model_definitions_setup.js new file mode 100644 index 00000000000..48e5e06b178 --- /dev/null +++ b/addons/account/static/tests/helpers/model_definitions_setup.js @@ -0,0 +1,5 @@ +/** @odoo-module **/ + +import { addModelNamesToFetch } from '@bus/../tests/helpers/model_definitions_helpers'; + +addModelNamesToFetch(['account.move']);