Odoo is one of the Fastest growing ERP solutions out there in the market. But what makes Odoo Special

The Answer is Simple

Odoo offers software solutions for more than a dozen of business related necessities such as purchase, sale, accounting, warehouse, manufacturing, project management etc.

Forte of Odoo platform is that all these modules can integrate with each other and work synchronously.

So, in this tutorial, we’ll demonstrate to you generally accepted methods to install Odoo by yourself on Windows computer and how to add models, databases, security, and webpages. We likewise demonstrate to accomplish a similar outcome through Odoo Enterprise – the online platform that Odoo provides to its clients.

How to Install Odoo?

Remove old OpenERP instance

In case that there are any former OpenERP installations on your PC, we should first delete them so as to forestall conceivable software clashes.

1. In Windows 7 tap Start > Control Panel

2. Click Programs

3. Then click the Uninstall a program

4. Search Programs and Features – OpenERP

5. Select OpenERP [… ] and press Uninstall

Delete old PostgreSQL database server

OpenERP utilizes a PostgreSQL database to store all data. Thus, we should first expel the old PostgreSQL database server from your PC.

1 . Search Programs and Features – PostgreSQL

2.  Choose PostgreSQL [… ] and tap Uninstall/Change

3. Toward the end of the PostgreSQL database server uninstallation procedure, a popup notification will show up telling that –

  • the PostgreSQL data folder for OpenERP
  • the (Windows) service user account openpgsvc have not been automatically deleted.

Since we’re cleaning our framework, utilize Windows Explorer to search to the folder C:Program Files (x86) and remove the whole subfolder OpenERP […].

We’ll additionally delete the (Windows) service user account openpgsvc that has been made amid the past OpenERP installation. In case that we avoid this step, we’ll get glitches when the new PostgreSQL database server will be introduced by the Odoo installation file. All the more particularly, the system will complain as the openpgsvc service account as of now exists.

1.Tap the Windows Start option

2.Type cmd and to open a Windows command line, press [Ctrl] + [Shift] + [Enter] with administrator rights

3.In the event that Windows would display a security warning, press Yes to confirm

4.Then type net user/delete openpgsvc

5.Tap the Enter key

A message will show up telling the effective elimination of the service user account.

Install the latest Odoo software version

As we said that Odoo is open source software so, you can download the full software from the Odoo site and can locally install it on your PC. This is a decent method to find Odoo.

  • Explore to https://www.odoo.com and click the Download option
  • Then you have to enter your name, email address, and select Windows
  • Tap Download Now to download the Odoo installation file
  • Right-click the document Odoo downloaded file and choose Run as administrator to install Odoo in your PC. In case that Windows would display a security warning, click Yes to validate.
  • In the next page click OK to begin the installation.
  • Close all the other programs and tap Next to proceed.
  • Click the I Agree option to accept the agreement terms.
  • Then click Next to install the Odoo Server and the PostgreSQL Database Server both.
  • The subsequent screen comprises the default login certifications that Odoo will use to get to the PostgreSQL Database Server. Tap Next.
  • Now click install to begin the Odoo installation.
  • Odoo is presently being installed on your PC.
  • Note that the installation of Odoo software takes significant time. Try not to interfere with the installation process despite the fact that you think it has hanged down.
  • A different popup will show up amid the installation of the PostgreSQL Database Server, as this product is incorporated into the Odoo installation document.
  • Tap Next to complete the process of Odoo installation.
  • Now the Odoo and the PostgreSQL Database Server both are presently launched on your PC. Click on the Finish button to close the installation window. Odoo will then automatically begin.

Your default browser will then be initiated with the database control board of Odoo.

Using Odoo Online Via Odoo Enterprise

Rather than Odoo installation on your PC, you can likewise directly utilize Odoo online through the ‘Odoo Enterprise’ online platform. This is exceptionally fascinating for SMEs as the security, updates, execution, and management of the server will be completely overseen by Odoo. Also, you can utilize Odoo through a secured https link.

For most SMEs Odoo Enterprise will turn out to be the most efficient answer for their everyday business organization. You can browse diverse App Bundles that best matches your regular needs. An App Bundle comprises only of accredited Odoo modules, that target a particular business requirement i.e. CRM and Sales.

  • Explore to https://www.odoo.com/page/start and write a name for your Odoo Enterprise instance.
  • Tap on Try Now! to proceed with the registration of your free account of Odoo Enterprise.
  • Finish the registration form to enable your Odoo Enterprise account.
  • Enter your name, email address, and password.
  • Click on Start Using button to make your Odoo Enterprise account.

