[FIX] web: re-introduce many2one_reference field and formatter
This field type has been forgotten in the PR that converts web fields to wowl, probably because it wasn't tested. This commit defines a Component and a formatter to use for that field type, in wowl views, s.t. we no longer rely on the legacy implementation. X-original-commit: 540e113d107b59af23dc9726a55f5b8376248247 Part-of: odoo/odoo#101661
This commit is contained in:
@@ -200,7 +200,7 @@ export function formatFloatTime(value, options = {}) {
|
||||
let hour = Math.floor(value);
|
||||
// Although looking quite overkill, the following line ensures that we do
|
||||
// not have float issues while still considering that 59s is 00:00.
|
||||
let min = Math.floor(Math.round((value % 1) * 100) / 100 * 60);
|
||||
let min = Math.floor((Math.round((value % 1) * 100) / 100) * 60);
|
||||
if (min === 60) {
|
||||
min = 0;
|
||||
hour = hour + 1;
|
||||
@@ -211,7 +211,7 @@ export function formatFloatTime(value, options = {}) {
|
||||
}
|
||||
let sec = "";
|
||||
if (options.displaySeconds) {
|
||||
sec = ":" + `${(Math.round((value % 1) * 3600) - min * 60)}`.padStart(2, "0");
|
||||
sec = ":" + `${Math.round((value % 1) * 3600) - min * 60}`.padStart(2, "0");
|
||||
}
|
||||
return `${isNegative ? "-" : ""}${hour}:${min}${sec}`;
|
||||
}
|
||||
@@ -421,6 +421,7 @@ registry
|
||||
.add("html", (value) => value)
|
||||
.add("integer", formatInteger)
|
||||
.add("many2one", formatMany2one)
|
||||
.add("many2one_reference", formatInteger)
|
||||
.add("one2many", formatX2many)
|
||||
.add("many2many", formatX2many)
|
||||
.add("monetary", formatMonetary)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
import { IntegerField } from "../integer/integer_field";
|
||||
|
||||
registry.category("fields").add("many2one_reference", IntegerField);
|
||||
@@ -0,0 +1,69 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { getFixture, getNodesTextContent } from "@web/../tests/helpers/utils";
|
||||
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
|
||||
|
||||
let serverData;
|
||||
let target;
|
||||
|
||||
QUnit.module("Fields", (hooks) => {
|
||||
hooks.beforeEach(() => {
|
||||
target = getFixture();
|
||||
serverData = {
|
||||
models: {
|
||||
partner: {
|
||||
fields: {
|
||||
res_id: {
|
||||
string: "Ressource Id",
|
||||
type: "many2one_reference",
|
||||
},
|
||||
},
|
||||
records: [
|
||||
{ id: 1, res_id: 10 },
|
||||
{ id: 2, res_id: false },
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
setupViewRegistries();
|
||||
});
|
||||
|
||||
QUnit.module("Many2OneReferenceField");
|
||||
|
||||
QUnit.test("Many2OneReferenceField in form view", async function (assert) {
|
||||
await makeView({
|
||||
type: "form",
|
||||
serverData,
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
arch: '<form><field name="res_id"/></form>',
|
||||
});
|
||||
|
||||
assert.strictEqual(target.querySelector(".o_field_widget input").value, "10");
|
||||
});
|
||||
|
||||
QUnit.test("Many2OneReferenceField in list view", async function (assert) {
|
||||
await makeView({
|
||||
type: "list",
|
||||
serverData,
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
arch: '<list><field name="res_id"/></list>',
|
||||
});
|
||||
|
||||
assert.deepEqual(getNodesTextContent(target.querySelectorAll(".o_data_cell")), ["10", ""]);
|
||||
});
|
||||
|
||||
QUnit.test("should be 0 when unset", async function (assert) {
|
||||
await makeView({
|
||||
type: "form",
|
||||
serverData,
|
||||
resModel: "partner",
|
||||
resId: 2,
|
||||
arch: '<form><field name="res_id"/></form>',
|
||||
});
|
||||
|
||||
assert.strictEqual(target.querySelector(".o_field_widget input").value, "");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user