| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Odoo Apps Dependencies |
Discuss (mail)
|
| Lines of code | 543 |
| Technical Name |
product_auto_reference |
| License | LGPL-3 |
Product Auto Reference - Odoo 18
📋 Description
This module automatically generates internal product references based on the product category hierarchy.
Reference format: PARENT_CODE + CHILD_CODE + ... + SEQUENCE
Example: PUI002010001
PUI: Parent category code (Powers)002: Level 1 child category code (Motors)010: Level 2 child category code (Single-phase)0001: Automatic sequential number
✨ Features
1. Category Management
- Add a Code field on product categories
- Automatic calculation of Prefix based on hierarchy
- Display of Next Number in sequence
- Automatic creation of an
ir.sequencefor each category - Automatic update of prefixes when hierarchy changes
2. Product Management
- Automatic reference generation on creation
- Auto Reference option that can be enabled/disabled per product
- Button to Regenerate reference manually
- Reference update when category changes
3. Administration Tools
- Automatic initialization of sequences from existing database
- Reset sequences
- Manual definition of next number
- Analysis wizard to identify existing references
🚀 Installation
- Copy the module to your Odoo addons directory
- Update the apps list: Apps → Update Apps List
- Search for "Product Auto Reference" and click Install
📖 User Guide
Initial Configuration
Step 1: Configure Category Codes
- Go to Inventory → Configuration → Product Categories
- For each category, fill in the Category Code field
Example structure:
Powers (PUI) ├── Electric Motors (002) │ ├── Single-phase (010) │ │ ├── 0.5-1.5 kW (001) │ │ └── 2-5 kW (002) │ └── Three-phase (011) │ ├── 0.5-1.5 kW (001) │ └── 2-5 kW (002) └── Transformers (003)
The Reference Prefix field will be calculated automatically:
PUI→ Prefix:PUISingle-phase→ Prefix:PUI0020100.5-1.5 kW(under Single-phase) → Prefix:PUI002010001
Step 2: Initialize Sequences (if you already have products)
Option A: From existing database
- Go to Inventory → Configuration → Initialize Sequences
- Select Mode: Automatic
- Click Initialize
The system will:
- Analyze all your existing products
- Identify references that match category prefixes
- Set next number = maximum number found + 1
Option B: Reset to zero
⚠️ Warning: This resets all sequences to 1
Daily Usage
Create a product with automatic reference
- Go to Inventory → Products → Create
- Select a Product Category
- The Auto Ref field is checked by default
- Do not fill the Internal Reference field
- Save
→ The reference will be generated automatically!
Example:
- Category:
Powers > Electric Motors > Single-phase > 0.5-1.5 kW - Prefix:
PUI002010001 - Generated reference:
PUI0020100010001
Create a product with manual reference
- Create the product
- Uncheck the Auto Ref field
- Fill in the Internal Reference manually
Regenerate a reference
On the product form:
- Click the Regenerate Reference button (at the top)
- A new reference will be generated
🔧 Advanced Management
Modify the next sequence number
- Go to a Product Category
- Click Set Next Number
- Enter the desired number
- Validate
Reset a sequence
- Go to a Product Category
- Click Reset Sequence
- Confirm
→ The next number will be 1
Change category hierarchy
If you move a category in the tree:
- The Reference Prefix is automatically recalculated
- The Sequence is updated
- Child categories are also updated
⚠️ Note: Already created products keep their old reference. Use the Regenerate Reference button if necessary.
🎯 Usage Examples
Example 1: Electrical Equipment
Structure:
ELE (Electrical) ├── MOT (Motors) │ ├── AC (Alternating Current) │ │ ├── MONO (Single-phase) │ │ └── TRI (Three-phase) │ └── DC (Direct Current) └── TRF (Transformers)
Generated references:
- Three-phase motor:
ELEMOTACTRI0001 - Single-phase motor:
ELEMOTACMONO0001 - Transformer:
ELETRF0001
Example 2: Hardware
Structure:
QUI (Hardware) ├── VIS (Screws) │ ├── BTC (Wood cross-head) │ │ ├── 30 (3.0mm) │ │ └── 40 (4.0mm) │ └── MTL (Metals) └── CHE (Anchors)
Generated references:
- Wood screw 3.0mm:
QUIVISBTC300001 - Wood screw 4.0mm:
QUIVISBTC400001 - Metal screw:
QUIVISMTL0001
⚙️ Technical Configuration
Sequence Structure
The module uses ir.sequence with the following parameters:
- Prefix: Automatically calculated from hierarchy
- Padding: 4 digits (0001, 0002, ..., 9999)
- Increment: +1
- Implementation: Standard
Added Fields
On product.category:
category_code(Char): Category codesequence_id(Many2one): Link to ir.sequencenext_number(Integer, computed): Next numberreference_prefix(Char, computed, stored): Calculated prefix
On product.template:
auto_reference(Boolean): Enable/disable auto generation
🔒 Access Rights
- Users: Can create products with auto reference
- Administrators: Full access + sequence initialization
🐛 Troubleshooting
Problem: Reference is not generated
Checks:
- Is the Auto Ref field checked?
- Does the category have a Code filled in?
- Do all parent categories have a code?
Problem: Duplicate reference
Solutions:
- Use the Initialize Sequences wizard in automatic mode
- Verify that each category has a unique sequence
- Manually set the next number
Problem: Prefix is not correct
Causes:
- A parent category doesn't have a code
- The hierarchy has been modified
Solution:
- Check all codes in the hierarchy
- The prefix should recalculate automatically
📝 Important Notes
- Code length: Codes can be any length, but be consistent
- Spaces: Codes must not contain spaces
- Uniqueness: Each category code must be unique in the entire database
- Padding: The sequence uses 4 digits by default (0001-9999)
- Persistence: Sequences are saved even after module uninstallation
📄 License
LGPL-3
👨💻 Author
Developed by Mr X
Please log in to comment on this module