Skip to content

Commit

Permalink
[IMP] *: remove space between currency symbol and value
Browse files Browse the repository at this point in the history
With this commit, formatMonetary does not
create anymore a space between a currency
and a value if the currency is placed
first.
  • Loading branch information
Polymorphe57 committed Oct 17, 2018
1 parent e3ff3b1 commit e442a5f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
30 changes: 15 additions & 15 deletions addons/account/static/tests/reconciliation_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,11 +952,11 @@ QUnit.module('account', {
var widget = clientAction.widgets[0];

assert.strictEqual(clientAction.$('.accounting_view tfoot .cell_right, .accounting_view tfoot .cell_left').text().replace(/[\n\r\s]+/g, ' '),
"$ 1,175.00$ 32.58$ 2,000.00", "should display the different amounts with the currency");
"$1,175.00$32.58$2,000.00", "should display the different amounts with the currency");
widget.$('.accounting_view thead .mv_line td:first').trigger('click');

assert.strictEqual(clientAction.$('.accounting_view tbody').text().replace(/[\n\r\s]+/g, ' '),
" 101200 2017-02-07 INV/2017/0012 $ 650.00 ", "should display the created reconciliation line with the currency");
" 101200 2017-02-07 INV/2017/0012 $650.00 ", "should display the created reconciliation line with the currency");

clientAction.destroy();
});
Expand Down Expand Up @@ -1047,7 +1047,7 @@ QUnit.module('account', {
});
clientAction.appendTo($('#qunit-fixture'));

assert.strictEqual(clientAction.$('.accounting_view tfoot .cell_right, .accounting_view tfoot .cell_left').text().replace(/[$, ]+/g, ''), " 1175.00 32.58 2000.00", "should display the open balance values");
assert.strictEqual(clientAction.$('.accounting_view tfoot .cell_right, .accounting_view tfoot .cell_left').text().replace(/[$, ]+/g, ''), "1175.0032.582000.00", "should display the open balance values");

var widget = clientAction.widgets[0];

Expand Down Expand Up @@ -1079,8 +1079,8 @@ QUnit.module('account', {

widget.$('.create .create_amount input').val('1100.00').trigger('input');

assert.strictEqual(widget.$('.accounting_view tbody .cell_right').text().trim().replace(/[\n\r\s\u00a0]+/g, ' '), "$ 1100.00", "should display the value 1100.00 in right column");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_right').text(), "$ 75.00", "should display 'Open Balance' line because the rest to reconcile is 75.00");
assert.strictEqual(widget.$('.accounting_view tbody .cell_right').text().trim().replace(/[\n\r\s\u00a0]+/g, ' '), "$1100.00", "should display the value 1100.00 in right column");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_right').text(), "$75.00", "should display 'Open Balance' line because the rest to reconcile is 75.00");
assert.strictEqual(widget.$('.accounting_view tbody tr').length, 1, "should have ever only the created reconcile line");
assert.strictEqual(widget.$('.accounting_view tbody tr').text().replace(/[\n\r\s$,]+/g, ' '), " 101200 New SAJ/2014/002 and SAJ/2014/003 1100.00 ",
"the new line should be update the amout");
Expand All @@ -1092,9 +1092,9 @@ QUnit.module('account', {
$('.ui-autocomplete .ui-menu-item a:contains(101000 Current Assets)').trigger('mouseenter').trigger('click');
widget.$('.create .create_label input').val('test0').trigger('input');

assert.strictEqual(widget.$('.accounting_view tbody .cell_left:last').text().trim().replace(/[\n\r\s\u00a0]+/g, ' '), "$ 100.00", "should display the value 100.00 in left column");
assert.strictEqual(widget.$('.accounting_view tbody .cell_left:last').text().trim().replace(/[\n\r\s\u00a0]+/g, ' '), "$100.00", "should display the value 100.00 in left column");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_label').text(), "Open balance", "should display 'Open Balance'");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_right').text(), "$ 175.00", "should display 'Open Balance' line because the rest to reconcile is 175.00");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_right').text(), "$175.00", "should display 'Open Balance' line because the rest to reconcile is 175.00");
assert.strictEqual(widget.$('.accounting_view tbody tr').length, 2, "should have 2 created reconcile lines");
assert.strictEqual(widget.$('.accounting_view tbody tr:eq(1)').text().replace(/[\n\r\s$,]+/g, ' '), " 101000 New test0 100.00 ",
"the new line should have the selected account, name and amout");
Expand All @@ -1109,9 +1109,9 @@ QUnit.module('account', {
$('.ui-autocomplete .ui-menu-item a:contains(101000 Current Assets)').trigger('mouseenter').trigger('click');
widget.$('.create .create_label input').val('test1').trigger('input');

assert.strictEqual(widget.$('.accounting_view tbody .cell_right:last').text().trim().replace(/[\n\r\s\u00a0]+/g, ' '), "$ 200.00", "should display the value 200.00 in left column");
assert.strictEqual(widget.$('.accounting_view tbody .cell_right:last').text().trim().replace(/[\n\r\s\u00a0]+/g, ' '), "$200.00", "should display the value 200.00 in left column");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_label').text(), "Open balance", "should display 'Open balance'");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_left').text(), "$ 25.00", "should display 'Open balance' with 25.00 in left column");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_left').text(), "$25.00", "should display 'Open balance' with 25.00 in left column");
assert.strictEqual(widget.$('.accounting_view tbody tr').length, 3, "should have 3 created reconcile lines");

clientAction.destroy();
Expand Down Expand Up @@ -1199,26 +1199,26 @@ QUnit.module('account', {
widget.$('.create .create_label input').val('test1').trigger('input');
widget.$('.create .create_amount input').val('1100').trigger('input');

assert.strictEqual(widget.$('.accounting_view tbody .cell_right:last').text().trim().replace(/[\n\r\s\u00a0]+/g, ' '), "$ 1100.00", "should display the value 1100.00 in left column");
assert.strictEqual(widget.$('.accounting_view tbody .cell_right:last').text().trim().replace(/[\n\r\s\u00a0]+/g, ' '), "$1100.00", "should display the value 1100.00 in left column");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_label').text(), "Open balance", "should display 'Open Balance'");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_right').text(), "$\u00a075.00", "should display 'Open Balance' with 75.00 in right column");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_right').text(), "$75.00", "should display 'Open Balance' with 75.00 in right column");
assert.strictEqual(widget.$('.accounting_view tbody tr').length, 1, "should have 1 created reconcile lines");

widget.$('.create .create_tax_id input').trigger('click');
$('.ui-autocomplete .ui-menu-item a:contains(10.00%)').trigger('mouseenter').trigger('click');

assert.strictEqual(widget.$('.accounting_view tbody .cell_right').text().trim().replace(/[\n\r\s\u00a0]+/g, ' '), "$ 1000.00 $ 100.00", "should have 2 created reconcile lines with right column values");
assert.strictEqual(widget.$('.accounting_view tbody .cell_right').text().trim().replace(/[\n\r\s\u00a0]+/g, ' '), "$1000.00 $100.00", "should have 2 created reconcile lines with right column values");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_label').text(), "Open balance", "should display 'Open Balance'");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_right').text(), "$\u00a075.00", "should display 'Open Balance' with 75.00 in right column");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_right').text(), "$75.00", "should display 'Open Balance' with 75.00 in right column");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_left').text(), "", "should display 'Open Balance' without any value in left column");
assert.strictEqual(widget.$('.accounting_view tbody tr').length, 2, "should have 2 created reconcile lines");

