Skip to content

Commit 46afd5d

Browse files
committed
[IMP] web: fields/fields => fields/format.js + test
1 parent 520b437 commit 46afd5d

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

addons/web/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@
472472
'web.qunit_suite_tests': [
473473
'base/static/tests/base_settings_tests.js',
474474
'web/static/tests/core/**/*.js',
475+
'web/static/tests/fields/**/*.js',
475476
'web/static/tests/webclient/**/*.js',
476477
('remove', 'web/static/tests/webclient/**/helpers.js'),
477478
'web/static/tests/legacy/**/*.js',

addons/web/static/src/fields/fields.js renamed to addons/web/static/src/fields/format.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
/**
44
* Returns a string representing an many2one. If the value is false, then we
5-
* return an empty string. Note that it accepts two types of input parameters:
5+
* return an empty string. Note that it accepts two types of input parameters:
66
* an array, in that case we assume that the many2one value is of the form
77
* [id, nameget], and we return the nameget, or it can be an object, and in that
88
* case, we assume that it is a record datapoint from a BasicModel.
99
*
1010
* @param {Array|Object|false} value
11-
* @param {Object} [field]
12-
* a description of the field (note: this parameter is ignored)
1311
* @param {{escape?: boolean}} [options] additional options
1412
* @param {boolean} [options.escape=false] if true, escapes the formatted value
1513
* @returns {string}
1614
*/
17-
export function formatMany2one(value, field, options) {
15+
export function formatMany2one(value, options) {
1816
if (!value) {
1917
value = "";
2018
} else if (Array.isArray(value)) {

addons/web/static/src/legacy/debug_manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { editModelDebug } from "../core/debug/debug_service";
44
import { json_node_to_xml } from "../views/view_utils";
5-
import { formatMany2one } from "../fields/fields";
5+
import { formatMany2one } from "../fields/format";
66
import { parseDateTime, formatDateTime } from "../core/l10n/dates";
77

88
const { Component, hooks, tags } = owl;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/** @odoo-module **/
2+
3+
import { formatMany2one } from "@web/fields/format";
4+
5+
QUnit.module("Format Fields", {}, () => {
6+
QUnit.test("formatMany2one", function (assert) {
7+
assert.strictEqual(formatMany2one(null), "");
8+
assert.strictEqual(formatMany2one([1, "A M2O value"]), "A M2O value");
9+
assert.strictEqual(
10+
formatMany2one({
11+
data: { display_name: "A M2O value" },
12+
}),
13+
"A M2O value"
14+
);
15+
16+
assert.strictEqual(
17+
formatMany2one([1, "A M2O value"], { escape: true }),
18+
"A%20M2O%20value"
19+
);
20+
assert.strictEqual(
21+
formatMany2one(
22+
{
23+
data: { display_name: "A M2O value" },
24+
},
25+
{ escape: true }
26+
),
27+
"A%20M2O%20value",
28+
);
29+
});
30+
});

0 commit comments

Comments
 (0)