Alternative Product Codes
by Terrabit https://www.terrabit.ro , Dorin Hongu https://www.terrabit.roAlternative Product Codes
Extra codes & smarter product search
Manage multiple alternative codes per product and find any item by any of its codes. This module is useful when the same product is known under different references — supplier codes, manufacturer part numbers, legacy codes, or customer-specific identifiers — and your team needs to locate it regardless of which code they have at hand.
✨ Key features:
- Adds a dedicated Alternative tab on the product form where you can record any number of extra codes, reorder them, and optionally hide individual codes from the combined display.
- Exposes a computed Alternative Code field (visible in the product list and on order and transfer lines) that concatenates all visible codes for quick reference.
- Extends product search so that typing an alternative code returns the matching product, on both product templates and their variants. The search is opt-in and tunable (result limit, minimum length) from the Inventory settings.
- Surfaces the alternative code column on Sales Order, Purchase Order, and Stock Move lines, keeping the code visible throughout the order-to-delivery flow.
- Adds a free-text Used For field on the product to note what the item can be used for, aiding identification and cross-selling.
- A daily scheduled action (inactive by default) splits codes entered on one line and separated by
;or,into one alternative record per code, without creating codes the product already has. Spaces are kept as part of the code (OEM numbers such as366 200 05 01). Activate it in Settings > Technical > Automation > Scheduled Actions when needed.
Alternative Search Settings
Navigate to Inventory > Configuration > Settings, section Products (the settings are added after Units of Measure & Packagings), to configure the alternative-code search and the product selection list:
| Setting | System Parameter | Default | Effect |
|---|---|---|---|
| Alternative Search (checkbox) | alternative.search_name |
disabled | When enabled, product name-search queries also scan alternative codes. |
| Alternative Limit (shown when Alternative Search is ticked) | alternative.limit |
10 | Maximum number of products added to a selection list by alternative code; 0 means no limit. |
| Minimum Length (shown when Alternative Search is ticked) | alternative.length_min |
3 | Minimum number of characters typed before the alternative codes are searched. A shorter text cannot use the trigram index and would scan the whole table. |
| Code Before Name | alternative.dropdown_code_first |
disabled | The product selection list shows [code] name instead of the name with the code muted on the right. |
| Show Stock in Dropdown | alternative.dropdown_show_qty |
disabled | The product selection list shows, muted on the right, the quantity on hand of storable products. |
These values are stored as ir.config_parameter system parameters and can also be
set directly via Settings > Technical > Parameters > System Parameters if needed.
Large Databases (Index on Alternative Codes)
Alternative codes (product.alternative.name) use a trigram (GIN) index, so a search
such as ilike '%4561%' does not scan the whole table.
- The PostgreSQL extension
pg_trgmmust be available. Without it Odoo creates no index on the column. - Odoo adds
unaccentto the index only whenpublic.unaccent(text)isIMMUTABLE. Otherwise the index is created without it and the search, which callsunaccent(name) ILIKE unaccent(...), cannot use it. Odoo logs PostgreSQL function 'unaccent' is present but not immutable in that case.
Checking unaccent
SELECT oid::regprocedure, provolatile FROM pg_proc WHERE proname = 'unaccent';
- odoo.sh needs nothing: the extension lives in
unaccent_schemaand the platform adds anIMMUTABLEwrapperpublic.unaccent(text)(provolatile = i). - Self-hosted, with the extension installed in
public,unaccent(text)isSTABLE(s). Do not useALTER FUNCTION public.unaccent(text) IMMUTABLE, and do not replace the extension's function: the change is part of the extension,pg_dumpdoes not keep it, and restoring the database fails on every index that usesunaccent(functions in index expression must be marked IMMUTABLE). The Odoo database manager then reports Couldn't restore database.
Setting up unaccent like odoo.sh (self-hosted)
Run as a superuser, then restart Odoo (it reads the function status at startup). The
script moves the extension to its own schema, adds the IMMUTABLE wrapper and rebuilds
the indexes that used the extension's function. Rebuilding blocks writes on those tables,
so run it in a maintenance window.
BEGIN;
CREATE SCHEMA IF NOT EXISTS unaccent_schema;
ALTER EXTENSION unaccent SET SCHEMA unaccent_schema;
CREATE FUNCTION public.unaccent(text) RETURNS text
LANGUAGE sql IMMUTABLE PARALLEL SAFE STRICT
AS $$ SELECT unaccent_schema.unaccent('unaccent_schema.unaccent'::regdictionary, $1) $$;
DO $$
DECLARE r record;
BEGIN
FOR r IN
SELECT DISTINCT i.indexrelid::regclass AS idx, pg_get_indexdef(i.indexrelid) AS def
FROM pg_index i
JOIN pg_depend d ON d.classid = 'pg_class'::regclass AND d.objid = i.indexrelid
WHERE d.refclassid = 'pg_proc'::regclass
AND d.refobjid = 'unaccent_schema.unaccent(text)'::regprocedure
LOOP
EXECUTE format('DROP INDEX %s', r.idx);
EXECUTE replace(r.def, 'unaccent_schema.unaccent(', 'public.unaccent(');
END LOOP;
END $$;
COMMIT;
The dictionary is schema-qualified on purpose. With a bare 'unaccent', PostgreSQL 17
cannot build the index (index builds run with a restricted search_path) and older
versions fail on restore.
Trigram indexes created while unaccent was STABLE do not contain unaccent. Odoo
compares only the access method (gin), not the expression, so it keeps them although
the search cannot use them. Drop them after the change and update the modules that
declare them (-u).
Creating the index on a large table
With millions of codes, create the index before updating the module, so writes are not blocked while it is built:
DROP INDEX IF EXISTS product_alternative__name_index;
CREATE INDEX CONCURRENTLY product_alternative__name_index
ON product_alternative USING gin (unaccent(name) gin_trgm_ops);
Leave out unaccent(...) if public.unaccent(text) is not IMMUTABLE. Odoo finds an
index with the expected name and access method and does not rebuild it.
Databases migrated from 18.0 already have the same index under another name
(product_alternative_name_unaccent_gin, created by the 18.0 module). Rename it instead
of building a new one:
DROP INDEX IF EXISTS product_alternative__name_index;
ALTER INDEX product_alternative_name_unaccent_gin RENAME TO product_alternative__name_index;
Search and Display Options
- Go to Inventory > Configuration > Settings and scroll to the Products section.
- Tick Alternative Search so that typing an alternative code in a product field finds the product. Below it, Alternative Limit caps the products added by alternative code (0 = no cap) and Minimum Length is the number of characters from which the alternative codes are searched.
- Optionally tick Code Before Name (the product selection list shows
[code] name) and Show Stock in Dropdown (the list shows the quantity on hand of storable products). - Click Save.
Adding Alternative Codes to a Product
- Open Inventory > Products > Products (or Sales > Products > Products) and select the product.
- Go to the Alternative tab and click Add a line. Enter one code per line in the Code column.
- Drag the handle to reorder the codes.
- Tick Hide on a code you do not want displayed (for example an old code). A hidden code is still searchable.
- Save.
On the General Information tab, Alternative Code shows the visible codes joined with ;.
Used For is a free text field, for example the compatible machines.
Searching by Alternative Code
In the product list, the Alternative Code column shows the codes of each product. Type a code in the search bar and choose Search Alternatives for: …. The search bar also searches Used For and Vendor Code (the vendor's product code).
With Alternative Search enabled, type an alternative code in the product field of a sales order, a purchase order, a transfer or any other product field: the product with that code is proposed together with the products found by name and internal reference. The field's own restrictions still apply (for example, a product that cannot be sold is not proposed on a sales order).
Alternative Code on Orders and Transfers
The Alternative Code column is available, hidden by default, on sales order lines, purchase order lines and transfer operations. To show it, click the optional columns button on the right of the column headers and tick Alternative Code. The column is read-only and shows the visible codes of the product.
Splitting Codes Entered on One Line
Codes imported on one line and separated by ; or , (for example
GDB1330; 0 986 424 795, 8DB 355 019-311) are split into one line per code by the scheduled
action Alternative: Split multi-code records. It is inactive after installation.
- Activate the developer mode and go to Settings > Technical > Automation > Scheduled Actions.
- Open Alternative: Split multi-code records and switch on Active, or click Run Manually for a single run.
The first code stays on the original line; the others become new lines with the same sequence and Hide flag. Spaces inside a code are kept, and a code the product already has is not created again.
Need help getting started?
Our 800+ apps on the Odoo Apps Store are used in Odoo implementations across Europe, the Americas, Asia and Africa — by companies we have never even met. That is the advantage of building modules that simply work.
Questions about this module? Write to us — the developers who build it will answer.
More apps by Terrabit
Other modules from the same publisher, built to work together. All apps →
| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Odoo Apps Dependencies |
•
Inventory (stock)
• Purchase (purchase) • Discuss (mail) • Invoicing (account) |
| Lines of code | 426 |
| Technical Name |
deltatech_alternative |
| License | OPL-1 |
| Website | https://www.terrabit.ro |
Odoo Proprietary License v1.0 This software and associated files (the "Software") may only be used (executed, modified, executed after modifications) if you have purchased a valid license from the authors, typically via Odoo Apps, or if you have received a written agreement from the authors of the Software (see the COPYRIGHT file). You may develop Odoo modules that use the Software as a library (typically by depending on it, importing it and using its resources), but without copying any source code or material from the Software. You may distribute those modules under the license of your choice, provided that this license is compatible with the terms of the Odoo Proprietary License (For example: LGPL, MIT, or proprietary licenses similar to this one). It is forbidden to publish, distribute, sublicense, or sell copies of the Software or modified copies of the Software. The above copyright notice and this permission notice must be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Please log in to comment on this module