Initial commit: Core packages

This commit is contained in:
Ernad Husremovic 2025-08-29 15:20:45 +02:00
commit 12c29a983b
9512 changed files with 8379910 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

View file

@ -0,0 +1,23 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="70" height="70" viewBox="0 0 70 70">
<defs>
<path id="icon-a" d="M4,5.35309892e-14 C36.4160122,9.87060235e-15 58.0836068,-3.97961823e-14 65,5.07020818e-14 C69,6.733808e-14 70,1 70,5 C70,43.0488877 70,62.4235458 70,65 C70,69 69,70 65,70 C61,70 9,70 4,70 C1,70 7.10542736e-15,69 7.10542736e-15,65 C7.25721566e-15,62.4676575 3.83358709e-14,41.8005206 3.60818146e-14,5 C-1.13686838e-13,1 1,5.75716207e-14 4,5.35309892e-14 Z"/>
<linearGradient id="icon-c" x1="100%" x2="0%" y1="0%" y2="100%">
<stop offset="0%" stop-color="#CD7690"/>
<stop offset="100%" stop-color="#CA5377"/>
</linearGradient>
<path id="icon-d" d="M18.0450069,57.225 C16.6239398,57.2249541 15.319401,56.4292666 14.6550625,55.1573449 C12.9601701,51.9125391 12,48.2137078 12,44.2875 C12,31.4261695 22.2974514,21 35,21 C47.7025486,21 58,31.4261695 58,44.2875 C58,48.2137078 57.0398299,51.9125391 55.3449375,55.1573449 C54.6806259,56.4292924 53.3760701,57.2249902 51.9549931,57.225 L18.0450069,57.225 Z M52.8888889,41.7 C51.4775035,41.7 50.3333333,42.8584723 50.3333333,44.2875 C50.3333333,45.7165277 51.4775035,46.875 52.8888889,46.875 C54.3002743,46.875 55.4444444,45.7165277 55.4444444,44.2875 C55.4444444,42.8584723 54.3002743,41.7 52.8888889,41.7 Z M35,28.7625 C36.4113854,28.7625 37.5555556,27.6040277 37.5555556,26.175 C37.5555556,24.7459723 36.4113854,23.5875 35,23.5875 C33.5886146,23.5875 32.4444444,24.7459723 32.4444444,26.175 C32.4444444,27.6040277 33.5886146,28.7625 35,28.7625 Z M17.1111111,41.7 C15.6997257,41.7 14.5555556,42.8584723 14.5555556,44.2875 C14.5555556,45.7165277 15.6997257,46.875 17.1111111,46.875 C18.5224965,46.875 19.6666667,45.7165277 19.6666667,44.2875 C19.6666667,42.8584723 18.5224965,41.7 17.1111111,41.7 Z M22.3506389,28.8925219 C20.9392535,28.8925219 19.7950833,30.0509941 19.7950833,31.4800219 C19.7950833,32.9090496 20.9392535,34.0675219 22.3506389,34.0675219 C23.7620243,34.0675219 24.9061944,32.9090496 24.9061944,31.4800219 C24.9061944,30.0509941 23.7620243,28.8925219 22.3506389,28.8925219 Z M47.6493611,28.8925219 C46.2379757,28.8925219 45.0938056,30.0509941 45.0938056,31.4800219 C45.0938056,32.9090496 46.2379757,34.0675219 47.6493611,34.0675219 C49.0607465,34.0675219 50.2049167,32.9090496 50.2049167,31.4800219 C50.2049167,30.0509941 49.0607465,28.8925219 47.6493611,28.8925219 Z M40.6952153,31.4423414 C39.686809,31.1156695 38.6082049,31.6784508 38.285566,32.6992195 L34.6181042,44.3034293 C31.9739028,44.501373 29.8888889,46.7346281 29.8888889,49.4625 C29.8888889,52.3205555 32.1772292,54.6375 35,54.6375 C37.8227708,54.6375 40.1111111,52.3205555 40.1111111,49.4625 C40.1111111,47.8636676 39.3946771,46.434559 38.269434,45.4852699 L41.9365764,33.8821113 C42.2591354,32.8612617 41.7033819,31.7690133 40.6952153,31.4423414 Z"/>
</defs>
<g fill="none" fill-rule="evenodd">
<mask id="icon-b" fill="#fff">
<use xlink:href="#icon-a"/>
</mask>
<g mask="url(#icon-b)">
<rect width="70" height="70" fill="url(#icon-c)"/>
<path fill="#FFF" fill-opacity=".383" d="M4,1.8 L65,1.8 C67.6666667,1.8 69.3333333,1.13333333 70,-0.2 C70,2.46666667 70,3.46666667 70,2.8 L1.10547097e-14,2.8 C-1.65952376e-14,3.46666667 -2.9161925e-14,2.46666667 -2.66453526e-14,-0.2 C0.666666667,1.13333333 2,1.8 4,1.8 Z" transform="matrix(1 0 0 -1 0 2.8)"/>
<path fill="#393939" d="M4,50 C2,50 -7.10542736e-15,49.851312 0,45.8367347 L0,26.3942795 L16.3536575,8.86200565 C29.4512192,-0.488174988 39.6666667,-2.3877551 47,3.16326531 C54.3333333,8.71428571 58,14.9591837 58,21.8979592 C55.8677728,29.7827578 54.7719047,33.7755585 54.7123959,33.8763613 C54.6528871,33.9771642 49.9857922,39.3517104 40.7111111,50 L4,50 Z" opacity=".324" transform="translate(0 20)"/>
<path fill="#000" fill-opacity=".383" d="M4,4 L65,4 C67.6666667,4 69.3333333,3 70,1 C70,3.66666667 70,5 70,5 L1.77635684e-15,5 C1.77635684e-15,5 1.77635684e-15,3.66666667 1.77635684e-15,1 C0.666666667,3 2,4 4,4 Z" transform="translate(0 65)"/>
<use fill="#000" fill-rule="nonzero" opacity=".3" xlink:href="#icon-d"/>
<path fill="#FFF" fill-rule="nonzero" d="M18.0450069,55.225 C16.6239398,55.2249541 15.319401,54.4292666 14.6550625,53.1573449 C12.9601701,49.9125391 12,46.2137078 12,42.2875 C12,29.4261695 22.2974514,19 35,19 C47.7025486,19 58,29.4261695 58,42.2875 C58,46.2137078 57.0398299,49.9125391 55.3449375,53.1573449 C54.6806259,54.4292924 53.3760701,55.2249902 51.9549931,55.225 L18.0450069,55.225 Z M52.8888889,39.7 C51.4775035,39.7 50.3333333,40.8584723 50.3333333,42.2875 C50.3333333,43.7165277 51.4775035,44.875 52.8888889,44.875 C54.3002743,44.875 55.4444444,43.7165277 55.4444444,42.2875 C55.4444444,40.8584723 54.3002743,39.7 52.8888889,39.7 Z M35,26.7625 C36.4113854,26.7625 37.5555556,25.6040277 37.5555556,24.175 C37.5555556,22.7459723 36.4113854,21.5875 35,21.5875 C33.5886146,21.5875 32.4444444,22.7459723 32.4444444,24.175 C32.4444444,25.6040277 33.5886146,26.7625 35,26.7625 Z M17.1111111,39.7 C15.6997257,39.7 14.5555556,40.8584723 14.5555556,42.2875 C14.5555556,43.7165277 15.6997257,44.875 17.1111111,44.875 C18.5224965,44.875 19.6666667,43.7165277 19.6666667,42.2875 C19.6666667,40.8584723 18.5224965,39.7 17.1111111,39.7 Z M22.3506389,26.8925219 C20.9392535,26.8925219 19.7950833,28.0509941 19.7950833,29.4800219 C19.7950833,30.9090496 20.9392535,32.0675219 22.3506389,32.0675219 C23.7620243,32.0675219 24.9061944,30.9090496 24.9061944,29.4800219 C24.9061944,28.0509941 23.7620243,26.8925219 22.3506389,26.8925219 Z M47.6493611,26.8925219 C46.2379757,26.8925219 45.0938056,28.0509941 45.0938056,29.4800219 C45.0938056,30.9090496 46.2379757,32.0675219 47.6493611,32.0675219 C49.0607465,32.0675219 50.2049167,30.9090496 50.2049167,29.4800219 C50.2049167,28.0509941 49.0607465,26.8925219 47.6493611,26.8925219 Z M40.6952153,29.4423414 C39.686809,29.1156695 38.6082049,29.6784508 38.285566,30.6992195 L34.6181042,42.3034293 C31.9739028,42.501373 29.8888889,44.7346281 29.8888889,47.4625 C29.8888889,50.3205555 32.1772292,52.6375 35,52.6375 C37.8227708,52.6375 40.1111111,50.3205555 40.1111111,47.4625 C40.1111111,45.8636676 39.3946771,44.434559 38.269434,43.4852699 L41.9365764,31.8821113 C42.2591354,30.8612617 41.7033819,29.7690133 40.6952153,29.4423414 Z"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View file