Before really making the online Odoo Enterprise database, you first need to indicate an Odoo application that’ll be placed into your database. For this guide, we pick the CRM app, any way you can choose any application you need.

So, click on Install CRM.

Subsequent to making the online Odoo Enterprise database, you will be signed in with the user account you just made. This will consequently be installed as an administrator account. Notice that the CRM application is as of now established amid the installation of the database.

Because Odoo is open source software, developers can expand the source code and create custom modules. They would then be able to choose to make their work accessible to the Odoo community. These community modules can’t be utilized inside the Odoo Enterprise platform. Contact Odoo or one of its official allies, in the event that you would like to utilize any community module.

Subscription To Odoo Enterprise

Fortunately, you can at present utilize Odoo Enterprise for free (up to 2 users) after your time for testing. You just require a (free) Odoo Enterprise membership to benefit from this offer.

  • Explore to https://accounts.odoo.com/web to locate your current Odoo Enterprise instance.
  • Tap the drop-down option and choose Subscribe OpenERP Enterprise.
  • You’ll see a review of the new Odoo Enterprise membership that we’re going to make.
  • Finish the registration form and click on Update my details option to proceed onward to the next page.
  • Now click Confirm to activate the new Odoo Enterprise subscription.
  • At last, click Continue button to close the Odoo Enterprise subscription page.

Create a New Database

Odoo handles a (PostgreSQL) database for collecting all the data. After the local installation of Odoo on your computer this database should be created first.

  • Fill all the fields in Create a New Database form page. And click Create database button.
  • The database is promptly being built.
  • After a few minutes, the new database will be placed in Odoo and you will automatically be signed in with the default user admin.

Quick Start an Odoo instance

In Odoo, we can make a directory and instantly begin a server instance for it. We can begin by making the directory named todo-app for our instance as explained here –

$ mkdir ~/odoo-dev/todo-app
$ cd ~/odoo-dev/todo-app

Presently we can also make thetodo_minimal module within it and instate the Odoo instance –

$ ~/odoo-dev/odoo/odoo.py scaffold todo_minimal

$ ~/odoo-dev/odoo/odoo.py start -itodo_minimal

The scaffold command will make a module directory utilizing a predefined layout.

The start command will make a database with the present directory name and adds it to the addon path automatically. Thus, the modules will be accessible to be installed. Moreover, we utilized the -ialternative to likewise install our todo_minimal module.

It will pause for a minute to instate the database, and ultimately, we will notice an INFO log message Modules loaded. At that point, the server will be prepared to tune in to client requests.

By default, the database is instated with demonstration information, which is helpful for development databases. Open http://:8069 in your browser to be displayed with the login screen. Admin is the default administrator account with the password as admin. Press CTRL + C, at whatever point you need to stop the Odoo server instance and come back to the command line.

In case that you are hosting Odoo software on a virtual machine, you may need to do some network arrangement to have the capacity to utilize it as a server. The least complex arrangement is to switch the VM network type from NAT to Bridged. Ideally, this can enable you to locate the suitable arrangement in your virtualization programming documentation.

The Organization of a Module

Before making our first model in Odoo, we have to discern about the model. A model is a Python class that serves to a business element (fields) that are put away in PostgreSQL database. In Odoo all business elements are actualized as model or class. ModelOfields (class property) are described as fields or attributes or columns in a database.

Models depict business objects, for example, a sales order, an opportunity, or an accomplice (client, provider, etc.). A model has data fields and can likewise characterize particular business logic.

An Odoo module can include various components –

Business Objects

Announced as Python classes, these sources are consequently persevered by Odoo in view of their setup.

Data Files

CSV or XML documents proclaiming metadata (reports or views), demonstration data, configuration data (modules parameterization), and so on.

Web Controllers

Control requests for from internet browsers.

Static Web Data

Images, JavaScript or CSS files utilized by the website or web interface.

Making The Application Model

Now we will learn to make a new model called ‘demo.access.rights’, with only one simple field. Make a new Python file within the ‘models’ directory and build a new model with a field –

Our to-do tasks will have a name title text, an active flag, and a done flag. The active field will have a unique significance for Odoo; by default, records with a False value in it which will not be visible to the user. We will utilize it to remove the tasks beyond anyone’s ability to see without really erasing them.

Updating a Module

For our progressions to produce results, the module must be updated.