widget.$('.create .create_tax_id input').trigger('click');
$('.ui-autocomplete .ui-menu-item a:contains(20.00%)').trigger('mouseenter').trigger('click');

assert.strictEqual(widget.$('.accounting_view tbody .cell_right').text().trim().replace(/[\n\r\s\u00a0]+/g, ' '), "$ 1100.00 $ 220.00", "should have 2 created reconcile lines with right column values");
assert.strictEqual(widget.$('.accounting_view tbody .cell_right').text().trim().replace(/[\n\r\s\u00a0]+/g, ' '), "$1100.00 $220.00", "should have 2 created reconcile lines with right column values");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_label').text(), "Open balance", "should display 'Open balance'");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_left').text(), "$\u00a0145.00", "should display 'Open balance' with 145.00 in right column");
assert.strictEqual(widget.$('.accounting_view tfoot .cell_left').text(), "$145.00", "should display 'Open balance' with 145.00 in right column");
assert.strictEqual(widget.$('.accounting_view tbody tr').length, 2, "should have 2 created reconcile lines");

clientAction.destroy();
Expand Down
24 changes: 16 additions & 8 deletions addons/web/static/src/js/fields/field_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ function formatMonetary(value, field, options) {
if (currency.position === "after") {
return formatted_value += ' ' + currency.symbol;
} else {
return currency.symbol + ' ' + formatted_value;
return currency.symbol + formatted_value;
}
}
/**
Expand Down Expand Up @@ -541,12 +541,6 @@ function parseFloat(value) {
*/
function parseMonetary(value, field, options) {
var values = value.split(' ');
if (values.length === 1) {
return parseFloat(value);
}
else if (values.length !== 2) {
throw new Error(_.str.sprintf(core._t("'%s' is not a correct monetary field"), value));
}
options = options || {};
var currency = options.currency;
if (!currency) {
Expand All @@ -557,7 +551,21 @@ function parseMonetary(value, field, options) {
}
currency = session.get_currency(currency_id);
}
return parseFloat(values[0] === currency.symbol ? values[1] : values[0]);
if (values.length === 1) {
// case value[0] === currency.symbol corresponds to a currency symbol before float
if (!currency) {
return parseFloat(value);
} else {
if (value.split(' ').length > 1) {
throw new Error(_.str.sprintf(core._t("'%s' is not a correct monetary field"), value));
}
return parseFloat(value[0] === currency.symbol ? value.slice(1) : value);
}
}
else if (values.length !== 2) {
throw new Error(_.str.sprintf(core._t("'%s' is not a correct monetary field"), value));
}
return parseFloat(values[0]);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions addons/web/static/tests/fields/basic_fields_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ QUnit.module('basic_fields', {
id: 1,
qux: -8.89859,
currency_id: 1,
}]
}];
var form = createView({
View: FormView,
model: 'partner',
Expand All @@ -686,7 +686,7 @@ QUnit.module('basic_fields', {
});

// Non-breaking space between the currency and the amount
assert.strictEqual(form.$('.o_field_widget').first().text(), '$\u00a0-8.9',
assert.strictEqual(form.$('.o_field_widget').first().text(), '$-8.9',
'The value should be displayed properly.');

form.$buttons.find('.o_form_button_edit').click();
Expand All @@ -701,7 +701,7 @@ QUnit.module('basic_fields', {

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',
assert.strictEqual(form.$('.o_field_widget').first().text(), '$109.2',
'The new value should be rounded properly.');

form.destroy();
Expand Down Expand Up @@ -3083,7 +3083,7 @@ QUnit.module('basic_fields', {
});

// Non-breaking space between the currency and the amount
assert.strictEqual(form.$('.o_field_widget').first().text(), '$\u00a09.10',
assert.strictEqual(form.$('.o_field_widget').first().text(), '$9.10',
'The value should be displayed properly.');

form.$buttons.find('.o_form_button_edit').click();
Expand All @@ -3098,7 +3098,7 @@ QUnit.module('basic_fields', {

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(), '$\u00a0108.25',
assert.strictEqual(form.$('.o_field_widget').first().text(), '$108.25',
'The new value should be rounded properly.');

form.destroy();
Expand Down Expand Up @@ -3248,7 +3248,7 @@ QUnit.module('basic_fields', {
'The typed value should be correctly displayed.');

list.$buttons.find('.o_list_button_save').click();
assert.strictEqual(list.$('tr.o_data_row td:not(.o_list_record_selector):contains($)').text(), '$\u00a0108.25',
assert.strictEqual(list.$('tr.o_data_row td:not(.o_list_record_selector):contains($)').text(), '$108.25',
'The new value should be rounded properly.');

list.destroy();
Expand Down Expand Up @@ -3288,9 +3288,9 @@ QUnit.module('basic_fields', {
},
});

assert.strictEqual(form.$('.o_field_monetary').first().html(), "$ 9.10",
assert.strictEqual(form.$('.o_field_monetary').first().html(), "$9.10",
"readonly value should contain the currency");
assert.strictEqual(form.$('.o_field_monetary').first().next().html(), "$ 4.20",
assert.strictEqual(form.$('.o_field_monetary').first().next().html(), "$4.20",
"readonly value should contain the currency");

form.$buttons.find('.o_form_button_edit').click();
Expand Down Expand Up @@ -3386,7 +3386,7 @@ QUnit.module('basic_fields', {

form.$el.click(); // focusout the input

assert.strictEqual($o2m.find('.o_field_widget[name=qux]').html(), "$ 22.00",
assert.strictEqual($o2m.find('.o_field_widget[name=qux]').html(), "$22.00",
"the value should have been formatted after losing the focus");

// test the monetary field inside the many2many
Expand Down
2 changes: 1 addition & 1 deletion addons/web/static/tests/fields/field_utils_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ QUnit.test('parse monetary', function(assert) {
assert.strictEqual(fieldUtils.parse.monetary("-100.00"), -100);
assert.strictEqual(fieldUtils.parse.monetary("1,000.00"), 1000);
assert.strictEqual(fieldUtils.parse.monetary("1,000,000.00"), 1000000);
assert.strictEqual(fieldUtils.parse.monetary("$ 125.00", {}, {currency_id: 3}), 125);
assert.strictEqual(fieldUtils.parse.monetary("$125.00", {}, {currency_id: 3}), 125);
assert.strictEqual(fieldUtils.parse.monetary("1,000.00 €", {}, {currency_id: 1}), 1000);
assert.throws(function() {fieldUtils.parse.monetary("$ 12.00", {}, {currency_id: 3})}, /is not a correct/);
assert.throws(function() {fieldUtils.parse.monetary("$ 12.00", {}, {currency_id: 1})}, /is not a correct/);
Expand Down
2 changes: 1 addition & 1 deletion addons/web/static/tests/views/list_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ QUnit.module('Views', {
assert.strictEqual(list.$('tbody tr:first td:nth(2)').text().replace(/\s/g, ' '),
'1200.00 €', "currency_id column should not be in the table");
assert.strictEqual(list.$('tbody tr:nth(1) td:nth(2)').text().replace(/\s/g, ' '),
'$ 500.00', "currency_id column should not be in the table");
'$500.00', "currency_id column should not be in the table");

list.destroy();
});
Expand Down

0 comments on commit e442a5f

Please sign in to comment.