Skip to Content
Menu
This question has been flagged
2 Replies
1915 Views

when i perform any action in odoo then in backened which addons file is used and which method and which view code is execute.

  

when i click on new button on project module then in backened which controller is worked , which method is execute.

Avatar
Discard
Best Answer

Hello,

When you perform an action in Odoo, like clicking the New button in the Project module, Odoo triggers a flow involving the frontend (views) and backend (methods).

Frontend: Views and Actions

When you click the button, Odoo checks the view (form or list) that you're interacting with. In this case, the New button usually opens a form view to create a new project. You can use Developer Mode to inspect the view and understand which action is being triggered.

Backend: Methods and Models

Once the button is clicked, Odoo calls a method in the backend. For example, the New button typically triggers the create method in the project.project model. This method is responsible for creating a new record and can be found in the models file at addons/project/models/project.py.

Controller (If Applicable)

If you're working with frontend-related features, a controller might be involved. Controllers handle web-based actions and are located in the controllers/ folder. However, for basic backend actions like creating a project, controllers are usually not involved.

How to Trace What's Happening
  • Use Developer Mode: You can track which view and action are triggered when performing any task.
  • Check Logs: Odoo logs (e.g., odoo.log) will show which methods are executed, giving you insights into the backend flow.
  • Branching and Conditional Logic: Sometimes, methods in the backend handle multiple conditions depending on user inputs or system state, which you can also trace through developer tools.

----------------------------------------------------------------------------------------------------

It’s understandable that the role of controllers in Odoo's MVC (Model-View-Controller) structure can be confusing, as Odoo doesn't always follow the traditional MVC pattern, especially when it comes to backend operations. Let me clarify this for you.

Odoo's MVC Structure:
  1. Model (M):
    • This represents the data layer in Odoo. It deals with creating, updating, deleting records (like creating projects, adding tasks, etc.). Models are defined in the models folder and interact with the database.
    • Example: The project.project and project.task models manage the logic for creating and manipulating projects and tasks.
  2. View (V):
    • Views in Odoo define how data is presented to the user. They are usually form views, tree views, kanban views, etc., and are defined in XML files. This is how Odoo allows users to interact with models.
    • Example: When you open a project form or task view, you are interacting with Odoo views.
  3. Controller (C):
    • In Odoo, controllers are primarily used for handling web requests, API calls, and frontend operations (e.g., website, eCommerce). Controllers handle HTTP requests and usually reside in the controllers folder.
    • In the backend, when you perform operations like creating projects, adding or deleting tasks, controllers are generally not involved. These actions are managed directly by the models and triggered by views (through actions, buttons, etc.).
    • Controllers are involved when dealing with web requests, such as in the website module or REST API calls, but not for regular backend data manipulation (e.g., project and task management).
How it Works in Your Case (Projects and Tasks in Backend):
  • Creating a project or task in the backend directly interacts with the model (project.project or project.task), which processes the data and stores it in the database.
  • Deleting a task is handled in a similar way by the model's unlink method.
  • No controller is involved because you are not dealing with a web request. Instead, the model handles all the business logic and database operations.
When Are Controllers Used?
  • Frontend Operations: For handling web page interactions or requests from users via the website or portal (e.g., submitting forms on a website).
  • REST API: When exposing API endpoints or custom routes that interact with the Odoo backend.
  • Web Clients: If your app requires custom logic that needs to be triggered via HTTP requests, then you would define a controller.
Example of Odoo Project App Flow:
  • Create Project: You create a project from the form view. The request goes through the view and interacts directly with the project.project model.
  • Add Tasks: When you add tasks, the action is processed directly by the project.task model.
  • Delete Tasks: Deleting tasks uses the model’s unlink method, and no controller is involved unless it's a frontend request.

Let me know, if it helps :)

Avatar
Discard
Author Best Answer

Hi, Thank you for the reply. I got some inputs. When I studied online about how MVC working in Odoo, I am getting different answers and little bit confused. Specifically about controllers. For example, 

In the back end, I am creating projects, adding tasks and deleting one or two tasks. In this case also controllers not involved ? Please clarify. For example, The models folder is not included any code related controller according to Odoo MVC ? for Project App

Avatar
Discard

Hello, please refer to my answer again. I have added an explanation of how the MVC structure works with reference to your question after the separator.

Related Posts Replies Views Activity
1
Oct 15
4204
1
Jun 25
512
0
May 25
640
2
Apr 25
2661
1
Feb 25
996