[FIX] web: currency digits

- Set the currency rounding to 0.001 (3 digits)
- Create an account move
- Add an account move line, set an account

When switching from edit/read-only mode, the rounding switches from 2 to
3 digits.

This is because, in edit mode, the format method is the method of the
float widget. Therefore, in this case, the formatting doesn't take into
account the currency rounding.

To avoid this, we simply use a `noSymbol` flag to avoid adding the
currency symbol, while keeping the monetary rounding.

opw-800279
This commit is contained in:
Nicolas Martinelli
2017-12-29 09:20:18 +01:00
committed by Nicolas Martinelli
parent 0126823f98
commit 88afd055cf
3 changed files with 60 additions and 3 deletions
@@ -562,8 +562,8 @@ var FieldMonetary = InputField.extend({
this.tagName = 'div';
this.className += ' o_input';
// use the formatFloat function in edit
this.formatType = 'float';
// do not display currency symbol in edit
this.formatOptions.noSymbol = true;
}
this.formatOptions.currency = this.currency;
@@ -290,7 +290,7 @@ function formatMonetary(value, field, options) {
digits: (currency && currency.digits) || options.digits,
});
if (!currency) {
if (!currency || options.noSymbol) {
return formatted_value;
}
if (currency.position === "after") {
@@ -2420,6 +2420,63 @@ QUnit.module('basic_fields', {
form.destroy();
});
QUnit.test('monetary field with currency digits != 2', function (assert) {
assert.expect(5);
this.data.partner.records = [{
id: 1,
bar: false,
foo: "pouet",
int_field: 68,
qux: 99.1234,
currency_id: 1,
}];
this.data.currency.records = [{
id: 1,
display_name: "VEF",
symbol: "Bs.F",
position: "after",
digits: [16, 4],
}];
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form string="Partners">' +
'<sheet>' +
'<field name="qux" widget="monetary"/>' +
'<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(), '99.1234\u00a0Bs.F',
'The value should be displayed properly.');
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('input').first().val(), '99.1234',
'The input should be rendered without the currency symbol.');
assert.strictEqual(form.$('input').parent().children().eq(1).text(), 'Bs.F',
'The input should be followed by a span containing the currency symbol.');
form.$('input').first().val('99.111111111').trigger('input');
assert.strictEqual(form.$('input').first().val(), '99.111111111',
'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(), '99.1111\u00a0Bs.F',
'The new value should be rounded properly.');
form.destroy();
});
QUnit.test('monetary field in editable list view', function (assert) {
assert.expect(9);