@ -0,0 +1,104 @@
/** @odoo-module **/
import { Dropdown } from "@web/core/dropdown/dropdown";
import { registry } from "@web/core/registry";
import { useAutofocus, useService } from "@web/core/utils/hooks";
import { sprintf } from "@web/core/utils/strings";
const { Component, useState } = owl;
const favoriteMenuRegistry = registry.category("favoriteMenu");
/**
* 'Add to board' menu
*
* Component consisiting of a toggle button, a text input and an 'Add' button.
* The first button is simply used to toggle the component and will determine
* whether the other elements should be rendered.
* The input will be given the name (or title) of the view that will be added.
* Finally, the last button will send the name as well as some of the action
* properties to the server to add the current view (and its context) to the
* user's dashboard.
* This component is only available in actions of type 'ir.actions.act_window'.
* @extends Component
*/
export class AddToBoard extends Component {
setup() {
this.notification = useService("notification");
this.rpc = useService("rpc");
this.state = useState({ name: this.env.config.getDisplayName() });
useAutofocus();
}
//---------------------------------------------------------------------
// Protected
//---------------------------------------------------------------------
async addToBoard() {
const { domain, globalContext } = this.env.searchModel;
const { context, groupBys, orderBy } = this.env.searchModel.getPreFavoriteValues();
const comparison = this.env.searchModel.comparison;
const contextToSave = {
...Object.fromEntries(
Object.entries(globalContext).filter(
(entry) => !entry[0].startsWith("search_default_")
)
),
...context,
orderedBy: orderBy,
group_by: groupBys,
dashboard_merge_domains_contexts: false,
};
if (comparison) {
contextToSave.comparison = comparison;
}
const result = await this.rpc("/board/add_to_dashboard", {
action_id: this.env.config.actionId || false,
context_to_save: contextToSave,
domain,
name: this.state.name,
view_mode: this.env.config.viewType,
});
if (result) {
this.notification.add(
this.env._t("Please refresh your browser for the changes to take effect."),
{
title: sprintf(this.env._t(`"%s" added to dashboard`), this.state.name),
type: "warning",
}
);
this.state.name = this.env.config.getDisplayName();
} else {
this.notification.add(this.env._t("Could not add filter to dashboard"), {
type: "danger",
});
}
}
//---------------------------------------------------------------------
// Handlers
//---------------------------------------------------------------------
/**
* @param {KeyboardEvent} ev
*/
onInputKeydown(ev) {
if (ev.key === "Enter") {
ev.preventDefault();
this.addToBoard();
}
}
}
AddToBoard.template = "board.AddToBoard";
AddToBoard.components = { Dropdown };
export const addToBoardItem = {
Component: AddToBoard,
groupNumber: 4,
isDisplayed: ({ config }) => config.actionType === "ir.actions.act_window" && config.actionId,
};
favoriteMenuRegistry.add("add-to-board", addToBoardItem, { sequence: 10 });

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="board.AddToBoard" owl="1">
<Dropdown class="'o_add_to_board'">
<t t-set-slot="toggler">Add to my dashboard</t>
<div class="px-3 py-2">
<input type="text" class="o_input" t-ref="autofocus" t-model.trim="state.name" t-on-keydown="onInputKeydown" />
</div>
<div class="px-3 py-2">
<button type="button" class="btn btn-primary" t-on-click="addToBoard">Add</button>
</div>
</Dropdown>
</t>
</templates>

View file

@ -0,0 +1,160 @@
odoo.define("board.AddToBoardMenu", function (require) {
"use strict";
const Context = require("web.Context");
const Domain = require("web.Domain");
const { Dropdown } = require("@web/core/dropdown/dropdown");
const FavoriteMenu = require("web.FavoriteMenu");
const { sprintf } = require("web.utils");
const { useAutofocus } = require("@web/core/utils/hooks");
const { Component, useState } = owl;
/**
* 'Add to board' menu
*
* Component consisiting of a toggle button, a text input and an 'Add' button.
* The first button is simply used to toggle the component and will determine
* whether the other elements should be rendered.
* The input will be given the name (or title) of the view that will be added.
* Finally, the last button will send the name as well as some of the action
* properties to the server to add the current view (and its context) to the
* user's dashboard.
* This component is only available in actions of type 'ir.actions.act_window'.
*/
class AddToBoardMenu extends Component {
setup() {
this.interactive = true;
this.state = useState({
name: this.env.action.name || "",
open: false,
});
useAutofocus();
}
//---------------------------------------------------------------------
// Private
//---------------------------------------------------------------------
/**
* This is the main function for actually saving the dashboard. This method
* is supposed to call the route /board/add_to_dashboard with proper
* information.
* @private
*/
async addToBoard() {
const searchQuery = this.env.searchModel.get("query");
const context = new Context(this.env.action.context);
context.add(searchQuery.context);
context.add({
group_by: searchQuery.groupBy,
orderedBy: searchQuery.orderedBy,
});
if (
searchQuery.timeRanges &&
Object.prototype.hasOwnProperty.call(searchQuery.timeRanges, "fieldName")
) {
context.add({
comparison: searchQuery.timeRanges,
});
}
let controllerQueryParams;
this.env.searchModel.trigger("get-controller-query-params", (params) => {
controllerQueryParams = params || {};
});
controllerQueryParams.context = controllerQueryParams.context || {};
const queryContext = controllerQueryParams.context;
delete controllerQueryParams.context;
context.add(Object.assign(controllerQueryParams, queryContext));
const domainArray = new Domain(this.env.action.domain || []);
const domain = Domain.prototype.normalizeArray(
domainArray.toArray().concat(searchQuery.domain)
);
const evalutatedContext = context.eval();
for (const key in evalutatedContext) {
if (
Object.prototype.hasOwnProperty.call(evalutatedContext, key) &&
/^search_default_/.test(key)
) {
delete evalutatedContext[key];
}
}
evalutatedContext.dashboard_merge_domains_contexts = false;
Object.assign(this.state, {
name: $(".o_input").val() || "",
open: false,
});
const result = await this.env.services.rpc({
route: "/board/add_to_dashboard",
params: {
action_id: this.env.action.id || false,
context_to_save: evalutatedContext,
domain: domain,
view_mode: this.env.view.type,
name: this.state.name,
},
});
if (result) {
this.env.services.notification.notify({
title: sprintf(this.env._t("'%s' added to dashboard"), this.state.name),
message: this.env._t(
"Please refresh your browser for the changes to take effect."
),
type: "warning",
});
} else {
this.env.services.notification.notify({
message: this.env._t("Could not add filter to dashboard"),
type: "danger",
});
}
}
//---------------------------------------------------------------------
// Handlers
//---------------------------------------------------------------------
/**
* @private
* @param {KeyboardEvent} ev
*/
onInputKeydown(ev) {
switch (ev.key) {
case "Enter":
ev.preventDefault();
this.addToBoard();
break;
case "Escape":
// Gives the focus back to the component.
ev.preventDefault();
ev.target.blur();
break;
}
}
//---------------------------------------------------------------------
// Static
//---------------------------------------------------------------------
/**
* @param {Object} env
* @returns {boolean}
*/
static shouldBeDisplayed(env) {
return env.action.type === "ir.actions.act_window";
}
}
AddToBoardMenu.props = {};
AddToBoardMenu.template = "board.AddToBoard";
AddToBoardMenu.components = { Dropdown };
FavoriteMenu.registry.add("add-to-board-menu", AddToBoardMenu, 10);
return AddToBoardMenu;
});

