Finding the right products quickly in your Odoo system can significantly impact your sales team’s efficiency. When dealing with multiple customers who use their own product codes or references, the standard Odoo search functionality might fall short. This comprehensive tutorial will guide you through implementing an Odoo custom product search that allows you to find products using customer-specific codes, making your sales process more streamlined and user-friendly.
Why You Need Custom Product Search in Odoo
Many businesses face the challenge of managing products that have different reference codes for different customers. For example, a manufacturer might have an internal product code “ABC123,” but Customer A refers to it as “CUST-A-456,” while Customer B calls it “REF-B-789.” Without proper Odoo custom product search functionality, your sales team would struggle to quickly locate products during order entry.
The standard Odoo search typically looks for matches in product names and internal references. However, when customers provide their own reference codes, sales representatives often waste valuable time trying to locate the correct products. This tutorial addresses this pain point by showing you how to extend Odoo’s search capabilities.
Setting Up Your Development Environment
Before implementing your Odoo custom product search solution, ensure you have the proper development environment configured. You’ll need access to your Odoo installation’s custom addons directory and the ability to restart the Odoo service. Make sure you have developer mode enabled in your Odoo instance, as this will help you identify the correct view inheritance points.
Step-by-Step Implementation Guide
1. Create the Module Folder Structure
In your custom add-ons folder, create a new folder named product_customer_ref_search. Inside this folder, create the following files and sub-folders:
__init__.py__manifest__.pymodels/(folder)__init__.pyproduct_template.pyviews/(folder)product_template_views.xmlstatic/(folder)description/(folder)icon.png(or your module icon)
This structure forms the foundation of your Odoo custom product search module, organizing all necessary components in a logical hierarchy.
2. Configure the Manifest File (__manifest__.py)
This file is a configuration file that tells Odoo how to install and use your module. Add the following content to your __manifest__.py file:
{
'name': 'Product Customer Reference Search', # This name appears in the Apps menu
'version': '1.0', # Initial release version
'category': 'Sales', # Categorized under Sales as it extends sales order functionality
'summary': 'Adds customer_ref column to products to enable product search on sales order lines using customer reference column.', # Short summary
'description': 'Adds customer_ref column to products and enables name search based on that column on sales order lines.', # Detailed description
'author': 'Odoistic', # Author of the module
'depends': ['product', 'sale'], # Depends on product and sale modules as we are extending them
'data': [
'views/product_template_views.xml', # XML file to add new field to product form
],
'installable': True,
'application': True,
'auto_install': False,
'images': ['static/description/icon.png'], # Path to your module icon
}
The manifest file is crucial for your Odoo custom product search module as it defines dependencies and ensures proper integration with existing Odoo modules.
3. Define the Model Extension (models/product_template.py)
This file customizes the product.template model to add the customer_ref field. Add the following code to models/product_template.py:
from odoo import fields, models, api
class ProductTemplate(models.Model):
_inherit = 'product.template' # Inherit the standard product.template model
customer_ref = fields.Char(string='Customer Reference', copy=False) # New field to store customer-specific product reference
@api.model
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
if args is None:
args = []
if name:
# Search by product name or internal reference (default Odoo search)
# OR by the new customer_ref field
domain = ['|', ('name', operator, name), ('default_code', operator, name), '|', ('customer_ref', operator, name)]
product_ids = self._search(domain + args, limit=limit, access_rights_uid=name_get_uid)
else:
product_ids = self._search(args, limit=limit, access_rights_uid=name_get_uid)
return self.browse(product_ids).name_get()
def name_get(self):
# This method changes how the product name appears in the dropdown menu
# It will now show both the product name and the customer reference
result = []
for product in self:
name = product.name
if product.customer_ref:
name = f"[{product.customer_ref}] {name}" # Format: [Customer Ref] Product Name
result.append((product.id, name))
return result
This code extends the standard product model to include customer reference functionality, making your Odoo custom product search more comprehensive and user-friendly.
4. Update models/__init__.py
This file ensures that your new model extension is imported when the module loads. Add the following line to models/__init__.py:
from . import product_template # Import your new model file
5. Create the View Extension (views/product_template_views.xml)
This XML file adds the customer_ref field to the product form in the Odoo backend. To find the correct inheritance ID, activate developer mode in Odoo (Settings -> Activate the developer mode). Go to a product form, click the “bug” icon, and select “View Form” to get the External ID of the product template form view. It’s typically product.product_template_form_view.
Add the following content to views/product_template_views.xml:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="product_template_customer_ref_form_view_inherit" model="ir.ui.view">
<field name="name">product.template.customer.ref.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<field name="default_code" position="after">
<field name="customer_ref"/>
</field>
</field>
</record>
</odoo>
This XML configuration integrates the customer reference field seamlessly into the existing product form, enhancing your Odoo custom product search capabilities.
6. Update __init__.py (Main Module)
Ensure your module’s main __init__.py imports the models directory. Add the following line to the root __init__.py file of your product_customer_ref_search module:
from . import models
7. Restart Odoo Service and Install the Module
After making these changes, restart your Odoo service. In Odoo, go to “Apps” -> “Update Apps List”. Search for “Product Customer Reference Search” and click “Install”.
Testing Your Odoo Custom Product Search
Once installed, test your Odoo custom product search functionality by:
- Adding Customer References: Navigate to any product and add a customer reference code in the new field
- Testing Search Functionality: Create a new sales order and try searching for products using the customer reference codes
- Verifying Display Format: Confirm that products display with both their names and customer references in the format
[Customer Ref] Product Name
Advanced Customization Options
Your Odoo custom product search can be further enhanced with additional features:
Multiple Customer References
For businesses dealing with multiple customers who each have different reference codes for the same product, consider extending the model to support multiple customer references through a one-to-many relationship.
Search Priority Configuration
Implement search priority settings that allow administrators to configure whether customer references should take precedence over product names in search results.
Integration with Customer-Specific Views
Create customer-specific product views that automatically filter and display products using that customer’s reference codes, making the Odoo custom product search even more targeted.
Best Practices for Implementation
When implementing your Odoo custom product search solution, follow these best practices:
Data Migration: If you have existing products, plan for data migration to populate customer reference fields. Create import templates that allow bulk updates of customer references.
User Training: Ensure your sales team understands how to use the new search functionality and how to maintain customer reference data.
Performance Optimization: For large product catalogs, consider adding database indexes on the customer reference field to maintain search performance.
Backup Strategy: Always backup your database before installing custom modules, especially in production environments.
Troubleshooting Common Issues
If your Odoo custom product search isn’t working as expected, check these common issues:
Module Installation: Verify that all dependencies are properly installed and that there are no conflicts with existing modules.
Field Visibility: Ensure the customer reference field appears in the product form and that users have appropriate access rights.
Search Results: Test search functionality with various input patterns to confirm that the search domain is working correctly.
Maintaining Your Custom Search Module
Regular maintenance of your Odoo custom product search module ensures continued functionality:
- Version Compatibility: Test the module with Odoo updates to ensure compatibility
- Performance Monitoring: Monitor search performance as your product catalog grows
- User Feedback: Collect feedback from users to identify improvement opportunities
Conclusion
Implementing an Odoo custom product search solution significantly improves your sales team’s efficiency when dealing with customer-specific product codes. This tutorial provided a comprehensive approach to extending Odoo’s search capabilities, from basic setup through advanced customization options.
The code examples and step-by-step instructions enable you to create a robust search system that accommodates various customer reference scenarios. Remember to test thoroughly in a development environment before deploying to production, and consider the advanced customization options to further enhance your Odoo custom product search functionality.
For more advanced Odoo customizations and development tutorials, explore additional resources on Odoo’s official documentation and consider joining the Odoo Community Association for ongoing support and collaboration opportunities.
This tutorial demonstrates how to implement a comprehensive Odoo custom product search solution. For additional customization or enterprise-level implementations, consider consulting with Odoo development specialists who can tailor the solution to your specific business requirements.
Discover more from teguhteja.id
Subscribe to get the latest posts sent to your email.