The least complex and quickest approach to make all the variations to a module successful is to go to the terminal window where you will have Odoo running. Stop it by pressing CTRL + C, and afterward restart it asking for the module upgrade.

To begin updating the server, the todo_minimal module in the todo-app database, utilize the accompanying command –

$ cd ~/odoo-dev/todo-app # we should be in the right directory

$ ./odoo.py start -u todo_minimal

The – u alternative plays out an upgrade process on the above-given list of modules. For this situation, we update only the todo_minimal module.

Building up a module is an iterative procedure. You should perform your changes in progressive steps and much of the time install them with a module upgrade. Doing as such will make it less demanding to identify errors sooner. As well as to narrow down the guilty party when the error message isn’t sufficiently clear. What’s more, this can be extremely common when beginning with Odoo development.

Adding menu options

Since we have a model to save our data, how about we make it accessible on the UI. All we require is to add a menu option to open the to-do task model in order to use it. This is accomplished utilizing an XML data document.

We will reuse the templates.xml data document and edit it.

We will have two records here – a window action and a menu option The Communication top menu to the UI was included by the mail module dependency. We can distinguish the identifier of the particular menu option where we need to append our own menu option by probing that module, it is mail_feeds.

Likewise, our menu option executes the todo_task_action action we made. The window action opens a tree view for the todo.task model.

In case we update the module currently and attempt the menu option just included, it will open an automatically created view for our model, permitting to add and alter records.

Views ought to be described for models to be presented to the users. Yet Odoo is sufficiently fair to do that automatically when we don’t, so we can operate with our model immediately, without having any list or form views described still.

Creating Odoo Views

All data of the Odoo programs are saved as objects. Views are described to open these objects to the user. Odoo utilizes dynamic UI, which implies it isn’t statically managed by a few codes, it is powerfully operated from XML descriptions. Also, these screen descriptions are termed views.

In Odoo, views characterize the path by which the models/objects showed to user end. Views are of a few kinds; each view speaks to a method of representation. They make the modules easier to understand and can change as indicated by the need. A few kinds of views in Odoo are – tree, search, form, graph, pivot, calendar, Kanab and much more. Every sort of view is unique, ‘tree’ view offers the list view of objects, Form view shows a solitary object, Search view filters the items.

Here we are going to talk about:

1. Calendar View

In this view type, the records are represented in a calendar type. Hence, it can be seen as days, week, or month. In application part, this view is more executed to plan a day, set appointments, to-do etc. Calendar view gives schedule view for the information.

string – The title string for the view.

date_start – A DateTime field to determine the beginning date for the logbook object this property is required.

date_stop – A DateTime field to determine the end date. Ignored if date_delay attribute is determined.

date_delay – A numeric field for a record to determine the time in hours. This attribute will get inclination over date_stop to be ignored.

day_length – An integer number to indicate the length of working day. By default, it is 8 hours.

color – A field, for the most part, many2many, to colorize calendar objects.

mode – A string value to set default zoom or view mode. This can be one of following for calendar view, (by default, it is a month):

  • Day
  • Week
  • Month

2. Graph View

As the name depicts it gives a graphical perspective of the information, as Bar chart, Line graph, and Pie chart. Graph view is a conglomeration of each and every record in a model, which is usually pictured in pie, bar, and line.

The pie chart is the default type of the graph. To transform it into a bar graph, we have to define the type. You additionally may adjust the orientation. The principal field is the X-axis and the second one is the Y-axis. The discretionary third one is the Z-axis for 3D graphs.

interval – This is significant for date fields and is the time interim used to aggregate time information by ‘month’, ‘day’, ‘week’, ‘quarter’, or ‘year’

name – Name is constantly required. It is the name of the fields utilized for the graph. It is more probably employed for grouping instead of aggregating.

3. Pivot View

The Pivot view represents the data as tables, a powerful analysis grid. Pivot view over and over creates table progressively, while changing the row or column or field. The user can choose the row and column field to signify to the table. Every time when a user modifies the fields, it calls corresponding SQL inquiries and produces tables as needs are. So, Pivot tables are called as dynamic analysis matrix.

row (by default) – Groups the row by the particularized field. Each group gets its own row in pivot view.

Col – Creates groups in columns.

By clicking ‘+’ we can include user particular field in the column, also on the row side. At that point, pivot view will create the table as per that field. The accompanying table with rows as task and column as Assignation date > Day. Every time user can make his own personalized tables.

Window Action:

We have to characterize this view in real life keeping in mind the end goal to see them. In Odoo action renders each and every view, for example, tree, form, pivot, calendar, graph, and so on.

