mirror of
https://github.com/bringout/oca-ocb-report.git
synced 2026-04-22 02:42:05 +02:00
19.0 vanilla
This commit is contained in:
parent
62d197ac8b
commit
184bb0e321
667 changed files with 691406 additions and 239886 deletions
|
|
@ -0,0 +1,55 @@
|
|||
import { getFixture } from "@odoo/hoot";
|
||||
import { animationFrame } from "@odoo/hoot-mock";
|
||||
import { Spreadsheet } from "@odoo/o-spreadsheet";
|
||||
import { makeSpreadsheetMockEnv } from "@spreadsheet/../tests/helpers/model";
|
||||
import {
|
||||
getService,
|
||||
makeMockServer,
|
||||
MockServer,
|
||||
mountWithCleanup,
|
||||
patchWithCleanup,
|
||||
} from "@web/../tests/web_test_helpers";
|
||||
import { loadBundle } from "@web/core/assets";
|
||||
import { WebClient } from "@web/webclient/webclient";
|
||||
/**
|
||||
* @param {object} params
|
||||
* @param {object} [params.serverData]
|
||||
* @param {function} [params.mockRPC]
|
||||
* @param {number} [params.spreadsheetId]
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export async function createSpreadsheetDashboard(params = {}) {
|
||||
let model = undefined;
|
||||
patchWithCleanup(Spreadsheet.prototype, {
|
||||
setup() {
|
||||
super.setup();
|
||||
model = this.env.model;
|
||||
},
|
||||
});
|
||||
|
||||
await makeSpreadsheetMockEnv(params);
|
||||
await loadBundle("web.chartjs_lib");
|
||||
await mountWithCleanup(WebClient);
|
||||
await getService("action").doAction({
|
||||
type: "ir.actions.client",
|
||||
tag: "action_spreadsheet_dashboard",
|
||||
params: {
|
||||
dashboard_id: params.spreadsheetId,
|
||||
},
|
||||
});
|
||||
|
||||
return { model, fixture: getFixture() };
|
||||
}
|
||||
|
||||
export async function createDashboardActionWithData(data) {
|
||||
if (!MockServer.env) {
|
||||
await makeMockServer();
|
||||
}
|
||||
const json = JSON.stringify(data);
|
||||
const [dashboard] = MockServer.env["spreadsheet.dashboard"];
|
||||
dashboard.spreadsheet_data = json;
|
||||
dashboard.json_data = json;
|
||||
const { fixture, model } = await createSpreadsheetDashboard({ spreadsheetId: dashboard.id });
|
||||
await animationFrame();
|
||||
return { fixture, model };
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
import { SpreadsheetModels, defineSpreadsheetModels } from "@spreadsheet/../tests/helpers/data";
|
||||
import { fields, models, onRpc } from "@web/../tests/web_test_helpers";
|
||||
import { RPCError } from "@web/core/network/rpc";
|
||||
|
||||
export function getDashboardServerData() {
|
||||
return {
|
||||
models: {
|
||||
"spreadsheet.dashboard": {},
|
||||
"spreadsheet.dashboard.group": {},
|
||||
},
|
||||
views: {},
|
||||
};
|
||||
}
|
||||
|
||||
export class SpreadsheetDashboard extends models.Model {
|
||||
_name = "spreadsheet.dashboard";
|
||||
|
||||
name = fields.Char({ string: "Name" });
|
||||
spreadsheet_data = fields.Char({});
|
||||
json_data = fields.Char({});
|
||||
is_published = fields.Boolean({ string: "Is published" });
|
||||
dashboard_group_id = fields.Many2one({ relation: "spreadsheet.dashboard.group" });
|
||||
favorite_user_ids = fields.Many2many({ relation: "res.users", string: "Favorite Users" });
|
||||
is_favorite = fields.Boolean({ compute: "_compute_is_favorite", string: "Is Favorite" });
|
||||
|
||||
_compute_is_favorite() {
|
||||
for (const record of this) {
|
||||
record.is_favorite = record.favorite_user_ids.includes(this.env.uid);
|
||||
}
|
||||
}
|
||||
|
||||
_records = [
|
||||
{
|
||||
id: 1,
|
||||
spreadsheet_data: "{}",
|
||||
json_data: "{}",
|
||||
name: "Dashboard CRM 1",
|
||||
dashboard_group_id: 1,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
spreadsheet_data: "{}",
|
||||
json_data: "{}",
|
||||
name: "Dashboard CRM 2",
|
||||
dashboard_group_id: 1,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
spreadsheet_data: "{}",
|
||||
json_data: "{}",
|
||||
name: "Dashboard Accounting 1",
|
||||
dashboard_group_id: 2,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export class SpreadsheetDashboardGroup extends models.Model {
|
||||
_name = "spreadsheet.dashboard.group";
|
||||
|
||||
name = fields.Char({ string: "Name" });
|
||||
published_dashboard_ids = fields.One2many({
|
||||
relation: "spreadsheet.dashboard",
|
||||
relation_field: "dashboard_group_id",
|
||||
});
|
||||
|
||||
_records = [
|
||||
{ id: 1, name: "Container 1", published_dashboard_ids: [1, 2] },
|
||||
{ id: 2, name: "Container 2", published_dashboard_ids: [3] },
|
||||
];
|
||||
}
|
||||
|
||||
function mockDashboardDataController(_request, { res_id }) {
|
||||
const [record] = this.env["spreadsheet.dashboard"].search_read([["id", "=", parseInt(res_id)]]);
|
||||
if (!record) {
|
||||
const error = new RPCError(`Dashboard ${res_id} does not exist`);
|
||||
error.data = {};
|
||||
throw error;
|
||||
}
|
||||
return {
|
||||
snapshot: JSON.parse(record.spreadsheet_data),
|
||||
revisions: [],
|
||||
};
|
||||
}
|
||||
|
||||
onRpc("/spreadsheet/dashboard/data/<int:res_id>", mockDashboardDataController);
|
||||
|
||||
export function defineSpreadsheetDashboardModels() {
|
||||
const SpreadsheetDashboardModels = [SpreadsheetDashboard, SpreadsheetDashboardGroup];
|
||||
Object.assign(SpreadsheetModels, SpreadsheetDashboardModels);
|
||||
defineSpreadsheetModels();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue