[IMP] web: fetch raw data for record in debug
This commit introduces a new debug menu item in form view that allows to read all the raw fields data of the current record in JSON format. task-3509462 closes odoo/odoo#137260 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
committed by
Julien Carion (juca)
parent
9444a3e0c4
commit
ae62a08cbc
@@ -189,6 +189,49 @@ export function viewMetadata({ component, env }) {
|
||||
|
||||
debugRegistry.category("form").add("viewMetadata", viewMetadata);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// View Raw Record Data
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class RawRecordDialog extends Component {
|
||||
get content() {
|
||||
const record = this.props.record;
|
||||
return JSON.stringify(record, Object.keys(record).sort(), 2);
|
||||
}
|
||||
}
|
||||
RawRecordDialog.template = xml`
|
||||
<Dialog title="props.title">
|
||||
<pre t-esc="content"/>
|
||||
</Dialog>`;
|
||||
RawRecordDialog.components = { Dialog };
|
||||
RawRecordDialog.props = {
|
||||
record: { type: Object },
|
||||
title: { type: String },
|
||||
close: { type: Function },
|
||||
};
|
||||
|
||||
export function viewRawRecord({ component, env }) {
|
||||
const { resId, resModel } = component.model.config;
|
||||
if (!resId) {
|
||||
return null;
|
||||
}
|
||||
const description = _t("View Raw Record Data");
|
||||
return {
|
||||
type: "item",
|
||||
description,
|
||||
callback: async () => {
|
||||
const records = await component.model.orm.read(resModel, [resId]);
|
||||
env.services.dialog.add(RawRecordDialog, {
|
||||
title: _t("Raw Record Data: %s(%s)", resModel, resId),
|
||||
record: records[0],
|
||||
});
|
||||
},
|
||||
sequence: 325,
|
||||
};
|
||||
}
|
||||
|
||||
debugRegistry.category("form").add("viewRawRecord", viewRawRecord);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Set Defaults
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -28,7 +28,13 @@ import {
|
||||
} from "../../helpers/utils";
|
||||
import { createWebClient, doAction, getActionManagerServerData } from "../../webclient/helpers";
|
||||
import { openViewItem } from "@web/webclient/debug_items";
|
||||
import { editSearchView, editView, setDefaults, viewMetadata } from "@web/views/debug_items";
|
||||
import {
|
||||
editSearchView,
|
||||
editView,
|
||||
setDefaults,
|
||||
viewMetadata,
|
||||
viewRawRecord,
|
||||
} from "@web/views/debug_items";
|
||||
import { fieldService } from "@web/core/field_service";
|
||||
|
||||
import { Component, xml } from "@odoo/owl";
|
||||
@@ -662,6 +668,47 @@ QUnit.module("DebugMenu", (hooks) => {
|
||||
assert.containsNone(target, ".modal");
|
||||
});
|
||||
|
||||
QUnit.test("fetch raw data: basic rendering", async (assert) => {
|
||||
prepareRegistriesWithCleanup();
|
||||
patchWithCleanup(odoo, {
|
||||
debug: true,
|
||||
});
|
||||
|
||||
registry.category("services").add("user", makeFakeUserService());
|
||||
registry.category("debug").category("form").add("viewRawRecord", viewRawRecord);
|
||||
|
||||
const serverData = getActionManagerServerData();
|
||||
serverData.actions[1234] = {
|
||||
id: 1234,
|
||||
xml_id: "action_1234",
|
||||
name: "Partners",
|
||||
res_model: "partner",
|
||||
res_id: 27,
|
||||
type: "ir.actions.act_window",
|
||||
views: [[false, "form"]],
|
||||
};
|
||||
serverData.models.partner.records = [{ id: 27, display_name: "p1" }];
|
||||
|
||||
const mockRPC = async (route, args) => {
|
||||
if (args.method === "check_access_rights") {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
};
|
||||
const webClient = await createWebClient({ serverData, mockRPC });
|
||||
await doAction(webClient, 1234);
|
||||
await click(target.querySelector(".o_debug_manager button"));
|
||||
await click(target.querySelector(".o_debug_manager .dropdown-item"));
|
||||
assert.containsOnce(target, ".modal");
|
||||
assert.strictEqual(
|
||||
target.querySelector(".modal-title").textContent,
|
||||
"Raw Record Data: partner(27)"
|
||||
);
|
||||
assert.strictEqual(
|
||||
target.querySelector(".modal-body pre").textContent,
|
||||
'{\n "bar": false,\n "display_name": "p1",\n "foo": false,\n "id": 27,\n "m2o": false,\n "name": "name",\n "o2m": [],\n "write_date": false\n}'
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("view metadata: basic rendering", async (assert) => {
|
||||
prepareRegistriesWithCleanup();
|
||||
patchWithCleanup(odoo, {
|
||||
|
||||
Reference in New Issue
Block a user