KEMBAR78
How to Call Python Function from Menu Item | PPTX
How to Call Python
Function from Menu Item
in Odoo
Enterprise
Introduction
Enterprise
In this slide we’ll discuss how to call python function from
menu item in odoo. Server action can be used to call a python
method that should work when we click on a menu item.
Enterprise
Here we are going to use execute python code action. For that
we can create a python function named test_function that works
when we click on the menu named Accessories. For this, first let
us create a menu item with the name accessories and link it to
action category_python_action. Then we create a server action
with id category_python_action and specify the base model on
which the function should work by giving the model_id. We
specify the function to be called in the code section.
Enterprise
Enterprise
Now we have the action all set for the work, we can now
define the python function inside the model we specified
in the action. The function should be inside the model
that we specified in the model_id field. Here we have
created a function to filter products that belong to the
accessories category( with id=5) and return the view for
it. We will need this case when we can't get the required
filtering via XML or any situation where python code is
required to get a specific task done.
Enterprise
Enterprise
The output of the code will create a menu item named accessories
that will show products that belong to the accessories category when
clicked on it. Products with category having id=5 is filtered here.
Enterprise
We can also create the server action from the user interface by
going to settings -> technical -> actions -> server actions.
Enterprise
We can create a server action accordingly form UI.
For More Info.
Check our company website for related
blogs and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.
Enterprise
www.cybrosys.com

How to Call Python Function from Menu Item

  • 1.
    How to CallPython Function from Menu Item in Odoo Enterprise
  • 2.
    Introduction Enterprise In this slidewe’ll discuss how to call python function from menu item in odoo. Server action can be used to call a python method that should work when we click on a menu item.
  • 3.
    Enterprise Here we aregoing to use execute python code action. For that we can create a python function named test_function that works when we click on the menu named Accessories. For this, first let us create a menu item with the name accessories and link it to action category_python_action. Then we create a server action with id category_python_action and specify the base model on which the function should work by giving the model_id. We specify the function to be called in the code section.
  • 4.
  • 5.
    Enterprise Now we havethe action all set for the work, we can now define the python function inside the model we specified in the action. The function should be inside the model that we specified in the model_id field. Here we have created a function to filter products that belong to the accessories category( with id=5) and return the view for it. We will need this case when we can't get the required filtering via XML or any situation where python code is required to get a specific task done.
  • 6.
  • 7.
    Enterprise The output ofthe code will create a menu item named accessories that will show products that belong to the accessories category when clicked on it. Products with category having id=5 is filtered here.
  • 8.
    Enterprise We can alsocreate the server action from the user interface by going to settings -> technical -> actions -> server actions.
  • 9.
    Enterprise We can createa server action accordingly form UI.
  • 10.
    For More Info. Checkour company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com