summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields_tests.js
diff options
context:
space:
mode:
authorMartin Geubelle <mge@odoo.com>2017-09-14 16:35:14 +0200
committerMartin Geubelle <mge@odoo.com>2017-09-15 11:03:09 +0200
commit74c27d81ed299441d3ba07c2181d0e9830b1fec0 (patch)
tree44eb1fe7a51d0e523323e8c4a7b025b70566a37c /addons/web/static/tests/fields/relational_fields_tests.js
parent135a6fb45b0e1278f7a11399a0893fc2137dccda (diff)
[FIX] web: deal with `can_create` and `can_write` option in M2O
The server postproccess the view to add attributes on many2one fields, i.e. `can_create` and `can_write`, according to access rights. These attributes are parsed by the client as string but should also be parsed by the many2one when evaluating them. The mock server has also been adapted to set these attributes.
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index 2020e0124f3..75ee8e8bf3e 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -1362,6 +1362,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();