Using o-spreadsheet features and functions is done using the same import module as if it was installed from npm. Additionaly, by adding the library as dev dependency in package.json[1], IDEs can now leverage Typescript types for autocomplete and type checking. The "alpha" release tag is always the lastest master version. [1] enable web tooling `addons/web/tooling/enable.sh` ;) closes odoo/odoo#115972 Related: odoo/enterprise#38471 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
/** @odoo-module */
|
|
|
|
import { nextTick } from "@web/../tests/helpers/utils";
|
|
import * as spreadsheet from "@odoo/o-spreadsheet";
|
|
import { createModelWithDataSource } from "./model";
|
|
const uuidGenerator = new spreadsheet.helpers.UuidGenerator();
|
|
|
|
/** @typedef {import("@odoo/o-spreadsheet").Model} Model */
|
|
|
|
/**
|
|
*
|
|
* @param {Model} model
|
|
*/
|
|
export function insertChartInSpreadsheet(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 createSpreadsheetWithChart(params = {}) {
|
|
const model = await createModelWithDataSource({
|
|
mockRPC: params.mockRPC,
|
|
});
|
|
|
|
insertChartInSpreadsheet(model, params.type);
|
|
|
|
const env = model.config.custom.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,
|
|
};
|
|
}
|