diff options
| author | Sébastien Theys <seb@odoo.com> | 2018-07-10 13:52:28 +0200 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2018-07-17 11:50:35 +0200 |
| commit | f241441433046c41e4f3edd05d5d69028da1f8a7 (patch) | |
| tree | 5224ef02e0ad137f96219339b38fadeae7dca38f /addons/web/static/tests/fields/relational_fields_tests.js | |
| parent | d1f1cc9c275de726de3cd2491c8d8b4866bbeb0e (diff) | |
[IMP] web: add control + create tags to customize "add a line"
The default "add a line" button creates a new line with the default values from the model. Sometimes we want to create a new line with different default values (or more generally a customized context), which is possible with this commit. Moreover it is possible to create multiple buttons for multiple default values/contexts.
This works both for in-line creation ("editable=") and dialog creation.
The new tags are:
<control> defines custom controls for the current view.
Does not support any attribute, but can have children:
<create> adds a button to create a new element on the current list.
This makes sense when the parent tree view is inside a One2many field.
If any create is defined, it will overwrite the default "add a line" button.
For more information and example, have a look at the Views documentation.
Technically, the commit will:
- parse the new XML tags (+ add appropriate validation)
- display the buttons based on the XML
- on button click/keyboard: pull up the additional context information from the button event up to the default_get
- add unit tests
- add documentation
PR #25209
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 106 |
1 files changed, 106 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 54620fcf958..2001bed1d65 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -9797,6 +9797,112 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('add a line custom control editable', function (assert) { + assert.expect(4); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: + '<form string="Partners">' + + '<field name="p">' + + '<tree editable="bottom">' + + '<control>' + + '<create string="Add food" context="" />' + + '<create string="Add pizza" context="{\'default_display_name\': \'pizza\'}"/>' + + '</control>' + + + '<control>' + + '<create string="Add pasta" context="{\'default_display_name\': \'pasta\'}"/>' + + '</control>' + + + '<field name="display_name"/>' + + '</tree>' + + '<form>' + + '<field name="display_name"/>' + + '</form>' + + '</field>' + + '</form>', + }); + + // new controls correctly added + assert.strictEqual($('.o_field_x2many_list_row_add').length, 1); + assert.strictEqual($('.o_field_x2many_list_row_add').text(), "Add foodAdd pizzaAdd pasta"); + + // click add food + // check it's empty + form.$('.o_field_x2many_list_row_add a:eq(0)').click(); + assert.strictEqual($('.o_data_cell').text(), ""); + + // click add pizza + // save the modal + // check it's pizza + form.$('.o_field_x2many_list_row_add a:eq(1)').click(); + // click add pasta + form.$('.o_field_x2many_list_row_add a:eq(2)').click(); + form.$buttons.find('.o_form_button_save').click(); + assert.strictEqual($('.o_data_cell').text(), "pizzapasta"); + + form.destroy(); + }); + + QUnit.test('add a line custom control non-editable', function (assert) { + assert.expect(5); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: + '<form string="Partners">' + + '<field name="p">' + + '<tree>' + + '<control>' + + '<create string="Add food" context="" />' + + '<create string="Add pizza" context="{\'default_display_name\': \'pizza\'}" />' + + '</control>' + + + '<control>' + + '<create string="Add pasta" context="{\'default_display_name\': \'pasta\'}" />' + + '</control>' + + + '<field name="display_name"/>' + + '</tree>' + + '<form>' + + '<field name="display_name"/>' + + '</form>' + + '</field>' + + '</form>', + }); + + // new controls correctly added + assert.strictEqual($('.o_field_x2many_list_row_add').length, 1); + assert.strictEqual($('.o_field_x2many_list_row_add').text(), "Add foodAdd pizzaAdd pasta"); + + // click add food + // check it's empty + form.$('.o_field_x2many_list_row_add a:eq(0)').click(); + $('.modal .modal-footer .btn-primary:first').click(); + assert.strictEqual($('.o_data_cell').text(), ""); + + // click add pizza + // save the modal + // check it's pizza + form.$('.o_field_x2many_list_row_add a:eq(1)').click(); + $('.modal .modal-footer .btn-primary:first').click(); + assert.strictEqual($('.o_data_cell').text(), "pizza"); + + // click add pasta + // save the whole record + // check it's pizzapasta + form.$('.o_field_x2many_list_row_add a:eq(2)').click(); + $('.modal .modal-footer .btn-primary:first').click(); + assert.strictEqual($('.o_data_cell').text(), "pizzapasta"); + + form.destroy(); + }); + QUnit.test('one2many form view with action button', function (assert) { // once the action button is clicked, the record is reloaded (via the // on_close handler, executed because the python method does not return |
