
Learn how to add buttons inside Group By tree views in Odoo to perform actions directly from grouped records, improving user workflows and batch processing.
In Odoo, adding buttons inside the Group By tree view allows users to perform specific actions directly from grouped records. This functionality can be useful for triggering custom processes, such as batch updates or record confirmations, without navigating into individual records. This blog will explain how to add buttons inside a group view using <groupby> and <button> tags.
In Odoo, the <groupby> tag is used to group records in a tree view. By placing buttons inside the group view, you provide users with a way to trigger actions directly from the grouped results. Below is an example showing how to add buttons inside a grouped tree view.
In this example, we will add a "Confirm Orders" button inside the group view for the sale.order model. The button will appear within the grouped records and trigger an action when clicked.
Here is the XML structure to define a tree view in Odoo and add a button inside a <groupby> tag:
<record id="view_sale_order_tree" model="ir.ui.view">
<field name="name">sale.order.tree</field>
<field name="model">sale.order</field>
<field name="arch" type="xml">
<tree string="Sales Orders">
<field name="name"/>
<field name="date_order"/>
<groupby>
<button name="action_confirm_orders" type="object" string="Confirm Orders" class="oe_highlight"/>
</groupby>
</tree>
</field>
</record>
In this XML example, the records are grouped using the <groupby> tag, and a button labeled "Confirm Orders" is added. The button is associated with a method action_confirm_orders, which will be defined in Python.
Next, we will define the method action_confirm_orders in the sale.order model. This method will handle the logic when the button is clicked.
from odoo import models, api
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.multi
def action_confirm_orders(self):
for order in self:
if order.state == 'draft':
order.action_confirm()
In this method, we check whether the sale order is in the "draft" state, and if so, it is confirmed when the button is clicked.
Adding buttons inside the Group By tree view improves user experience by allowing direct actions on grouped records. This is especially useful for batch processing, where users can apply actions like confirmations, approvals, or other custom workflows with a single click.
Adding buttons inside the Group By tree view in Odoo is a powerful feature that streamlines workflows and enhances user productivity. Whether you need to batch confirm records or trigger other actions, this approach simplifies the process by allowing actions to be performed directly from the grouped view.
Your email address will not be published. Required fields are marked *