summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/basic_fields_tests.js
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2017-12-29 12:18:58 +0100
committerNicolas Martinelli <nim-odoo@users.noreply.github.com>2018-01-04 11:32:04 +0100
commit38e73da092f3bb3377edac983aea37aceed4ed3f (patch)
tree25b35e1072dca75e369ca7ffcb27d1864282067d /addons/web/static/tests/fields/basic_fields_tests.js
parent8e181c99c233f1a0e068f9218449add174a9a2b6 (diff)
[IMP] web: support variable digits
In v10, a `Float` field with `widget="monetary"` option uses the decimal precision of the field. In v11, however, it uses the decimal precision of the currency. However, in many cases `widget="monetary"` is used in the sole purpose of displaying the currency symbol. The precision of the field sould be kept. This commit introduces the support of the decimal precision of the field for this specific use case thanks to the `field_digits` option: ``` <field name="pouet" widget="monetary" options="{'field_digits': True}" /> ``` If such an option is used, the field precision will prevail over the currency precision. Related to #21686 opw-800279
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/basic_fields_tests.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js
index 6fc104246d6..9ea423250e4 100644
--- a/addons/web/static/tests/fields/basic_fields_tests.js
+++ b/addons/web/static/tests/fields/basic_fields_tests.js
@@ -587,6 +587,52 @@ QUnit.module('basic_fields', {
form.destroy();
});
+ QUnit.test('float field with monetary widget and decimal precision', function (assert) {
+ assert.expect(5);
+
+ this.data.partner.records = [{
+ id: 1,
+ qux: -8.89859,
+ currency_id: 1,
+ }]
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<sheet>' +
+ '<field name="qux" widget="monetary" options="{\'field_digits\': True}"/>' +
+ '<field name="currency_id" invisible="1"/>' +
+ '</sheet>' +
+ '</form>',
+ res_id: 1,
+ session: {
+ currencies: _.indexBy(this.data.currency.records, 'id'),
+ },
+ });
+
+ // Non-breaking space between the currency and the amount
+ assert.strictEqual(form.$('.o_field_widget').first().text(), '$\u00a0-8.9',
+ 'The value should be displayed properly.');
+
+ form.$buttons.find('.o_form_button_edit').click();
+ assert.strictEqual(form.$('input').val(), '-8.9',
+ 'The input should be rendered without the currency symbol.');
+ assert.strictEqual(form.$('input').parent().children().first().text(), '$',
+ 'The input should be preceded by a span containing the currency symbol.');
+
+ form.$('input').val('109.2458938598598').trigger('input');
+ assert.strictEqual(form.$('input').val(), '109.2458938598598',
+ 'The value should not be formated yet.');
+
+ form.$buttons.find('.o_form_button_save').click();
+ // Non-breaking space between the currency and the amount
+ assert.strictEqual(form.$('.o_field_widget').first().text(), '$\u00a0109.2',
+ 'The new value should be rounded properly.');
+
+ form.destroy();
+ });
+
QUnit.module('FieldEmail');
QUnit.test('email field in form view', function (assert) {