From 951e287c2c33fdea8b4d479be8ba082aed6d8ebe Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Wed, 11 May 2022 08:43:07 +0000 Subject: [PATCH] [IMP] web: Allow to hide the currency symbol on FieldMonetary widget In some cases, we want to use the regular FieldMonetary widget (performing the amount rounding correctly) but without displaying the currency symbol since the currency code is displayed elsewhere. This is needed because some currencies are using the same currency symbol like USD / MXN. Task: 2555114 Part-of: odoo/odoo#91448 --- .../src/legacy/js/fields/basic_fields.js | 2 +- .../tests/legacy/fields/basic_fields_tests.js | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/legacy/js/fields/basic_fields.js b/addons/web/static/src/legacy/js/fields/basic_fields.js index 2efd6738fef..c9b73940ab8 100644 --- a/addons/web/static/src/legacy/js/fields/basic_fields.js +++ b/addons/web/static/src/legacy/js/fields/basic_fields.js @@ -1258,7 +1258,7 @@ var FieldMonetary = NumericField.extend({ // Prepare and add the input var def = this._prepareInput(this.$input).appendTo(this.$el); - if (this.currency) { + if (this.currency && !this.nodeOptions.no_symbol) { // Prepare and add the currency symbol var $currencySymbol = $('', {text: this.currency.symbol}); if (this.currency.position === "after") { diff --git a/addons/web/static/tests/legacy/fields/basic_fields_tests.js b/addons/web/static/tests/legacy/fields/basic_fields_tests.js index 3ff7545ce4c..451b73ada70 100644 --- a/addons/web/static/tests/legacy/fields/basic_fields_tests.js +++ b/addons/web/static/tests/legacy/fields/basic_fields_tests.js @@ -5782,6 +5782,33 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('monetary field without currency symbol', async function (assert) { + assert.expect(1); + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'
' + + '' + + '' + + '' + + '' + + '
', + res_id: 5, + session: { + currencies: _.indexBy(this.data.currency.records, 'id'), + }, + }); + + await testUtils.form.clickEdit(form); + + // Non-breaking space between the currency and the amount + assert.strictEqual(form.$('.o_field_widget[name=qux] input').val(), "9.10", "The currency symbol is not displayed"); + + form.destroy(); + }); + QUnit.test('monetary field in editable list view', async function (assert) { assert.expect(9);