summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorRomeo Fragomeli <rfr@odoo.com>2021-02-04 09:53:26 +0000
committerRomeo Fragomeli <rfr@odoo.com>2021-02-18 10:09:22 +0000
commitbbcd8ce097e62bd1d9ba3a61608324a80a111c24 (patch)
tree3f75c094e84c8794b33fc655c66d24fd40804a06 /addons
parent0f6ad2a690f76d6bbbe92106fc8360f99eaac6c2 (diff)
[FIX] stock: traceability report mounted called twice
Before this commit, the 'mounted' method of the ControlPanel in the traceability report was called twice. It happened because the traceability report updated the ControlPanel before being actually mounted, so mounted was called once when the traceability report was mounted, and once when the update was applied. Ideally, this should not be an issue (this isn't an issue with owl). However, in Odoo, we mix layers of Owl Components and legacy widgets. In these situations, the above scenario isn't properly handled (and can't be). As a consequence, in mobile (enterprise), it crashed because an handler bound in mounted (thus twice) was only unbound once. This commit avoids the issue as the update was actually useless. Steps to reproduces (Mobile): * Go to Manufacturing (MRP) * Open the "burger menu" * Select "Products" -> "Lots/Serial Numbers" * Select one product in the list (unfold group first) * Click on the "Traceability" ("stat button") * Select one line to go to the form view * Go back to the previous view using breadcrumb * Optional: Go to another app if the screen can't scroll (e.g. go to Sales) * Scroll the view => Bug
Diffstat (limited to 'addons')
-rw-r--r--addons/stock/static/src/js/stock_traceability_report_backend.js4
-rw-r--r--addons/stock/static/tests/stock_traceability_report_backend_tests.js80
2 files changed, 80 insertions, 4 deletions
diff --git a/addons/stock/static/src/js/stock_traceability_report_backend.js b/addons/stock/static/src/js/stock_traceability_report_backend.js
index f723ade6961..6a504cd2b12 100644
--- a/addons/stock/static/src/js/stock_traceability_report_backend.js
+++ b/addons/stock/static/src/js/stock_traceability_report_backend.js
@@ -99,10 +99,6 @@ var stock_report_generic = AbstractAction.extend({
});
return this.$buttons;
},
- do_show: function() {
- this._super();
- this.update_cp();
- },
});
core.action_registry.add("stock_report_generic", stock_report_generic);
diff --git a/addons/stock/static/tests/stock_traceability_report_backend_tests.js b/addons/stock/static/tests/stock_traceability_report_backend_tests.js
index 20a9d809d70..5ab69403544 100644
--- a/addons/stock/static/tests/stock_traceability_report_backend_tests.js
+++ b/addons/stock/static/tests/stock_traceability_report_backend_tests.js
@@ -1,10 +1,13 @@
odoo.define('stock.stock_traceability_report_backend_tests', function (require) {
"use strict";
+ const ControlPanel = require('web.ControlPanel');
const dom = require('web.dom');
const StockReportGeneric = require('stock.stock_report_generic');
const testUtils = require('web.test_utils');
+ const { createActionManager, dom: domUtils } = testUtils;
+
/**
* Helper function to instantiate a stock report action.
* @param {Object} params
@@ -67,5 +70,82 @@ odoo.define('stock.stock_traceability_report_backend_tests', function (require)
report.destroy();
});
+
+ QUnit.test("mounted is called once when returning on 'Stock report' from breadcrumb", async assert => {
+ // This test can be removed as soon as we don't mix legacy and owl layers anymore.
+ assert.expect(7);
+
+ let mountCount = 0;
+
+ ControlPanel.patch('test.ControlPanel', T => {
+ class ControlPanelPatchTest extends T {
+ mounted() {
+ mountCount = mountCount + 1;
+ this.__uniqueId = mountCount;
+ assert.step(`mounted ${this.__uniqueId}`);
+ super.mounted(...arguments);
+ }
+ willUnmount() {
+ assert.step(`willUnmount ${this.__uniqueId}`);
+ super.mounted(...arguments);
+ }
+ }
+ return ControlPanelPatchTest;
+ });
+
+ const actionManager = await createActionManager({
+ actions: [
+ {
+ id: 42,
+ name: "Stock report",
+ tag: 'stock_report_generic',
+ type: 'ir.actions.client',
+ context: {},
+ params: {},
+ },
+ ],
+ archs: {
+ 'partner,false,form': '<form><field name="display_name"/></form>',
+ 'partner,false,search': '<search></search>',
+ },
+ data: {
+ partner: {
+ fields: {
+ display_name: { string: "Displayed name", type: "char" },
+ },
+ records: [
+ {id: 1, display_name: "Genda Swami"},
+ ],
+ },
+ },
+ mockRPC: function (route) {
+ if (route === '/web/dataset/call_kw/stock.traceability.report/get_html') {
+ return Promise.resolve({
+ html: '<a class="o_stock_reports_web_action" href="#" data-active-id="1" data-res-model="partner">Go to form view</a>',
+ });
+ }
+ return this._super.apply(this, arguments);
+ },
+ intercepts: {
+ do_action: ev => actionManager.doAction(ev.data.action, ev.data.options),
+ },
+ });
+
+ await actionManager.doAction(42);
+ await domUtils.click(actionManager.$('.o_stock_reports_web_action'));
+ await domUtils.click(actionManager.$('.breadcrumb-item:first'));
+ actionManager.destroy();
+
+ assert.verifySteps([
+ 'mounted 1',
+ 'willUnmount 1',
+ 'mounted 2',
+ 'willUnmount 2',
+ 'mounted 3',
+ 'willUnmount 3',
+ ]);
+
+ ControlPanel.unpatch('test.ControlPanel');
+ });
});
});