Currently, it is essential to keep track of our employees' working hours. For this, we have the Odoo attendance module. What we rarely put into practice is how to create an attendance machine using this tool in a simple way.
What do we need?
- An Odoo instance
- A Raspberry Pi with the latest version of Raspbian installed
- A touchscreen compatible with our Raspberry
It is also recommended to put the Raspberry and the screen in a unified case. Various options can be found on different online shopping websites.
Setting up our Odoo
The first thing will be to go to the Attendance settings and configure our application permissions:
The attendance mode shows us what types of selection. Manual selection allows us to select manually, and barcode/RFID allows us to read through our employee card. If we choose manual selection, it is recommended to set the Employee Pin.
If we are using a version earlier than 17, we need to create a user and save their password. This user should only have the Kiosk Mode User permissions. This can be found in the Human Resources section. This user is the one people will use to clock in, so it’s important they have the least amount of permissions possible. Additionally, we should configure this user so that their default action upon logging in is to go to the kiosk. If we are using version 17, we need to save the URL proposed by Odoo.
Setting up the Raspberry
The second step is to access our Raspberry and install some components:
$ apt-get install python3-selenium chromium-chromedriver
This will install Selenium, a system that allows us to open the browser in a controlled way from an application, and Chromedriver, a Chrome application prepared to be controlled.
Scripts
The next step is to create the script we will use to launch automatically. To do this, we will create a file on the Raspberry called autorun.py in our home directory.
If we are using version 16 or earlier, the code will be as follows:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
# Replace 'your_username' and 'your_password' with your actual credentials
username = ''
password = ''
website = ''
executable_path = "chromedriver"
# Set up Chrome options for kiosk mode
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--kiosk') # Launch in kiosk mode
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']);
chrome_options.add_experimental_option("prefs", {
"profile.default_content_setting_values.autoplay": 1, # Allow autoplay
"profile.default_content_setting_values.muted": False, # Unmute by default
"credentials_enable_service": False,
"profile": {
"password_manager_enabled": False
},
})
# Initialize the Chrome browser with kiosk mode
driver = webdriver.Chrome(executable_path=executable_path,options=chrome_options)
# Navigate to the login page
driver.get(website)
username_field = driver.find_element("name", "login") # Adjust the locator strategy based on your HTML structure
password_field = driver.find_element("name", "password")
submit_button = driver.find_element("xpath", "//form//button")
username_field.send_keys(username)
password_field.send_keys(password)
# Submit the form
submit_button.click()
time.sleep(10)
webdriver.find_element("class name", "o_action_manager").click()
This will automatically open the correct website. We just need to define the values for username, password, and our instance link.
If we are using version 17, the code will be simpler:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
# Replace 'your_username' and 'your_password' with your actual credentials
website = ''
executable_path = "chromedriver"
# Set up Chrome options for kiosk mode
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--kiosk') # Launch in kiosk mode
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']);
chrome_options.add_experimental_option("prefs", {
"profile.default_content_setting_values.autoplay": 1, # Allow autoplay
"profile.default_content_setting_values.muted": False, # Unmute by default
"credentials_enable_service": False,
"profile": {
"password_manager_enabled": False
},
})
# Initialize the Chrome browser with kiosk mode
driver = webdriver.Chrome(executable_path=executable_path,options=chrome_options)
# Navigate to the login page
driver.get(website)
Finally, we need to ensure this script runs automatically when the Raspberry starts. There are several ways to do this, but we suggest one:
$ mkdir -p ~/.config/autostart
$ cd ~/.config/autostart
$ nano attendance-machine.desktop
Inside the file, we will put the following:
[Desktop Entry]
Type=Application
Name=Attendance Machine
Exec=python3 ~/autorun.py
X-GNOME-Autostart-enabled=true
Bonus Track: Using an RFID Reader
We are often asked to allow the use of card readers. To do this, we will make the following changes. First of all, it is recommended to buy two identical RFID readers (one will be used to configure employees, and the other will go to the Raspberry). If we want, we can also use a screen that is not touch-sensitive if we only use the Barcode/RFID mode. We will assign each employee the Badge ID field with their card value.
From this point on, they can use their card directly on our attendance machine.
Conclusions
As we have seen, it is easy to create our own attendance system in Odoo with accessible tools. We hope this helps you create your own machine.