summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields_tests.js
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2018-03-27 10:17:06 +0200
committerLucas Perais (lpe) <lpe@odoo.com>2018-03-28 09:18:07 +0200
commit07435b110440ba41e559373c4494e674e68e5724 (patch)
tree7e96c60eebb0228fd5e83d89439025d6bbd751a8 /addons/web/static/tests/fields/relational_fields_tests.js
parentb33d5af4a74e3f4ca515826d4683065e32005e85 (diff)
[FIX] web: correctly display reference field in subview
Have a form view with a O2M. The model at the 'many' end has a reference field Have a record of the second model display in a modal (by clicking on a record in the o2m list) Before this commit: The field reference was not filled up This was because the fields to fetch on the modal creation weren't correctly set. Obvisouly, it also created problem when trying to change the record on the modal: spawning tracebacks because the reference field was not present in the local datas After this commit: The display of the reference field is as expected both in the original form and in the modal OPW 1829822 closes #22468 closes #23896
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js93
1 files changed, 93 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 b35c3b67e71..c2fc768a467 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -10867,6 +10867,99 @@ QUnit.module('relational_fields', {
QUnit.module('FieldReference');
+ QUnit.test('Reference field in modal readonly mode', function (assert) {
+ assert.expect(4);
+
+ this.data.partner.records[0].p = [2];
+ this.data.partner.records[1].trululu = 1;
+ this.data.partner.records[1].reference = 'product,41';
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<field name="reference"/>' +
+ '<field name="p"/>' +
+ '</form>',
+ archs: {
+ 'partner,false,form': '<form><field name="reference"/></form>',
+ 'partner,false,list': '<tree><field name="display_name"/></tree>',
+ },
+ res_id: 1,
+ });
+
+ // Cuurent Form
+ assert.equal(form.$('.o_form_uri.o_field_widget[name=reference]').text(), 'xphone',
+ 'the field reference of the form should have the right value');
+
+ var $cell_o2m = form.$('.o_data_cell');
+ assert.equal($cell_o2m.text(), 'second record',
+ 'the list should have one record');
+
+ $cell_o2m.click();
+
+ // In modal
+ var $modal = $('.modal-dialog.modal-lg');
+ assert.equal($modal.length, 1,
+ 'there should be one modal opened');
+
+ assert.equal($modal.find('.o_form_uri.o_field_widget[name=reference]').text(), 'xpad',
+ 'The field reference in the modal should have the right value');
+
+ $modal.find('.o_form_button_cancel').click();
+
+ form.destroy();
+ });
+
+ QUnit.test('Reference field in modal write mode', function (assert) {
+ assert.expect(5);
+
+ this.data.partner.records[0].p = [2];
+ this.data.partner.records[1].trululu = 1;
+ this.data.partner.records[1].reference = 'product,41';
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<field name="reference"/>' +
+ '<field name="p"/>' +
+ '</form>',
+ archs: {
+ 'partner,false,form': '<form><field name="reference"/></form>',
+ 'partner,false,list': '<tree><field name="display_name"/></tree>',
+ },
+ res_id: 1,
+ });
+
+ // current form
+ form.$buttons.find('.o_form_button_edit').click();
+
+ var $fieldRef = form.$('.o_field_widget.o_field_many2one[name=reference]');
+ assert.equal($fieldRef.find('option:selected').text(), 'Product',
+ 'The reference field\'s model should be Product');
+ assert.equal($fieldRef.find('.o_input.ui-autocomplete-input').val(), 'xphone',
+ 'The reference field\'s record should be xphone');
+
+ form.$('.o_data_cell').click();
+
+ // In modal
+ var $modal = $('.modal-dialog.modal-lg');
+ assert.equal($modal.length, 1,
+ 'there should be one modal opened');
+
+ var $fieldRefModal = $modal.find('.o_field_widget.o_field_many2one[name=reference]');
+
+ assert.equal($fieldRefModal.find('option:selected').text(), 'Product',
+ 'The reference field\'s model should be Product');
+ assert.equal($fieldRefModal.find('.o_input.ui-autocomplete-input').val(), 'xpad',
+ 'The reference field\'s record should be xpad');
+
+ form.destroy();
+ });
+
QUnit.test('reference in form view', function (assert) {
assert.expect(15);