summaryrefslogtreecommitdiff
path: root/addons/web
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2017-09-15 18:09:39 +0200
committerChristophe Simonis <chs@odoo.com>2017-09-15 18:09:39 +0200
commit66ca68732431dd6bfc3c6df1fe17ef6fab98da40 (patch)
treedc6ad0715b030fadddc5ed502aac9ba01a58a1b4 /addons/web
parent6aebc800538b6fabd79c6cd1e819ef6d961e7589 (diff)
parented901bedcb7c8b840ae5cf4731b946e998b8b141 (diff)
[MERGE] forward port branch saas-17 up to ed901bedcb7
Diffstat (limited to 'addons/web')
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js8
-rw-r--r--addons/web/static/src/js/fields/upgrade_fields.js22
-rw-r--r--addons/web/static/src/js/views/form/form_renderer.js9
-rw-r--r--addons/web/static/src/js/views/kanban/kanban_model.js3
-rw-r--r--addons/web/static/src/js/views/kanban/kanban_renderer.js6
-rw-r--r--addons/web/static/src/js/views/list/list_editable_renderer.js3
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js50
-rw-r--r--addons/web/static/tests/fields/upgrade_fields_tests.js22
-rw-r--r--addons/web/static/tests/helpers/mock_server.js4
-rw-r--r--addons/web/static/tests/views/kanban_tests.js81
-rw-r--r--addons/web/static/tests/views/list_tests.js49
11 files changed, 244 insertions, 13 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index b5d779039d6..7df5b390a2c 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -94,8 +94,12 @@ 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.nodeOptions.no_create;
- this.can_write = 'can_write' in this.attrs ? this.attrs.can_write : true;
+
+ // should normally also be set, except in standalone M20
+ this.can_create = ('can_create' in this.attrs ? JSON.parse(this.attrs.can_create) : true) &&
+ !this.nodeOptions.no_create;
+ this.can_write = 'can_write' in this.attrs ? JSON.parse(this.attrs.can_write) : true;
+
this.nodeOptions = _.defaults(this.nodeOptions, {
quick_create: true,
});
diff --git a/addons/web/static/src/js/fields/upgrade_fields.js b/addons/web/static/src/js/fields/upgrade_fields.js
index 4c3b26b9802..9d61036ab8b 100644
--- a/addons/web/static/src/js/fields/upgrade_fields.js
+++ b/addons/web/static/src/js/fields/upgrade_fields.js
@@ -52,9 +52,9 @@ var AbstractFieldUpgrade = {
*
* @abstract
* @private
- * @param {JQuery} the 'Enterprise' label to insert
+ * @param {jQuery} $enterpriseLabel the 'Enterprise' label to insert
*/
- _insertEnterpriseLabel: function ($enterprise_label) {},
+ _insertEnterpriseLabel: function ($enterpriseLabel) {},
/**
* Opens the Upgrade dialog.
*
@@ -127,6 +127,15 @@ var UpgradeBoolean = FieldBoolean.extend(AbstractFieldUpgrade, {
events: _.extend({}, AbstractField.prototype.events, {
'click input': '_onInputClicked',
}),
+ /**
+ * Re-renders the widget with the label
+ *
+ * @param {jQuery} $label
+ */
+ renderWithLabel: function ($label) {
+ this.$label = $label;
+ this._render();
+ },
//--------------------------------------------------------------------------
// Private
@@ -136,8 +145,9 @@ var UpgradeBoolean = FieldBoolean.extend(AbstractFieldUpgrade, {
* @override
* @private
*/
- _insertEnterpriseLabel: function ($enterprise_label) {
- this.$el.append('&nbsp;').append($enterprise_label);
+ _insertEnterpriseLabel: function ($enterpriseLabel) {
+ var $el = this.$label || this.$el;
+ $el.append('&nbsp;').append($enterpriseLabel);
},
/**
* @override
@@ -170,8 +180,8 @@ var UpgradeRadio = FieldRadio.extend(AbstractFieldUpgrade, {
* @override
* @private
*/
- _insertEnterpriseLabel: function ($enterprise_label) {
- this.$('label').last().append('&nbsp;').append($enterprise_label);
+ _insertEnterpriseLabel: function ($enterpriseLabel) {
+ this.$('label').last().append('&nbsp;').append($enterpriseLabel);
},
/**
* @override
diff --git a/addons/web/static/src/js/views/form/form_renderer.js b/addons/web/static/src/js/views/form/form_renderer.js
index 7d962e223ce..8f1724c3e64 100644
--- a/addons/web/static/src/js/views/form/form_renderer.js
+++ b/addons/web/static/src/js/views/form/form_renderer.js
@@ -805,11 +805,16 @@ var FormRenderer = BasicRenderer.extend({
// Attach the tooltips on the fields' label
_.each(this.allFieldWidgets[this.state.id], function (widget) {
+ var idForLabel = self.idsForLabels[widget.name];
+ var $label = idForLabel ? self.$('label[for=' + idForLabel + ']') : $();
if (core.debug || widget.attrs.help || widget.field.help) {
- var idForLabel = self.idsForLabels[widget.name];
- var $label = idForLabel ? self.$('label[for=' + idForLabel + ']') : $();
self._addFieldTooltip(widget, $label);
}
+ if (widget.attrs.widget === 'upgrade_boolean') {
+ // this widget needs a reference to its $label to be correctly
+ // rendered
+ widget.renderWithLabel($label);
+ }
});
},
/**
diff --git a/addons/web/static/src/js/views/kanban/kanban_model.js b/addons/web/static/src/js/views/kanban/kanban_model.js
index 400d73c0b7d..04ee7012bc4 100644
--- a/addons/web/static/src/js/views/kanban/kanban_model.js
+++ b/addons/web/static/src/js/views/kanban/kanban_model.js
@@ -157,6 +157,9 @@ var KanbanModel = BasicModel.extend({
id: new_group.res_id,
display_name: new_group.value,
};
+ } else if (groupedField.type === 'selection') {
+ var value = _.findWhere(groupedField.selection, {1: new_group.value});
+ changes[groupedFieldName] = value && value[0] || false;
} else {
changes[groupedFieldName] = new_group.value;
}
diff --git a/addons/web/static/src/js/views/kanban/kanban_renderer.js b/addons/web/static/src/js/views/kanban/kanban_renderer.js
index 49752ca2678..b46d1f7c5fd 100644
--- a/addons/web/static/src/js/views/kanban/kanban_renderer.js
+++ b/addons/web/static/src/js/views/kanban/kanban_renderer.js
@@ -145,10 +145,10 @@ var KanbanRenderer = BasicRenderer.extend({
* @returns {Deferred}
*/
updateColumn: function (localID, columnState) {
- var column = _.findWhere(this.widgets, {db_id: localID});
- this.widgets.splice(_.indexOf(this.widgets, column), 1); // remove column from widgets' list
var newColumn = new KanbanColumn(this, columnState, this.columnOptions, this.recordOptions);
- this.widgets.push(newColumn);
+ var index = _.findIndex(this.widgets, {db_id: localID});
+ var column = this.widgets[index];
+ this.widgets[index] = newColumn;
return newColumn.insertAfter(column.$el).then(column.destroy.bind(column));
},
/**
diff --git a/addons/web/static/src/js/views/list/list_editable_renderer.js b/addons/web/static/src/js/views/list/list_editable_renderer.js
index 229c61733e5..7984ebf21e1 100644
--- a/addons/web/static/src/js/views/list/list_editable_renderer.js
+++ b/addons/web/static/src/js/views/list/list_editable_renderer.js
@@ -477,6 +477,9 @@ ListRenderer.include({
return this._selectRow(rowIndex).then(function () {
var record = self.state.data[rowIndex];
var correctedIndex = colIndex - getNbButtonBefore(colIndex);
+ if (correctedIndex >= (self.allFieldWidgets[record.id] || []).length) {
+ return $.Deferred().reject();
+ }
var fieldIndex = self._activateFieldWidget(record, correctedIndex, {
inc: 1,
wrap: wrap,
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index 48245df73cf..fc969aeae87 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -1363,6 +1363,56 @@ QUnit.module('relational_fields', {
form.destroy();
});
+ QUnit.test('can_create and can_write option on a many2one', function (assert) {
+ assert.expect(5);
+
+ this.data.product.options = {
+ can_create: "false",
+ can_write: "false",
+ };
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<sheet>' +
+ '<field name="product_id" can_create="false" can_write="false"/>' +
+ '</sheet>' +
+ '</form>',
+ archs: {
+ 'product,false,form': '<form string="Products"><field name="display_name"/></form>',
+ },
+ mockRPC: function (route) {
+ if (route === '/web/dataset/call_kw/product/get_formview_id') {
+ return $.when(false);
+ }
+ return this._super.apply(this, arguments);
+ },
+ });
+
+ form.$('.o_field_many2one input').click();
+ assert.strictEqual($('.ui-autocomplete .o_m2o_dropdown_option:contains(Create)').length, 0,
+ "there shouldn't be any option to search and create");
+
+ $('.ui-autocomplete li:contains(xpad)').mouseenter().click();
+ assert.strictEqual(form.$('.o_field_many2one input').val(), "xpad",
+ "the correct record should be selected");
+ assert.strictEqual(form.$('.o_field_many2one .o_external_button').length, 1,
+ "there should be an external button displayed");
+
+ form.$('.o_field_many2one .o_external_button').click();
+ assert.strictEqual($('.modal .o_form_view.o_form_readonly').length, 1,
+ "there should be a readonly form view opened");
+
+ $('.modal .o_form_button_cancel').click();
+
+ form.$('.o_field_many2one input').val('new product').trigger('keyup').trigger('focusout');
+
+ assert.strictEqual($('.modal').length, 0, "should not display the create modal");
+ form.destroy();
+ });
+
QUnit.test('pressing enter in a m2o in an editable list', function (assert) {
assert.expect(9);
var done = assert.async();
diff --git a/addons/web/static/tests/fields/upgrade_fields_tests.js b/addons/web/static/tests/fields/upgrade_fields_tests.js
index babc32b60a8..427ec7b54e3 100644
--- a/addons/web/static/tests/fields/upgrade_fields_tests.js
+++ b/addons/web/static/tests/fields/upgrade_fields_tests.js
@@ -39,6 +39,28 @@ QUnit.module('upgrade_fields', {
form.destroy();
});
+ QUnit.test('widget upgrade_boolean in a form view', function (assert) {
+ assert.expect(3);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form>' +
+ '<div class="o_field"><field name="bar" widget="upgrade_boolean"/></div>' +
+ '<div class="o_label"><label for="bar"/><div>Coucou</div></div>' +
+ '</form>',
+ });
+
+ assert.strictEqual(form.$('.o_field .label').length, 0,
+ "the upgrade label shouldn't be inside the field section");
+ assert.strictEqual(form.$('.o_label .label').length, 1,
+ "the upgrade label should be inside the label section");
+ assert.strictEqual(form.$('.o_label').text(), "Bar EnterpriseCoucou",
+ "the upgrade label should be inside the label section");
+ form.destroy();
+ });
+
});
});
});
diff --git a/addons/web/static/tests/helpers/mock_server.js b/addons/web/static/tests/helpers/mock_server.js
index 3cf69b323b8..5b559529371 100644
--- a/addons/web/static/tests/helpers/mock_server.js
+++ b/addons/web/static/tests/helpers/mock_server.js
@@ -255,6 +255,10 @@ var MockServer = Class.extend({
var relModel, relFields;
_.each(fieldNodes, function (node, name) {
var field = fields[name];
+ if (field.type === "many2one" || field.type === "many2many") {
+ node.attrs.can_create = node.attrs.can_create || "true";
+ node.attrs.can_write = node.attrs.can_write || "true";
+ }
if (field.type === "one2many" || field.type === "many2many") {
field.views = {};
_.each(node.children, function (children) {
diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js
index f070a6928a2..e2ec975f0f0 100644
--- a/addons/web/static/tests/views/kanban_tests.js
+++ b/addons/web/static/tests/views/kanban_tests.js
@@ -662,6 +662,48 @@ QUnit.module('Views', {
kanban.destroy();
});
+ QUnit.test('drag and drop a record, grouped by selection', function (assert) {
+ assert.expect(6);
+
+ var kanban = createView({
+ View: KanbanView,
+ model: 'partner',
+ data: this.data,
+ arch: '<kanban class="o_kanban_test" on_create="quick_create">' +
+ '<templates>' +
+ '<t t-name="kanban-box">' +
+ '<div><field name="state"/></div>' +
+ '</t>' +
+ '</templates>' +
+ '</kanban>',
+ groupBy: ['state'],
+ mockRPC: function (route, args) {
+ if (route === '/web/dataset/resequence') {
+ assert.ok(true, "should call resequence");
+ return $.when(true);
+ }
+ if (args.model === 'partner' && args.method === 'write') {
+ assert.deepEqual(args.args[1], {state: 'def'});
+ }
+ return this._super(route, args);
+ },
+ });
+ assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length, 1,
+ "column should contain 1 record(s)");
+ assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 1,
+ "column should contain 1 record(s)");
+
+ var $record = kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record:first');
+ var $group = kanban.$('.o_kanban_group:nth-child(2)');
+ testUtils.dragAndDrop($record, $group);
+
+ assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length, 0,
+ "column should now contain 0 record(s)");
+ assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 2,
+ "column should contain 2 record(s)");
+ kanban.destroy();
+ });
+
QUnit.test('kanban view with default_group_by', function (assert) {
assert.expect(7);
this.data.partner.records.product_id = 1;
@@ -1970,6 +2012,45 @@ QUnit.module('Views', {
"counter should display the sum of int_field values");
kanban.destroy();
});
+
+ QUnit.test('keep adding quickcreate in first column after a record from this column was moved', function (assert) {
+ assert.expect(2);
+
+ var kanban = createView({
+ View: KanbanView,
+ model: 'partner',
+ data: this.data,
+ arch:
+ '<kanban on_create="quick_create">' +
+ '<field name="int_field"/>' +
+ '<templates><t t-name="kanban-box">' +
+ '<div><field name="foo"/></div>' +
+ '</t></templates>' +
+ '</kanban>',
+ groupBy: ['int_field'],
+ mockRPC: function (route, args) {
+ if (route === '/web/dataset/resequence') {
+ return $.when(true);
+ }
+ return this._super(route, args);
+ },
+ });
+
+ var $quickCreateGroup;
+ var $groups;
+ _quickCreateAndTest();
+ testUtils.dragAndDrop($groups.first().find('.o_kanban_record:first'), $groups.eq(1));
+ _quickCreateAndTest();
+ kanban.destroy();
+
+ function _quickCreateAndTest() {
+ kanban.$buttons.find('.o-kanban-button-new').click();
+ $quickCreateGroup = kanban.$('.o_kanban_quick_create').closest('.o_kanban_group');
+ $groups = kanban.$('.o_kanban_group');
+ assert.strictEqual($quickCreateGroup[0], $groups[0],
+ "quick create should have been added in the first column");
+ }
+ });
});
});
diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js
index 9585f154b80..f16194026dd 100644
--- a/addons/web/static/tests/views/list_tests.js
+++ b/addons/web/static/tests/views/list_tests.js
@@ -2275,6 +2275,55 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('skip buttons when navigating list view with TAB (end)', function (assert) {
+ assert.expect(2);
+
+ var list = createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree editable="bottom">' +
+ '<field name="foo"/>' +
+ '<button name="kikou" string="Kikou" type="object"/>' +
+ '</tree>',
+ res_id: 1,
+ });
+
+ list.$('tbody tr:eq(2) td:eq(1)').click();
+ assert.strictEqual(list.$('tbody tr:eq(2) input[name="foo"]')[0], document.activeElement,
+ "foo should be focused");
+ list.$('tbody tr:eq(2) input[name="foo"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB}));
+ assert.strictEqual(list.$('tbody tr:eq(3) input[name="foo"]')[0], document.activeElement,
+ "next line should be selected");
+
+ list.destroy();
+ });
+
+ QUnit.test('skip buttons when navigating list view with TAB (middle)', function (assert) {
+ assert.expect(2);
+
+ var list = createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree editable="bottom">' +
+ '<field name="foo"/>' +
+ '<button name="kikou" string="Kikou" type="object"/>' +
+ '<field name="int_field"/>' +
+ '</tree>',
+ res_id: 1,
+ });
+
+ list.$('tbody tr:eq(2) td:eq(1)').click();
+ assert.strictEqual(list.$('tbody tr:eq(2) input[name="foo"]')[0], document.activeElement,
+ "foo should be focused");
+ list.$('tbody tr:eq(2) input[name="foo"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB}));
+ assert.strictEqual(list.$('tbody tr:eq(2) input[name="int_field"]')[0], document.activeElement,
+ "int_field should be focused");
+
+ list.destroy();
+ });
+
QUnit.test('navigation: moving down with keydown', function (assert) {
assert.expect(2);