diff --git a/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-form-view.png b/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-form-view.png index 7d798cdeb..15e0e5795 100644 Binary files a/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-form-view.png and b/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-form-view.png differ diff --git a/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-list-view.png b/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-list-view.png index 6b812913e..74a22bc80 100644 Binary files a/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-list-view.png and b/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-list-view.png differ diff --git a/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-search-view-fields.png b/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-search-view-fields.png index 3cd2ffae1..9d191e751 100644 Binary files a/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-search-view-fields.png and b/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-search-view-fields.png differ diff --git a/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-search-view-filters.png b/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-search-view-filters.png index f3ab0cc1a..e22c73761 100644 Binary files a/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-search-view-filters.png and b/content/developer/tutorials/server_framework_101/03_build_user_interface/custom-search-view-filters.png differ diff --git a/content/developer/tutorials/server_framework_101/05_connect_the_dots.rst b/content/developer/tutorials/server_framework_101/05_connect_the_dots.rst index 08eec6701..92539670e 100644 --- a/content/developer/tutorials/server_framework_101/05_connect_the_dots.rst +++ b/content/developer/tutorials/server_framework_101/05_connect_the_dots.rst @@ -1131,10 +1131,9 @@ accessed directly using :code:`record.field`. .. code-block:: python :caption: `real_estate_property.py` - :emphasize-lines: 1,5-27 + :emphasize-lines: 1,4-26 address_id = fields.Many2one(string="Address", comodel_name='res.partner') - [...] @api.model_create_multi @@ -1174,43 +1173,61 @@ preconfigured tasks. We have already seen how to :ref:`link menu items to XML-defined window actions `. To link a **button** to an XML-defined -action, a `button` element must be added to the view, with its `type` attribute set to `action`. The -`name` attribute should reference the XML ID of the action to be executed, following the format +action, add a `button` element to the view, with its `type` attribute set to `action`. Use the +`name` attribute to reference the XML ID of the action to execute, following the format `%(XML_ID)d`. .. example:: - In the following example, a button is added to the product form view to display all products in - the same category. + In the following example, a button is added to the product form view to display all other + products in the same category. .. code-block:: xml -
- -
-
-
-
+ + Products + product + + [("id", "!=", active_id), ("category_id", "=", context.get('current_category_id'))] + + list,form + + + +
+ +
+
+
+
+
.. note:: - The button is placed at the top of the form view by using a button container (`button_box`). - The `context` attribute is used to: - - Filter the products to display only those in the same category as the current product. + - Pass the current category ID to the action which filters out products from other + categories. - Prevent users from creating or editing products when browsing them through the button. .. seealso:: - Reference documentation on :ref:`button containers - `. + - Reference documentation on :ref:`button containers + `. + - Reference documentation on :ref:`environment variables for Python expressions in views + `. .. exercise:: - Replace the property form view's :guilabel:`Offers` notebook page with a **stat button**. This - button should: + Replace the :guilabel:`Offers` notebook page in the property form view with a **stat button**. + This button should: - Be placed at the top of the property form view. - Display the total number of offers for the property. @@ -1222,22 +1239,21 @@ action, a `button` element must be added to the view, with its `type` attribute ` in form views. - Find icon codes (`fa-`) in the `Font Awesome v4 catalog `_. - - Ensure that your count computations :ref:`scale with the number of records to process - `. - - Assign the `default_` context key to a button to define default values when creating - new records opened through that button. + - Ensure your count computations :ref:`remain efficient as the number of records to process + grow `. + - Use the `default_` context key to set default values when creating new records + through that button. .. spoiler:: Solution .. code-block:: python :caption: `real_estate_property.py` - :emphasize-lines: 4,8-15 + :emphasize-lines: 4,7-14 offer_ids = fields.One2many( string="Offers", comodel_name='real.estate.offer', inverse_name='property_id' ) offer_count = fields.Integer(string="Offer Count", compute='_compute_offer_count') - [...] @api.depends('offer_ids') @@ -1272,21 +1288,26 @@ action, a `button` element must be added to the view, with its `type` attribute .. code-block:: xml :caption: `real_estate_property_views.xml` - :emphasize-lines: 2-12 + :emphasize-lines: 4-14 - -
- -
+ [...] + +
+ +
+ [...] +
+ [...] +
.. _tutorials/server_framework_101/model_actions: @@ -1298,38 +1319,169 @@ methods that execute custom business logic. These methods enable more complex wo processing the current records, configuring client actions depending on these records, or integrating with external systems. -To link a button to a model-defined action, its `type` attribute must be set to `object`, and its -`name` attribute must be set to the name of the model method to call when the button is clicked. The -method receives the current recordset through `self` and should return a dictionary acting as an -action descriptor. +To link a button to a model-defined action, set its `type` attribute to `object`, and use the `name` +attribute to specify the model method that should be called when the button is clicked. The method +receives the current recordset through `self` and should return a value indicating the result of the +action. .. example:: - In the following example, + In the following example, a button is added to the product category form view to ensure that all + products in the category have a positive margin. + + .. code-block:: xml + +