View file

@ -0,0 +1,91 @@
/** @odoo-module **/
import { useService } from "@web/core/utils/hooks";
import { View } from "@web/views/view";
import { makeContext } from "@web/core/context";
const { Component, onWillStart } = owl;
export class BoardAction extends Component {
setup() {
const rpc = useService("rpc");
const userService = useService("user");
this.actionService = useService("action");
const action = this.props.action;
this.formViewId = false;
this.isValid = true;
onWillStart(async () => {
let result = BoardAction.cache[action.actionId];
if (!result) {
result = await rpc("/web/action/load", { action_id: action.actionId });
BoardAction.cache[action.actionId] = result;
}
if (!result) {
// action does not exist
this.isValid = false;
return;
}
const viewMode = action.viewMode || result.views[0][1];
const formView = result.views.find((v) => v[1] === "form");
if (formView) {
this.formViewId = formView[0];
}
this.viewProps = {
resModel: result.res_model,
type: viewMode,
display: { controlPanel: false },
selectRecord: (resId) => this.selectRecord(result.res_model, resId),
};
const view = result.views.find((v) => v[1] === viewMode);
if (view) {
this.viewProps.viewId = view[0];
}
const searchView = result.views.find((v) => v[1] === "search");
this.viewProps.views = [
[this.viewProps.viewId || false, viewMode],
[(searchView && searchView[0]) || false, "search"],
];
if (action.context) {
this.viewProps.context = makeContext([
action.context,
{ lang: userService.context.lang },
]);
if ("group_by" in this.viewProps.context) {
const groupBy = this.viewProps.context.group_by;
this.viewProps.groupBy = typeof groupBy === "string" ? [groupBy] : groupBy;
}
if ("comparison" in this.viewProps.context) {
const comparison = this.viewProps.context.comparison;
if (
comparison !== null &&
typeof comparison === "object" &&
"domains" in comparison &&
"fieldName" in comparison
) {
// Some comparison object with the wrong form might have been stored in db.
// This is why we make the checks on the keys domains and fieldName
this.viewProps.comparison = comparison;
}
}
}
if (action.domain) {
this.viewProps.domain = action.domain;
}
if (viewMode === "list") {
this.viewProps.allowSelectors = false;
}
});
}
selectRecord(resModel, resId) {
this.actionService.doAction({
type: "ir.actions.act_window",
res_model: resModel,
views: [[this.formViewId, "form"]],
res_id: resId,
});
}
}
BoardAction.template = "board.BoardAction";
BoardAction.components = { View };
BoardAction.cache = {};

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="board.BoardAction" owl="1">
<t t-if="isValid">
<View t-props="viewProps"/>
</t>
<t t-else="">
<div class="text-center text-warning m-1">Invalid action</div>
</t>
</t>
</templates>

View file

@ -0,0 +1,135 @@
/** @odoo-module **/
import { browser } from "@web/core/browser/browser";
import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
import { Dropdown } from "@web/core/dropdown/dropdown";
import { DropdownItem } from "@web/core/dropdown/dropdown_item";
import { useService } from "@web/core/utils/hooks";
import { renderToString } from "@web/core/utils/render";
import { useSortable } from "@web/core/utils/sortable";
import { standardViewProps } from "@web/views/standard_view_props";
import { BoardAction } from "./board_action";
const { blockDom, Component, useState, useRef } = owl;
export class BoardController extends Component {
setup() {
this.board = useState(this.props.board);
this.rpc = useService("rpc");
this.dialogService = useService("dialog");
if (this.env.isSmall) {
this.selectLayout("1", false);
} else {
const mainRef = useRef("main");
useSortable({
ref: mainRef,
elements: ".o-dashboard-action",
handle: ".o-dashboard-action-header",
cursor: "move",
groups: ".o-dashboard-column",
connectGroups: true,
onDrop: ({ element, previous, parent }) => {
const fromColIdx = parseInt(element.parentElement.dataset.idx, 10);
const fromActionIdx = parseInt(element.dataset.idx, 10);
const toColIdx = parseInt(parent.dataset.idx, 10);
const toActionIdx = previous ? parseInt(previous.dataset.idx, 10) + 1 : 0;
if (fromColIdx !== toColIdx) {
// to reduce visual flickering
element.classList.add("d-none");
}
this.moveAction(fromColIdx, fromActionIdx, toColIdx, toActionIdx);
},
});
}
}
moveAction(fromColIdx, fromActionIdx, toColIdx, toActionIdx) {
const action = this.board.columns[fromColIdx].actions[fromActionIdx];
if (fromColIdx !== toColIdx) {
// action moving from a column to another
this.board.columns[fromColIdx].actions.splice(fromActionIdx, 1);
this.board.columns[toColIdx].actions.splice(toActionIdx, 0, action);
} else {
// move inside a column
if (fromActionIdx === toActionIdx) {
return;
}
const actions = this.board.columns[fromColIdx].actions;
if (fromActionIdx < toActionIdx) {
actions.splice(toActionIdx + 1, 0, action);
actions.splice(fromActionIdx, 1);
} else {
actions.splice(fromActionIdx, 1);
actions.splice(toActionIdx, 0, action);
}
}
this.saveBoard();
}
selectLayout(layout, save = true) {
const currentColNbr = this.board.colNumber;
const nextColNbr = layout.split("-").length;
if (nextColNbr < currentColNbr) {
// need to move all actions in last cols in the last visible col
const cols = this.board.columns;
const lastVisibleCol = cols[nextColNbr - 1];
for (let i = nextColNbr; i < currentColNbr; i++) {
lastVisibleCol.actions.push(...cols[i].actions);
cols[i].actions = [];
}
}
this.board.layout = layout;
this.board.colNumber = nextColNbr;
if (save) {
this.saveBoard();
}
if (document.querySelector("canvas")) {
// horrible hack to force charts to be recreated so they pick up the
// proper size. also, no idea why raf is needed :(
browser.requestAnimationFrame(() => this.render(true));
}
}
closeAction(column, action) {
this.dialogService.add(ConfirmationDialog, {
body: this.env._t("Are you sure that you want to remove this item?"),
confirm: () => {
const index = column.actions.indexOf(action);
column.actions.splice(index, 1);
this.saveBoard();
},
cancel: () => {},
});
}
toggleAction(action, save = true) {
action.isFolded = !action.isFolded;
if (save) {
this.saveBoard();
}
}
saveBoard() {
const templateFn = renderToString.app.getTemplate("board.arch");
const bdom = templateFn(this.board, {});
const root = document.createElement("rendertostring");
blockDom.mount(bdom, root);
const result = xmlSerializer.serializeToString(root);
const arch = result.slice(result.indexOf("<", 1), result.indexOf("</rendertostring>"));
this.rpc("/web/view/edit_custom", {
custom_id: this.board.customViewId,
arch,
});
this.env.bus.trigger("CLEAR-CACHES");
}
}
BoardController.template = "board.BoardView";
BoardController.components = { BoardAction, Dropdown, DropdownItem };
BoardController.props = {
...standardViewProps,
board: Object,
};
const xmlSerializer = new XMLSerializer();

View file

@ -0,0 +1,46 @@
.o_dashboard {
height: 100%;
overflow: auto;
}
.o-dashboard-layout {
display: grid;
}
.o-dashboard-layout-1 {
grid-template-columns: 1fr;
}
.o-dashboard-layout-1-1 {
grid-template-columns: 1fr 1fr;
}
.o-dashboard-layout-1-1-1 {
grid-template-columns: 1fr 1fr 1fr;
}
.o-dashboard-layout-2-1 {
grid-template-columns: 2fr 1fr;
}
.o-dashboard-layout-1-2 {
grid-template-columns: 1fr 2fr;
}
.o-dashboard-column {
overflow-x: scroll;
}
.o-dashboard-action {
align-self: start;
> .o_view_controller {
padding: 0 12px 12px 12px;
.o_graph_renderer canvas {
height: 300px;
}
}
.o_column_quick_create, .o_control_panel {
display: none;
}
}
.o-dashboard-action > h3 > span > i {
font-size: 12px;
}

View file

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="board.BoardView" owl="1">
<div class="o_dashboard d-flex flex-column">
<t t-if="board.isEmpty">
<t t-call="board.NoContent"/>
</t>
<t t-else="">
<t t-call="board.Content"/>
</t>
</div>
</t>
<t t-name="board.Content" owl="1">
<div t-if="!env.isSmall" class="o-dashboard-header d-flex justify-content-end">
<Dropdown togglerClass="'btn btn-secondary m-2 p-2'">
<t t-set-slot="toggler">
<img t-attf-src="/board/static/img/layout_{{board.layout}}.png" width="16" height="16" alt=""/>
Change Layout
</t>
<t t-foreach="'1 1-1 1-1-1 1-2 2-1'.split(' ')" t-as="layout" t-key="layout">
<DropdownItem onSelected="() => this.selectLayout(layout)">
<img t-attf-src="/board/static/img/layout_{{layout}}.png" alt=""/>
<i t-if="layout == board.layout" class="fa fa-check fa-lg text-success" aria-label='Layout' role="img" title="Layout"/>
</DropdownItem>
</t>
</Dropdown>
</div>
<div class="o-dashboard-layout flex-grow-1" t-attf-class="o-dashboard-layout-{{board.layout}}" t-ref="main">
<t t-foreach="board.columns" t-as="column" t-key="column_index">
<div t-if="column_index lt board.colNumber" class="o-dashboard-column h-100" t-att-data-idx="column_index">
<t t-foreach="column.actions" t-as="action" t-key="action.id">
<div class="o-dashboard-action mx-3 my-1 bg-view border" t-att-data-idx="action_index">
<h3 t-attf-class="o-dashboard-action-header {{action.title ? '' : 'oe_header_empty'}} p-2 m-2">
<span> <t t-esc="action.title"/> </span>
<span t-if="!env.isSmall" class="btn float-end p-1 text-muted" t-on-click="() => this.closeAction(column, action)"><i class="fa fa-close"/></span>
<span class="btn float-end p-1 text-muted" t-if="!action.isFolded" t-on-click="() => this.toggleAction(action, !env.isSmall)"><i class="fa fa-window-minimize"/></span>
<span class="btn float-end p-1 text-muted" t-if="action.isFolded" t-on-click="() => this.toggleAction(action, !env.isSmall)"><i class="fa fa-window-maximize"/></span>
</h3>
<BoardAction t-if="!action.isFolded" action="action" />
</div>
</t>
</div>
</t>
</div>
</t>
<t t-name="board.NoContent" owl="1">
<div class="o_view_nocontent">
<div class="o_nocontent_help">
<p class="o_view_nocontent_neutral_face">
Your personal dashboard is empty
</p>
<p>
To add your first report into this dashboard, go to any
menu, switch to list or graph view, and click <i>"Add to
Dashboard"</i> in the extended search options.
</p>
<p>
You can filter and group data before inserting into the
dashboard using the search options.
</p>
</div>
</div>
</t>
<t t-name="board.arch" owl="1">
<form t-att-string="title">
<board t-att-style="layout">
<column t-foreach="columns" t-as="column" t-key="column_index">
<t t-foreach="column.actions" t-as="action" t-key="action_index">
<action
t-att-name="action.actionId"
t-att-string="action.title"
t-att-view_mode="action.viewMode"
t-att-context="action.context"
t-att-domain="action.domain"
t-att-fold="action.isFolded ? 1 : 0"/>
</t>
</column>
</board>
</form>
</t>
</templates>

View file

@ -0,0 +1,82 @@
/** @odoo-module **/
import { _lt } from "@web/core/l10n/translation";
import { registry } from "@web/core/registry";
import { BoardController } from "./board_controller";
import { XMLParser } from "@web/core/utils/xml";
import { Domain } from "@web/core/domain";
export class BoardArchParser extends XMLParser {
parse(arch, customViewId) {
let nextId = 1;
const archInfo = {
title: null,
layout: null,
colNumber: 0,
isEmpty: true,
columns: [{ actions: [] }, { actions: [] }, { actions: [] }],
customViewId,
};
let currentIndex = -1;
this.visitXML(arch, (node) => {
switch (node.tagName) {
case "form":
archInfo.title = node.getAttribute("string");
break;
case "board":
archInfo.layout = node.getAttribute("style");
archInfo.colNumber = archInfo.layout.split("-").length;
break;
case "column":
currentIndex++;
break;
case "action": {
archInfo.isEmpty = false;
const isFolded = Boolean(
node.hasAttribute("fold") ? parseInt(node.getAttribute("fold"), 10) : 0
);
let action = {
id: nextId++,
title: node.getAttribute("string"),
actionId: parseInt(node.getAttribute("name"), 10),
viewMode: node.getAttribute("view_mode"),
context: node.getAttribute("context"),
isFolded,
};
if (node.hasAttribute("domain")) {
let domain = node.getAttribute("domain");
// Since bfadb8e491fe2acda63a79f9577eaaec8a1c8d9c some databases might have
// double-encoded domains in the db, so we need to unescape them before use.
// TODO: remove unescape in saas-16.3
domain = _.unescape(domain);
action.domain = new Domain(domain).toList();
// so it can be serialized when reexporting board xml
action.domain.toString = () => node.getAttribute("domain");
}
archInfo.columns[currentIndex].actions.push(action);
break;
}
}
});
return archInfo;
}
}
export const boardView = {
type: "form",
display_name: _lt("Board"),
Controller: BoardController,
props: (genericProps, view) => {
const { arch, info } = genericProps;
const board = new BoardArchParser().parse(arch, info.customViewId);
return {
...genericProps,
className: "o_dashboard",
board,
};
},
};
registry.category("views").add("board", boardView);

