[FIX] account: adapt AccountMoveFormCompiler hack

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) <wan@odoo.com>
Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
This commit is contained in:
Brice bib Bartoletti
2023-01-21 00:57:25 +01:00
parent 765f653af3
commit 43076cdd26
4 changed files with 53 additions and 1 deletions
+1
View File
@@ -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',
],
},
@@ -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;
@@ -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':
`<form js_class='account_move_form'>
<sheet>
<notebook>
<page id="invoice_tab" name="invoice_tab" string="Invoice Lines"></page>
<page id="aml_tab" string="Journal Items" name="aml_tab"></page>
</notebook>
</sheet>
</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");
});
});
@@ -0,0 +1,5 @@
/** @odoo-module **/
import { addModelNamesToFetch } from '@bus/../tests/helpers/model_definitions_helpers';
addModelNamesToFetch(['account.move']);