The Odoo Development Guide featured Share-1th-Start using Odoo development (1)

Source: Internet
Author: User
Tags psql vmware fusion turnkey linux css preprocessor

Introduction

Before we enter Odoo, we need to build our development environment and learn about its basic management tasks.

In this chapter, we will learn how to set up a working environment, where we will build our Odoo application. We'll learn how to set up a Debian or Ubuntu system to host a development server instance, and how to install Odoo from GitHub source code. We will then learn how to set up file sharing with Samba, which will allow us to run Odoo files from workstations running Windows or any other operating system.

Odoo is built with the Python programming language, which uses the PostgreSQL database for data storage, which is the two main requirements of the Odoo mainframe. To run Odoo from the source code, we first need to install the Python library it relies on. You can then download the Odoo source code from GitHub. While we can download the zip file or tarball, we'll see that if we get the source code using the GIT version control application it will be better; it will also help us to install it on our Odoo host.

Set up a host for the Odoo server

A debian/ubuntu system is recommended for Odoo servers. You can still work on your favorite desktop system, whether it's Windows, Mac, or Linux.

Odoo can run on a variety of operating systems, so why choose Debian at the expense of other operating systems? Because Debian is considered a reference deployment platform for the Odoo team; it has the best support. If we use Debian/ubuntu, it will be easier to find help and additional resources.

It is also a platform for most developers to work on, and most deployments are done on this platform. So, inevitably, odoo developers will be happy with the Debian/ubuntu platform. Even if you are a Windows background, it is important that you understand it.

In this chapter, you will learn how to set up and process Odoo on a debianbased-based system, using only the command line. For families with Windows systems, we'll show you how to set up a virtual machine to host the Odoo server. As an additional bonus, the technology you will learn here will also allow you to manage Odoo in your cloud server, where your only access will be accessed through secure Shell (SSH).

Keep in mind that these instructions are intended to create a new development system. If you want to try some of these on an existing system, always back up early so that you can recover it if a problem occurs.

Services for the Debian host

As mentioned earlier, we need a debian-based-based Odoo server host. If this is your first time using Linux, you may notice that Ubuntu is a Linux distribution based on debianbased, so they are very similar.

Odoo is guaranteed to use the current stable version of Debian or Ubuntu. In writing, these are Debian 8 "Jessie" and Ubuntu 16.04.1 LTS (xenial Xerus). Both environments have Python 2.7, which is a necessary condition for running Odoo. It is worth mentioning that Odoo does not support Python 3, so Python 2 is required.

If you are already running Ubuntu or another debian-based-based release, you can set it up; this also works as an Odoo host.

For Windows and Mac operating systems, install Python, PostgreSQL, and all dependencies; Next, run Odoo directly from the source program. However, this can be a challenge, so our recommendation is to use a virtual machine running a Debian or Ubuntu server. You can choose your favorite virtualization software to get a working Debian system in a virtual machine.

If you need some guidance, here are some suggestions for virtualization software. There are several options, such as Microsoft Hyper-V (available in some versions of Windows systems), Oracle VirtualBox, and VMware Workstation player (VMware Fusion for Mac). VMware Workstation players may be easier to use and free downloads can be found on https://my.vmware.com/web/vmware/downloads.

For the Linux image used, installing Ubuntu server is more friendly than Debian. If you start with Linux, I recommend that you try using an existing image. TurnKey Linux provides easy-to-use pre-installed images in a variety of formats, including ISO. The ISO format will work with any virtualization software you choose, even on bare metal machines you may own. A good option might be a third-party Lapp image, including Python and PostgreSQL, which can be found in Http://www.turnkeylinux.org/lapp.

Once installed and started, you should be able to log on to the command-line shell.

Create a user account for Odoo

If you are logged in with the Superuser root account, then your first task should be to create a normal user account to use your work as it is considered a bad work practice as root. In particular, if you start it as root, the Odoo server will refuse to run.

If you are using Ubuntu, you may not need this because the installation process must be guided by the creation of a user.

First, make sure that sudo is installed. Our working users will need it. If you are logged in as root, execute the following command:

# apt-get Update && apt-get upgrade# Install system updates

# Apt-get Install sudo# make sure "sudo" is installed

The next set of commands will create an Odoo user:

# useradd-m-G sudo-s/bin/bash odoo# Create an "odoo" user with sudo capability

# passwd Odoo # request and set a password for the new user

You can convert Odoo to any user name you want. The –M option ensures that its home directory is created. The –g sudo option adds it to the Sudoers list so that it can run the command as root. The –s/bin/bash option sets the default shell to bash, which is better than the default sh.

Now we can log in as a new user and set up Odoo.

Installing Odoo from the source program

Ready-made Odoo packages, such as Windows (. exe), Debian (. deb), CentOS (. rpm), and source code tarballs (. tar.gz), can be found on nightly.odoo.com.

As developers, we want to install them directly from the GitHub repositories. This will give us more control over the version and the update.

To keep it neat, create a/odoo–dev subdirectory within our home directory home to work.

Throughout this book, we assume that/odoo–dev is the directory where your Odoo server is installed.