view_mode – A comma-separated rundown of view types (Kanban, from, and tree) as a string. These types will be available in the provided views list. By tapping on the buttons, we can without any difficulty get different view types of the same objects.

Making the security groups

Okay, now that we have understood making a model, the following activity is to make the security groups with the particular rights that you might want to provide for this group.

Odoo is exceptionally adaptable regarding the matter of security. We can manage what users can do and what they can’t on various levels. Likewise, we can control voluntarily every one of the four essential tasks – create, read, write, unlink. i.e. allow only create, allow only read, grant consent to only create or delete.

On fields or menu level we can –

  • Hide fields or menus for a few users and display them for others.
  • Control fields to read only for a few users and allow them to be editable for others.
  • Demonstrate distinctive variations to single out the Selection fields for various users.

On the fields level of security res.groups and res.users models are utilized. These models identify with each other as many2many. This implies a user can be a part of various groups and a single group can be attributed to numerous users.

Firstly, open up the ir.model.access.csv file (under security/) and take a look at the highest part of the file.

When you watch at this file you’ll observe that there are a couple of columns. Let’s know about them a bit into detail:

Id – An interesting identifier for the record (they ought to dependably be special!)

Name – This is the depiction that is appeared in the front-end and is the title of the security group.

model_id:id – The name of the model where a person has to make a security lead for. Supplant the ‘.’ by a ‘_’. In case that you have a model named ‘this.model’ it ought to turn into ‘this_model’ and it ought to constantly be prefixed with model_. So, this would move toward becoming ‘model_this_model’.

group_id:id – A bizarre name of the group.

perm_read – When this is set to 1 it implies that every user that are in the group have an access to read on this model. In case that it is set to 0 it implies that the users don’t have rights to read.

perm_write – When this is set to 1 it implies that every user that is in the group have an access to write on this model. In case that it is set to 0 it implies that the users don’t have the rights to write.

perm_create – When this is set to 1 it implies that every user that is in the group have an access to create on this model. In case that it is set to 0 it implies that the users don’t have rights to create.

perm_unlink – When this is set to 1 it implies that all users that are in the group have an access to erase on this model. In case that it is set to 0 it implies that the users don’t have the rights to erase.

Let’s commence writing the security groups. For example, we will create two groups, one with total rights for writing, reading, creating and deleting (admin behavior) and another group that can just read the records. Let us see the result of it.

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink

demo_admin,Modeladminaccess,model_demo_access_rights,user_access_right

demo_user,Modeluseraccess,model_demo_access_rights

We have built two lines, that suggests two groups, which are both for the model ‘demo.access.rights’, where the primary group holds all rights on the model and the second group can just read data (view the 1,1,1,1 and the 1,0,0,0).

Have you noticed anything else too? There is a group_id in the field termed ‘user_access_rights_demo.group_manager’ on the first line. Also, named ‘user_access_rights_demo.group_user’ on the second line. What do those two suggest?

The first section (‘user_access_rights_demo’) is the title of the module where you are building groups for. The second section, ‘group_manager’ will connect to an XML record in which we will define the rest of the details. Add those lines to the CSV file. Then save it and close it.

However, if you want all users to view only their own to-do tasks. For this, we require a record rule arranging a filter on the records the base group can view. Within the security/ directory, include a todo_access_rules.xml file to set the record rule –

ToDo Tasks only for owner

[(‘create_uid’,’=’,user.id)]

This is all we require to do to configure the module security.

Building the groups and selection in XML

Thus, as you’ve composed the groups in the CSV we have the principles yet in the CSV file, they link to ‘group_user’ and ‘group_manager’, that we haven’t made anywhere yet. So, let’s create them!

Make another XML document in the ‘security’ folder with the goal that we can write the XML side. We will give a name to that document – ‘group_file.xml’.

We now require three things:

  • A group named ‘group_manager’
  • A group named ‘group_user’
  • A record that will link both of these groups in a drop-down, so as to display it in the user in his form.

Let’s begin by writing a record which will demonstrate our both groups in a drop-down:

This will make an option in the user form that has the name ‘Demo module access’ and a depiction ‘User access level for this module’. The series can be utilized to indicate where it must come in the view. As you’re finished with this part it will demonstrate this choice: ‘Demo Module Access’.

Then comes the second part of this process. We presently need to make two group records ( ‘group_manager’ and ‘group_user’) with the goal that the CSV can discover and utilize these gatherings. The code should be as such-

