USING ODOO 13
Introduction
This writing supposed to be a cheat sheet for helping myself to learn about Odoo, Odoo Development and also anyone who want to read this.
Odoo already have a good documentation in their websites you can check it here https://www.odoo.com/documentation/13.0/
What you need
Odoo source
you can get the source from odoo.com or github
https://www.odoo.com/page/download or https://github.com/odoo/odoo. Right now I'm using the https://www.odoo.com/page/download . I did using the github twice so I'm already familiar with it but now i want to explore something new and maybe we will find something.
Python v3.6++ (intermediate level).
https://www.python.org/downloads/windows/
You can learn some basic “web development with python” first if you still new at programming. Search with google.
Postgresql https://www.postgresql.org/download/
I’m using win Os for development and Visual Studio Code for IDE
What should you read first
Installation procedure from documentation
https://www.odoo.com/documentation/13.0/setup/install.html#setup-install-source
Module development from documentation
1. Installation
This is just a review from the document and few adjustment to my environment. Also maybe a cheat sheet for personal use.
Next should be the installation cheat sheet.
Create directory for this practice or project. I create a directory called odoo_practice. And put the source code here.
Install python and set virtual environment. Then install dependency library from requirements.txt
Install postgres. Add postgres\<ver>\bin to PATH. Create new user with privilege to CAN LOGIN and CREATE DATABASE. Don’t use default user postgres
for windows download build tools for visual studio
1.1 Create Directory and put Source Codes
I have create odoo_practice directory to put the source code.
Next should be the directory structure from the source code.
1.2 Set Up Python Development Environment
Make sure python is ready on system environment. You can do this by opening command prompt and type python.
python -m venv <name_of_your_environment>
I learn to create python environment from
https://www.django-rest-framework.org/tutorial/quickstart/
or you can always google it.
I need a separate
environment from my main or OS environment because I have a few
project that using python with different version of library.
For this practice I’m using envforodoo13. Then activate the environment
Install the requirements using pip install -r requirements.txt
1.3 Postgres
I think the doc already give detailed how to. It’s pointed out that we should create new user and not using the default user. So maybe I don’t need to put longer explanation in here. But here goes.
Open pgAdmin
Go to Login/Group Roles
I’m using odoodb_admin as user for postgres
Set Password. I’m setting to admin.
Set Privileges. Can Login ? And Create Database to YES as pointed in odoo doc.
Create database odoo13db.
1.4 Microsoft Build Tools
Same here I think the document already have detail explanation. But from my experiences, I already have Visual Studio 2019 CE with the build tools. And I forgot how to install it.
1.5 Running Odoo
I have few difficulties in first time running Odoo, it’s been a while so I don’t remember that much. In document they use this command to run Odoo
python odoo-bin -r dbuser -w dbpassword --addons-path=addons -d mydb
But it turn out that I have to use –init=base to load odoo with data. You can read the command line reference here https://www.odoo.com/documentation/13.0/reference/cmdline.html#reference-cmdline-server-database
so go to odoo directory then run
python odoo-bin -r odoodb_admin -w admin --addons-path=addons -d odoo13db –init=base
but too bad I got error
It
turns out we don’t have odoo-bin file. If you go to github, the
odoo-bin files is there. But I download it from
https://www.odoo.com/page/download
doesn’t contain odoo-bin.
I compare the two download zip files it turn out to be quite different.
I try to run it again but got error. It
seems that it can’t find addons directory.
It
seems that the addons directory located inside the odoo directory so
it should be like this
python odoo-bin -r odoodb_admin -w admin --addons-path=odoo/addons -d odoo13db –init=base
we
counter a few error but now it working.
Wait for few minutes to load and create the data and you can go to http://localhost:8069/ to view the result or login page.
Use (username and password) admin for admin role and (username and password) demo for demo role
Module Development
This also review from existing Odoo document and making this review also as cheat sheet for personal use or anyone who want use it. If you want to use it immediately you should read Getting Started with Odoo or in Odoo terms it’s General use, here is the link https://www.odoo.com/documentation/user/13.0/general.html
Getting familiar with Odoo User Interface and basic of the General Use will have a benefit for longer time.
Now lets get back to reviewing the module development. From the document
https://www.odoo.com/documentation/13.0/howtos/backend.html#build-an-odoo-module
what we can learn is
Basic understanding Module Composition
Create module using scaffold command
Model creation and basic understanding about ORM in Odoo
Creating Menu and also understanding Action
But from this we still can’t see it in action in the app because you have to go to
https://www.odoo.com/documentation/13.0/howtos/backend.html#basic-views
to learn about the front-end or Views creation.
With these 2 simple courses you just create basic CRUD (create, read, update, delete) with additional feature without having too much code. But you still have to update Access Rights so User or the Admin can use the module.
Too make it simple here is the cheat sheet.
Scaffold first for the base module then loop this
Create model function/method.
Update the view, create Tree and Form view
Update the menu. So you can test it in browser
Update the Access Rights or you won’t see the Menu and can’t access the view
Re-run odoo-bin with arguments -u <module_name> to update what you make or changes
In the Odoo document they not mention that you have to update the access rights after the Basic View Course. I’m having a hard time searching why my menu doesn’t show up in the main menu.
I will do the exercise first the OpenAcademy module the Course model then try a new model with different name.
So anyway Now lets try the exercise from Odoo document and review it one by one and also testing it.
From the document exercise we have to invoke the command scaffold. From the next image you can see that we have to invoke in the command line.
The document tell us to invoke the command and put it into addons directory. But that will make the modules being save in addons directory along with other modules that Odoo already use. It will make you hard to manage.
Because of that, I choose to create directory of my own. So it will be easier to manage. For now create myaddons directory inside Odoo directory so the directory will be at the same level with addons directory. You can use mkdir command or just use right click > new folder. The next image will show you where to put it.
so if you follow along from the beginning just use your virtual environment and type
python odoo-bin scaffold openacademy odoo/myaddons
it will automatically create the necessary files for empty modules as the image shown below.
So now you know how to create a module, but it doesn’t stop here because we just only create an empty modules or in other words just creating a directory, with simple files. Next we’re going to create a class in model.py. You can read more about models in the document here https://www.odoo.com/documentation/13.0/reference/orm.html#models . But if you just wanna know from me then to make it simple its just a representation of table in database or a storage.
Now let’s go and create Course model. In the document it says that we have to edit the models.py files in openacademy/models directory. You can also create another files if you don’t want to create in models.py but you have to edit other files so your files is loaded by Odoo framework. Anyway we wont do that right now. So go ahead edit the models.py just the same as document told you to do. Below is the image before edit.
and after edit it becomes.
As you can see it’s all the same with the document.
You can run the odoo-bin to test if you made some error in editing models.py or not. If you want to test it out just add argument -u openacademy in the command line
Menu in Odoo is being created in xml files that being loaded into the application as long as the files is written in openacademy/__manifest__.py files. The document told us to create new files and add some line in views/openacademy.xml. But right now I’m just gonna write in views.xml because the files its a default files when it modules being generated through scaffold. As you can see in the next image of __manifest__.py.
And
the next image is the default files of view.xml which already
contains xml tag <menuitem>.
.
Next image will show you a bit different than the document. I think the result should be the same.
It’s should be fine if you try to run the update again
With
this we have a basic Menu and Action with a simple view. But we still
can view it in the app.
let’s just try it. Make sure the odoo-bin is running after update. And go to localhost:8069 and login using username : admin and password : admin.
If you see in the main menu. Our Open Academy Menu still not show. That just because the modules have not being installed in Odoo.
To Install the modules go to Apps, search module OpenAcademy. If you can’t find it like image below.
Try
to tick off the Apps Tag so it will show every modules that named
openacademy. Below is the image if we tick off the Apps Tag.
Go ahead and Install it.
Even
after install the modules. The menu doesn’t show. That’s why we
need the security files to let
the user have access to it.
First un-comment ‘security/ir.model.access.csv’ in __manifest__.py.
And edit the ir.model.access.csv file.
If
you notice. I’m using base.group_user
as
group id that can have access. This is just temporary as the Odoo
document will be using group_manager
as
group id.
You can try to update the app again. Restart the command line odoo-bin and don’t forget to use -u openacademy as argument. Refresh the browser then see the menu will be shown in main menu.
And
if you try to click it, it will redirect user to Open Academy List
view.
You
can now try and test the Create Button and start input sample data.
If
it’s work the data will be saved and can be shown in the list view.
I
think that’s it for today. Don’t forget to check the security
part in the Document otherwise you’ll get confused on how to manage
access rights here the link
https://www.odoo.com/documentation/13.0/howtos/backend.html#security
That’s
it for today I will be editing this and adding some new sample.
after try to view this writing for few times. maybe i need to make it into parts. so when the page load it will load a bit faster
Comments