[FIX] web,stock,mrp: check if viewSwitcherEntries exists
When using the ControlPanel's bottom-right slot in another component, if `viewSwitcherEntries` wasn't defined in `env.config` it would raise a traceback, as the template would try to check an `undefined`'s length. Removed the workaround that added an empty `viewSwitcherEntries` in the forecast report and the bom overview report since it's no longer necessary. closes odoo/odoo#112415 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
-2
@@ -10,8 +10,6 @@ const { Component } = owl;
|
||||
export class BomOverviewControlPanel extends Component {
|
||||
setup() {
|
||||
this.controlPanelDisplay = {};
|
||||
// Cannot use 'control-panel-bottom-right' slot without this, as viewSwitcherEntries doesn't exist in this.env.config here.
|
||||
this.env.config.viewSwitcherEntries = [];
|
||||
}
|
||||
|
||||
//---- Handlers ----
|
||||
|
||||
@@ -10,22 +10,10 @@ import { ForecastedDetails } from "./forecasted_details";
|
||||
import { ForecastedHeader } from "./forecasted_header";
|
||||
import { ForecastedWarehouseFilter } from "./forecasted_warehouse_filter";
|
||||
|
||||
const { Component, onWillStart, useState, useSubEnv } = owl;
|
||||
const { Component, onWillStart, useState } = owl;
|
||||
|
||||
export class StockForecasted extends Component {
|
||||
setup() {
|
||||
useSubEnv({
|
||||
...this.env,
|
||||
//ControlPanel trick : Allow the use of ControlPanel's bottom-right while disabling search to avoid errors
|
||||
searchModel: {
|
||||
searchMenuTypes: [],
|
||||
},
|
||||
config: {
|
||||
...this.env.config,
|
||||
viewSwitcherEntries: [],
|
||||
}
|
||||
});
|
||||
|
||||
this.orm = useService("orm");
|
||||
this.action = useService("action");
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
<Pager t-props="pagerProps"/>
|
||||
</div>
|
||||
|
||||
<t t-if="env.config.viewSwitcherEntries.length > 1">
|
||||
<t t-if="env.config.viewSwitcherEntries and env.config.viewSwitcherEntries.length > 1">
|
||||
<nav class="btn-group o_cp_switch_buttons ms-auto">
|
||||
<t t-foreach="env.config.viewSwitcherEntries" t-as="view" t-key="view.type">
|
||||
<button class="btn btn-light o_switch_view "
|
||||
@@ -139,7 +139,7 @@
|
||||
<Pager t-props="pagerProps"/>
|
||||
</div>
|
||||
|
||||
<t t-if="env.config.viewSwitcherEntries.length > 1">
|
||||
<t t-if="env.config.viewSwitcherEntries and env.config.viewSwitcherEntries.length > 1">
|
||||
<nav class="btn-group o_cp_switch_buttons">
|
||||
<t t-set="view" t-value="env.config.viewSwitcherEntries.find((v) => v.active)" />
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { click, getFixture, nextTick } from "@web/../tests/helpers/utils";
|
||||
import { click, getFixture, mount, nextTick } from "@web/../tests/helpers/utils";
|
||||
import { ControlPanel } from "@web/search/control_panel/control_panel";
|
||||
import { makeWithSearch, setupControlPanelServiceRegistry } from "./helpers";
|
||||
import { Component, xml } from "@odoo/owl";
|
||||
import { makeTestEnv } from "../helpers/mock_env";
|
||||
|
||||
let target;
|
||||
let serverData;
|
||||
@@ -132,4 +134,22 @@ QUnit.module("Search", (hooks) => {
|
||||
await nextTick();
|
||||
assert.containsNone(target, ".o_pager");
|
||||
});
|
||||
|
||||
QUnit.test("control panel without bottom-right specifics", async (assert) => {
|
||||
class CustomPage extends Component {}
|
||||
CustomPage.components = { ControlPanel };
|
||||
CustomPage.template = xml `
|
||||
<ControlPanel display="{'top-right':false}">
|
||||
<t t-set-slot="control-panel-bottom-right">
|
||||
<div class="o_new_bottom_right">Something else</div>
|
||||
</t>
|
||||
</ControlPanel>
|
||||
`;
|
||||
// Minimal config, still needs at least an empty breadcrumbs to setup a control_panel
|
||||
const env = { ...await makeTestEnv(), config: { breadcrumbs: [], } };
|
||||
parent = await mount(CustomPage, target, { env });
|
||||
assert.containsOnce(target, ".o_new_bottom_right");
|
||||
assert.containsNone(target, ".o_cp_switch_buttons");
|
||||
assert.containsNone(target, ".o_pager");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user