The ‘name’ field will be the content that is displayed to the user in the front-end.

By inserting the ‘users’ field (that links to another group user) you can state that by default the users that have a place with the other group ought to be added to this particular group.

That’s it! You’ve just learned to build your own particular security groups and made them accessible on the client form with the goal that you can set up this for every user by his own.

Making building blocks in Odoo

Before you can begin making another building block you should make another module and set up the manifest.py effectively. Open up your manifest.py and include the site as a dependency:

# The website module has to be installed and is needed to add a building block

depends’: [‘website’],

Without this dependency, you can’t make and join new building blocks to the Odoo site.

Presently make another XML file named “snippets.xml” beneath the “views” folder.

In this file, we will include all the code to make the building block (snippet) and to make it appear in the editor.

Now we will begin the real task of making a building block that has a title (h3) stating “Our references” with four logos below the title.

We initially make another XML record. Subsequent to doing this we add all our code inside a section block and in this, we make a compartment div. Inside this area and container, you can actually code anything you like, this is the structure for any building block. By and large, when you make a building block you attempt to use however much bootstrap classes as could be expected.

You’re as of now well halfway finished to your own particular building block. In the event that you would install this module right now all the code would be there that is required for a building block, yet regardless we need to indicate it in the editor with the goal that we can utilize it.

Adding the Building Block to The Editor

Now it’s time to add a building block view to the editor so you can instantly discover it from the editor.

You can do this by acquiring the default “website.snippets” record and completing an XPath in the “snippet_structure” id, which includes the fundamental composition of the editor. Examine this code:

<!– This record will create a preview of the building block in the left menu from where you choose the blocks –>

Let’s understand this code further. In this xpath component, we include a div and we utilize the t-snippet component created by Odoo. By doing as such Odoo comprehends we need to add a snippet view to the editor.

At last, save the file and add it in the manifest.py document with the goal that it gets loaded:

# always loaded

‘data’: [

# Load the snippets (building block code) when installing

‘views/snippets.xml’,

]

When you currently install the module, you will see your new building block is accessible for use by the editor.

Congrats you’ve just made your own building block!

Rules for Workflow Transition:

Workflow transitions can be confined to a particular group. Users out of the group cannot trigger the change.

Go to: Settings – > Workflow – > Transitions

A Transition consists of:

Source Activity – It characterizes the starting condition of transition (e.g. draft)

Destination Activity – It characterizes the finishing condition of transition (e.g. waiting)

Signal(Button Name) – It characterizes activity name (e.g. submit_hr)

Condition – It is utilized to check if workflow instance advances through the transition or not (e.g. True)

Group Required – It characterizes a group to provide access to (e.g. HR/Employee)

We can also characterize the group from XML side for the transition.

For instance:

Object-Relational Mapping

A key part of Odoo is its ORM layer. This layer abstains from writing most SQL by hand and gives security services2 and extensibility.

Business objects are announced as Python classes expanding Model which incorporates them into the automated ingenuity framework.

Models can be set up by installing various attributes in their definition. The most vital attribute is _name which is needed and characterizes the model name in the Odoo framework. Here is a negligibly full meaning of a model:

from odoo import models

class MinimalModel(models.Model):

_name = ‘test.model’

Including business logic

We need to add business logic to clear the effectively finished tasks. We will likely include the More button option, displayed at the highest point on the list when we select lines. We will utilize an exceptionally simple wizard for this, opening an affirmation dialogue, where we can execute a strategy to inactivate the performed tasks.

Wizards employ an unusual sort of model for temporary information -Atransient model. We will promptly add it to the models.py file as shown below –

Transient models act simply like normal models, yet their information is temporary and will, in the long run, be cleansed from the database. For this situation, we needn’t bother with any fields, since no extra info will be asked to the user. It simply has a strategy that will be requested when the affirmation button is clicked. It records all tasks that are done and afterward orders their active flag to False.

Next, we have to include the corresponding UI. In the templates.xml file, add the accompanying code:

To-do Clear Wizard

todo.task.clear

All done tasks will be cleared, even if

unselected.

Continue?

The first record characterizes the form for the dialog window. It has an affirmation content and two buttons on the footer – clear and cancel. The clear option when clicked will call the do_clear_done() strategy described prior. The second record is an activity that includes the corresponding choice in the More button for the to-do tasks model.

Removing Odoo Support User from Odoo chat

The majority of us don’t need support user to appear in our list of individuals to chat with and particularly not when you’re selling Odoo to clients.

So, how would you delete this user?

First, open your addons folder and look for the addon im_odoo_support.

Go to the folder views and after that open the XML document im_odoo_support.xml. In this document, you can specifically observe that there is a function and it seems to Odoo Support. Thus, simply move ahead and comment this block out as such:

Go to im_odoo_support/static/src/xml/and open the file im_odoo_support.xml. You’ll view an li class here for Odoo Support as well. Comment it out this way:

Then restart your Odoo server and refresh your module. You can do this with the help of this command:

./odoo.py – u im_odoo_support

Now open Odoo in your browser and you’ll notice there is no more ‘Odoo Support’ user in the list.

Creating Webpages

Prior to creating a web page you have to make a controller. The controller will report to Odoo which URL connects to that website page. Open up your module and make a folder named ‘controllers’ in case that you don’t have one. Then make a __init__ file and add the given line of code in it:

# -*- coding: utf-8 -*-

from . import example

Since you have an import that is straightforwardly stacked by Odoo you ought to create another Python document. Name this new document ‘example.py’, this will be the controller.

Time to make our first controller!

So as to give a user a chance to navigate to a particular page, you will require a @http.route. The @http.route will report to Odoo that we have to link the url ‘/example’ to a particular site page. Within the @http.routewe can notice the four variables.

Next, to calling @http.route you should give the Python function a name, in this case, render_example_page(self). See that self has likewise moved along in functions in the front-end of Odoo, much the same as in the backend.

At last, you have to restore the function. Since the function has to know which XML record should be called we move it along like this:

return http.request.render(‘create_webpage_demo.example_page’, {})

http.request.render will request the view renderer from the Odoo system in the sections “()” you need to determine the module_name.page_name.

Close the Python document, head into the ‘views’ folder and make another XML file named ‘example_webpage.xml’. You have to add this XML file in the manifest.py first:

‘data’: [

‘views/example_webpage.xml’,

],

Then return to your example_webpage.xml file and make another XML record. You’ll view that making another site page is similarly as simple as making an Odoo view. Add the following code in your module:

You can add all your content here.<br/>

The record begins with a template-id, which is indistinguishable from making views in Odoo. Odoo will then realize that the controller requires to render the XML view that we’re presently coding. Did you observe the page=”True” key? As Odoo has to know whether it is a web page or not there is a key ‘page’ included in Odoo. By inserting this key to True Odoo recognizes it’ll turn into a web page.

Afterward, we have the accompanying line:

<t t-call=”website.layout”&gt;

Due to this Odoo knows that it has to take the default web page layout and must utilize it to this XML record. The div class oe_structure will append the feature to utilize building blocks inside Odoo. Thus, other people, who work on your Odoo not having technical knowledge, will be capable to use building blocks for styling the web pages.

Finally, save this page, update your module and open your Odoo. In the website go to /example. In the XML record that we just created add the given line of code:

<a t-attf-href=”/example/detail” class=”btnbtn-info”>Company detail page</a>

Through this Odoo system will be triggered the moment you click on that button. Odoo can evaluate this code and identifies that you need to open the page /example/detail.

Now build another function in the controller to control this.

Go to the Python file ‘example.py’ again, just as we did before with the first one. There will be only one addition to the code. We’ll further transfer data to the next web page. Create a second function that links to /example/result.

Passing Data to the Web Page

You can call data from the database in controllers as well. It simply acts somewhat different. Usually, in Odoo you would do this:

companies = self.env[‘res.company’].search([])

It’s not probable to make it like this in the controller, however. In the controller, we need to apply ‘http.request.env’ to retrieve data from a model. So, your code will view like this:

companies = http.request.env[‘res.company’].sudo().search([])

The last thing is to pass this data, which is in the variable companies, to the web page. Do it like this:

return http.request.render(‘create_webpage_demo.detail_page’, {

# pass company details to the webpage in a variable

‘companies’: companies})

So, it’s totally established on the controller side to open up the page/detail/example and to pass whole data to the web page. The ultimate code of your function will seem as such:

@http.route(‘/example/detail’,type=’http’,auth=’public’,website=True)

def navigate_to_detail_page(self):

# This will get all company details (in case of multicompany this are multiple records)

Due to this {‘companies’: companies} in the dictionary complete data from all companies will pass along to the web page.

Conclusion

In the whole process, we got familiar with the module development method, comprising adding a database, module upgrades and adding various models and blocks to make the regular changes efficient in the Odoo software.

Copyright © 2024 Probytes.