First, make sure that you are logged in as a user that we create now or during the installation process, rather than as root user. Assuming your user is Odoo, use the following command to confirm:

$ WhoAmI Odoo

$ echo $HOME

/home/odoo

Now we can use this script. It shows us how to install Odoo from the source code into the Debian/ubuntu system.

First, install the basic dependencies so that we get started:

$ sudo apt-get update && sudo apt-get upgrade# installation system updates

$ sudo apt-get install git# git

$ sudo apt-get install npm# installation Nodejs and its package manager

$ sudo ln-s/usr/bin/nodejs/usr/bin/node# call node runs Nodejs

$ sudo npm install-g less less-plugin-clean-css# install less compiler

Starting with version 9.0, the Odoo Web client needs to install the less CSS preprocessor in the system to render the Web page correctly. To install this, we need the node. node. js and NPM.

Next, we need to get the Odoo source code and install all of its dependencies. The Odoo source code includes a utility script that, in the odoo/setup/directory, helps us to install the required dependencies on the Debian/ubuntu system:

$ mkdir ~/odoo-dev# Create a directory to work in

$ cd ~/odoo-dev# Go to our work directory

$ git clone https://github.com/odoo/odoo.git-b 10.0--depth=1# Get Odoo sourcecode

$./odoo/setup/setup_dev.py setup_deps# installs Odoo system dependencies

$./odoo/setup/setup_dev.py setup_pg# installs PostgreSQL & DB Superuser for Unixuser

Finally, Odoo should be ready to use. The ~ symbol is a shortcut to our home directory (for example,/home/odoo). The git–b lo.o option tells Git to explicitly download Odoo's 10.0 branch. This is superfluous at the time of writing, since 10.0 is the default branch; However, this may change, so it may make the script a testament to the future. The ––depth=l option tells git to download only the last version, not the complete change history, making the download smaller and faster.

To start an Odoo server instance, simply run:

$ ~/odoo-dev/odoo/odoo-bin

By default, the Odoo instance listens on port 8069, so if we point the browser to http://<server–address>:8o69, we will reach these instances. When we first visited it, it showed us an assistant to create a new database, as shown in the following:

As a developer, we need to use several databases, so it's easier to create them from the command line, so we'll learn how to do that. Now press CTRL + C on the terminal to stop the Odoo server and return to the command prompt.

Initialize a new Odoo database

In order to be able to create a new database, your users must be a PostgreSQL super user. The following command creates a PostgreSQL super user for the current UNIX user:

$ sudo createuser--superuser $ (whoami)

To create a new database, use the Createdb command. Let's create a demo database:

$ createdb Demo

To initialize the database using Odoo data mode, we should use the –D option to run Odoo on an empty database:

$ ~/odoo-dev/odoo/odoo-bin-d Demo

This will take a few minutes to initialize a demo database, which ends with an Infolog message, Modules loaded.

Note that it may not be the last log message, it can be in the last three to four rows. In this way, the server is ready to listen for client requests.

By default, this initializes the database with demo data, which is often useful for developing databases. To initialize a database ––without–demo–data=all that does not have demo data.

Now open http://<server–name>:8069, your browser will be displayed on the login screen. If you do not know your server name, type the hostname command in the terminal to locate it or the ifconfig command to find the IP address.

If you host Odoo in a virtual machine, you may need to set up some network configurations so that you can access it from the host system. The simplest solution is to change the virtual machine network type from Nat to bridge. This way, the client virtual machine does not share the host IP address, but instead has its own IP address. You can also use NAT, but this requires you to configure port forwarding so your system knows that some ports, such as 8069, should be handled by a virtual machine. If you're having trouble, hopefully these details will help you find the information in the documentation for your chosen virtualization software.

Managing Databases

We've learned how to create and initialize a new Odoo database from the command line. There are more commands worth managing the database.

We already know how to use the Createdb command to create an empty database, but it can also create a new database ––template option by copying an existing database

Make sure that your Odoo instance is stopped, and that you do not have another connection open to the demo database that we just created, and then run this:

$ createdb--template=demo demo-test

In fact, every time you create a database, you use a template. If not specified, a pre-defined Templatel is used.

To list existing databases on your system, you can use the –L option with the PostgreSQL psql utility:

$ psql-l

Running it will list the two databases we have created so far: demo and Demo–test. The list also displays the encoding used in each database. The default value is UTF-8, which is the encoding required for the Odoo database.

To delete a database that you no longer need (or you need to recreate it) to use the dropdb command:

$ dropdb Demo-test

Now you know the basics of working with databases. For more information about PostgreSQL, please refer to the official documentation: http://www.postgresql.org/docs/.

Deleting a database command irrevocably destroys your data. Use this command with caution, and before you use this command, always make a backup of the important database.

For more information, please visit the Open source Xuanshuo (OSCG)-"Resource download" to get the Odoo Development Guide for detailed reading, here is very grateful to Lao Yang for our Odoo community's significant contribution efforts, so that the overall Odoo development practice level overall greatly improved.

Odoo Development Guide featured Share-1th-Start using Odoo development (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.