[FIX] web: readonly monetary field onchange currency
Before this fix:
A readonly monetary field was not updating
its currency symbol when selecting another currency.
Scenario:
1. Activate multi-currency with $ (default) and €
2. In hr_expense, go to My Expenses to Submit
3. Create a new expense
4. Select 'EUR' as currency
=> Unit Price is correctly updated with €, but not Total.
With this fix:
Total displays the correct currency in edit mode.
Explanation:
Monetary fields in readonly are relying on _formatValue() to
display their value.
_formatValue() uses this.formatOptions.currency, which stores
the currency at loading of the field. We must update its value
whenever there is a change of currency.
opw-783378
This commit is contained in:
@@ -638,6 +638,7 @@ var FieldMonetary = InputField.extend({
|
||||
var currencyField = this.nodeOptions.currency_field || this.field.currency_field || 'currency_id';
|
||||
var currencyID = this.record.data[currencyField] && this.record.data[currencyField].res_id;
|
||||
this.currency = session.get_currency(currencyID);
|
||||
this.formatOptions.currency = this.currency; // _formatValue() uses formatOptions
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -2347,9 +2347,14 @@ QUnit.module('basic_fields', {
|
||||
});
|
||||
|
||||
QUnit.test('monetary field with real monetary field in model', function (assert) {
|
||||
assert.expect(4);
|
||||
assert.expect(7);
|
||||
|
||||
this.data.partner.fields.qux.type = "monetary";
|
||||
this.data.partner.fields.quux = {
|
||||
string: "Quux", type: "monetary", digits: [16,1], searchable: true, readonly: true,
|
||||
};
|
||||
|
||||
(_.find(this.data.partner.records, function (record) { return record.id === 5 })).quux = 4.2;
|
||||
|
||||
this.data.partner.onchanges = {
|
||||
bar: function (obj) {
|
||||
@@ -2364,6 +2369,7 @@ QUnit.module('basic_fields', {
|
||||
arch:'<form string="Partners">' +
|
||||
'<sheet>' +
|
||||
'<field name="qux"/>' +
|
||||
'<field name="quux"/>' +
|
||||
'<field name="currency_id"/>' +
|
||||
'<field name="bar"/>' +
|
||||
'</sheet>' +
|
||||
@@ -2374,7 +2380,9 @@ QUnit.module('basic_fields', {
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(form.$('.o_field_monetary').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",
|
||||
"readonly value should contain the currency");
|
||||
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
@@ -2385,12 +2393,16 @@ QUnit.module('basic_fields', {
|
||||
form.$('input[type="checkbox"]').click(); // Change the field on which the monetary depends
|
||||
assert.strictEqual(form.$('.o_field_monetary > input').length, 1,
|
||||
"After the onchange, the monetary <input/> should not have been duplicated");
|
||||
assert.strictEqual(form.$('.o_field_monetary[name=quux]').length, 1,
|
||||
"After the onchange, the monetary readonly field should not have been duplicated");
|
||||
|
||||
var $dropdown = form.$('.o_field_many2one input').autocomplete('widget');
|
||||
form.$('.o_field_many2one input').click();
|
||||
$dropdown.find('li:not(.o_m2o_dropdown_option):last').mouseenter().click();
|
||||
assert.strictEqual(form.$('.o_field_monetary > span').html(), "€",
|
||||
"After currency change, the monetary field currency should have been updated");
|
||||
assert.strictEqual(form.$('.o_field_monetary').first().next().html(), "4.20 €",
|
||||
"readonly value should contain the updated currency");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user