[FIX] web: MonetaryField: read currency_field in options

In the xml definition of views, a 'currency_field' can be specified
in the node options:

<field name="amount" widget='monetary'
       options="{'currency_field': 'currency_id'}"/>

It indicates which field the monetary widget has to use to
determine the currency to display.

Before this rev., the widget didn't look for the 'currency_field'
in the options, but directly in the node attrs, so this simply
didn't work. This was for example the case on the crm.lead kanban
and form views.
This commit is contained in:
Aaron Bohy
2017-05-17 12:36:16 +02:00
parent 59584283c5
commit ba6a3a91ae
2 changed files with 32 additions and 1 deletions
@@ -548,7 +548,7 @@ var FieldMonetary = InputField.extend({
* @private
*/
_setCurrency: function () {
var currencyField = this.attrs.currency_field || this.field.currency_field || 'currency_id';
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);
},
@@ -1769,6 +1769,37 @@ QUnit.module('basic_fields', {
form.destroy();
});
QUnit.test('monetary field with monetary field given in options', function (assert) {
assert.expect(1);
this.data.partner.fields.qux.type = "monetary";
this.data.partner.fields.company_currency_id = {
string: "Company Currency", type: "many2one", relation: "currency",
};
this.data.partner.records[4].company_currency_id = 2;
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form string="Partners">' +
'<sheet>' +
'<field name="qux" options="{\'currency_field\': \'company_currency_id\'}"/>' +
'<field name="company_currency_id"/>' +
'</sheet>' +
'</form>',
res_id: 5,
session: {
currencies: _.indexBy(this.data.currency.records, 'id'),
},
});
assert.strictEqual(form.$('.o_field_monetary').html(), "9.10&nbsp;€",
"field monetary should be formatted with correct currency");
form.destroy();
});
QUnit.test('should keep the focus when being edited in x2many lists', function (assert) {
assert.expect(6);