| __pycache__ | ||
| models | ||
| tests | ||
| views | ||
| __init__.py | ||
| __manifest__.py | ||
| .gitignore | ||
| CHANGELOG.md | ||
| DATE_FORMAT_GUIDE.md | ||
| EXAMPLES.md | ||
| INSTALLATION.md | ||
| INVENTORY_ADJUSTMENT_GUIDE.md | ||
| PERFORMANCE_OPTIMIZATION.md | ||
| QUICK_START.md | ||
| README.md | ||
Product Lot Sequence Per Product
This module extends Odoo's lot and serial number generation to support unique sequences per product, aligning Odoo 18 with the behavior introduced in Odoo 19.
Features
- Per-Product Sequence Configuration: Define a unique sequence for lot/serial number generation for each product.
- Inventory Tab Integration: Configure the custom sequence directly on the product form under the Inventory tab.
- Automatic Generation: Lot/serial numbers generated during incoming receipts and manufacturing orders follow the product-specific sequence.
- Performance Optimized: Batch generation for large quantities (500,000+ units) using optimized database queries.
- Fallback Mechanism: If no sequence is defined for a product, it falls back to the global lot/serial sequence.
- UI Enhancements: Avoids generation of invalid "0" lot numbers in manual and wizard flows.
Configuration
- Navigate to Inventory > Products.
- Open or create a product.
- Go to the Inventory tab.
- Set the Custom Lot/Serial prefix to define a new sequence or select an existing sequence from the Lot Sequence field.
- The Next Number field displays the next lot/serial number that will be generated.
Behavior
- Incoming Shipments: When receiving products, if a product has a custom sequence, the generated lot/serial numbers will follow this sequence.
- Manufacturing Orders: When producing products, the finished lots/serials will be generated using the product's custom sequence.
- Manual Creation: Creating lots/serials manually or via "Generate Serials/Lots" will respect the product's sequence if configured.
Performance Optimizations
The module includes several performance optimizations for handling large quantities:
Batch Sequence Allocation
- Uses PostgreSQL's
generate_series()to allocate multiple sequence numbers in a single database query - Reduces database operations from N queries to 1 query for N lots
- Automatically activated for quantities > 10 units
Batch Lot Creation
- Creates all lot records in a single
create()operation - Significantly faster for large quantities (100+ units)
- Maintains data integrity and uniqueness
Performance Benchmarks
- Small batch (10 units): < 5 seconds
- Medium batch (100 units): < 10 seconds
- Large batch (500 units): < 30 seconds
- Very large batch (5,000 units): < 2 minutes
- Extreme batch (500,000 units): Optimized for production use
When Optimizations Apply
- Batch allocation: Automatically used when generating > 10 lots at once
- Applies to: Incoming shipments, manufacturing orders, and manual generation
Technical Details
-
The module adds a
lot_sequence_idfield toproduct.templateto link the sequence. -
It overrides the
stock.lotcreation to use the product's sequence with batch optimization. -
It extends
stock.moveandstock.move.lineto handle UI inputs and normalize "0" or empty inputs. -
It overrides
mrp.production._prepare_stock_lot_valuesto ensure manufacturing flows use the product sequence. -
Uses
_allocate_sequence_batch()method for efficient sequence number allocation.
Testing
The module includes comprehensive test suites:
Performance Tests
Run performance tests to verify optimization:
odoo-bin -c odoo.conf -d your_database --test-tags product_lot_sequence_per_product.performance
Inventory Adjustment Tests
Test auto-generation in inventory adjustments:
odoo-bin -c odoo.conf -d your_database --test-tags product_lot_sequence_per_product
Dependencies
stockmrp
Compatibility
- Odoo 18
- Requires
mrpmodule for manufacturing order support