Starting from Odoo Version 10, a mobile app has been introduced that
allows access to all Odoo apps, including custom modules.
/** @odoo-module **/
import mobile from "@web_mobile/js/services/core";
if (mobile.methods.vibrate) {
mobile.methods.vibrate({"duration":100});
}
In this code,
import mobile from "@web_mobile/js/services/core"; - Importing mobile
object
if (mobile.methods.addHomeShortcut) { - Check service available
userMenuRegistry.add("web_mobile.shortcut", shortcutItem); - Execute
method
The web_mobile service acts as a bridge between the mobile device and
Odoo’s JavaScript framework. It provides several built-in utility
functions.
In the example above, the vibrate method is used to make the device
vibrate for a given duration.
Examples of Mobile Utilities
1. Display a Toast Message
mobile.methods.showToast({'message': 'Message sent'});
This method displays a toast message in the mobile app.
2. Display a Snackbar
mobile.methods.showSnackBar({'message': 'Message is deleted',
'btn_text': 'Undo'});
Snackbar messages appear at the bottom of the screen and can include
an action button like “Undo”.
3. Display a Notification
mobile.showNotification({
'title': 'Simple Notification',
'message': 'This is a test for a simple notification'
});
This method shows a standard notification with a title and message in
the mobile app.
4. Add a Contact
var contact = {
'name': 'Michel Fletcher',
'mobile': '9999999999',
'phone': '7954856587',
'fax': '765898745',
'email': 'michel.fletcher@agrolait.example.com',
'website': 'http://www.agrolait.com',
'street': '69 rue de Namur',
'street2': false,
'country_id': [21, 'Belgium'],
'state_id': false,
'city': 'Wavre',
'zip': '1300',
'parent_id': [8, 'Agrolait'],
'function': 'Analyst',
'image': '<< BASE 64 Image Data >>'
};
mobile.methods.addContact(contact);
The addContact method can be used to create a new contact directly
on the mobile device.
5. Scan a Barcode
mobile.methods.scanBarcode();
The scanBarcode method is used to scan barcodes or QR codes using the
mobile device’s camera.
6. Switch Between Accounts
mobile.methods.switchAccount();
The switchAccount method allows the user to switch accounts within
the Odoo mobile app.
These mobile methods help developers leverage native mobile
functionalities inside Odoo, enabling more interactive and
device-aware user experiences.