Odoo is a virtual jungle with immense possibilities of customization, to deal with the diverse territories of an organization or industry. The Open Source ERP constantly expand its effectiveness via third-party applications. The rich API library and web administrations in Odoo help in bringing qualitative innovations every now and then. The android integrations with Odoo, facilitates the new generation business, a way to modernize, combine, and facilitate the business operations in new dimensions.
Here I’m Going to discuss creating an Android application, that communicates with odoo server.I’m doing this tutorial in Android Studio.
For Android Studio Installation,
you can Visit here: https://developer.android.com/studio/install
First of All, let’s Create a new project:
You can go to file > new > new project Or Do it from this window
Create a new project by filling up this window.
The next thing we have to do is, downloading and installing the OOG Box API
This can get a bit technical.
Firstly, you have to go to https://github.com/oogbox/odoo-mobile-api
Then a page will appear like the below image
Click the clone or download button, and choose Download ZIP
Now extract this file to a folder you like, and it will have a name like “odoo-mobile-api-1.0.0”
Now go to your project location and create a new folder named libraries. And paste the extracted folder to that folder.
Now, the directory structure will look somewhat like below:
In the next step, we have to add this to settings Gradle, Try the below code
include ':app'
include 'libraries:odoo-mobile-api-1.0.0'
Now we are partially set to get into the code, But there is one more important thing we have to do i.e. including the OOG Box API in your apps build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
}
implementation 'com.oogbox.api:odoo:1.0.1'
Now, Let’s get coded:
Here I create an application that simply lets the user login to odoo.
So I have created a login page, and I have set the host to mydomain.com
Let’s see the code.
These are my imports from OOG Box.api
import oogbox.api.odoo.OdooClient;
import oogbox.api.odoo.OdooUser;
import oogbox.api.odoo.client.AuthError;
import oogbox.api.odoo.client.OdooVersion;
import oogbox.api.odoo.client.listeners.AuthenticateListener;
import oogbox.api.odoo.client.helper.OdooErrorException;
import oogbox.api.odoo.client.listeners.OdooErrorListener;
import oogbox.api.odoo.client.listeners.OdooConnectListener;
And we can set up the login by the below code.
client = new OdooClient.Builder(getApplicationContext())
.setHost("http://"+ip)
.setErrorListener(new OdooErrorListener() {
@Override
public void onError(OdooErrorException error) {
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
// Error exception with detail of errors
}
})
// Success connection
.setConnectListener(new OdooConnectListener() {
@Override
public void onConnected(OdooVersion version) {
ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_spinner_dropdown_item, databases);
List<String> databases = client.getDatabases();
dataBases = (Spinner)findViewById(R.id.spinnerDataBases);
dataBases.setAdapter(listAdapter);
}).build();
}
In the above code, I have established a connection to the server and fetched the names of Odoo databases and put across in a spinner.
Now let’s see how the login works.
buttonLogin.setOnClickListener(new View.OnClickListener() {
@Override
AuthenticateListener loginCallback = new AuthenticateListener() {
public void onClick(View v) {
public void onLoginSuccess(OdooUser user) {
@Override
Intent intent = new Intent(getApplicationContext(),HomeActivity.class);
intent.putExtra("sessionId",user.sessionId);
startActivity(intent);
Toast.makeText(getApplicationContext(),error.toString(),Toast.LENGTH_LONG).show();
}
@Override
public void onLoginFail(AuthError error) {
}
String password = editPassword.getText().toString();
};
String email = editEmail.getText().toString();
});
client.authenticate(email,password,dataBases.getSelectedItem().toString(),loginCallback);
}
Here, I have a button named button Login, I have set an onclick method to it.
When a click is performed, the username and the password along with the database selected from the spinner is sent to Odoo. And If the username and password get correct, It will return an Odoo user object. You can get the session id from this object and you can use it for odooClient.setSession() method.
Now we can use the Odoo object for any communication with the server just like the volley does.