Files
odoo_source/addons/spreadsheet/static/tests/utils/chart.js
T
Lucas Lefèvre a20032cc1c [MOV] spreadsheet: move module to community
The spreadsheet module is moved to the community version
for the upcoming spreadsheet dashboards

This module is the core engine of spreadsheets in Odoo.
It contains `o-spreadsheet` library (o_spreadsheet.js) and all basic
integrations with odoo such as accounting formulas, lists, pivot, filters, etc.

This module alone does not have any action or menu to open a spreadsheet.
Those actions come with `documents_spreadsheet` module or the upcoming
`spreadsheet_dashboard` module.

Task 2799682

Part-of: odoo/odoo#97606
2022-09-10 02:54:51 +02:00

72 lines
1.8 KiB
JavaScript

/** @odoo-module */
import { nextTick } from "@web/../tests/helpers/utils";
import spreadsheet from "@spreadsheet/o_spreadsheet/o_spreadsheet_extended";
import { createModelWithDataSource } from "./model";
const uuidGenerator = new spreadsheet.helpers.UuidGenerator();
/** @typedef {import("@spreadsheet/o_spreadsheet/o_spreadsheet").Model} Model */
/**
*
* @param {Model} model
*/
export function insertGraphInSpreadsheet(model, type = "odoo_bar") {
const definition = getChartDefinition(type);
model.dispatch("CREATE_CHART", {
sheetId: model.getters.getActiveSheetId(),
id: definition.id,
position: {
x: 10,
y: 10,
},
definition,
});
}
/**
*
* @param {Object} params
* @param {function} [params.mockRPC]
* @param {string} [params.type]
*
* @returns { Promise<{ model: Model, env: Object }>}
*/
export async function createSpreadsheetWithGraph(params = {}) {
const model = await createModelWithDataSource({
mockRPC: params.mockRPC,
});
insertGraphInSpreadsheet(model, params.type);
const env = model.config.evalContext.env;
env.model = model;
await nextTick();
return { model, env };
}
function getChartDefinition(type) {
return {
metaData: {
groupBy: ["foo", "bar"],
measure: "__count",
order: null,
resModel: "partner",
},
searchParams: {
comparison: null,
context: {},
domain: [],
groupBy: [],
orderBy: [],
},
stacked: true,
title: "Partners",
background: "#FFFFFF",
legendPosition: "top",
verticalAxisPosition: "left",
dataSourceId: uuidGenerator.uuidv4(),
id: uuidGenerator.uuidv4(),
type,
};
}