View file

@ -0,0 +1,526 @@
/** @odoo-module **/
import { addToBoardItem } from "@board/add_to_board/add_to_board";
import {
click,
getFixture,
patchWithCleanup,
mouseEnter,
triggerEvent,
} from "@web/../tests/helpers/utils";
import {
applyFilter,
applyGroup,
editConditionField,
editConditionOperator,
editConditionValue,
removeFacet,
toggleAddCustomFilter,
toggleAddCustomGroup,
toggleComparisonMenu,
toggleFavoriteMenu,
toggleFilterMenu,
toggleGroupByMenu,
toggleMenuItem,
toggleMenuItemOption,
} from "@web/../tests/search/helpers";
import { createWebClient, doAction } from "@web/../tests/webclient/helpers";
import { browser } from "@web/core/browser/browser";
import { registry } from "@web/core/registry";
import LegacyAddToBoard from "board.AddToBoardMenu";
import LegacyFavoriteMenu from "web.FavoriteMenu";
import testUtils from "web.test_utils";
import { makeFakeUserService } from "@web/../tests/helpers/mock_services";
const patchDate = testUtils.mock.patchDate;
const favoriteMenuRegistry = registry.category("favoriteMenu");
let serverData;
let target;
QUnit.module("Board", (hooks) => {
hooks.beforeEach(() => {
const models = {
board: {
fields: {},
records: [],
},
partner: {
fields: {
display_name: { string: "Displayed name", type: "char", searchable: true },
foo: {
string: "Foo",
type: "char",
default: "My little Foo Value",
searchable: true,
},
bar: { string: "Bar", type: "boolean" },
int_field: {
string: "Integer field",
type: "integer",
group_operator: "sum",
},
},
records: [
{
id: 1,
display_name: "first record",
foo: "yop",
int_field: 3,
},
{
id: 2,
display_name: "second record",
foo: "lalala",
int_field: 5,
},
{
id: 4,
display_name: "aaa",
foo: "abc",
int_field: 2,
},
],
},
};
LegacyFavoriteMenu.registry.add("add-to-board-menu", LegacyAddToBoard, 10);
favoriteMenuRegistry.add("add-to-board", addToBoardItem, { sequence: 10 });
serverData = { models };
target = getFixture();
});
QUnit.module("Add to dashboard");
QUnit.test("save actions to dashboard", async function (assert) {
assert.expect(6);
serverData.models.partner.fields.foo.sortable = true;
serverData.views = {
"partner,false,list": '<list><field name="foo"/></list>',
"partner,false,search": "<search></search>",
};
patchWithCleanup(browser, { setTimeout: (fn) => fn() });
const mockRPC = (route, args) => {
if (route === "/board/add_to_dashboard") {
assert.deepEqual(
args.context_to_save.group_by,
["foo"],
"The group_by should have been saved"
);
assert.deepEqual(
args.context_to_save.orderedBy,
[
{
name: "foo",
asc: true,
},
],
"The orderedBy should have been saved"
);
assert.strictEqual(
args.context_to_save.fire,
"on the bayou",
"The context of a controller should be passed and flattened"
);
assert.strictEqual(args.action_id, 1, "should save the correct action");
assert.strictEqual(args.view_mode, "list", "should save the correct view type");
return Promise.resolve(true);
}
};
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
context: { fire: "on the bayou" },
views: [[false, "list"]],
});
assert.containsOnce(target, ".o_list_view", "should display the list view");
// Sort the list
await click(document.querySelector(".o_column_sortable"));
// Group It
await toggleGroupByMenu(target);
await toggleAddCustomGroup(target);
await applyGroup(target);
// add this action to dashboard
await toggleFavoriteMenu(target);
await testUtils.dom.triggerEvent($(".o_add_to_board button.dropdown-toggle"), "mouseenter");
await testUtils.fields.editInput($(".o_add_to_board input"), "a name");
await testUtils.dom.click($(".o_add_to_board .dropdown-menu button"));
});
QUnit.test("save two searches to dashboard", async function (assert) {
// the second search saved should not be influenced by the first
assert.expect(2);
patchWithCleanup(browser, { setTimeout: (fn) => fn() });
serverData.views = {
"partner,false,list": '<list><field name="foo"/></list>',
"partner,false,search": "<search></search>",
};
const mockRPC = (route, args) => {
if (route === "/board/add_to_dashboard") {
if (filter_count === 0) {
assert.deepEqual(
args.domain,
[["display_name", "ilike", "a"]],
"the correct domain should be sent"
);
}
if (filter_count === 1) {
assert.deepEqual(
args.domain,
[["display_name", "ilike", "b"]],
"the correct domain should be sent"
);
}
filter_count += 1;
return Promise.resolve(true);
}
};
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "list"]],
});
var filter_count = 0;
// Add a first filter
await toggleFilterMenu(target);
await toggleAddCustomFilter(target);
await editConditionValue(target, 0, "a");
await applyFilter(target);
// Add it to dashboard
await toggleFavoriteMenu(target);
await testUtils.dom.triggerEvent($(".o_add_to_board button.dropdown-toggle"), "mouseenter");
await testUtils.dom.click($(".o_add_to_board .dropdown-menu button"));
// Remove it
await testUtils.dom.click(target.querySelector(".o_facet_remove"));
// Add the second filter
await toggleFilterMenu(target);
await toggleAddCustomFilter(target);
await editConditionValue(target, 0, "b");
await applyFilter(target);
// Add it to dashboard
await toggleFavoriteMenu(target);
await testUtils.dom.triggerEvent(
target.querySelector(".o_add_to_board button.dropdown-toggle"),
"mouseenter"
);
await testUtils.dom.click(target.querySelector(".o_add_to_board .dropdown-menu button"));
});
QUnit.test("save a action domain to dashboard", async function (assert) {
// View domains are to be added to the dashboard domain
assert.expect(1);
patchWithCleanup(browser, { setTimeout: (fn) => fn() });
var view_domain = ["display_name", "ilike", "a"];
var filter_domain = ["display_name", "ilike", "b"];
var expected_domain = ["&", view_domain, filter_domain];
serverData.views = {
"partner,false,list": '<list><field name="foo"/></list>',
"partner,false,search": "<search></search>",
};
const mockRPC = (route, args) => {
if (route === "/board/add_to_dashboard") {
assert.deepEqual(args.domain, expected_domain, "the correct domain should be sent");
return Promise.resolve(true);
}
};
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "list"]],
domain: [view_domain],
});
// Add a filter
await toggleFilterMenu(target);
await toggleAddCustomFilter(target);
await editConditionValue(target, 0, "b");
await applyFilter(target);
// Add it to dashboard
await toggleFavoriteMenu(target);
await testUtils.dom.triggerEvent(
target.querySelector(".o_add_to_board button.dropdown-toggle"),
"mouseenter"
);
// add
await testUtils.dom.click(target.querySelector(".o_add_to_board .dropdown-menu button"));
});
QUnit.test("add to dashboard with no action id", async function (assert) {
assert.expect(2);
serverData.views = {
"partner,false,pivot": '<pivot><field name="foo"/></pivot>',
"partner,false,search": "<search/>",
};
registry.category("services").add("user", makeFakeUserService());
const webClient = await createWebClient({ serverData });
await doAction(webClient, {
id: false,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
});
await toggleFavoriteMenu(target);
assert.containsNone(target, ".o_add_to_board");
// Sanity check
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
});
await toggleFavoriteMenu(target);
assert.containsOnce(target, ".o_add_to_board");
});
QUnit.test(
"correctly save the time ranges of a reporting view in comparison mode",
async function (assert) {
assert.expect(1);
const unpatchDate = patchDate(2020, 6, 1, 11, 0, 0);
serverData.models.partner.fields.date = {
string: "Date",
type: "date",
sortable: true,
};
serverData.views = {
"partner,false,pivot": '<pivot><field name="foo"/></pivot>',
"partner,false,search": '<search><filter name="Date" date="date"/></search>',
};
const mockRPC = (route, args) => {
if (route === "/board/add_to_dashboard") {
assert.deepEqual(args.context_to_save.comparison, {
domains: [
{
arrayRepr: [
"&",
["date", ">=", "2020-07-01"],
["date", "<=", "2020-07-31"],
],
description: "July 2020",
},
{
arrayRepr: [
"&",
["date", ">=", "2020-06-01"],
["date", "<=", "2020-06-30"],
],
description: "June 2020",
},
],
fieldName: "date",
});
return Promise.resolve(true);
}
};
registry.category("services").add("user", makeFakeUserService());
patchWithCleanup(browser, { setTimeout: (fn) => fn() }); // makes mouseEnter work
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
});
// filter on July 2020
await toggleFilterMenu(target);
await toggleMenuItem(target, "Date");
await toggleMenuItemOption(target, "Date", "July");
// compare July 2020 to June 2020
await toggleComparisonMenu(target);
await toggleMenuItem(target, 0);
// add the view to the dashboard
await toggleFavoriteMenu(target);
await mouseEnter(target.querySelector(".o_add_to_board .dropdown-toggle"));
const input = target.querySelector(".o_add_to_board .dropdown-menu input");
await testUtils.fields.editInput(input, "Pipeline");
await testUtils.dom.click($(".o_add_to_board div button"));
unpatchDate();
}
);
QUnit.test("Add a view to dashboard (keynav)", async function (assert) {
serverData.views = {
"partner,false,pivot": '<pivot><field name="foo"/></pivot>',
"partner,false,search": "<search/>",
};
registry.category("services").add("user", makeFakeUserService());
patchWithCleanup(browser, { setTimeout: (fn) => fn() }); // makes mouseEnter work
const mockRPC = (route) => {
if (route === "/board/add_to_dashboard") {
assert.step("add to board");
return Promise.resolve(true);
}
};
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
});
await toggleFavoriteMenu(target);
await mouseEnter(target.querySelector(".o_add_to_board .dropdown-toggle"));
const input = target.querySelector(".o_add_to_board .dropdown-menu input");
await testUtils.fields.editInput(input, "Pipeline");
await triggerEvent(input, null, "keydown", { key: "Enter" });
assert.verifySteps(["add to board"]);
});
QUnit.test("Add a view with dynamic domain", async function (assert) {
assert.expect(1);
serverData.views = {
"partner,false,pivot": '<pivot><field name="foo"/></pivot>',
"partner,false,search": `
<search>
<filter name="filter" domain="[('user_id','=',uid)]"/>
</search>`,
};
registry.category("services").add("user", makeFakeUserService());
patchWithCleanup(browser, { setTimeout: (fn) => fn() }); // makes mouseEnter work
const mockRPC = (route, args) => {
if (route === "/board/add_to_dashboard") {
assert.deepEqual(args.domain, ["&", ["int_field", "<=", 3], ["user_id", "=", 7]]);
return Promise.resolve(true);
}
};
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "pivot"]],
domain: [["int_field", "<=", 3]],
context: { search_default_filter: 1 },
});
await toggleFavoriteMenu(target);
await mouseEnter(target.querySelector(".o_add_to_board .dropdown-toggle"));
const input = target.querySelector(".o_add_to_board .dropdown-menu input");
await testUtils.fields.editInput(input, "Pipeline");
await triggerEvent(input, null, "keydown", { key: "Enter" });
});
QUnit.test("Add a view to dashboard doesn't save default filters", async function (assert) {
assert.expect(2);
serverData.views = {
"partner,false,pivot": '<pivot><field name="foo"/></pivot>',
"partner,false,list": '<list><field name="foo"/></list>',
"partner,false,search": `
<search>
<filter name="filter" domain="[('foo','!=','yop')]"/>
</search>`,
};
registry.category("services").add("user", makeFakeUserService());
patchWithCleanup(browser, { setTimeout: (fn) => fn() }); // makes mouseEnter work
const mockRPC = (route, args) => {
if (route === "/board/add_to_dashboard") {
assert.deepEqual(args.domain, [["foo", "=", "yop"]]);
assert.deepEqual(args.context_to_save, {
pivot_measures: ["__count"],
pivot_column_groupby: [],
pivot_row_groupby: [],
orderedBy: [],
group_by: [],
dashboard_merge_domains_contexts: false,
});
return Promise.resolve(true);
}
};
const webClient = await createWebClient({ serverData, mockRPC });
await doAction(webClient, {
id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [
[false, "list"],
[false, "pivot"],
],
context: { search_default_filter: 1 },
});
await click(target, ".o_switch_view.o_pivot");
// Remove default filter ['foo', '!=', 'yop']
await removeFacet(target);
// Add a filter ['foo', '=', 'yop']
await toggleFilterMenu(target);
await toggleAddCustomFilter(target);
await editConditionField(target, 0, "foo");
await editConditionOperator(target, 0, "=");
await editConditionValue(target, 0, "yop");
await applyFilter(target);
// Add to dashboard
await toggleFavoriteMenu(target);
await mouseEnter(target.querySelector(".o_add_to_board .dropdown-toggle"));
const input = target.querySelector(".o_add_to_board .dropdown-menu input");
await testUtils.fields.editInput(input, "Pipeline");
await triggerEvent(input, null, "keydown", { key: "Enter" });
});
});

