summaryrefslogtreecommitdiff
path: root/doc/reference
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2018-07-10 13:52:28 +0200
committerSébastien Theys <seb@odoo.com>2018-07-17 11:50:35 +0200
commitf241441433046c41e4f3edd05d5d69028da1f8a7 (patch)
tree5224ef02e0ad137f96219339b38fadeae7dca38f /doc/reference
parentd1f1cc9c275de726de3cd2491c8d8b4866bbeb0e (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 'doc/reference')
-rw-r--r--doc/reference/views.rst50
1 files changed, 50 insertions, 0 deletions
diff --git a/doc/reference/views.rst b/doc/reference/views.rst
index 568bd7eade7..542adf7a3d5 100644
--- a/doc/reference/views.rst
+++ b/doc/reference/views.rst
@@ -308,6 +308,56 @@ Possible children elements of the list view are:
:ref:`form view <reference/views/form>` is also valid and will
be used when setting up the inline form view
+``control``
+ defines custom controls for the current view.
+
+ This makes sense if the parent ``tree`` view is inside a One2many field.
+
+ Does not support any attribute, but can have children:
+
+ ``create``
+ adds a button to create a new element on the current list.
+
+ .. note:: If any ``create`` is defined, it will overwrite the default
+ "add a line" button.
+
+ The following attributes are supported:
+
+ ``string`` (required)
+ The text displayed on the button.
+
+ ``context``
+ This context will be merged into the existing context
+ when retrieving the default value of the new record.
+
+ For example it can be used to override default values.
+
+
+ The following example will override the default "add a line" button
+ by replacing it with 3 new buttons:
+ "Add a product", "Add a section" and "Add a note".
+
+ "Add a product" will set the field 'display_type' to its default value.
+
+ The two other buttons will set the field 'display_type'
+ to be respectively 'line_section' and 'line_note'.
+
+ .. code-block:: xml
+
+ <control>
+ <create
+ string="Add a product"
+ />
+ <create
+ string="Add a section"
+ context="{'default_display_type': 'line_section'}"
+ />
+ <create
+ string="Add a note"
+ context="{'default_display_type': 'line_note'}"
+ />
+ </control>
+
.. _reference/views/form:
Forms