[FIX] web: fix field_digits monetary options

Before this commit, the `field_digits` options of the monetary field
has not been reimplemented since the owl conversion and so the digits
of the currency was used.
Now, when the `field_digits` option is given, the digits of the field
is used instead of the currency digits.

task 3072702

closes odoo/odoo#111308

X-original-commit: 996cc74745a2fb72547053991a79d233d6916587
Related: odoo/enterprise#36568
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Michael (mcm)
2023-02-03 05:09:17 +01:00
parent 013c0f9c93
commit ed95be9a95
4 changed files with 41 additions and 22 deletions
@@ -362,7 +362,7 @@ export function formatMonetary(value, options = {}) {
currencyId = Array.isArray(dataValue) ? dataValue[0] : dataValue;
}
const currency = session.currencies[currencyId];
const digits = (currency && currency.digits) || options.digits;
const digits = options.digits || (currency && currency.digits);
let formattedValue;
if (options.humanReadable) {
@@ -448,7 +448,7 @@ export function formatText(value) {
}
export function formatJson(value) {
return value && JSON.stringify(value) || "";
return (value && JSON.stringify(value)) || "";
}
registry
@@ -22,9 +22,10 @@ export class MonetaryField extends Component {
}
get currencyId() {
const currencyField = this.props.currencyField ||
this.props.record.fields[this.props.name].currency_field ||
"currency_id";
const currencyField =
this.props.currencyField ||
this.props.record.fields[this.props.name].currency_field ||
"currency_id";
const currency = this.props.record.data[currencyField];
return currency && currency[0];
}
@@ -40,8 +41,8 @@ export class MonetaryField extends Component {
}
get currencyDigits() {
if (this.props.digits) {
return this.props.digits;
if (this.props.useFieldDigits) {
return this.props.record.fields[this.props.name].digits;
}
if (!this.currency) {
return null;
@@ -66,7 +67,7 @@ MonetaryField.props = {
...standardFieldProps,
currencyField: { type: String, optional: true },
inputType: { type: String, optional: true },
digits: { type: Array, optional: true },
useFieldDigits: { type: Boolean, optional: true },
hideSymbol: { type: Boolean, optional: true },
placeholder: { type: String, optional: true },
};
@@ -82,7 +83,7 @@ MonetaryField.extractProps = ({ attrs }) => {
return {
currencyField: attrs.options.currency_field,
inputType: attrs.type,
digits: [16, 2], // FIXME WOWL
useFieldDigits: attrs.options.field_digits,
hideSymbol: attrs.options.no_symbol,
placeholder: attrs.placeholder,
};
@@ -169,9 +169,18 @@ QUnit.module("Fields", (hooks) => {
assert.strictEqual(formatFloatTime(3.5), "03:30");
assert.strictEqual(formatFloatTime(0.25), "00:15");
assert.strictEqual(formatFloatTime(2 / 60, { displaySeconds: true }), "00:02:00");
assert.strictEqual(formatFloatTime(2 / 60 + 1 / 3600, { displaySeconds: true }), "00:02:01");
assert.strictEqual(formatFloatTime(2 / 60 + 2 / 3600, { displaySeconds: true }), "00:02:02");
assert.strictEqual(formatFloatTime(2 / 60 + 3 / 3600, { displaySeconds: true }), "00:02:03");
assert.strictEqual(
formatFloatTime(2 / 60 + 1 / 3600, { displaySeconds: true }),
"00:02:01"
);
assert.strictEqual(
formatFloatTime(2 / 60 + 2 / 3600, { displaySeconds: true }),
"00:02:02"
);
assert.strictEqual(
formatFloatTime(2 / 60 + 3 / 3600, { displaySeconds: true }),
"00:02:03"
);
assert.strictEqual(formatFloatTime(0.25, { displaySeconds: true }), "00:15:00");
assert.strictEqual(formatFloatTime(0.25 + 15 / 3600, { displaySeconds: true }), "00:15:15");
assert.strictEqual(formatFloatTime(0.25 + 45 / 3600, { displaySeconds: true }), "00:15:45");
@@ -182,17 +191,26 @@ QUnit.module("Fields", (hooks) => {
assert.strictEqual(formatFloatTime(2, options), "2:00");
assert.strictEqual(formatFloatTime(3.5, options), "3:30");
assert.strictEqual(formatFloatTime(3.5, { ...options, displaySeconds: true }), "3:30:00");
assert.strictEqual(formatFloatTime(3.5 + 15 / 3600, { ...options, displaySeconds: true }), "3:30:15");
assert.strictEqual(formatFloatTime(3.5 + 45 / 3600, { ...options, displaySeconds: true }), "3:30:45");
assert.strictEqual(formatFloatTime(56 / 3600, { ...options, displaySeconds: true }), "0:00:56");
assert.strictEqual(
formatFloatTime(3.5 + 15 / 3600, { ...options, displaySeconds: true }),
"3:30:15"
);
assert.strictEqual(
formatFloatTime(3.5 + 45 / 3600, { ...options, displaySeconds: true }),
"3:30:45"
);
assert.strictEqual(
formatFloatTime(56 / 3600, { ...options, displaySeconds: true }),
"0:00:56"
);
assert.strictEqual(formatFloatTime(-0.5, options), "-0:30");
});
QUnit.test("formatJson", function (assert) {
assert.strictEqual(formatJson(false), '');
assert.strictEqual(formatJson({}), '{}');
assert.strictEqual(formatJson({1: 111}), '{"1":111}');
assert.strictEqual(formatJson({"9": 11, 666: 42}), '{"9":11,"666":42}');
assert.strictEqual(formatJson(false), "");
assert.strictEqual(formatJson({}), "{}");
assert.strictEqual(formatJson({ 1: 111 }), '{"1":111}');
assert.strictEqual(formatJson({ 9: 11, 666: 42 }), '{"9":11,"666":42}');
});
QUnit.test("formatInteger", function (assert) {
@@ -273,8 +291,8 @@ QUnit.module("Fields", (hooks) => {
);
assert.deepEqual(
formatMonetary(1234567.654, { currencyId: 11, digits: [69, 1] }),
"$\u00a01,234,567.65",
"currency digits should take over options digits when both are defined"
"$\u00a01,234,567.7",
"options digits should take over currency digits when both are defined"
);
// GES TODO do we keep below behavior ?
@@ -872,7 +872,7 @@ QUnit.module("Fields", (hooks) => {
name: "USD",
symbol: "$",
position: "before",
digits: [0, 1],
digits: [0, 4],
},
},
});