[FIX] web: prevent record creation in M2O with option {'no_create': True}

before this fix, if you enter a random string and exit focus you'll be
prompted to create it.
This commit is contained in:
Christophe Matthieu
2017-04-28 11:32:05 +02:00
committed by Géry Debongnie
parent 76e6a0e356
commit 9da93dc232
3 changed files with 27 additions and 6 deletions
@@ -93,7 +93,7 @@ var FieldMany2One = AbstractField.extend({
this._super.apply(this, arguments);
this.limit = 7;
this.orderer = new concurrency.DropMisordered();
this.can_create = 'can_create' in this.attrs ? this.attrs.can_create : true;
this.can_create = ('can_create' in this.attrs ? this.attrs.can_create : true) && !this.nodeOptions.no_create;
this.can_write = 'can_write' in this.attrs ? this.attrs.can_write : true;
this.nodeOptions = _.defaults(this.nodeOptions, {
quick_create: true,
@@ -1409,12 +1409,12 @@ QUnit.module('basic_fields', {
'The value should be displayed properly.');
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('input.o_form_input').val(), '9.10',
assert.strictEqual(form.$('input.o_form_input').first().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');
form.$('input.o_form_input').first().val('108.2458938598598').trigger('input');
assert.strictEqual(form.$('input.o_form_input').val(), '108.2458938598598',
'The value should not be formated yet.');
@@ -1450,13 +1450,13 @@ QUnit.module('basic_fields', {
'The value should be displayed properly.');
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('input.o_form_input').val(), '0.00',
assert.strictEqual(form.$('input.o_form_input').first().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',
form.$('input.o_form_input').first().val('108.2458938598598').trigger('input');
assert.strictEqual(form.$('input.o_form_input').first().val(), '108.2458938598598',
'The value should not be formated yet.');
form.$buttons.find('.o_form_button_save').click();
@@ -557,6 +557,27 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('no_create option on a many2one', function (assert) {
assert.expect(1);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="product_id" options="{\'no_create\': True}"/>' +
'</sheet>' +
'</form>',
});
form.$('.o_form_field_many2one input').focus();
form.$('.o_form_field_many2one input').val('new partner').trigger('keyup').trigger('focusout');
assert.strictEqual($('.modal').length, 0, "should not display the create modal");
form.destroy();
});
QUnit.module('FieldOne2Many');
QUnit.test('one2many basic properties', function (assert) {