Are you looking to add automatic sequence fields to your products or other records Odoo ? Creating custom sequence fields can help you organize your inventory with unique identifiers that follow a specific pattern. In this comprehensive tutorial, I’ll walk you through the exact steps to implement automatic sequence fields for products and other records in your system.
Why Use Automatic Sequence Fields?
First and foremost, automatic sequence fields provide several key benefits for your business:
- They create consistent product numbering across your inventory
- They eliminate manual entry errors
- They save time during product creation
- They maintain organized record-keeping
Furthermore, automatic sequences work similarly to other common numbering systems, such as those found in sales orders or inventory items.
Understanding Sequence Fields in Your System
Before diving into implementation, let’s examine how sequence fields typically function. When you look at sales orders, you’ll notice they often start with a specific letter (like “S”) followed by five digits. The system automatically generates these numbers in sequence.
For instance, when creating a new sales order, the system assigns the next available number. This same concept can be applied to products or any other record type in your system.
Setting Up Your First Automatic Sequence Field
Now, let’s create an automatic sequence field for products. Follow these straightforward steps:
Step 1: Create a New Field for the Sequence
First, you need to establish a field to store the sequence information:
- Navigate to your product settings
- Select “Add new field”
- Choose “Character field” (CH) as the field type
- Name your field something clear like “Automatic Sequence” or “Product Sequence”
Additionally, make sure to select options that prevent manual editing of this field. You want the system to manage this value automatically.
Step 2: Configure Field Properties
When setting up your sequence field, consider these important properties:
- Choose a prefix for your sequence (like “P” for products)
- Set the number of digits (five digits works well for most cases)
- Decide if you want additional information in your sequence code
- Make the field read-only to prevent manual changes
Moreover, the field should be managed by the system rather than manually updated by users.
Step 3: Create Automation Rules
This crucial step connects the sequence field to an automatic numbering system:
- Navigate to “Automated Actions” or “Automation Rules”
- Create a new rule triggered on “Save” of a product record
- Add a condition: “If Automatic Sequence is not set”
- Set the action to execute code that will generate the next sequence
Most importantly, the automation code will call the sequencing functionality to generate the next number in sequence.
The Technical Implementation
Now, let’s explore the technical aspects of implementing automatic sequences. The system uses an IR sequence object to manage numbering. To access this functionality in your automation code, you’ll need to:
- Reference the sequence code “product_sequence” (or your chosen sequence name)
- Call the “next_by_code” method to get the next number
- Update your record with the generated sequence
Here’s a simplified version of what your code might look like:
def generate_product_sequence(record):
if not record.auto_sequence:
sequence = self.env['ir.sequence'].next_by_code('product_sequence')
record.auto_sequence = sequence
return True
Additionally, you’ll need to ensure your sequence is properly defined in the system.
Testing Your Automatic Sequence
After implementing your automatic sequence, it’s essential to test it thoroughly:
- Create a new product and save it
- Verify that the system automatically assigns a sequence (e.g., “P00001”)
- Create another product and confirm the sequence increments properly (e.g., “P00002”)
- Test edge cases like duplicating products to ensure each gets a unique sequence
Furthermore, check that existing products without sequences get assigned one when saved.
Advanced Sequence Customization
Once you’ve mastered basic sequences, you can explore more advanced customization options:
Custom Sequence Patterns
You can create more complex sequence patterns by:
- Adding date components (year, month, day)
- Including product category codes
- Incorporating location or warehouse identifiers
- Using custom separators between components
For example, instead of just “P00001”, you might create something like “P-2023-CAT-00001” for more detailed organization.
Different Sequences for Different Product Types
If you manage various product types, you might want distinct sequence patterns for each:
- Create separate sequence definitions for each product type
- Modify your automation code to select the appropriate sequence based on product attributes
- Use different prefixes for different product categories (e.g., “HW” for hardware, “SW” for software)
This approach enables more granular organization of your product catalog.
Common Issues and Solutions
When implementing automatic sequences, you might encounter these common challenges:
Sequence Gaps
Problem: You notice gaps in your sequence numbering. Solution: This often occurs when transactions are canceled during creation. It’s generally harmless and preferable to having duplicate numbers.
Migration of Existing Records
Problem: You have existing products without sequence numbers. Solution: Create a one-time script to assign sequences to all existing records without disrupting your operations.
Sequence Conflicts
Problem: Two records try to obtain the same sequence number simultaneously. Solution: The system handles this with transaction isolation, but you might need to implement additional locking for high-volume systems.
Integration with Other Systems
Your automatic sequence can integrate with other aspects of your system:
- Include sequences in barcodes for easy scanning
- Use sequences in report templates for consistent documentation
- Reference sequences in API calls for external system integration
- Incorporate sequences in search functionalities for quick lookups
Moreover, consistent sequence formatting makes data exchange with external systems more reliable.
Best Practices for Sequence Management
To ensure long-term success with your automatic sequences, follow these best practices:
- Document your sequence format and purpose
- Plan for growth by using sufficient digits (e.g., five digits allows for 99,999 products)
- Consider using year prefixes to reset numbering annually
- Implement proper error handling in your sequence generation code
- Avoid changing sequence formats after implementation to prevent confusion
Additionally, regularly audit your sequences to ensure they’re working as expected.
Real-World Applications of Automatic Sequences
Automatic sequence fields prove valuable across various business contexts:
Inventory Management
In warehouse operations, automatic sequences help track products throughout their lifecycle. Each product receives a unique identifier, making it easy to locate, move, and monitor inventory levels.
Manufacturing
For manufacturing businesses, sequence fields can track products from raw materials through assembly to finished goods. This creates a continuous chain of identification that improves quality control.
Retail Operations
Retail businesses use sequence fields to organize products across multiple locations, simplifying restocking, transfers, and sales tracking.
Service Industries
Even service-based businesses can benefit by assigning sequence numbers to service packages, making billing and service delivery more organized.
Performance Considerations
When implementing automatic sequences, consider these performance factors:
- Sequence generation adds a small overhead to save operations
- For bulk imports, consider pre-generating sequences to improve performance
- Index sequence fields in your database for faster searches
- Monitor sequence usage to ensure you don’t approach numbering limits
Furthermore, proper implementation ensures minimal impact on system performance.
Conclusion: Your Path to Organized Product Management
In conclusion, automatic sequence fields provide a powerful way to organize your products and other records systematically. By following the steps outlined in this tutorial, you’ve learned how to implement and customize sequence fields to meet your specific business needs.
Remember that consistent sequence numbering improves operational efficiency, reduces errors, and creates a more professional appearance in your business documents and interfaces.
Now that you understand how automatic sequences work, you can implement them across various record types in your system for better organization and productivity.
Additional Resources
To further enhance your knowledge about automatic sequence fields and related topics, check out these helpful resources:
- Official Documentation on Sequence Fields
- Advanced Automation Techniques
- Product Management Best Practices
- Database Performance Optimization
I hope this tutorial has provided valuable insights into creating and managing automatic sequence fields for your products and other records!
Did you find this tutorial helpful? Let us know in the comments below how automatic sequences have improved your product management processes.
Discover more from teguhteja.id
Subscribe to get the latest posts sent to your email.


Pingback: Odoo March 2025 Tutorials - teguhteja.id