Files
odoo_source/addons/spreadsheet/static/tests/utils/list.js
T
Adrien Minne (adrm) d70da3f734 [REF] spreadsheet: move list dataSources to UI
Before this commit, the list's dataSources were managed by the core plugin
`ListCorePlugin`. This didn't make sense since dataSources aren't core data:

- they are neither exported nor imported
- they can be different for each user (their ids were generated via uuidv4
at import)
- managing them required to handle local command in the core plugin

Moved the dataSources management to the UI plugin `ListUIPlugin` and moved
the relevant getters inside this plugin. Changed the ids of the dataSources
to be the same as the list's id + a prefix, to avoid having to maintain a
mapping `listId` <=> `dataSourceId` .

This commit also removes the dataSourceId from the INSERT_ODOO_LIST
command, which have no place here since this is a core command and the
dataSources are now a pure UI concept.

Task: 3293491
Part-of: odoo/odoo#120136
2023-05-05 17:06:45 +02:00

66 lines
1.9 KiB
JavaScript

/** @odoo-module */
import { generateListDefinition } from "./data";
import { createModelWithDataSource, waitForDataSourcesLoaded } from "./model";
/** @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,
});
}
/**
*
* @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.custom.env;
env.model = model;
await waitForDataSourcesLoaded(model);
return { model, env };
}