[IMP] web: Numeric fields can be non-formatted
This commit introduces a new option in fields inheriting from type Numeric
which is `format`.
By default, Numeric fields are formatted according to their subtypes and locale
Adding, in a view, the option format set to a falsy value
will prevent the field's value from being formatted.
```
<field name="int_field" options="{\'format\': false}"/>
```
Task 2050119
This commit is contained in:
committed by
Aaron Bohy
parent
7ace5a986a
commit
4c1feefd13
@@ -365,6 +365,16 @@ var InputField = DebouncedField.extend({
|
||||
var NumericField = InputField.extend({
|
||||
tagName: 'span',
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
init() {
|
||||
this._super.apply(this, arguments);
|
||||
this.shouldFormat = Boolean(
|
||||
JSON.parse('format' in this.nodeOptions ? this.nodeOptions.format : true)
|
||||
);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -427,7 +437,7 @@ var NumericField = InputField.extend({
|
||||
* @private
|
||||
*/
|
||||
_formatValue: function (value) {
|
||||
if (this.mode === 'edit' && this.nodeOptions.type === 'number') {
|
||||
if (!this.shouldFormat || (this.mode === 'edit' && this.nodeOptions.type === 'number')) {
|
||||
return value;
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
|
||||
@@ -4812,6 +4812,70 @@ QUnit.module('basic_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('integer field without formatting', async function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
this.data.partner.records = [{
|
||||
'id': 999,
|
||||
'int_field': 8069,
|
||||
}];
|
||||
|
||||
var form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="int_field" options="{\'format\': \'false\'}"/>' +
|
||||
'</form>',
|
||||
res_id: 999,
|
||||
translateParameters: {
|
||||
thousands_sep: ",",
|
||||
grouping: [3, 0],
|
||||
},
|
||||
});
|
||||
|
||||
assert.ok(form.$('.o_form_view').hasClass('o_form_readonly'), 'Form in readonly mode');
|
||||
assert.strictEqual(form.$('.o_field_widget[name=int_field]').text(), '8069',
|
||||
'Integer value must not be formatted');
|
||||
await testUtils.form.clickEdit(form);
|
||||
|
||||
assert.strictEqual(form.$('.o_field_widget').val(), '8069',
|
||||
'Integer value must not be formatted');
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('integer field is formatted by default', async function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
this.data.partner.records = [{
|
||||
'id': 999,
|
||||
'int_field': 8069,
|
||||
}];
|
||||
|
||||
var form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="int_field" />' +
|
||||
'</form>',
|
||||
res_id: 999,
|
||||
translateParameters: {
|
||||
thousands_sep: ",",
|
||||
grouping: [3, 0],
|
||||
},
|
||||
});
|
||||
assert.ok(form.$('.o_form_view').hasClass('o_form_readonly'), 'Form in readonly mode');
|
||||
assert.strictEqual(form.$('.o_field_widget[name=int_field]').text(), '8,069',
|
||||
'Integer value must be formatted by default');
|
||||
await testUtils.form.clickEdit(form);
|
||||
|
||||
assert.strictEqual(form.$('.o_field_widget').val(), '8,069',
|
||||
'Integer value must be formatted by default');
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.module('FieldFloatTime');
|
||||
|
||||
|
||||
@@ -1570,6 +1570,15 @@ order.
|
||||
|
||||
<field name="int_value" options='{"type": "number", "step": 100}'/>
|
||||
|
||||
- format: should the number be formatted. (true by default)
|
||||
|
||||
By default, numbers are formatted according to locale parameters.
|
||||
This option will prevent the field's value from being formatted.
|
||||
|
||||
.. code-block:: xml
|
||||
|
||||
<field name="int_value" options='{"format": false}'/>
|
||||
|
||||
- float (FieldFloat)
|
||||
This is the default field type for fields of type *float*.
|
||||
|
||||
@@ -1602,6 +1611,15 @@ order.
|
||||
|
||||
<field name="int_value" options='{"type": "number", "step": 0.1}'/>
|
||||
|
||||
- format: should the number be formatted. (true by default)
|
||||
|
||||
By default, numbers are formatted according to locale parameters.
|
||||
This option will prevent the field's value from being formatted.
|
||||
|
||||
.. code-block:: xml
|
||||
|
||||
<field name="int_value" options='{"format": false}'/>
|
||||
|
||||
- float_time (FieldFloatTime)
|
||||
The goal of this widget is to display properly a float value that represents
|
||||
a time interval (in hours). So, for example, 0.5 should be formatted as 0:30,
|
||||
|
||||
Reference in New Issue
Block a user