[IMP] spreadsheet: update o_spreadsheet to latest version

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>
This commit is contained in:
Lucas Lefèvre
2022-11-28 14:51:24 +01:00
parent 2fdd998a9a
commit 4bb43e2554
33 changed files with 454 additions and 440 deletions
@@ -13,7 +13,7 @@ const { Model } = spreadsheet;
async function downloadSpreadsheet(env, action) {
const { orm, name, data, stateUpdateMessages } = action.params;
const dataSources = new DataSources(orm);
const model = new Model(migrate(data), { dataSources }, stateUpdateMessages);
const model = new Model(migrate(data), { external: { dataSources } }, stateUpdateMessages);
await dataSources.waitForAllLoaded();
await waitForDataLoaded(model);
const { files } = model.exportXLSX();
@@ -5,8 +5,8 @@ const { coreTypes } = spreadsheet;
/** Plugin that link charts with Odoo menus. It can contain either the Id of the odoo menu, or its xml id. */
export default class ChartOdooMenuPlugin extends spreadsheet.CorePlugin {
constructor() {
super(...arguments);
constructor(config) {
super(config);
this.odooMenuReference = {};
}
@@ -16,9 +16,9 @@ const { CorePlugin } = spreadsheet;
*/
export default class OdooChartCorePlugin extends CorePlugin {
constructor(getters, history, range, dispatch, config, uuidGenerator) {
super(getters, history, range, dispatch, config, uuidGenerator);
this.dataSources = config.dataSources;
constructor(config) {
super(config);
this.dataSources = config.external.dataSources;
/** @type {Object.<string, Chart>} */
this.charts = {};
@@ -11,9 +11,9 @@ const DATA_SOURCE_ID = "CURRENCIES";
*/
class CurrencyPlugin extends spreadsheet.UIPlugin {
constructor(getters, history, dispatch, config) {
super(getters, history, dispatch, config);
this.dataSources = config.dataSources;
constructor(config) {
super(config);
this.dataSources = config.external.dataSources;
if (this.dataSources) {
this.dataSources.add(DATA_SOURCE_ID, CurrencyDataSource);
}
@@ -29,8 +29,8 @@ import { checkFiltersTypeValueCombination } from "@spreadsheet/global_filters/he
import { _t } from "@web/core/l10n/translation";
export class GlobalFiltersCorePlugin extends spreadsheet.CorePlugin {
constructor() {
super(...arguments);
constructor(config) {
super(config);
/** @type {Object.<string, GlobalFilter>} */
this.globalFilters = {};
}
@@ -43,9 +43,9 @@ const { UuidGenerator } = spreadsheet.helpers;
const uuidGenerator = new UuidGenerator();
export default class GlobalFiltersUIPlugin extends spreadsheet.UIPlugin {
constructor(getters, history, dispatch, config) {
super(getters, history, dispatch, config);
this.orm = config.evalContext.env ? config.evalContext.env.services.orm : undefined;
constructor(config) {
super(config);
this.orm = config.external.env ? config.external.env.services.orm : undefined;
/**
* Cache record display names for relation filters.
* For each filter, contains a promise resolving to
@@ -3,9 +3,9 @@ import spreadsheet from "@spreadsheet/o_spreadsheet/o_spreadsheet_extended";
const { CorePlugin } = spreadsheet;
export default class IrMenuPlugin extends CorePlugin {
constructor(getters, history, range, dispatch, config, uuidGenerator) {
super(getters, history, range, dispatch, config, uuidGenerator);
this.env = config.evalContext.env;
constructor(config) {
super(config);
this.env = config.external.env;
}
/**
+4 -8
View File
@@ -32,16 +32,12 @@ cellMenuRegistry.add("list_see_record", {
name: _lt("See record"),
sequence: 200,
action: async (env) => {
const sheetId = env.model.getters.getActiveSheetId();
const { col, row } = env.model.getters.getPosition();
const position = env.model.getters.getMainCellPosition(sheetId, col, row);
await SEE_RECORD_LIST({ sheetId, ...position }, env);
const position = env.model.getters.getActivePosition();
await SEE_RECORD_LIST(position, env);
},
isVisible: (env) => {
const sheetId = env.model.getters.getActiveSheetId();
const { col, row } = env.model.getters.getPosition();
const position = env.model.getters.getMainCellPosition(sheetId, col, row);
return SEE_RECORD_LIST_VISIBLE({ sheetId, ...position }, env);
const position = env.model.getters.getActivePosition();
return SEE_RECORD_LIST_VISIBLE(position, env);
},
});
@@ -5,8 +5,8 @@ import { getFirstListFunction, getNumberOfListFormulas } from "./list_helpers";
const { astToFormula } = spreadsheet;
export const SEE_RECORD_LIST = async ({ sheetId, col, row }, env) => {
const cell = env.model.getters.getCell(sheetId, col, row);
export const SEE_RECORD_LIST = async (position, env) => {
const cell = env.model.getters.getCell(position);
if (!cell) {
return;
}
@@ -14,7 +14,7 @@ export const SEE_RECORD_LIST = async ({ sheetId, col, row }, env) => {
const evaluatedArgs = args
.map(astToFormula)
.map((arg) => env.model.getters.evaluateFormula(arg));
const listId = env.model.getters.getListIdFromPosition(sheetId, col, row);
const listId = env.model.getters.getListIdFromPosition(position);
const { model } = env.model.getters.getListDefinition(listId);
const dataSource = await env.model.getters.getAsyncListDataSource(listId);
const recordId = dataSource.getIdFromPosition(evaluatedArgs[1] - 1);
@@ -32,7 +32,7 @@ export const SEE_RECORD_LIST = async ({ sheetId, col, row }, env) => {
export const SEE_RECORD_LIST_VISIBLE = (position, env) => {
const evaluatedCell = env.model.getters.getEvaluatedCell(position);
const cell = env.model.getters.getCell(position.sheetId, position.col, position.row);
const cell = env.model.getters.getCell(position);
return (
evaluatedCell.type !== "empty" &&
evaluatedCell.type !== "error" &&
@@ -31,9 +31,9 @@ import { sprintf } from "@web/core/utils/strings";
const { CorePlugin } = spreadsheet;
export default class ListCorePlugin extends CorePlugin {
constructor(getters, history, range, dispatch, config, uuidGenerator) {
super(getters, history, range, dispatch, config, uuidGenerator);
this.dataSources = config.dataSources;
constructor(config) {
super(config);
this.dataSources = config.external.dataSources;
this.nextId = 1;
/** @type {Object.<string, List>} */
@@ -80,16 +80,8 @@ export default class ListCorePlugin extends CorePlugin {
handle(cmd) {
switch (cmd.type) {
case "INSERT_ODOO_LIST": {
const {
sheetId,
col,
row,
id,
definition,
dataSourceId,
linesNumber,
columns,
} = cmd;
const { sheetId, col, row, id, definition, dataSourceId, linesNumber, columns } =
cmd;
const anchor = [col, row];
this._addList(id, definition, dataSourceId, linesNumber);
this._insertList(sheetId, anchor, id, linesNumber, columns);
@@ -11,11 +11,11 @@ const { astToFormula } = spreadsheet;
*/
export default class ListUIPlugin extends spreadsheet.UIPlugin {
constructor(getters, history, dispatch, config, selection) {
super(getters, history, dispatch, config, selection);
constructor(config) {
super(config);
/** @type {string} */
this.selectedListId = undefined;
this.env = config.evalContext.env;
this.env = config.external.env;
}
beforeHandle(cmd) {
@@ -146,14 +146,12 @@ export default class ListUIPlugin extends spreadsheet.UIPlugin {
* Get the id of the list at the given position. Returns undefined if there
* is no list at this position
*
* @param {string} sheetId Id of the sheet
* @param {number} col Index of the col
* @param {number} row Index of the row
* @param {{ sheetId: string; col: number; row: number}} position
*
* @returns {string|undefined}
*/
getListIdFromPosition(sheetId, col, row) {
const cell = this.getters.getCell(sheetId, col, row);
getListIdFromPosition(position) {
const cell = this.getters.getCell(position);
if (cell && cell.isFormula) {
const listFunction = getFirstListFunction(cell.content);
if (listFunction) {
File diff suppressed because it is too large Load Diff
+4 -8
View File
@@ -31,16 +31,12 @@ cellMenuRegistry.add("pivot_see_records", {
name: _lt("See records"),
sequence: 175,
action: async (env) => {
const sheetId = env.model.getters.getActiveSheetId();
const { col, row } = env.model.getters.getPosition();
const position = env.model.getters.getMainCellPosition(sheetId, col, row);
await SEE_RECORDS_PIVOT({ sheetId, ...position }, env);
const position = env.model.getters.getActivePosition();
await SEE_RECORDS_PIVOT(position, env);
},
isVisible: (env) => {
const sheetId = env.model.getters.getActiveSheetId();
const { col, row } = env.model.getters.getPosition();
const position = env.model.getters.getMainCellPosition(sheetId, col, row);
return SEE_RECORDS_PIVOT_VISIBLE({ sheetId, ...position }, env);
const position = env.model.getters.getActivePosition();
return SEE_RECORDS_PIVOT_VISIBLE(position, env);
},
});
@@ -4,8 +4,8 @@ import { getFirstPivotFunction, getNumberOfPivotFormulas } from "./pivot_helpers
const { astToFormula } = spreadsheet;
export const SEE_RECORDS_PIVOT = async ({ sheetId, col, row }, env) => {
const cell = env.model.getters.getCell(sheetId, col, row);
export const SEE_RECORDS_PIVOT = async (position, env) => {
const cell = env.model.getters.getCell(position);
if (!cell) {
return;
}
@@ -13,7 +13,7 @@ export const SEE_RECORDS_PIVOT = async ({ sheetId, col, row }, env) => {
const evaluatedArgs = args
.map(astToFormula)
.map((arg) => env.model.getters.evaluateFormula(arg));
const pivotId = env.model.getters.getPivotIdFromPosition(sheetId, col, row);
const pivotId = env.model.getters.getPivotIdFromPosition(position);
const { model } = env.model.getters.getPivotDefinition(pivotId);
const dataSource = await env.model.getters.getAsyncPivotDataSource(pivotId);
const slice = functionName === "ODOO.PIVOT.HEADER" ? 1 : 2;
@@ -40,7 +40,7 @@ export const SEE_RECORDS_PIVOT = async ({ sheetId, col, row }, env) => {
export const SEE_RECORDS_PIVOT_VISIBLE = (position, env) => {
const evaluatedCell = env.model.getters.getEvaluatedCell(position);
const cell = env.model.getters.getCell(position.sheetId, position.col, position.row);
const cell = env.model.getters.getCell(position);
return (
evaluatedCell.type !== "empty" &&
evaluatedCell.type !== "error" &&
@@ -36,9 +36,9 @@ import { sprintf } from "@web/core/utils/strings";
const { CorePlugin } = spreadsheet;
export default class PivotCorePlugin extends CorePlugin {
constructor(getters, history, range, dispatch, config, uuidGenerator) {
super(getters, history, range, dispatch, config, uuidGenerator);
this.dataSources = config.dataSources;
constructor(config) {
super(config);
this.dataSources = config.external.dataSources;
this.nextId = 1;
/** @type {Object.<string, Pivot>} */
@@ -43,8 +43,8 @@ function pivotPeriodToFilterValue(timeRange, value) {
}
export default class PivotUIPlugin extends spreadsheet.UIPlugin {
constructor() {
super(...arguments);
constructor(config) {
super(config);
/** @type {string} */
this.selectedPivotId = undefined;
this.selection.observe(this, {
@@ -60,7 +60,7 @@ export default class PivotUIPlugin extends spreadsheet.UIPlugin {
case "ZonesSelected": {
const sheetId = this.getters.getActiveSheetId();
const { col, row } = event.anchor.cell;
const cell = this.getters.getCell(sheetId, col, row);
const cell = this.getters.getCell({ sheetId, col, row });
if (cell !== undefined && cell.content.startsWith("=ODOO.PIVOT.HEADER(")) {
const filters = this.getFiltersMatchingPivot(cell.content);
this.dispatch("SET_MANY_GLOBAL_FILTER_VALUE", { filters });
@@ -136,14 +136,12 @@ export default class PivotUIPlugin extends spreadsheet.UIPlugin {
* Get the id of the pivot at the given position. Returns undefined if there
* is no pivot at this position
*
* @param {string} sheetId Id of the sheet
* @param {number} col Index of the col
* @param {number} row Index of the row
* @param {{ sheetId: string; col: number; row: number}} position
*
* @returns {string|undefined}
*/
getPivotIdFromPosition(sheetId, col, row) {
const cell = this.getters.getCell(sheetId, col, row);
getPivotIdFromPosition(position) {
const cell = this.getters.getCell(position);
if (cell && cell.isFormula) {
const pivotFunction = getFirstPivotFunction(cell.content);
if (pivotFunction) {
@@ -124,7 +124,7 @@ QUnit.module(
"Links between charts and ir.menus are correctly imported/exported",
async function (assert) {
const env = await makeTestEnv({ serverData: this.serverData });
const model = new Model({}, { evalContext: { env } });
const model = new Model({}, { external: { env } });
createBasicChart(model, chartId);
model.dispatch("LINK_ODOO_MENU_TO_CHART", {
chartId,
@@ -136,7 +136,7 @@ QUnit.module(
1,
"Link to odoo menu is exported"
);
const importedModel = new Model(exportedData, { evalContext: { env } });
const importedModel = new Model(exportedData, { external: { env } });
const chartMenu = importedModel.getters.getChartOdooMenu(chartId);
assert.equal(chartMenu.id, 1, "Link to odoo menu is imported");
}
@@ -144,7 +144,7 @@ QUnit.module(
QUnit.test("Can undo-redo a LINK_ODOO_MENU_TO_CHART", async function (assert) {
const env = await makeTestEnv({ serverData: this.serverData });
const model = new Model({}, { evalContext: { env } });
const model = new Model({}, { external: { env } });
createBasicChart(model, chartId);
model.dispatch("LINK_ODOO_MENU_TO_CHART", {
chartId,
@@ -159,7 +159,7 @@ QUnit.module(
QUnit.test("link is removed when figure is deleted", async function (assert) {
const env = await makeTestEnv({ serverData: this.serverData });
const model = new Model({}, { evalContext: { env } });
const model = new Model({}, { external: { env } });
createBasicChart(model, chartId);
model.dispatch("LINK_ODOO_MENU_TO_CHART", {
chartId,
@@ -378,8 +378,7 @@ QUnit.module("spreadsheet > Global filters model", {}, () => {
assert.equal(listDomain.length, 7, "it should have updated the list domain");
const newModel = new Model(model.exportData(), {
evalContext: model.config.evalContext,
dataSources: model.config.dataSources,
external: model.config.external,
});
assert.equal(newModel.getters.getGlobalFilters().length, 2);
@@ -639,8 +638,10 @@ QUnit.module("spreadsheet > Global filters model", {}, () => {
const model = new Model(
{},
{
dataSources: new DataSources({ ...orm, silent: orm }),
evalContext: { env: { services: { orm } } },
external: {
dataSources: new DataSources({ ...orm, silent: orm }),
env: { services: { orm } },
},
}
);
setupDataSourceEvaluation(model);
@@ -26,7 +26,7 @@ function beforeEach() {
QUnit.module("spreadsheet > menu link cells", { beforeEach }, () => {
QUnit.test("ir.menu linked based on xml id", async function (assert) {
const env = await makeTestEnv({ serverData: getMenuServerData() });
const model = new Model({}, { evalContext: { env } });
const model = new Model({}, { external: { env } });
setCellContent(model, "A1", "[label](odoo://ir_menu_xml_id/test_menu)");
const cell = getCell(model, "A1");
const evaluatedCell = getEvaluatedCell(model, "A1");
@@ -46,7 +46,7 @@ QUnit.module("spreadsheet > menu link cells", { beforeEach }, () => {
QUnit.test("ir.menu linked based on record id", async function (assert) {
const env = await makeTestEnv({ serverData: getMenuServerData() });
const model = new Model({}, { evalContext: { env } });
const model = new Model({}, { external: { env } });
setCellContent(model, "A1", "[label](odoo://ir_menu_id/2)");
const cell = getCell(model, "A1");
const evaluatedCell = getEvaluatedCell(model, "A1");
@@ -66,7 +66,7 @@ QUnit.module("spreadsheet > menu link cells", { beforeEach }, () => {
QUnit.test("ir.menu linked based on xml id which does not exists", async function (assert) {
const env = await makeTestEnv({ serverData: getMenuServerData() });
const model = new Model({}, { evalContext: { env } });
const model = new Model({}, { external: { env } });
setCellContent(model, "A1", "[label](odoo://ir_menu_xml_id/does_not_exists)");
assert.equal(
getCell(model, "A1").content,
@@ -81,7 +81,7 @@ QUnit.module("spreadsheet > menu link cells", { beforeEach }, () => {
QUnit.test("ir.menu linked based on record id which does not exists", async function (assert) {
const env = await makeTestEnv({ serverData: getMenuServerData() });
const model = new Model({}, { evalContext: { env } });
const model = new Model({}, { external: { env } });
setCellContent(model, "A1", "[label](odoo://ir_menu_id/9999)");
assert.equal(getCell(model, "A1").content, "[label](odoo://ir_menu_id/9999)");
assert.equal(getEvaluatedCell(model, "A1").value, "#LINK");
@@ -93,7 +93,7 @@ QUnit.module("spreadsheet > menu link cells", { beforeEach }, () => {
QUnit.test("Odoo link cells can be imported/exported", async function (assert) {
const env = await makeTestEnv({ serverData: getMenuServerData() });
const model = new Model({}, { evalContext: { env } });
const model = new Model({}, { external: { env } });
setCellContent(model, "A1", "[label](odoo://ir_menu_id/2)");
let cell = getCell(model, "A1");
let evaluatedCell = getEvaluatedCell(model, "A1");
@@ -109,7 +109,7 @@ QUnit.module("spreadsheet > menu link cells", { beforeEach }, () => {
"odoo://ir_menu_id/2",
"The link url should reference the correct menu"
);
const model2 = new Model(model.exportData(), { evalContext: { env } });
const model2 = new Model(model.exportData(), { external: { env } });
cell = getCell(model2, "A1");
evaluatedCell = getEvaluatedCell(model, "A1");
assert.equal(evaluatedCell.value, "label", "The value should be the menu name");
@@ -41,7 +41,7 @@ QUnit.test("click a web link", async (assert) => {
},
],
};
const model = new Model(data, { evalContext: { env } });
const model = new Model(data, { external: { env } });
const cell = getEvaluatedCell(model, "A1");
assert.strictEqual(urlRepresentation(cell.link, model.getters), "https://odoo.com");
openLink(cell.link, env);
@@ -68,7 +68,7 @@ QUnit.test("click a menu link", async (assert) => {
},
],
};
const model = new Model(data, { evalContext: { env } });
const model = new Model(data, { external: { env } });
const cell = getEvaluatedCell(model, "A1");
assert.strictEqual(urlRepresentation(cell.link, model.getters), "menu with xmlid");
openLink(cell.link, env);
@@ -112,7 +112,7 @@ QUnit.test("click a menu link", async (assert) => {
},
],
};
const model = new Model(data, { evalContext: { env } });
const model = new Model(data, { external: { env } });
const cell = getEvaluatedCell(model, "A1");
assert.strictEqual(urlRepresentation(cell.link, model.getters), "an odoo view");
openLink(cell.link, env);
@@ -101,7 +101,7 @@ QUnit.module("spreadsheet > list plugin", {}, () => {
QUnit.test("can select a List from cell formula", async function (assert) {
const { model } = await createSpreadsheetWithList();
const sheetId = model.getters.getActiveSheetId();
const listId = model.getters.getListIdFromPosition(sheetId, 0, 0);
const listId = model.getters.getListIdFromPosition({ sheetId, col: 0, row: 0 });
model.dispatch("SELECT_ODOO_LIST", { listId });
const selectedListId = model.getters.getSelectedListId();
assert.strictEqual(selectedListId, "1");
@@ -113,7 +113,7 @@ QUnit.module("spreadsheet > list plugin", {}, () => {
const { model } = await createSpreadsheetWithList();
setCellContent(model, "A1", `=-ODOO.LIST("1","1","foo")`);
const sheetId = model.getters.getActiveSheetId();
const listId = model.getters.getListIdFromPosition(sheetId, 0, 0);
const listId = model.getters.getListIdFromPosition({ sheetId, col: 0, row: 0 });
model.dispatch("SELECT_ODOO_LIST", { listId });
const selectedListId = model.getters.getSelectedListId();
assert.strictEqual(selectedListId, "1");
@@ -125,7 +125,7 @@ QUnit.module("spreadsheet > list plugin", {}, () => {
const { model } = await createSpreadsheetWithList();
setCellContent(model, "A1", `=3*ODOO.LIST("1","1","foo")`);
const sheetId = model.getters.getActiveSheetId();
const listId = model.getters.getListIdFromPosition(sheetId, 0, 0);
const listId = model.getters.getListIdFromPosition({ sheetId, col: 0, row: 0 });
model.dispatch("SELECT_ODOO_LIST", { listId });
const selectedListId = model.getters.getSelectedListId();
assert.strictEqual(selectedListId, "1");
@@ -143,7 +143,7 @@ QUnit.module("spreadsheet > list plugin", {}, () => {
const { model } = await createSpreadsheetWithList();
setCellContent(model, "A1", `=SUM(ODOO.LIST("1","1","foo"),1)`);
const sheetId = model.getters.getActiveSheetId();
const listId = model.getters.getListIdFromPosition(sheetId, 0, 0);
const listId = model.getters.getListIdFromPosition({ sheetId, col: 0, row: 0 });
model.dispatch("SELECT_ODOO_LIST", { listId });
const selectedListId = model.getters.getSelectedListId();
assert.strictEqual(selectedListId, "1");
@@ -156,7 +156,7 @@ QUnit.module("spreadsheet > list plugin", {}, () => {
setCellContent(model, "A1", `=ODOO.LIST(G10,"1","foo")`);
setCellContent(model, "G10", "1");
const sheetId = model.getters.getActiveSheetId();
const listId = model.getters.getListIdFromPosition(sheetId, 0, 0);
const listId = model.getters.getListIdFromPosition({ sheetId, col: 0, row: 0 });
model.dispatch("SELECT_ODOO_LIST", { listId });
const selectedListId = model.getters.getSelectedListId();
assert.strictEqual(selectedListId, "1");
@@ -28,7 +28,7 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => {
</pivot>`,
});
const sheetId = model.getters.getActiveSheetId();
const pivotId = model.getters.getPivotIdFromPosition(sheetId, 2, 2);
const pivotId = model.getters.getPivotIdFromPosition({ sheetId, col: 2, row: 2 });
model.dispatch("SELECT_PIVOT", { pivotId });
const selectedPivotId = model.getters.getSelectedPivotId();
assert.strictEqual(selectedPivotId, "1");
@@ -50,7 +50,7 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => {
text: `=-PIVOT("1","probability","bar","false","foo","2")`,
});
const sheetId = model.getters.getActiveSheetId();
const pivotId = model.getters.getPivotIdFromPosition(sheetId, 2, 2);
const pivotId = model.getters.getPivotIdFromPosition({ sheetId, col: 2, row: 2 });
model.dispatch("SELECT_PIVOT", { pivotId });
const selectedPivotId = model.getters.getSelectedPivotId();
assert.strictEqual(selectedPivotId, "1");
@@ -73,7 +73,7 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => {
text: `=3*PIVOT("1","probability","bar","false","foo","2")+2`,
});
const sheetId = model.getters.getActiveSheetId();
const pivotId = model.getters.getPivotIdFromPosition(sheetId, 2, 2);
const pivotId = model.getters.getPivotIdFromPosition({ sheetId, col: 2, row: 2 });
model.dispatch("SELECT_PIVOT", { pivotId });
const selectedPivotId = model.getters.getSelectedPivotId();
assert.strictEqual(selectedPivotId, "1");
@@ -96,7 +96,7 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => {
text: `=SUM(PIVOT("1","probability","bar","false","foo","2"),PIVOT("1","probability","bar","false","foo","2"))`,
});
const sheetId = model.getters.getActiveSheetId();
const pivotId = model.getters.getPivotIdFromPosition(sheetId, 2, 2);
const pivotId = model.getters.getPivotIdFromPosition({ sheetId, col: 2, row: 2 });
model.dispatch("SELECT_PIVOT", { pivotId });
const selectedPivotId = model.getters.getSelectedPivotId();
assert.strictEqual(selectedPivotId, "1");
@@ -110,7 +110,7 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => {
setCellContent(model, "C3", `=ODOO.PIVOT(G10,"probability","bar","false","foo","2")+2`);
setCellContent(model, "G10", "1");
const sheetId = model.getters.getActiveSheetId();
const pivotId = model.getters.getPivotIdFromPosition(sheetId, 2, 2);
const pivotId = model.getters.getPivotIdFromPosition({ sheetId, col: 2, row: 2 });
model.dispatch("SELECT_PIVOT", { pivotId });
const selectedPivotId = model.getters.getSelectedPivotId();
assert.strictEqual(selectedPivotId, "1");
@@ -133,7 +133,7 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => {
text: `=3*SUM(PIVOT("1","probability","bar","false","foo","2"),PIVOT("1","probability","bar","false","foo","2"))+2*PIVOT("1","probability","bar","false","foo","2")`,
});
const sheetId = model.getters.getActiveSheetId();
const pivotId = model.getters.getPivotIdFromPosition(sheetId, 2, 2);
const pivotId = model.getters.getPivotIdFromPosition({ sheetId, col: 2, row: 2 });
model.dispatch("SELECT_PIVOT", { pivotId });
const selectedPivotId = model.getters.getSelectedPivotId();
assert.strictEqual(selectedPivotId, "1");
@@ -38,7 +38,7 @@ export async function createSpreadsheetWithChart(params = {}) {
insertChartInSpreadsheet(model, params.type);
const env = model.config.evalContext.env;
const env = model.config.external.env;
env.model = model;
await nextTick();
return { model, env };
@@ -18,7 +18,7 @@ export function getCellValue(model, xc, sheetId = model.getters.getActiveSheetId
*/
export function getCell(model, xc, sheetId = model.getters.getActiveSheetId()) {
const { col, row } = toCartesian(xc);
return model.getters.getCell(sheetId, col, row);
return model.getters.getCell({ sheetId, col, row });
}
export function getEvaluatedCell(model, xc, sheetId = model.getters.getActiveSheetId()) {
@@ -62,7 +62,7 @@ export async function createSpreadsheetWithList(params = {}) {
sheetId: params.sheetId,
});
const env = model.config.evalContext.env;
const env = model.config.external.env;
env.model = model;
await waitForDataSourcesLoaded(model);
return { model, env };
@@ -16,7 +16,7 @@ const { Model } = spreadsheet;
*/
export function setupDataSourceEvaluation(model) {
model.config.dataSources.addEventListener("data-source-updated", () => {
model.config.external.dataSources.addEventListener("data-source-updated", () => {
const sheetId = model.getters.getActiveSheetId();
model.dispatch("EVALUATE_CELLS", { sheetId });
});
@@ -37,9 +37,10 @@ export async function createModelWithDataSource(params = {}) {
mockRPC: params.mockRPC,
});
const model = new Model(params.spreadsheetData, {
evalContext: { env },
//@ts-ignore
dataSources: new DataSources(env.services.orm.silent),
external: {
env,
dataSources: new DataSources(env.services.orm.silent),
},
});
setupDataSourceEvaluation(model);
await nextTick(); // initial async formulas loading
@@ -61,7 +62,7 @@ export async function waitForDataSourcesLoaded(model) {
// Read a first time in order to trigger the RPC
readAllCellsValue();
//@ts-ignore
await model.config.dataSources.waitForAllLoaded();
await model.config.external.dataSources.waitForAllLoaded();
await nextTick();
// Read a second time to trigger the compute format (which could trigger a RPC for currency, in list)
readAllCellsValue();
@@ -32,7 +32,7 @@ export async function insertPivotInSpreadsheet(model, params) {
},
name: "Partner Pivot",
};
const dataSource = model.config.dataSources.create(PivotDataSource, definition);
const dataSource = model.config.external.dataSources.create(PivotDataSource, definition);
await dataSource.load();
const { cols, rows, measures } = dataSource.getTableStructure().export();
const table = {
@@ -68,7 +68,7 @@ export async function createSpreadsheetWithPivot(params = {}) {
});
const arch = params.arch || serverData.views["partner,false,pivot"];
await insertPivotInSpreadsheet(model, { arch });
const env = model.config.evalContext.env;
const env = model.config.external.env;
env.model = model;
await waitForDataSourcesLoaded(model);
return { model, env };
+1 -1
View File
@@ -21,7 +21,7 @@ export async function mountSpreadsheet(model) {
const app = new App(Spreadsheet, {
props: { model },
templates: templates,
env: model.config.evalContext.env,
env: model.config.external.env,
test: true,
});
registerCleanup(() => app.destroy());
@@ -17,9 +17,8 @@ cellMenuRegistry.add("move_lines_see_records", {
name: _lt("See records"),
sequence: 176,
async action(env) {
const sheetId = env.model.getters.getActiveSheetId();
const { col, row } = env.model.getters.getPosition();
const cell = env.model.getters.getCell(sheetId, col, row);
const position = env.model.getters.getActivePosition();
const cell = env.model.getters.getCell(position);
const { args } = getFirstAccountFunction(cell.content);
let [code, date_range, offset, companyId, includeUnposted] = args
.map(astToFormula)
@@ -38,11 +37,9 @@ cellMenuRegistry.add("move_lines_see_records", {
await env.services.action.doAction(action);
},
isVisible: (env) => {
const sheetId = env.model.getters.getActiveSheetId();
const { col, row } = env.model.getters.getPosition();
const position = env.model.getters.getMainCellPosition(sheetId, col, row);
const evaluatedCell = env.model.getters.getEvaluatedCell({ sheetId, ...position });
const cell = env.model.getters.getCell(sheetId, position.col, position.row);
const position = env.model.getters.getActivePosition();
const evaluatedCell = env.model.getters.getEvaluatedCell(position);
const cell = env.model.getters.getCell(position);
return (
!evaluatedCell.error &&
evaluatedCell.value !== "" &&
@@ -9,9 +9,9 @@ const DATA_SOURCE_ID = "ACCOUNTING_AGGREGATES";
*/
export default class AccountingPlugin extends spreadsheet.UIPlugin {
constructor(getters, history, dispatch, config) {
super(getters, history, dispatch, config);
this.dataSources = config.dataSources;
constructor(config) {
super(config);
this.dataSources = config.external.dataSources;
if (this.dataSources) {
this.dataSources.add(DATA_SOURCE_ID, AccountingDataSource);
}
@@ -62,7 +62,7 @@ QUnit.module("spreadsheet_account > Accounting Drill down", { beforeEach }, () =
}
},
});
const env = model.config.evalContext.env;
const env = model.config.external.env;
env.model = model;
setCellContent(model, "A1", `=ODOO.BALANCE("100", 2020)`);
setCellContent(model, "A2", `=ODOO.BALANCE("100", 0)`);
@@ -211,9 +211,8 @@ export class DashboardLoader {
const model = new Model(
migrate(JSON.parse(data)),
{
evalContext: { env: this.env, orm: this.orm },
external: { env: this.env, orm: this.orm, dataSources },
mode: "dashboard",
dataSources,
},
revisions
);
@@ -14,15 +14,15 @@ clickableCellRegistry.add("pivot", {
clickableCellRegistry.add("pivot_set_filter_matching", {
condition: (position, env) => {
const cell = env.model.getters.getCell(position.sheetId, position.col, position.row);
const cell = env.model.getters.getCell(position);
return (
SEE_RECORDS_PIVOT_VISIBLE(position, env) &&
getFirstPivotFunction(cell.content).functionName === "ODOO.PIVOT.HEADER" &&
env.model.getters.getFiltersMatchingPivot(cell.content).length > 0
);
},
action: ({ sheetId, col, row }, env) => {
const cell = env.model.getters.getCell(sheetId, col, row);
action: (position, env) => {
const cell = env.model.getters.getCell(position);
const filters = env.model.getters.getFiltersMatchingPivot(cell.content);
env.model.dispatch("SET_MANY_GLOBAL_FILTER_VALUE", { filters });
},