mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-21 01:32:02 +02:00
19.0 vanilla
This commit is contained in:
parent
d1963a3c3a
commit
2d3ee4855a
7430 changed files with 2687981 additions and 2965473 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 1.3 KiB |
|
|
@ -1,23 +1 @@
|
|||
<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>
|
||||
<svg width="50" height="50" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><path d="M4 8a4 4 0 0 1 4-4h17v17a4 4 0 0 1-4 4H4V8Z" fill="#FC868B"/><path d="M4 35a4 4 0 0 1 4-4h11v11a4 4 0 0 1-4 4H4V35Z" fill="#F9464C"/><path d="M25 46h4a4 4 0 0 0 4-4V31h-4a4 4 0 0 0-4 4v11Z" fill="#FBB945"/><path d="M31 17v4a4 4 0 0 0 4 4h11v-4a4 4 0 0 0-4-4H31Z" fill="#088BF5"/><path d="M31 4v4a4 4 0 0 0 4 4h11V8a4 4 0 0 0-4-4H31Z" fill="#2EBCFA"/><path d="M38 46h4a4 4 0 0 0 4-4V31h-4a4 4 0 0 0-4 4v11Z" fill="#F78613"/></svg>
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 522 B |
BIN
odoo-bringout-oca-ocb-board/board/static/description/icon_hi.png
Normal file
BIN
odoo-bringout-oca-ocb-board/board/static/description/icon_hi.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.8 KiB |
|
|
@ -1,12 +1,11 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { Dropdown } from "@web/core/dropdown/dropdown";
|
||||
import { rpc } from "@web/core/network/rpc";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { useAutofocus, useService } from "@web/core/utils/hooks";
|
||||
import { sprintf } from "@web/core/utils/strings";
|
||||
import { Component, useState } from "@odoo/owl";
|
||||
|
||||
const { Component, useState } = owl;
|
||||
const favoriteMenuRegistry = registry.category("favoriteMenu");
|
||||
const cogMenuRegistry = registry.category("cogMenu");
|
||||
|
||||
/**
|
||||
* 'Add to board' menu
|
||||
|
|
@ -22,9 +21,12 @@ const favoriteMenuRegistry = registry.category("favoriteMenu");
|
|||
* @extends Component
|
||||
*/
|
||||
export class AddToBoard extends Component {
|
||||
static template = "board.AddToBoard";
|
||||
static components = { Dropdown };
|
||||
static props = {};
|
||||
|
||||
setup() {
|
||||
this.notification = useService("notification");
|
||||
this.rpc = useService("rpc");
|
||||
this.state = useState({ name: this.env.config.getDisplayName() });
|
||||
|
||||
useAutofocus();
|
||||
|
|
@ -37,7 +39,6 @@ export class AddToBoard extends Component {
|
|||
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(
|
||||
|
|
@ -49,11 +50,8 @@ export class AddToBoard extends Component {
|
|||
group_by: groupBys,
|
||||
dashboard_merge_domains_contexts: false,
|
||||
};
|
||||
if (comparison) {
|
||||
contextToSave.comparison = comparison;
|
||||
}
|
||||
|
||||
const result = await this.rpc("/board/add_to_dashboard", {
|
||||
const result = await rpc("/board/add_to_dashboard", {
|
||||
action_id: this.env.config.actionId || false,
|
||||
context_to_save: contextToSave,
|
||||
domain,
|
||||
|
|
@ -63,15 +61,15 @@ export class AddToBoard extends Component {
|
|||
|
||||
if (result) {
|
||||
this.notification.add(
|
||||
this.env._t("Please refresh your browser for the changes to take effect."),
|
||||
_t("Please refresh your browser for the changes to take effect."),
|
||||
{
|
||||
title: sprintf(this.env._t(`"%s" added to dashboard`), this.state.name),
|
||||
title: _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"), {
|
||||
this.notification.add(_t("Could not add filter to dashboard"), {
|
||||
type: "danger",
|
||||
});
|
||||
}
|
||||
|
|
@ -92,13 +90,13 @@ export class AddToBoard extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
AddToBoard.template = "board.AddToBoard";
|
||||
AddToBoard.components = { Dropdown };
|
||||
|
||||
export const addToBoardItem = {
|
||||
Component: AddToBoard,
|
||||
groupNumber: 4,
|
||||
isDisplayed: ({ config }) => config.actionType === "ir.actions.act_window" && config.actionId,
|
||||
groupNumber: 20,
|
||||
isDisplayed: ({ config }) => {
|
||||
const { actionType, actionId, viewType } = config;
|
||||
return actionType === "ir.actions.act_window" && actionId && viewType !== "form";
|
||||
},
|
||||
};
|
||||
|
||||
favoriteMenuRegistry.add("add-to-board", addToBoardItem, { sequence: 10 });
|
||||
cogMenuRegistry.add("add-to-board", addToBoardItem, { sequence: 10 });
|
||||
|
|
|
|||
|
|
@ -1,16 +1,32 @@
|
|||
<?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 t-name="board.AddToBoard">
|
||||
<div class="o_add_to_board">
|
||||
<Dropdown>
|
||||
<button>
|
||||
<t t-call="Dashboard.DashboardIcon"/>
|
||||
Dashboard
|
||||
</button>
|
||||
<t t-set-slot="content">
|
||||
<div class="px-3 pb-2">
|
||||
<label class="mb-2">Add to my dashboard</label>
|
||||
<input type="text" class="o_input mb-3" t-ref="autofocus" t-model.trim="state.name" t-on-keydown="onInputKeydown" />
|
||||
<button type="button" class="btn btn-primary" t-on-click="addToBoard">Add</button>
|
||||
</div>
|
||||
</t>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="Dashboard.DashboardIcon">
|
||||
<svg viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg" class="o_ui_app_icon oi-large">
|
||||
<path d="M4 8C4 5.79086 5.79086 4 8 4H25V21C25 23.2091 23.2091 25 21 25H4V8Z" fill="var(--oi-color, #FC868B)"/>
|
||||
<path d="M4 35C4 32.7909 5.79086 31 8 31H19V42C19 44.2091 17.2091 46 15 46H4V35Z" fill="var(--oi-color, #F9464C)"/>
|
||||
<path d="M25 46H29C31.2091 46 33 44.2091 33 42V31H29C26.7909 31 25 32.7909 25 35V46Z" fill="var(--oi-color, #FBB945)"/>
|
||||
<path d="M31 17L31 21C31 23.2091 32.7909 25 35 25L46 25V21C46 18.7909 44.2091 17 42 17L31 17Z" fill="var(--oi-color, #088BF5)"/>
|
||||
<path d="M31 4L31 8C31 10.2091 32.7909 12 35 12L46 12V8C46 5.79086 44.2091 4 42 4L31 4Z" fill="var(--oi-color, #2EBCFA)"/>
|
||||
<path d="M38 46H42C44.2091 46 46 44.2091 46 42V31H42C39.7909 31 38 32.7909 38 35V46Z" fill="var(--oi-color, #F78613)"/>
|
||||
</svg>
|
||||
</t>
|
||||
</templates>
|
||||
|
|
|
|||
|
|
@ -1,160 +0,0 @@
|
|||
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;
|
||||
});
|
||||
|
|
@ -1,15 +1,20 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import { rpc } from "@web/core/network/rpc";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { View } from "@web/views/view";
|
||||
import { makeContext } from "@web/core/context";
|
||||
|
||||
const { Component, onWillStart } = owl;
|
||||
import { user } from "@web/core/user";
|
||||
import { Component, onWillStart } from "@odoo/owl";
|
||||
|
||||
export class BoardAction extends Component {
|
||||
static template = "board.BoardAction";
|
||||
static components = { View };
|
||||
static props = {
|
||||
action: Object,
|
||||
actionId: { type: Number, optional: true },
|
||||
className: { type: String, optional: true },
|
||||
};
|
||||
static cache = {};
|
||||
setup() {
|
||||
const rpc = useService("rpc");
|
||||
const userService = useService("user");
|
||||
this.actionService = useService("action");
|
||||
const action = this.props.action;
|
||||
this.formViewId = false;
|
||||
|
|
@ -47,27 +52,11 @@ export class BoardAction extends Component {
|
|||
];
|
||||
|
||||
if (action.context) {
|
||||
this.viewProps.context = makeContext([
|
||||
action.context,
|
||||
{ lang: userService.context.lang },
|
||||
]);
|
||||
this.viewProps.context = makeContext([action.context, { lang: user.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;
|
||||
|
|
@ -86,6 +75,3 @@ export class BoardAction extends Component {
|
|||
});
|
||||
}
|
||||
}
|
||||
BoardAction.template = "board.BoardAction";
|
||||
BoardAction.components = { View };
|
||||
BoardAction.cache = {};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="board.BoardAction" owl="1">
|
||||
<t t-name="board.BoardAction">
|
||||
<t t-if="isValid">
|
||||
<View t-props="viewProps"/>
|
||||
</t>
|
||||
|
|
|
|||
|
|
@ -1,21 +1,26 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
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 { rpc, rpcBus } from "@web/core/network/rpc";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { renderToString } from "@web/core/utils/render";
|
||||
import { useSortable } from "@web/core/utils/sortable";
|
||||
import { useSortable } from "@web/core/utils/sortable_owl";
|
||||
import { standardViewProps } from "@web/views/standard_view_props";
|
||||
import { BoardAction } from "./board_action";
|
||||
|
||||
const { blockDom, Component, useState, useRef } = owl;
|
||||
import { blockDom, Component, useState, useRef } from "@odoo/owl";
|
||||
|
||||
export class BoardController extends Component {
|
||||
static template = "board.BoardView";
|
||||
static components = { BoardAction, Dropdown, DropdownItem };
|
||||
static props = {
|
||||
...standardViewProps,
|
||||
board: Object,
|
||||
};
|
||||
|
||||
setup() {
|
||||
this.board = useState(this.props.board);
|
||||
this.rpc = useService("rpc");
|
||||
this.dialogService = useService("dialog");
|
||||
if (this.env.isSmall) {
|
||||
this.selectLayout("1", false);
|
||||
|
|
@ -92,7 +97,7 @@ export class BoardController extends Component {
|
|||
|
||||
closeAction(column, action) {
|
||||
this.dialogService.add(ConfirmationDialog, {
|
||||
body: this.env._t("Are you sure that you want to remove this item?"),
|
||||
body: _t("Are you sure that you want to remove this item?"),
|
||||
confirm: () => {
|
||||
const index = column.actions.indexOf(action);
|
||||
column.actions.splice(index, 1);
|
||||
|
|
@ -117,19 +122,12 @@ export class BoardController extends Component {
|
|||
const result = xmlSerializer.serializeToString(root);
|
||||
const arch = result.slice(result.indexOf("<", 1), result.indexOf("</rendertostring>"));
|
||||
|
||||
this.rpc("/web/view/edit_custom", {
|
||||
rpc("/web/view/edit_custom", {
|
||||
custom_id: this.board.customViewId,
|
||||
arch,
|
||||
});
|
||||
this.env.bus.trigger("CLEAR-CACHES");
|
||||
rpcBus.trigger("CLEAR-CACHES");
|
||||
}
|
||||
}
|
||||
|
||||
BoardController.template = "board.BoardView";
|
||||
BoardController.components = { BoardAction, Dropdown, DropdownItem };
|
||||
BoardController.props = {
|
||||
...standardViewProps,
|
||||
board: Object,
|
||||
};
|
||||
|
||||
const xmlSerializer = new XMLSerializer();
|
||||
|
|
|
|||
|
|
@ -30,10 +30,22 @@
|
|||
align-self: start;
|
||||
|
||||
> .o_view_controller {
|
||||
padding: 0 12px 12px 12px;
|
||||
padding: 0 6px 6px 6px;
|
||||
.o_content {
|
||||
max-height: 80vh;
|
||||
overflow: auto;
|
||||
> .o_renderer {
|
||||
min-width: 1200px;
|
||||
}
|
||||
}
|
||||
// graph view
|
||||
.o_graph_renderer canvas {
|
||||
height: 300px;
|
||||
}
|
||||
// calendar view
|
||||
.o_calendar_wrapper {
|
||||
height: 400px;
|
||||
}
|
||||
}
|
||||
|
||||
.o_column_quick_create, .o_control_panel {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="board.BoardView" owl="1">
|
||||
<t t-name="board.BoardView">
|
||||
<div class="o_dashboard d-flex flex-column">
|
||||
<t t-if="board.isEmpty">
|
||||
<t t-call="board.NoContent"/>
|
||||
|
|
@ -12,18 +12,20 @@
|
|||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="board.Content" owl="1">
|
||||
<t t-name="board.Content">
|
||||
<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">
|
||||
<Dropdown>
|
||||
<button class="btn btn-secondary m-2 p-2">
|
||||
<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>
|
||||
</button>
|
||||
<t t-set-slot="content">
|
||||
<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>
|
||||
</t>
|
||||
</Dropdown>
|
||||
</div>
|
||||
|
|
@ -46,7 +48,7 @@
|
|||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="board.NoContent" owl="1">
|
||||
<t t-name="board.NoContent">
|
||||
<div class="o_view_nocontent">
|
||||
<div class="o_nocontent_help">
|
||||
<p class="o_view_nocontent_neutral_face">
|
||||
|
|
@ -65,7 +67,7 @@
|
|||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="board.arch" owl="1">
|
||||
<t t-name="board.arch">
|
||||
<form t-att-string="title">
|
||||
<board t-att-style="layout">
|
||||
<column t-foreach="columns" t-as="column" t-key="column_index">
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
/** @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 { visitXML } from "@web/core/utils/xml";
|
||||
import { Domain } from "@web/core/domain";
|
||||
|
||||
export class BoardArchParser extends XMLParser {
|
||||
export class BoardArchParser {
|
||||
parse(arch, customViewId) {
|
||||
let nextId = 1;
|
||||
const archInfo = {
|
||||
|
|
@ -19,7 +15,7 @@ export class BoardArchParser extends XMLParser {
|
|||
};
|
||||
let currentIndex = -1;
|
||||
|
||||
this.visitXML(arch, (node) => {
|
||||
visitXML(arch, (node) => {
|
||||
switch (node.tagName) {
|
||||
case "form":
|
||||
archInfo.title = node.getAttribute("string");
|
||||
|
|
@ -36,7 +32,7 @@ export class BoardArchParser extends XMLParser {
|
|||
const isFolded = Boolean(
|
||||
node.hasAttribute("fold") ? parseInt(node.getAttribute("fold"), 10) : 0
|
||||
);
|
||||
let action = {
|
||||
const action = {
|
||||
id: nextId++,
|
||||
title: node.getAttribute("string"),
|
||||
actionId: parseInt(node.getAttribute("name"), 10),
|
||||
|
|
@ -45,11 +41,7 @@ export class BoardArchParser extends XMLParser {
|
|||
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);
|
||||
const domain = node.getAttribute("domain");
|
||||
action.domain = new Domain(domain).toList();
|
||||
// so it can be serialized when reexporting board xml
|
||||
action.domain.toString = () => node.getAttribute("domain");
|
||||
|
|
@ -65,7 +57,6 @@ export class BoardArchParser extends XMLParser {
|
|||
|
||||
export const boardView = {
|
||||
type: "form",
|
||||
display_name: _lt("Board"),
|
||||
Controller: BoardController,
|
||||
|
||||
props: (genericProps, view) => {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,434 @@
|
|||
import { addToBoardItem } from "@board/add_to_board/add_to_board";
|
||||
import { defineMailModels } from "@mail/../tests/mail_test_helpers";
|
||||
import { beforeEach, describe, expect, test } from "@odoo/hoot";
|
||||
import { hover, press, queryOne } from "@odoo/hoot-dom";
|
||||
import { animationFrame } from "@odoo/hoot-mock";
|
||||
import * as dsHelpers from "@web/../tests/core/domain_selector/domain_selector_helpers";
|
||||
import {
|
||||
contains,
|
||||
defineModels,
|
||||
fields,
|
||||
getDropdownMenu,
|
||||
getService,
|
||||
models,
|
||||
mountWithCleanup,
|
||||
onRpc,
|
||||
openAddCustomFilterDialog,
|
||||
removeFacet,
|
||||
selectGroup,
|
||||
serverState,
|
||||
switchView,
|
||||
toggleMenuItem,
|
||||
toggleSearchBarMenu,
|
||||
} from "@web/../tests/web_test_helpers";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { WebClient } from "@web/webclient/webclient";
|
||||
|
||||
describe.current.tags("desktop");
|
||||
|
||||
class Board extends models.Model {}
|
||||
|
||||
class Partner extends models.Model {
|
||||
name = fields.Char();
|
||||
foo = fields.Char({
|
||||
string: "Foo",
|
||||
default: "My little Foo Value",
|
||||
searchable: true,
|
||||
});
|
||||
bar = fields.Boolean({ string: "Bar" });
|
||||
int_field = fields.Integer({
|
||||
string: "Integer field",
|
||||
aggregator: "sum",
|
||||
});
|
||||
|
||||
_records = [
|
||||
{
|
||||
id: 1,
|
||||
name: "first record",
|
||||
foo: "yop",
|
||||
int_field: 3,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "second record",
|
||||
foo: "lalala",
|
||||
int_field: 5,
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: "aaa",
|
||||
foo: "abc",
|
||||
int_field: 2,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
defineModels([Board, Partner]);
|
||||
defineMailModels();
|
||||
const favoriteMenuRegistry = registry.category("favoriteMenu");
|
||||
|
||||
function getAddToDashboardMenu() {
|
||||
return getDropdownMenu(".o_add_to_board button.dropdown-toggle");
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
favoriteMenuRegistry.add("add-to-board", addToBoardItem, { sequence: 10 });
|
||||
});
|
||||
|
||||
test("save actions to dashboard", async () => {
|
||||
expect.assertions(6);
|
||||
|
||||
Partner._views = {
|
||||
list: '<list><field name="foo"/></list>',
|
||||
};
|
||||
|
||||
onRpc("/board/add_to_dashboard", async (request) => {
|
||||
const { params: args } = await request.json();
|
||||
expect(args.context_to_save.group_by).toEqual(["foo"], {
|
||||
message: "The group_by should have been saved",
|
||||
});
|
||||
expect(args.context_to_save.orderedBy).toEqual(
|
||||
[
|
||||
{
|
||||
name: "foo",
|
||||
asc: true,
|
||||
},
|
||||
],
|
||||
{ message: "The orderedBy should have been saved" }
|
||||
);
|
||||
expect(args.context_to_save.fire).toBe("on the bayou", {
|
||||
message: "The context of a controller should be passed and flattened",
|
||||
});
|
||||
expect(args.action_id).toBe(1, { message: "should save the correct action" });
|
||||
expect(args.view_mode).toBe("list", { message: "should save the correct view type" });
|
||||
return true;
|
||||
});
|
||||
|
||||
await mountWithCleanup(WebClient);
|
||||
await getService("action").doAction({
|
||||
id: 1,
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
context: { fire: "on the bayou" },
|
||||
views: [[false, "list"]],
|
||||
});
|
||||
|
||||
expect(".o_list_view").toHaveCount(1, { message: "should display the list view" });
|
||||
|
||||
// Sort the list
|
||||
await contains(".o_column_sortable").click();
|
||||
|
||||
// Group It
|
||||
await toggleSearchBarMenu();
|
||||
await selectGroup("foo");
|
||||
|
||||
// add this action to dashboard
|
||||
await hover(".o_add_to_board button.dropdown-toggle");
|
||||
await animationFrame();
|
||||
await contains(queryOne("input", { root: getAddToDashboardMenu() })).edit("a name", {
|
||||
confirm: false,
|
||||
});
|
||||
await contains(queryOne("button", { root: getAddToDashboardMenu() })).click();
|
||||
});
|
||||
|
||||
test("save two searches to dashboard", async () => {
|
||||
// the second search saved should not be influenced by the first
|
||||
expect.assertions(2);
|
||||
|
||||
Partner._views = {
|
||||
list: '<list><field name="foo"/></list>',
|
||||
search: `
|
||||
<search>
|
||||
<filter name="filter_on_a" string="Filter on a" domain="[['name', 'ilike', 'a']]"/>
|
||||
<filter name="filter_on_b" string="Filter on b" domain="[['name', 'ilike', 'b']]"/>
|
||||
</search>
|
||||
`,
|
||||
};
|
||||
|
||||
onRpc("/board/add_to_dashboard", async (request) => {
|
||||
const { params: args } = await request.json();
|
||||
if (filter_count === 0) {
|
||||
expect(args.domain).toEqual([["name", "ilike", "a"]], {
|
||||
message: "the correct domain should be sent",
|
||||
});
|
||||
}
|
||||
if (filter_count === 1) {
|
||||
expect(args.domain).toEqual([["name", "ilike", "b"]], {
|
||||
message: "the correct domain should be sent",
|
||||
});
|
||||
}
|
||||
|
||||
filter_count += 1;
|
||||
return true;
|
||||
});
|
||||
|
||||
await mountWithCleanup(WebClient);
|
||||
|
||||
await getService("action").doAction({
|
||||
id: 1,
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
views: [[false, "list"]],
|
||||
});
|
||||
|
||||
let filter_count = 0;
|
||||
// Add a first filter
|
||||
await toggleSearchBarMenu();
|
||||
await toggleMenuItem("Filter on a");
|
||||
|
||||
// Add it to dashboard
|
||||
await hover(".o_add_to_board button.dropdown-toggle");
|
||||
await animationFrame();
|
||||
await contains(queryOne("button", { root: getAddToDashboardMenu() })).click();
|
||||
|
||||
// Remove it
|
||||
await removeFacet("Filter on a");
|
||||
|
||||
// Add the second filter
|
||||
await toggleSearchBarMenu();
|
||||
await toggleMenuItem("Filter on b");
|
||||
|
||||
// Add it to dashboard
|
||||
await hover(".o_add_to_board button.dropdown-toggle");
|
||||
await animationFrame();
|
||||
await contains(queryOne("button", { root: getAddToDashboardMenu() })).click();
|
||||
});
|
||||
|
||||
test("save an action domain to dashboard", async () => {
|
||||
// View domains are to be added to the dashboard domain
|
||||
expect.assertions(1);
|
||||
|
||||
const viewDomain = ["name", "ilike", "a"];
|
||||
const filterDomain = ["name", "ilike", "b"];
|
||||
|
||||
const expectedDomain = ["&", viewDomain, filterDomain];
|
||||
|
||||
Partner._views = {
|
||||
list: '<list><field name="foo"/></list>',
|
||||
search: `
|
||||
<search>
|
||||
<filter name="filter" string="Filter" domain="[['name', 'ilike', 'b']]"/>
|
||||
</search>
|
||||
`,
|
||||
};
|
||||
|
||||
onRpc("/board/add_to_dashboard", async (request) => {
|
||||
const { params: args } = await request.json();
|
||||
expect(args.domain).toEqual(expectedDomain, {
|
||||
message: "the correct domain should be sent",
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
await mountWithCleanup(WebClient);
|
||||
|
||||
await getService("action").doAction({
|
||||
id: 1,
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
views: [[false, "list"]],
|
||||
domain: [viewDomain],
|
||||
});
|
||||
|
||||
// Add a filter
|
||||
await toggleSearchBarMenu();
|
||||
await toggleMenuItem("Filter");
|
||||
|
||||
// Add it to dashboard
|
||||
await hover(".o_add_to_board button.dropdown-toggle");
|
||||
await animationFrame();
|
||||
// add
|
||||
await contains(queryOne("button", { root: getAddToDashboardMenu() })).click();
|
||||
});
|
||||
|
||||
test("add to dashboard with no action id", async () => {
|
||||
expect.assertions(2);
|
||||
|
||||
Partner._views = {
|
||||
pivot: '<pivot><field name="foo"/></pivot>',
|
||||
};
|
||||
await mountWithCleanup(WebClient);
|
||||
|
||||
await getService("action").doAction({
|
||||
id: false,
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
views: [[false, "pivot"]],
|
||||
});
|
||||
await toggleSearchBarMenu();
|
||||
expect(".o_add_to_board").toHaveCount(0);
|
||||
|
||||
// Sanity check
|
||||
await getService("action").doAction({
|
||||
id: 1,
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
views: [[false, "pivot"]],
|
||||
});
|
||||
await toggleSearchBarMenu();
|
||||
expect(".o_add_to_board").toHaveCount(1);
|
||||
});
|
||||
|
||||
test("Add a view to dashboard (keynav)", async () => {
|
||||
Partner._views = {
|
||||
pivot: '<pivot><field name="foo"/></pivot>',
|
||||
};
|
||||
|
||||
// makes mouseEnter work
|
||||
|
||||
onRpc("/board/add_to_dashboard", () => {
|
||||
expect.step("add to board");
|
||||
return true;
|
||||
});
|
||||
|
||||
await mountWithCleanup(WebClient);
|
||||
|
||||
await getService("action").doAction({
|
||||
id: 1,
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
views: [[false, "pivot"]],
|
||||
});
|
||||
|
||||
await toggleSearchBarMenu();
|
||||
await hover(".o_add_to_board button.dropdown-toggle");
|
||||
await animationFrame();
|
||||
await contains(queryOne("input", { root: getAddToDashboardMenu() })).edit("Pipeline", {
|
||||
confirm: false,
|
||||
});
|
||||
await press("Enter");
|
||||
|
||||
expect.verifySteps(["add to board"]);
|
||||
});
|
||||
|
||||
test("Add a view with dynamic domain", async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
Partner._views = {
|
||||
pivot: '<pivot><field name="foo"/></pivot>',
|
||||
search: `
|
||||
<search>
|
||||
<filter name="filter" domain="[('user_id','=',uid)]"/>
|
||||
</search>`,
|
||||
};
|
||||
|
||||
// makes mouseEnter work
|
||||
|
||||
onRpc("/board/add_to_dashboard", async (request) => {
|
||||
const { params: args } = await request.json();
|
||||
expect(args.domain).toEqual(["&", ["int_field", "<=", 3], ["user_id", "=", 7]]);
|
||||
return true;
|
||||
});
|
||||
|
||||
await mountWithCleanup(WebClient);
|
||||
|
||||
await getService("action").doAction({
|
||||
id: 1,
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
views: [[false, "pivot"]],
|
||||
domain: [["int_field", "<=", 3]],
|
||||
context: { search_default_filter: 1 },
|
||||
});
|
||||
|
||||
await toggleSearchBarMenu();
|
||||
await hover(".o_add_to_board button.dropdown-toggle");
|
||||
await animationFrame();
|
||||
await contains(queryOne("input", { root: getAddToDashboardMenu() })).edit("Pipeline");
|
||||
});
|
||||
|
||||
test("Add a view to dashboard doesn't save default filters", async () => {
|
||||
expect.assertions(2);
|
||||
|
||||
Partner._views = {
|
||||
pivot: '<pivot><field name="foo"/></pivot>',
|
||||
list: '<list><field name="foo"/></list>',
|
||||
search: `
|
||||
<search>
|
||||
<filter name="filter" domain="[('foo','!=','yop')]"/>
|
||||
</search>`,
|
||||
};
|
||||
|
||||
// makes mouseEnter work
|
||||
serverState.debug = "1";
|
||||
|
||||
onRpc("/board/add_to_dashboard", async (request) => {
|
||||
const { params: args } = await request.json();
|
||||
expect(args.domain).toEqual([["foo", "=", "yop"]]);
|
||||
expect(args.context_to_save).toEqual({
|
||||
pivot_measures: ["__count"],
|
||||
pivot_column_groupby: [],
|
||||
pivot_row_groupby: [],
|
||||
orderedBy: [],
|
||||
group_by: [],
|
||||
dashboard_merge_domains_contexts: false,
|
||||
});
|
||||
return true;
|
||||
});
|
||||
onRpc("/web/domain/validate", () => {
|
||||
return true;
|
||||
});
|
||||
|
||||
await mountWithCleanup(WebClient);
|
||||
|
||||
await getService("action").doAction({
|
||||
id: 1,
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
views: [
|
||||
[false, "list"],
|
||||
[false, "pivot"],
|
||||
],
|
||||
context: { search_default_filter: 1 },
|
||||
});
|
||||
|
||||
await switchView("pivot");
|
||||
|
||||
// Remove default filter ['foo', '!=', 'yop']
|
||||
await removeFacet("filter");
|
||||
|
||||
// Add a filter ['foo', '=', 'yop']
|
||||
await toggleSearchBarMenu();
|
||||
await openAddCustomFilterDialog();
|
||||
await contains(dsHelpers.SELECTORS.debugArea).edit(`[("foo", "=", "yop")]`);
|
||||
await contains(".modal footer button").click();
|
||||
|
||||
// Add to dashboard
|
||||
await toggleSearchBarMenu();
|
||||
await hover(".o_add_to_board button.dropdown-toggle");
|
||||
await animationFrame();
|
||||
await contains(queryOne("input", { root: getAddToDashboardMenu() })).edit("Pipeline");
|
||||
});
|
||||
|
||||
test("Add to my dashboard is not available in form views", async () => {
|
||||
Partner._views = {
|
||||
list: '<list><field name="foo"/></list>',
|
||||
form: '<form><field name="foo"/></form>',
|
||||
};
|
||||
|
||||
await mountWithCleanup(WebClient);
|
||||
await getService("action").doAction({
|
||||
id: 1,
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
context: { fire: "on the bayou" },
|
||||
views: [
|
||||
[false, "list"],
|
||||
[false, "form"],
|
||||
],
|
||||
});
|
||||
|
||||
expect(".o_list_view").toHaveCount(1, { message: "should display the list view" });
|
||||
|
||||
// sanity check
|
||||
await contains(".o_cp_action_menus .dropdown-toggle").click();
|
||||
expect(".o-dropdown--menu .o_add_to_board").toHaveCount(1);
|
||||
|
||||
// open form view
|
||||
await contains(".o_data_cell").click();
|
||||
expect(".o_form_view").toHaveCount(1);
|
||||
|
||||
await contains(".o_cp_action_menus .dropdown-toggle").click();
|
||||
expect(".o-dropdown--menu").toHaveCount(1);
|
||||
expect(".o-dropdown--menu .o_add_to_board").toHaveCount(0);
|
||||
});
|
||||
|
|
@ -1,526 +0,0 @@
|
|||
/** @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" });
|
||||
});
|
||||
});
|
||||
711
odoo-bringout-oca-ocb-board/board/static/tests/board.test.js
Normal file
711
odoo-bringout-oca-ocb-board/board/static/tests/board.test.js
Normal file
|
|
@ -0,0 +1,711 @@
|
|||
import { BoardAction } from "@board/board_action";
|
||||
import { defineMailModels } from "@mail/../tests/mail_test_helpers";
|
||||
import { beforeEach, describe, expect, test } from "@odoo/hoot";
|
||||
import { queryAllTexts, queryOne } from "@odoo/hoot-dom";
|
||||
import {
|
||||
contains,
|
||||
defineModels,
|
||||
fields,
|
||||
mockService,
|
||||
models,
|
||||
mountView,
|
||||
onRpc,
|
||||
serverState,
|
||||
} from "@web/../tests/web_test_helpers";
|
||||
|
||||
class Board extends models.Model {}
|
||||
|
||||
class Partner extends models.Model {
|
||||
name = fields.Char({ string: "Displayed name", searchable: true });
|
||||
foo = fields.Char({
|
||||
string: "Foo",
|
||||
default: "My little Foo Value",
|
||||
searchable: true,
|
||||
});
|
||||
bar = fields.Boolean({ string: "Bar" });
|
||||
int_field = fields.Integer({
|
||||
string: "Integer field",
|
||||
aggregator: "sum",
|
||||
});
|
||||
|
||||
_records = [
|
||||
{
|
||||
id: 1,
|
||||
name: "first record",
|
||||
foo: "yop",
|
||||
int_field: 3,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "second record",
|
||||
foo: "lalala",
|
||||
int_field: 5,
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: "aaa",
|
||||
foo: "abc",
|
||||
int_field: 2,
|
||||
},
|
||||
];
|
||||
|
||||
_views = {
|
||||
"form,100000001": "<form/>",
|
||||
"search,100000002": "<search/>",
|
||||
"list,4": '<list string="Partner"><field name="foo"/></list>',
|
||||
};
|
||||
}
|
||||
|
||||
defineModels([Board, Partner]);
|
||||
defineMailModels();
|
||||
|
||||
beforeEach(() => {
|
||||
BoardAction.cache = {};
|
||||
});
|
||||
|
||||
describe.tags("desktop");
|
||||
describe("board_desktop", () => {
|
||||
test("display the no content helper", async () => {
|
||||
await mountView({
|
||||
type: "form",
|
||||
resModel: "board",
|
||||
arch: `
|
||||
<form string="My Dashboard" js_class="board">
|
||||
<board style="2-1">
|
||||
<column></column>
|
||||
</board>
|
||||
</form>`,
|
||||
});
|
||||
expect(".o_view_nocontent").toHaveCount(1);
|
||||
});
|
||||
|
||||
test("basic functionality, with one sub action", async () => {
|
||||
expect.assertions(19);
|
||||
onRpc("/web/action/load", () => {
|
||||
expect.step("load action");
|
||||
return {
|
||||
res_model: "partner",
|
||||
views: [[4, "list"]],
|
||||
};
|
||||
});
|
||||
onRpc("web_search_read", (args) => {
|
||||
expect(args.kwargs.domain).toEqual([["foo", "!=", "False"]], {
|
||||
message: "the domain should be passed",
|
||||
});
|
||||
expect(args.kwargs.context.orderedBy).toEqual(
|
||||
[
|
||||
{
|
||||
name: "foo",
|
||||
asc: true,
|
||||
},
|
||||
],
|
||||
{
|
||||
message:
|
||||
"orderedBy is present in the search read when specified on the custom action",
|
||||
}
|
||||
);
|
||||
});
|
||||
onRpc("/web/view/edit_custom", () => {
|
||||
expect.step("edit custom");
|
||||
return true;
|
||||
});
|
||||
onRpc("partner", "get_views", (args) => {
|
||||
expect(args.kwargs.views.find((v) => v[1] === "list")).toEqual([4, "list"]);
|
||||
});
|
||||
await mountView({
|
||||
type: "form",
|
||||
resModel: "board",
|
||||
arch: `
|
||||
<form string="My Dashboard" js_class="board">
|
||||
<board style="2-1">
|
||||
<column>
|
||||
<action context="{"orderedBy": [{"name": "foo", "asc": True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
|
||||
</column>
|
||||
</board>
|
||||
</form>`,
|
||||
});
|
||||
|
||||
expect(".o-dashboard-header").toHaveCount(1, { message: "should have rendered a header" });
|
||||
expect("div.o-dashboard-layout-2-1").toHaveCount(1, {
|
||||
message: "should have rendered a div with layout",
|
||||
});
|
||||
expect("td.o_list_record_selector").toHaveCount(0, {
|
||||
message: "td should not have a list selector",
|
||||
});
|
||||
expect("h3 span:contains(ABC)").toHaveCount(1, {
|
||||
message: "should have rendered a header with action string",
|
||||
});
|
||||
expect("tr.o_data_row").toHaveCount(3, { message: "should have rendered 3 data rows" });
|
||||
|
||||
expect(".o-dashboard-action .o_list_view").toHaveCount(1);
|
||||
|
||||
await contains("h3 i.fa-window-minimize").click();
|
||||
|
||||
expect(".o-dashboard-action .o_list_view").toHaveCount(0);
|
||||
|
||||
await contains("h3 i.fa-window-maximize").click();
|
||||
|
||||
// content is visible again
|
||||
expect(".o-dashboard-action .o_list_view").toHaveCount(1);
|
||||
expect.verifySteps(["load action", "edit custom", "edit custom"]);
|
||||
|
||||
// header should have dropdown with correct image
|
||||
expect(
|
||||
".o-dashboard-header .dropdown img[data-src='/board/static/img/layout_2-1.png']"
|
||||
).toHaveCount(1);
|
||||
|
||||
// change layout to 1-1
|
||||
await contains(".o-dashboard-header .dropdown img").click();
|
||||
await contains(".dropdown-item:nth-child(2)").click();
|
||||
expect(
|
||||
".o-dashboard-header .dropdown img[data-src='/board/static/img/layout_1-1.png']"
|
||||
).toHaveCount(1);
|
||||
expect("div.o-dashboard-layout-1-1").toHaveCount(1, {
|
||||
message: "should have rendered a div with layout",
|
||||
});
|
||||
|
||||
expect.verifySteps(["edit custom"]);
|
||||
});
|
||||
|
||||
test("views in the dashboard do not have a control panel", async () => {
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [
|
||||
[4, "list"],
|
||||
[5, "form"],
|
||||
],
|
||||
}));
|
||||
await mountView({
|
||||
type: "form",
|
||||
resModel: "board",
|
||||
arch: `
|
||||
<form string="My Dashboard" js_class="board">
|
||||
<board style="2-1">
|
||||
<column>
|
||||
<action context="{"orderedBy": [{"name": "foo", "asc": True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
|
||||
</column>
|
||||
</board>
|
||||
</form>`,
|
||||
});
|
||||
|
||||
expect(".o-dashboard-action .o_list_view").toHaveCount(1);
|
||||
expect(".o-dashboard-action .o_control_panel").toHaveCount(0);
|
||||
});
|
||||
|
||||
test("can render an action without view_mode attribute", async () => {
|
||||
// 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.
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [
|
||||
[4, "list"],
|
||||
[false, "form"],
|
||||
],
|
||||
}));
|
||||
|
||||
await mountView({
|
||||
type: "form",
|
||||
resModel: "board",
|
||||
arch: `
|
||||
<form string="My Dashboard" js_class="board">
|
||||
<board style="2-1">
|
||||
<column>
|
||||
<action context="{"orderedBy": [{"name": "foo", "asc": True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
|
||||
</column>
|
||||
</board>
|
||||
</form>`,
|
||||
});
|
||||
|
||||
expect(".o-dashboard-action .o_list_view").toHaveCount(1);
|
||||
});
|
||||
|
||||
test("can sort a sub list", async () => {
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [[4, "list"]],
|
||||
}));
|
||||
await mountView({
|
||||
type: "form",
|
||||
resModel: "board",
|
||||
arch: `
|
||||
<form string="My Dashboard" js_class="board">
|
||||
<board style="2-1">
|
||||
<column>
|
||||
<action context="{"orderedBy": [{"name": "foo", "asc": True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
|
||||
</column>
|
||||
</board>
|
||||
</form>`,
|
||||
});
|
||||
|
||||
expect(queryAllTexts("tr.o_data_row")).toEqual(["yop", "lalala", "abc"], {
|
||||
message: "should have correct initial data",
|
||||
});
|
||||
|
||||
await contains("th.o_column_sortable:contains(Foo)").click();
|
||||
expect(queryAllTexts("tr.o_data_row")).toEqual(["abc", "lalala", "yop"], {
|
||||
message: "data should have been sorted",
|
||||
});
|
||||
});
|
||||
|
||||
test("can open a record", async () => {
|
||||
expect.assertions(1);
|
||||
mockService("action", {
|
||||
doAction(action) {
|
||||
expect(action).toEqual({
|
||||
res_id: 1,
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
views: [[false, "form"]],
|
||||
});
|
||||
return true;
|
||||
},
|
||||
});
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [[4, "list"]],
|
||||
}));
|
||||
await mountView({
|
||||
type: "form",
|
||||
resModel: "board",
|
||||
arch: `
|
||||
<form string="My Dashboard" js_class="board">
|
||||
<board style="2-1">
|
||||
<column>
|
||||
<action context="{"orderedBy": [{"name": "foo", "asc": True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
|
||||
</column>
|
||||
</board>
|
||||
</form>`,
|
||||
});
|
||||
|
||||
await contains("tr.o_data_row td:contains(yop)").click();
|
||||
});
|
||||
|
||||
test("can open record using action form view", async () => {
|
||||
expect.assertions(1);
|
||||
Partner._views["form,5"] = '<form string="Partner"><field name="name"/></form>';
|
||||
mockService("action", {
|
||||
doAction(action) {
|
||||
expect(action).toEqual({
|
||||
res_id: 1,
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
views: [[5, "form"]],
|
||||
});
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [
|
||||
[4, "list"],
|
||||
[5, "form"],
|
||||
],
|
||||
}));
|
||||
|
||||
await mountView({
|
||||
type: "form",
|
||||
resModel: "board",
|
||||
arch: `
|
||||
<form string="My Dashboard" js_class="board">
|
||||
<board style="2-1">
|
||||
<column>
|
||||
<action context="{"orderedBy": [{"name": "foo", "asc": True}]}" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
|
||||
</column>
|
||||
</board>
|
||||
</form>`,
|
||||
});
|
||||
|
||||
await contains("tr.o_data_row td:contains(yop)").click();
|
||||
});
|
||||
|
||||
test("can drag and drop a view", async () => {
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [[4, "list"]],
|
||||
}));
|
||||
onRpc("/web/view/edit_custom", () => {
|
||||
expect.step("edit custom");
|
||||
return true;
|
||||
});
|
||||
await mountView({
|
||||
type: "form",
|
||||
resModel: "board",
|
||||
arch: `
|
||||
<form string="My Dashboard" js_class="board">
|
||||
<board style="2-1">
|
||||
<column>
|
||||
<action context="{"orderedBy": [{"name": "foo", "asc": True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
|
||||
</column>
|
||||
</board>
|
||||
</form>`,
|
||||
});
|
||||
|
||||
expect('.o-dashboard-column[data-idx="0"] .o-dashboard-action').toHaveCount(1);
|
||||
expect('.o-dashboard-column[data-idx="1"] .o-dashboard-action').toHaveCount(0);
|
||||
|
||||
await contains('.o-dashboard-column[data-idx="0"] .o-dashboard-action-header').dragAndDrop(
|
||||
'.o-dashboard-column[data-idx="1"]'
|
||||
);
|
||||
|
||||
expect('.o-dashboard-column[data-idx="0"] .o-dashboard-action').toHaveCount(0);
|
||||
expect('.o-dashboard-column[data-idx="1"] .o-dashboard-action').toHaveCount(1);
|
||||
expect.verifySteps(["edit custom"]);
|
||||
});
|
||||
|
||||
test("twice the same action in a dashboard", async () => {
|
||||
Partner._views["kanban,5"] = `
|
||||
<kanban>
|
||||
<templates>
|
||||
<t t-name="card">
|
||||
<field name="foo"/>
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>`;
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [
|
||||
[4, "list"],
|
||||
[5, "kanban"],
|
||||
],
|
||||
}));
|
||||
onRpc("/web/view/edit_custom", () => {
|
||||
expect.step("edit custom");
|
||||
return true;
|
||||
});
|
||||
await mountView({
|
||||
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>`,
|
||||
});
|
||||
|
||||
expect(".o-dashboard-action:eq(0) .o_list_view").toHaveCount(1);
|
||||
expect(".o-dashboard-action:eq(1) .o_kanban_view").toHaveCount(1);
|
||||
});
|
||||
|
||||
test("non-existing action in a dashboard", async () => {
|
||||
onRpc(
|
||||
"/web/action/load",
|
||||
() =>
|
||||
// server answer if the action doesn't exist anymore
|
||||
false
|
||||
);
|
||||
await mountView({
|
||||
type: "form",
|
||||
resModel: "board",
|
||||
arch: `
|
||||
<form string="My Dashboard" js_class="board">
|
||||
<board style="2-1">
|
||||
<column>
|
||||
<action context="{"orderedBy": [{"name": "foo", "asc": True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
|
||||
</column>
|
||||
</board>
|
||||
</form>`,
|
||||
});
|
||||
|
||||
expect("h3 span:contains(ABC)").toHaveCount(1);
|
||||
expect(".o-dashboard-action div:contains(Invalid action)").toHaveCount(1);
|
||||
});
|
||||
|
||||
test(`clicking on a kanban's button should trigger the action`, async () => {
|
||||
expect.assertions(4);
|
||||
Partner._views.kanban = `
|
||||
<kanban>
|
||||
<templates>
|
||||
<t t-name="card">
|
||||
<field name="foo"/>
|
||||
<button name="sitting_on_a_park_bench" type="object">Eying little girls with bad intent</button>
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>`;
|
||||
mockService("action", {
|
||||
doActionButton(params) {
|
||||
expect(params.resModel).toBe("partner");
|
||||
expect(params.resId).toBe(1);
|
||||
expect(params.name).toBe("sitting_on_a_park_bench");
|
||||
expect(params.type).toBe("object");
|
||||
},
|
||||
});
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
view_mode: "kanban",
|
||||
views: [[false, "kanban"]],
|
||||
}));
|
||||
await mountView({
|
||||
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>`,
|
||||
});
|
||||
|
||||
await contains(".btn.oe_kanban_action").click();
|
||||
});
|
||||
|
||||
test("Views should be loaded in the user's language", async () => {
|
||||
expect.assertions(2);
|
||||
serverState.lang = "fr_FR";
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [[4, "list"]],
|
||||
}));
|
||||
onRpc("get_views", (args) => {
|
||||
expect(args.kwargs.context.lang).toBe("fr_FR");
|
||||
});
|
||||
await mountView({
|
||||
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>`,
|
||||
});
|
||||
});
|
||||
|
||||
test("Dashboard should use correct groupby", async () => {
|
||||
expect.assertions(1);
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [[4, "list"]],
|
||||
}));
|
||||
onRpc("web_read_group", (args) => {
|
||||
expect(args.kwargs.groupby).toEqual(["bar"]);
|
||||
});
|
||||
await mountView({
|
||||
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>`,
|
||||
});
|
||||
});
|
||||
|
||||
test("Dashboard should use correct groupby when defined as a string of one field", async () => {
|
||||
expect.assertions(1);
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [[4, "list"]],
|
||||
}));
|
||||
onRpc("web_read_group", ({ kwargs }) => {
|
||||
expect(kwargs.groupby).toEqual(["bar"]);
|
||||
});
|
||||
await mountView({
|
||||
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>`,
|
||||
});
|
||||
});
|
||||
|
||||
test("click on a cell of pivot view inside dashboard", async () => {
|
||||
Partner._views["pivot,4"] = '<pivot><field name="int_field" type="measure"/></pivot>';
|
||||
mockService("action", {
|
||||
doAction(action) {
|
||||
expect.step("do action");
|
||||
expect(action.views).toEqual([
|
||||
[false, "list"],
|
||||
[false, "form"],
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [[4, "pivot"]],
|
||||
}));
|
||||
onRpc("formatted_read_group", (args) => {
|
||||
expect(args.kwargs.groupby).toEqual([]);
|
||||
});
|
||||
|
||||
await mountView({
|
||||
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>`,
|
||||
});
|
||||
|
||||
expect.verifySteps([]);
|
||||
|
||||
await contains(".o_pivot_view .o_pivot_cell_value").click();
|
||||
|
||||
expect.verifySteps(["do action"]);
|
||||
});
|
||||
|
||||
test("graphs in dashboard aren't squashed", async () => {
|
||||
Partner._views["graph,4"] = '<graph><field name="int_field" type="measure"/></graph>';
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [[4, "graph"]],
|
||||
}));
|
||||
await mountView({
|
||||
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>`,
|
||||
});
|
||||
|
||||
expect(".o-dashboard-action .o_graph_renderer").toHaveCount(1);
|
||||
expect(queryOne(".o-dashboard-action .o_graph_renderer canvas").offsetHeight).toBe(300);
|
||||
});
|
||||
|
||||
test("pivot view with property in pivot_column_groupby", async function () {
|
||||
Partner._fields.properties_definition = fields.PropertiesDefinition();
|
||||
Partner._fields.properties_definition = fields.PropertiesDefinition();
|
||||
Partner._fields.parent_id = fields.Many2one({ relation: "partner" });
|
||||
Partner._fields.properties = fields.Properties({
|
||||
definition_record: "parent_id",
|
||||
definition_record_field: "properties_definition",
|
||||
});
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [[false, "pivot"]],
|
||||
}));
|
||||
onRpc(({ method, kwargs }) => {
|
||||
if (method === "get_property_definition") {
|
||||
return {};
|
||||
} else if (method === "formatted_read_grouping_sets") {
|
||||
return [
|
||||
[{ __count: 3, __extra_domain: [] }],
|
||||
[
|
||||
{
|
||||
"properties.my_char": false,
|
||||
__extra_domain: [["properties.my_char", "=", false]],
|
||||
__count: 2,
|
||||
},
|
||||
{
|
||||
"properties.my_char": "aaa",
|
||||
__extra_domain: [["properties.my_char", "=", "aaa"]],
|
||||
__count: 1,
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
});
|
||||
await mountView({
|
||||
type: "form",
|
||||
resModel: "board",
|
||||
arch: `
|
||||
<form js_class="board">
|
||||
<board style="2-1">
|
||||
<column>
|
||||
<action context="{'pivot_column_groupby':['properties.my_char']}"/>
|
||||
</column>
|
||||
</board>
|
||||
</form>`,
|
||||
});
|
||||
expect(queryAllTexts(".o_pivot_cell_value div")).toEqual(["2", "1", "3"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe.tags("mobile");
|
||||
describe("board_mobile", () => {
|
||||
test("can't switch views in the dashboard", async () => {
|
||||
Partner._views["list,4"] = '<list string="Partner"><field name="foo"/></list>';
|
||||
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [[4, "list"]],
|
||||
}));
|
||||
await mountView({
|
||||
type: "form",
|
||||
resModel: "board",
|
||||
arch: `
|
||||
<form string="My Dashboard" js_class="board">
|
||||
<board style="2-1">
|
||||
<column>
|
||||
<action context="{"orderedBy": [{"name": "foo", "asc": True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
|
||||
</column>
|
||||
</board>
|
||||
</form>`,
|
||||
});
|
||||
|
||||
expect(".o-dashboard-header").toHaveCount(0, {
|
||||
message: "Couldn't allow user to Change layout",
|
||||
});
|
||||
expect(".o-dashboard-layout-1").toHaveCount(1, {
|
||||
message: "The display layout is force to 1",
|
||||
});
|
||||
expect(".o-dashboard-action .o_control_panel").not.toHaveCount();
|
||||
expect(".o-dashboard-action-header .fa-close").toHaveCount(0, {
|
||||
message: "Should not have a close action button",
|
||||
});
|
||||
});
|
||||
|
||||
test("Correctly soft switch to '1' layout on small screen", async () => {
|
||||
Partner._views["list,4"] = '<list string="Partner"><field name="foo"/></list>';
|
||||
|
||||
onRpc("/web/action/load", () => ({
|
||||
res_model: "partner",
|
||||
views: [[4, "list"]],
|
||||
}));
|
||||
await mountView({
|
||||
type: "form",
|
||||
resModel: "board",
|
||||
arch: `
|
||||
<form string="My Dashboard" js_class="board">
|
||||
<board style="2-1">
|
||||
<column>
|
||||
<action context="{"orderedBy": [{"name": "foo", "asc": True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
|
||||
</column>
|
||||
<column>
|
||||
<action context="{"orderedBy": [{"name": "foo", "asc": True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
|
||||
</column>
|
||||
</board>
|
||||
</form>`,
|
||||
});
|
||||
expect(".o-dashboard-layout-1").toHaveCount(1, {
|
||||
message: "The display layout is force to 1",
|
||||
});
|
||||
expect(".o-dashboard-column").toHaveCount(1, {
|
||||
message: "The display layout is force to 1 column",
|
||||
});
|
||||
expect(".o-dashboard-action").toHaveCount(2, {
|
||||
message: "The display should contains the 2 actions",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,907 +0,0 @@
|
|||
/** @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="{"orderedBy": [{"name": "foo", "asc": 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="{"orderedBy": [{"name": "foo", "asc": 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="{"orderedBy": [{"name": "foo", "asc": 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="{"orderedBy": [{"name": "foo", "asc": 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="{"orderedBy": [{"name": "foo", "asc": 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="{"orderedBy": [{"name": "foo", "asc": 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="{"orderedBy": [{"name": "foo", "asc": 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="{"orderedBy": [{"name": "foo", "asc": 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"]]);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
/** @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="{"orderedBy": [{"name": "foo", "asc": 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="{"orderedBy": [{"name": "foo", "asc": True}]}" view_mode="list" string="ABC" name="51" domain="[['foo', '!=', 'False']]"></action>
|
||||
</column>
|
||||
<column>
|
||||
<action context="{"orderedBy": [{"name": "foo", "asc": 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"
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue