https://github.com/odoo/o-spreadsheet/commit/ab6f47f9 [FIX] InternalViewport: compute the actual visible rect of a zone https://github.com/odoo/o-spreadsheet/commit/966c311e [REF] plugins: unify position getters API https://github.com/odoo/o-spreadsheet/commit/9f1c9695 [IMP] model: ignore type property in command payload https://github.com/odoo/o-spreadsheet/commit/862dacbc [REF] selection: rename getPosition to getActivePosition https://github.com/odoo/o-spreadsheet/commit/0144515a [REF] selection: getPosition return main position https://github.com/odoo/o-spreadsheet/commit/38422f4f [FIX] find and replace: scroll on single match. https://github.com/odoo/o-spreadsheet/commit/9be582c7 [FIX] selection_input: traceback when using unbounded ranges https://github.com/odoo/o-spreadsheet/commit/49285322 [IMP] doc: add tables of contents https://github.com/odoo/o-spreadsheet/commit/2c5d86af [IMP] model: config to provide external dependencies https://github.com/odoo/o-spreadsheet/commit/5b442218 [REF] plugins: use object in constructor https://github.com/odoo/o-spreadsheet/commit/ef98be1b [REM] plugins: remove useless modes https://github.com/odoo/o-spreadsheet/commit/4f20d05f [IMP] data: reorganize data top menu closes odoo/odoo#106583 Related: odoo/enterprise#34412 Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
/** @odoo-module */
|
|
|
|
import spreadsheet from "@spreadsheet/o_spreadsheet/o_spreadsheet_extended";
|
|
import { generateListDefinition } from "./data";
|
|
import { createModelWithDataSource, waitForDataSourcesLoaded } from "./model";
|
|
|
|
const uuidGenerator = new spreadsheet.helpers.UuidGenerator();
|
|
|
|
/** @typedef {import("@spreadsheet/o_spreadsheet/o_spreadsheet").Model} Model */
|
|
|
|
/**
|
|
* Insert a list in a spreadsheet model.
|
|
*
|
|
* @param {Model} model
|
|
* @param {Object} params
|
|
* @param {string} params.model
|
|
* @param {Array<string>} params.columns
|
|
* @param {number} [params.linesNumber]
|
|
* @param {[number, number]} [params.position]
|
|
* @param {string} [params.sheetId]
|
|
*/
|
|
export function insertListInSpreadsheet(model, params) {
|
|
const { definition, columns } = generateListDefinition(params.model, params.columns);
|
|
const [col, row] = params.position || [0, 0];
|
|
|
|
model.dispatch("INSERT_ODOO_LIST", {
|
|
sheetId: params.sheetId || model.getters.getActiveSheetId(),
|
|
definition,
|
|
linesNumber: params.linesNumber || 10,
|
|
columns,
|
|
id: model.getters.getNextListId(),
|
|
col,
|
|
row,
|
|
dataSourceId: uuidGenerator.uuidv4(),
|
|
});
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {Object} params
|
|
* @param {string} [params.model]
|
|
* @param {Array<string>} [params.columns]
|
|
* @param {Object} [params.serverData]
|
|
* @param {function} [params.mockRPC]
|
|
* @param {number} [params.linesNumber]
|
|
* @param {[number, number]} [params.position]
|
|
* @param {string} [params.sheetId]
|
|
*
|
|
* @returns { Promise<{ model: Model, env: Object }>}
|
|
*/
|
|
export async function createSpreadsheetWithList(params = {}) {
|
|
const model = await createModelWithDataSource({
|
|
mockRPC: params.mockRPC,
|
|
serverData: params.serverData,
|
|
});
|
|
|
|
insertListInSpreadsheet(model, {
|
|
columns: params.columns || ["foo", "bar", "date", "product_id"],
|
|
model: params.model || "partner",
|
|
linesNumber: params.linesNumber,
|
|
position: params.position,
|
|
sheetId: params.sheetId,
|
|
});
|
|
|
|
const env = model.config.external.env;
|
|
env.model = model;
|
|
await waitForDataSourcesLoaded(model);
|
|
return { model, env };
|
|
}
|