Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/web/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@
'web.qunit_suite_tests': [
'base/static/tests/base_settings_tests.js',
'web/static/tests/core/**/*.js',
'web/static/tests/fields/**/*.js',
'web/static/tests/webclient/**/*.js',
('remove', 'web/static/tests/webclient/**/helpers.js'),
'web/static/tests/legacy/**/*.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

/**
* Returns a string representing an many2one. If the value is false, then we
* return an empty string. Note that it accepts two types of input parameters:
* return an empty string. Note that it accepts two types of input parameters:
* an array, in that case we assume that the many2one value is of the form
* [id, nameget], and we return the nameget, or it can be an object, and in that
* case, we assume that it is a record datapoint from a BasicModel.
*
* @param {Array|Object|false} value
* @param {Object} [field]
* a description of the field (note: this parameter is ignored)
* @param {{escape?: boolean}} [options] additional options
* @param {boolean} [options.escape=false] if true, escapes the formatted value
* @returns {string}
*/
export function formatMany2one(value, field, options) {
export function formatMany2one(value, options) {
if (!value) {
value = "";
} else if (Array.isArray(value)) {
Expand Down
2 changes: 1 addition & 1 deletion addons/web/static/src/legacy/debug_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { editModelDebug } from "../core/debug/debug_service";
import { json_node_to_xml } from "../views/view_utils";
import { formatMany2one } from "../fields/fields";
import { formatMany2one } from "../fields/format";
import { parseDateTime, formatDateTime } from "../core/l10n/dates";

const { Component, hooks, tags } = owl;
Expand Down
30 changes: 30 additions & 0 deletions addons/web/static/tests/fields/format_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** @odoo-module **/

import { formatMany2one } from "@web/fields/format";

QUnit.module("Format Fields", {}, () => {
QUnit.test("formatMany2one", function (assert) {
assert.strictEqual(formatMany2one(null), "");
assert.strictEqual(formatMany2one([1, "A M2O value"]), "A M2O value");
assert.strictEqual(
formatMany2one({
data: { display_name: "A M2O value" },
}),
"A M2O value"
);

assert.strictEqual(
formatMany2one([1, "A M2O value"], { escape: true }),
"A%20M2O%20value"
);
assert.strictEqual(
formatMany2one(
{
data: { display_name: "A M2O value" },
},
{ escape: true }
),
"A%20M2O%20value",
);
});
});