diff --git a/addons/web/static/test/fields/basic_fields_tests.js b/addons/web/static/test/fields/basic_fields_tests.js index 374cda02fad..9ed0bb5c169 100644 --- a/addons/web/static/test/fields/basic_fields_tests.js +++ b/addons/web/static/test/fields/basic_fields_tests.js @@ -28,6 +28,7 @@ QUnit.module('basic_fields', { timmy: {string: "pokemon", type: "many2many", relation: 'partner_type', searchable: true}, product_id: {string: "Product", type: "many2one", relation: 'product', searchable: true}, sequence: {type: "integer", string: "Sequence", searchable: true}, + currency_id: {string: "Currency", type: "many2one", relation: "currency", searchable: true}, }, records: [{ id: 1, @@ -51,7 +52,8 @@ QUnit.module('basic_fields', { p: [], timmy: [], trululu: 1, - sequence: 4 + sequence: 4, + currency_id: 2, }, { id: 4, display_name: "aaa", @@ -61,7 +63,7 @@ QUnit.module('basic_fields', { qux: false, }, {id: 3, bar: true, foo: "gnap", int_field: 17, qux: -3.89859, m2o: 1, m2m: []}, - {id: 5, bar: false, foo: "blop", int_field: -4, qux: 9.1, m2o: 1, m2m: [1]}], + {id: 5, bar: false, foo: "blop", int_field: -4, qux: 9.1, m2o: 1, m2m: [1], currency_id: 1}], onchanges: {}, }, product: { @@ -86,6 +88,21 @@ QUnit.module('basic_fields', { {id: 14, display_name: "silver", color: 5}, ] }, + currency: { + fields: { + symbol: {string: "Currency Sumbol", type: "char", searchable: true}, + position: {string: "Currency Position", type: "char", searchable: true}, + }, + records: [{ + id: 1, + symbol: "$", + position: "before", + }, { + id: 2, + symbol: "€", + position: "after", + }] + }, }; } }, function () { @@ -1044,6 +1061,143 @@ QUnit.module('basic_fields', { }); + QUnit.module('FieldMonetary'); + + QUnit.test('monetary field in form view', function(assert) { + assert.expect(5); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'
', + res_id: 5, + session: { + currencies: _.indexBy(this.data.currency.records, 'id'), + }, + }); + + // Non-breaking space between the currency and the amount + assert.strictEqual(form.$('.o_form_field').first().text(), '$\u00a09.10', + 'The value should be displayed properly.'); + + form.$buttons.find('.o_form_button_edit').click(); + assert.strictEqual(form.$('input.o_form_input').val(), '9.10', + 'The input should be rendered without the currency symbol.'); + assert.strictEqual(form.$('input.o_form_input').parent().children().first().text(), '$', + 'The input should be preceded by a span containing the currency symbol.'); + + form.$('input.o_form_input').val('108.2458938598598').trigger('input'); + assert.strictEqual(form.$('input.o_form_input').val(), '108.2458938598598', + '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_form_field').first().text(), '$\u00a0108.25', + 'The new value should be rounded properly.'); + + form.destroy(); + }); + + QUnit.test('monetary field with currency symbol after', function(assert) { + assert.expect(5); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'', + res_id: 2, + session: { + currencies: _.indexBy(this.data.currency.records, 'id'), + }, + }); + + // Non-breaking space between the currency and the amount + assert.strictEqual(form.$('.o_form_field').first().text(), '0.00\u00a0€', + 'The value should be displayed properly.'); + + form.$buttons.find('.o_form_button_edit').click(); + assert.strictEqual(form.$('input.o_form_input').val(), '0.00', + 'The input should be rendered without the currency symbol.'); + assert.strictEqual(form.$('input.o_form_input').parent().children().eq(1).text(), '€', + 'The input should be followed by a span containing the currency symbol.'); + + form.$('input.o_form_input').val('108.2458938598598').trigger('input'); + assert.strictEqual(form.$('input.o_form_input').val(), '108.2458938598598', + '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_form_field').first().text(), '108.25\u00a0€', + 'The new value should be rounded properly.'); + + form.destroy(); + }); + + QUnit.test('monetary field in editable list view', function (assert) { + assert.expect(9); + + var list = createView({ + View: ListView, + model: 'partner', + data: this.data, + arch: '