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']);