
Dolibarr ERP & CRM is a versatile open-source platform that allows businesses to manage various aspects of their operations. One of its strengths lies in its modular architecture, enabling users to extend its functionality through custom modules. This guide will walk you through the process of creating a simple custom module in Dolibarr.
Understanding Dolibarr's Modular Architecture
Before diving into module creation, it's essential to understand how Dolibarr's modular system works. Each module in Dolibarr is a self-contained package that can add new features, modify existing ones, or integrate external services. Modules can include:
-
New menus and pages
-
Database tables
-
Business logic
-
Permissions
-
Triggers and hooks
By creating a custom module, you can tailor Dolibarr to meet specific business requirements without altering the core code, ensuring easier maintenance and upgrades.
Prerequisites
To create a custom module in Dolibarr, you'll need:
-
A working installation of Dolibarr (preferably the latest stable version)
-
Basic knowledge of PHP, HTML, and SQL
-
Access to the Dolibarr file system (via FTP, SSH, or local access)
-
A code editor (e.g., VS Code, Sublime Text)
Step-by-Step Guide to Creating a Custom Module
Step 1: Set Up the Module Directory
Navigate to the htdocs/custom
directory in your Dolibarr installation. This is where custom modules are stored. Create a new directory for your module, for example:
Replace mymodule
with your desired module name.
Step 2: Create the Module Descriptor File
The module descriptor defines the module's properties and is essential for Dolibarr to recognize and manage the module. Create a file named modMyModule.class.php
inside the htdocs/custom/mymodule/core/modules/
directory:
Populate modMyModule.class.php
with the following content:
Adjust the properties as needed, ensuring the numero
is unique to avoid conflicts with other modules.
Step 3: Define the Module's Structure
Organize your module's directory with the following structure:
-
admin/
: Contains administrative pages for module configuration. -
class/
: Contains PHP classes related to your module's business logic. -
core/modules/
: Contains the module descriptor. -
lang/
: Contains language files for translations. -
page/
: Contains public-facing pages of your module. -
sql/
: Contains SQL scripts for creating necessary database tables.
Step 4: Create the Setup Page
In admin/mymodule_setup.php
, create a basic setup page:
This page will appear under the module's configuration section in Dolibarr.
Step 5: Create a Language File
In lang/en_US/mymodule.lang
, add translations:
This allows for easy localization of your module's interface.
Step 6: Add a Public Page
In page/mymodule_page.php
, create a simple page:
This page can be accessed via the menu you define later.
Step 7: Define a Class (Optional)
If your module requires specific business logic or database interactions, define a class in class/myclass.class.php
:
Step 8: Create SQL Script (Optional)
If your module needs to create database tables, define them in sql/mymodule.sql
:
Dolibarr will execute this script upon module activation to set up necessary tables.
Step 9: Activate the Module
-
Log in to Dolibarr as an administrator.
-
Navigate to Home > Setup > Modules/Applications.
-
Find your module in the list (it should appear under the "Other" category).
-
Click Activate to enable the module.
Step 10: Test Your Module
-
Access the setup page via Home > Setup > Modules/Applications > My Module.
-
Navigate to the public page you created to ensure it's displaying correctly.
-
Verify that any database tables have been created as expected.
Conclusion
Creating a custom module in Dolibarr allows you to tailor the ERP/CRM system to your specific business needs. By following the steps outlined above, you can develop modules that integrate seamlessly with Dolibarr's architecture, ensuring maintainability and compatibility with future updates.
Remember to adhere to Dolibarr's development guidelines and best practices to maintain code quality and system stability. With this foundation, you can expand your module's functionality, integrate with external systems, and provide a more customized experience for your users.