View file

@ -0,0 +1,907 @@
/** @odoo-module **/
import { BoardAction } from "@board/board_action";
import { fakeCookieService } from "@web/../tests/helpers/mock_services";
import { click, dragAndDrop, getFixture, patchWithCleanup } from "@web/../tests/helpers/utils";
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
import { registry } from "@web/core/registry";
import { session } from "@web/session";
import AbstractModel from "web.AbstractModel";
import AbstractView from "web.AbstractView";
import ListView from "web.ListView";
import legacyViewRegistry from "web.view_registry";
const serviceRegistry = registry.category("services");
let serverData;
let target;
QUnit.module("Board", (hooks) => {
hooks.beforeEach(async () => {
target = getFixture();
BoardAction.cache = {};
serverData = {
models: {
board: {
fields: {},
records: [],
},
partner: {
fields: {
display_name: { string: "Displayed name", type: "char", searchable: true },
foo: {
string: "Foo",
type: "char",
default: "My little Foo Value",
searchable: true,
},
bar: { string: "Bar", type: "boolean" },
int_field: {
string: "Integer field",
type: "integer",
group_operator: "sum",
},
},
records: [
{
id: 1,
display_name: "first record",
foo: "yop",
int_field: 3,
},
{
id: 2,
display_name: "second record",
foo: "lalala",
int_field: 5,
},
{
id: 4,
display_name: "aaa",
foo: "abc",
int_field: 2,
},
],
},
},
views: {
"partner,100000001,form": "<form/>",
"partner,100000002,search": "<search/>",
},
};
setupViewRegistries();
});
QUnit.module("BoardView");
QUnit.test("display the no content helper", async function (assert) {
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column></column>
</board>
</form>`,
});
assert.containsOnce(target, ".o_view_nocontent");
});
QUnit.test("basic functionality, with one sub action", async function (assert) {
assert.expect(23);
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
assert.step("load action");
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
if (route === "/web/dataset/call_kw/partner/web_search_read") {
assert.deepEqual(
args.kwargs.domain,
[["foo", "!=", "False"]],
"the domain should be passed"
);
assert.deepEqual(
args.kwargs.context.orderedBy,
[
{
name: "foo",
asc: true,
},
],
"orderedBy is present in the search read when specified on the custom action"
);
}
if (route === "/web/view/edit_custom") {
assert.step("edit custom");
return Promise.resolve(true);
}
if (args.method === "get_views" && args.model == "partner") {
assert.deepEqual(
args.kwargs.views.find((v) => v[1] === "list"),
[4, "list"]
);
}
},
});
assert.containsOnce(target, ".o-dashboard-header", "should have rendered a header");
assert.containsOnce(
target,
"div.o-dashboard-layout-2-1",
"should have rendered a div with layout"
);
assert.containsNone(
target,
"td.o_list_record_selector",
"td should not have a list selector"
);
assert.containsOnce(
target,
"h3 span:contains(ABC)",
"should have rendered a header with action string"
);
assert.containsN(target, "tr.o_data_row", 3, "should have rendered 3 data rows");
assert.containsOnce(target, ".o-dashboard-action .o_list_view");
await click(target, "h3 i.fa-window-minimize");
assert.containsNone(target, ".o-dashboard-action .o_list_view");
await click(target, "h3 i.fa-window-maximize");
// content is visible again
assert.containsOnce(target, ".o-dashboard-action .o_list_view");
assert.verifySteps(["load action", "edit custom", "edit custom"]);
// header should have dropdown with correct image
assert.containsOnce(
target,
".o-dashboard-header .dropdown img[data-src='/board/static/img/layout_2-1.png']"
);
// change layout to 1-1
await click(target, ".o-dashboard-header .dropdown img");
await click(target, ".o-dashboard-header .dropdown-item:nth-child(2)");
assert.containsOnce(
target,
".o-dashboard-header .dropdown img[data-src='/board/static/img/layout_1-1.png']"
);
assert.containsOnce(
target,
"div.o-dashboard-layout-1-1",
"should have rendered a div with layout"
);
assert.verifySteps(["edit custom"]);
});
QUnit.test("views in the dashboard do not have a control panel", async function (assert) {
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [
[4, "list"],
[5, "form"],
],
});
}
},
});
assert.containsOnce(target, ".o-dashboard-action .o_list_view");
assert.containsNone(target, ".o-dashboard-action .o_control_panel");
});
QUnit.test("can render an action without view_mode attribute", async function (assert) {
// The view_mode attribute is automatically set to the 'action' nodes when
// the action is added to the dashboard using the 'Add to dashboard' button
// in the searchview. However, other dashboard views can be written by hand
// (see openacademy tutorial), and in this case, we don't want hardcode
// action's params (like context or domain), as the dashboard can directly
// retrieve them from the action. Same applies for the view_type, as the
// first view of the action can be used, by default.
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [
[4, "list"],
[false, "form"],
],
});
}
},
});
assert.containsOnce(target, ".o-dashboard-action .o_list_view");
});
QUnit.test("can sort a sub list", async function (assert) {
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
serverData.models.partner.fields.foo.sortable = true;
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
},
});
assert.strictEqual(
$("tr.o_data_row").text(),
"yoplalalaabc",
"should have correct initial data"
);
await click($(target).find("th.o_column_sortable:contains(Foo)")[0]);
assert.strictEqual(
$("tr.o_data_row").text(),
"abclalalayop",
"data should have been sorted"
);
});
QUnit.test("can open a record", async function (assert) {
assert.expect(1);
const fakeActionService = {
start() {
return {
doAction(action) {
assert.deepEqual(action, {
res_id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "form"]],
});
return Promise.resolve(true);
},
};
},
};
serviceRegistry.add("action", fakeActionService, { force: true });
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
serverData.models.partner.fields.foo.sortable = true;
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
},
});
await click($(target).find("tr.o_data_row td:contains(yop)")[0]);
});
QUnit.test("can open record using action form view", async function (assert) {
assert.expect(1);
const fakeActionService = {
start() {
return {
doAction(action) {
assert.deepEqual(action, {
res_id: 1,
res_model: "partner",
type: "ir.actions.act_window",
views: [[5, "form"]],
});
return Promise.resolve(true);
},
};
},
};
serviceRegistry.add("action", fakeActionService, { force: true });
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
serverData.views["partner,5,form"] =
'<form string="Partner"><field name="display_name"/></form>';
serverData.models.partner.fields.foo.sortable = true;
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [
[4, "list"],
[5, "form"],
],
});
}
},
});
await click($(target).find("tr.o_data_row td:contains(yop)")[0]);
});
QUnit.skip("can drag and drop a view", async function (assert) {
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
if (route === "/web/view/edit_custom") {
assert.step("edit custom");
return Promise.resolve(true);
}
},
});
assert.strictEqual(
target.querySelectorAll('.o-dashboard-column[data-idx="0"] .o-dashboard-action').length,
1
);
assert.strictEqual(
target.querySelectorAll('.o-dashboard-column[data-idx="1"] .o-dashboard-action').length,
0
);
await dragAndDrop(
'.o-dashboard-column[data-idx="0"] .o-dashboard-action-header',
'.o-dashboard-column[data-idx="1"]'
);
assert.strictEqual(
target.querySelectorAll('.o-dashboard-column[data-idx="0"] .o-dashboard-action').length,
0
);
assert.strictEqual(
target.querySelectorAll('.o-dashboard-column[data-idx="1"] .o-dashboard-action').length,
1
);
assert.verifySteps(["edit custom"]);
});
QUnit.test("twice the same action in a dashboard", async function (assert) {
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
serverData.views["partner,5,kanban"] = `
<kanban>
<templates>
<t t-name="kanban-box">
<div><field name="foo"/></div>
</t>
</templates>
</kanban>`;
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{}" view_mode="list" string="ABC" name="51" domain="[]"></action>
<action context="{}" view_mode="kanban" string="DEF" name="51" domain="[]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [
[4, "list"],
[5, "kanban"],
],
});
}
if (route === "/web/view/edit_custom") {
assert.step("edit custom");
return Promise.resolve(true);
}
},
});
var $firstAction = $(".o-dashboard-action:eq(0)");
assert.strictEqual(
$firstAction.find(".o_list_view").length,
1,
"list view should be displayed in 'ABC' block"
);
var $secondAction = $(".o-dashboard-action:eq(1)");
assert.strictEqual(
$secondAction.find(".o_kanban_view").length,
1,
"kanban view should be displayed in 'DEF' block"
);
});
QUnit.test("clicking on a kanban's button should trigger the action", async function (assert) {
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
// server answer if the action doesn't exist anymore
return Promise.resolve(false);
}
},
});
assert.containsOnce(target, "h3 span:contains(ABC)");
assert.containsOnce(target, "div.text-center:contains(Invalid action)");
});
QUnit.test("twice the same action in a dashboard", async function (assert) {
assert.expect(4);
serverData.views["partner,false,kanban"] = `
<kanban>
<templates>
<t t-name="kanban-box">
<div>
<div><field name="foo"/></div>
<button name="sitting_on_a_park_bench" type="object">Eying little girls with bad intent</button>
</div>
</t>
</templates>
</kanban>`;
const view = await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action name="149" string="Partner" view_mode="kanban" id="action_0_1"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
view_mode: "kanban",
views: [[false, "kanban"]],
});
}
if (route === "/web/dataset/search_read") {
return Promise.resolve({ records: [{ foo: "aqualung" }] });
}
},
});
patchWithCleanup(view.env.services.action, {
doActionButton(params) {
assert.strictEqual(params.resModel, "partner");
assert.strictEqual(params.resId, 1);
assert.strictEqual(params.name, "sitting_on_a_park_bench");
assert.strictEqual(params.type, "object");
},
});
await click(document.querySelector(".btn.oe_kanban_action"));
});
QUnit.test("Views should be loaded in the user's language", async function (assert) {
assert.expect(2);
patchWithCleanup(session.user_context, { lang: "fr_FR" });
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{'lang': 'en_US'}" view_mode="list" string="ABC" name="51" domain="[]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
if (args.method === "get_views") {
assert.strictEqual(args.kwargs.context.lang, "fr_FR");
}
},
});
});
QUnit.test("Dashboard should use correct groupby", async function (assert) {
assert.expect(1);
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{'group_by': ['bar']}" string="ABC" name="51"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
if (args.method === "web_read_group") {
assert.deepEqual(args.kwargs.groupby, ["bar"]);
}
},
});
});
QUnit.test("Dashboard should read comparison from context", async function (assert) {
assert.expect(2);
serverData.views["partner,4,pivot"] =
'<pivot><field name="int_field" type="measure"/></pivot>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action
name="356"
string="Sales Analysis pivot"
view_mode="pivot"
context="{
'comparison': {
'fieldName': 'date',
'domains': [
{
'arrayRepr': [],
'description': 'February 2023',
},
{
'arrayRepr': [],
'description': 'January 2023',
},
]
},
}"
/>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "pivot"]],
});
}
},
});
const columns = document.querySelectorAll(".o_pivot_origin_row");
assert.equal(columns[0].firstChild.textContent, "January 2023");
assert.equal(columns[1].firstChild.textContent, "February 2023");
});
QUnit.test(
"Dashboard should use correct groupby when defined as a string of one field",
async function (assert) {
assert.expect(1);
serverData.views["partner,4,list"] =
'<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{'group_by': 'bar'}" string="ABC" name="51"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
if (args.method === "web_read_group") {
assert.deepEqual(args.kwargs.groupby, ["bar"]);
}
},
});
}
);
QUnit.test(
"Dashboard should pass groupbys to legacy views",
async function (assert) {
assert.expect(2);
const TestModel = AbstractModel.extend({
__load: function (params) {
assert.deepEqual(params.groupedBy, ["bar"]);
}
});
const TestGridView = AbstractView.extend({
viewType: 'test_grid',
config: Object.assign({}, AbstractView.prototype.config, {
Model: TestModel,
}),
init: function (viewInfo, params) {
this._super.apply(this, arguments);
assert.deepEqual(params.groupBy, ["bar"]);
this.loadParams.groupedBy = params.groupBy;
}
});
legacyViewRegistry.add("test_grid", TestGridView);
serverData.views["partner,false,test_grid"] = `<div/>`;
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{'group_by': 'bar'}" string="ABC" name="51"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[false, "test_grid"]],
});
}
},
});
delete legacyViewRegistry.map.test_grid
}
);
QUnit.test("click on a cell of pivot view inside dashboard", async function (assert) {
serverData.views["partner,4,pivot"] =
'<pivot><field name="int_field" type="measure"/></pivot>';
const fakeActionService = {
start() {
return {
doAction(action) {
assert.step("do action");
assert.deepEqual(action.views, [
[false, "list"],
[false, "form"],
]);
},
};
},
};
serviceRegistry.add("action", fakeActionService, { force: true });
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action view_mode="pivot" string="ABC" name="51"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "pivot"]],
});
}
if (args.method === "web_read_group") {
assert.deepEqual(args.kwargs.groupby, ["bar"]);
}
},
});
assert.verifySteps([]);
await click(document.querySelector(".o_pivot_view .o_pivot_cell_value"));
assert.verifySteps(["do action"]);
});
QUnit.test("graphs in dashboard aren't squashed", async function (assert) {
registry.category("services").add("cookie", fakeCookieService);
serverData.views["partner,4,graph"] =
'<graph><field name="int_field" type="measure"/></graph>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action string="ABC" name="51"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "graph"]],
});
}
},
});
assert.containsOnce(target, ".o-dashboard-action .o_graph_renderer");
assert.strictEqual(
target.querySelector(".o-dashboard-action .o_graph_renderer canvas").offsetHeight,
300
);
});
QUnit.test("Carry over the filter to legacy views", async function (assert) {
const TestView = ListView.extend({
viewType: "test_view",
});
legacyViewRegistry.add("test_view", TestView);
serverData.views["partner,false,test_view"] = `<tree string="Partner"></tree>`;
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action string="ABC" name="Partners Action 1" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return {
id: 1,
name: "Partners Action 1",
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "test_view"]],
};
}
if (route === "/web/dataset/search_read") {
assert.deepEqual(args.domain, [["foo", "!=", "False"]]);
}
},
});
});
});

View file

@ -0,0 +1,124 @@
/** @odoo-module **/
import { getFixture } from "@web/../tests/helpers/utils";
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
let serverData;
let target;
QUnit.module("Board", (hooks) => {
hooks.beforeEach(async () => {
target = getFixture();
serverData = {
models: {
board: {
fields: {},
records: [],
},
partner: {
fields: {
foo: {
string: "Foo",
type: "char",
default: "My little Foo Value",
searchable: true,
},
},
records: [
{
id: 1,
foo: "yop",
},
],
},
},
views: {
"partner,100000001,form": "<form/>",
"partner,100000002,search": "<search/>",
},
};
setupViewRegistries();
});
QUnit.module("BoardView");
QUnit.test("can't switch views in the dashboard", async (assert) => {
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
},
});
assert.containsNone(target, ".o-dashboard-header", "Couldn't allow user to Change layout");
assert.containsOnce(target, ".o-dashboard-layout-1", "The display layout is force to 1");
assert.isNotVisible(
target.querySelector(".o-dashboard-action .o_control_panel"),
"views in the dashboard do not have a control panel"
);
assert.containsNone(
target,
".o-dashboard-action-header .fa-close",
"Should not have a close action button"
);
});
QUnit.test("Correctly soft switch to '1' layout on small screen", async function (assert) {
serverData.views["partner,4,list"] = '<tree string="Partner"><field name="foo"/></tree>';
await makeView({
serverData,
type: "form",
resModel: "board",
arch: `
<form string="My Dashboard" js_class="board">
<board style="2-1">
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
<column>
<action context="{&quot;orderedBy&quot;: [{&quot;name&quot;: &quot;foo&quot;, &quot;asc&quot;: True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
</column>
</board>
</form>`,
mockRPC(route, args) {
if (route === "/web/action/load") {
return Promise.resolve({
res_model: "partner",
views: [[4, "list"]],
});
}
},
});
assert.containsOnce(target, ".o-dashboard-layout-1", "The display layout is force to 1");
assert.containsOnce(
target,
".o-dashboard-column",
"The display layout is force to 1 column"
);
assert.containsN(
target,
".o-dashboard-action",
2,
"The display should contains the 2 actions"
);
});
});