Odoo is a versatile open-source business management tool that enhances efficiency and streamlines operations. It offers interconnected applications like CRM, accounting, inventory, project management, HR, and eCommerce. Its modular design allows for customization, and its user-friendly interface caters to both technical and non-technical users, automating workflows and improving customer interactions.
In this blog, we delve into the wizard that appears upon clicking a Kanban tile, exploring its functionality and potential applications. Beginning with the creation of a model and a corresponding form view, we proceed to demonstrate the creation of a notebook within that model, integrating a one2many model. Through this exploration, readers gain insights into leveraging wizards within Odoo for enhanced user experiences and streamlined workflows.
Firstly create a model,
from odoo import fields, models, api
class OrderList(models.Model):
_name = 'order.list'
_description = 'Order list'
name = fields.Char(readonly=True)
description = fields.Char()
quantity = fields.Float()
order_food_id = fields.Many2one('order.food')
The model created above serves as a One2many relationship for the model below. To establish this relationship, I'm introducing a Many2one field to establish a connection between the two models. This field is then employed as the inverse field, enabling the creation of a One2many field.
from odoo import fields, models
class OrderFood(models.Model):
_name = 'order.food'
Name = fields.Char(string=’Name’)
order_list_ids = fields.One2many('order.list', 'order_food_id')
Now, create a model for the wizard. Create the model as a transient model since we don't need to store the data permanently. In the model, include fields such as name, quantity, price, and image.
from odoo import fields, models
class FoodOrderTransient(models.TransientModel):
_name = 'food.order'
_description = 'Food order'
name = fields.Char(readonly=True)
quantity = fields.Integer()
company_id = fields.Many2one('res.company', store=True, copy=False,
string="Company",
default=lambda self:
self.env.user.company_id.id)
currency_id = fields.Many2one('res.currency', string="Currency",
related='company_id.currency_id',
default=lambda self:
self.env.user.company_id.currency_id.id)
price = fields.Monetary(readonly=True)
image = fields.Binary()
Next, we will create a view for the model order.food.
Specify the name, set the model as our model, and define the view mode to determine how the view should be displayed.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="order_food_kanban" model="ir.ui.view">
<field name="name">order.food.form</field>
<field name="model">order.food</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name"/>
</group>
<notebook>
<page string="Menu">
<div>
<group>
<kanban action="action_order_food"
type="object">
<field name="name"/>
<field name="price"/>
<field name="image"/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_global_click">
<div class="o_kanban_image">
<field name="image"
nolabel="1"
widget="image"/>
</div>
<div class="oe_kanban_details">
<ul>
<div>
</div>
<li class="mb4">
<h3>
<field name="name"/>
</h3>
</li>
<li>
<field name="price"/>
</li>
<li>
<field name="uom_id"/>
</li>
</ul>
</div>
</div>
</t>
</templates>
</kanban>
</group>
</div>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record id="action_order_food" model="ir.actions.act_window">
<field name="name">Food Order</field>
<field name="res_model">order.food</field>
<field name="view_mode">kanban</field>
<field name="view_id" ref="order_food_kanban"/>
</record>
<menuitem id="order_food_menu_root" name="Food Order" action="action_order_food"/>
</odoo>
Within the Kanban view, we defined an action with the type set as an object. Now, we need to write a function to create the wizard.
def action_order_food(self):
view = self.search([])
for rec in view:
res = {
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'food.order',
'target': 'new',
'context': {
'default_name': rec.name,
'default_price': rec.price,
'default_image': rec.image
}
}
return res
Specify the type and view_mode as form, set res_model as our transient model, and set the target as new to view it like a wizard.
Default values for the wizard are passed through the context. Include this action inside the Kanban tag and set type = object.
<kanban action="action_order_food"
type="object">
After clicking the Kanban tile, a wizard will be displayed.
Integrating wizards with Kanban views in Odoo 17 represents a significant enhancement in usability and functionality, supporting businesses in achieving streamlined operations and enhanced user experiences.
To read more about How Can Open a Wizard When Clicking on Kanban Tile Odoo 16, refer to our blog How Can Open a Wizard When Clicking on Kanban Tile Odoo 16.