Skip to main content
iVentureTeam

many2many_barcode_tags

Tags for barcodes, with one change: when a quick-create hits a duplicate barcode, the error is allowed to surface instead of being quietly handled.

Siddharth JambukiyaSiddharth JambukiyaOdoo Techno-Functional Consultant
August 27, 2026Updated September 8, 20265 min read
Technical namemany2many_barcode_tags
Field typesmany2many
Viewsform
Modulestock, the Inventory app
Used in core1 occurrence, the barcodes field on the unit of measure form in stock
VersionsOdoo 20.0, Odoo 19.0
No-code setupNo. Studio offers plain tags; this variant is set in view XML
Alternativesmany2many_tags, many2one_barcode, many2many_tags_avatar

What the barcode tags field does

Barcodes have to be unique. That is enforced in the database, which means an attempt to create a second record with an existing barcode comes back as a constraint violation rather than as a friendly validation message.

Odoo's tags widget lets you create a new record by typing a value and pressing enter, a quick create. When a quick create fails, the standard behavior is to assume the typed value was not enough information and to open a full creation dialog instead, so the user can fill in what was missing.

For a duplicate barcode that is exactly wrong. Nothing was missing; the value simply cannot be used. Opening a dialog invites the user to try again with the same barcode and fail again, this time with a less clear error. This widget changes that one case: a uniqueness violation is rethrown, so the user sees the failure rather than a dialog.

What this means for your team

Barcode uniqueness is the sort of constraint that only matters when it is violated, and then it matters a lot: two units of measure sharing a barcode means a scan is ambiguous, and ambiguity in a warehouse becomes a mispick.

The interface lesson is more general than barcodes. Falling back to a creation dialog on any failure is a reasonable default, but it assumes every failure is about incomplete data. Where a constraint is the likely cause, that assumption turns a clear error into a confusing loop, and the fix is to let the specific error through.

Supported options in Odoo 19

The widget declares no options of its own. It spreads the tags widget's descriptor unchanged, so the options below are inherited and behave normally. Read from many2many_barcode_tags.js and the tags field, Odoo 19.0.

OptionTypeWhat it does
no_quick_createbooleanInherited from the tags widget. Removes creation from the typed text entirely, which sidesteps the situation this widget handles.(default: false)
no_createbooleanInherited. Removes both creation paths from the dropdown.(default: false)
create_name_fieldfieldInherited. Field the typed text is written into when quick-creating a tag.
color_fieldfieldInherited from the tags widget. Names an integer field used to color the tags.

The error test looks at debug information. The widget decides whether an error is a uniqueness violation by inspecting the error's debug payload for the database driver's constraint name. That payload is present in the situations this widget was written for, but it is not guaranteed, so the behavior degrades to the standard fallback rather than failing.

Working examples

The core usage

<field name="barcode_ids"
       widget="many2many_barcode_tags"/>

No options. The only difference from plain tags is what happens when a quick create fails.

Preventing quick create entirely

<field name="barcode_ids"
       widget="many2many_barcode_tags"
       options="{'no_quick_create': True}"/>

Inherited from the tags widget. A stricter answer where barcodes should only be created through their own form.

The plain tags widget

<field name="barcode_ids" widget="many2many_tags"/>

Same rendering, but a duplicate barcode opens a creation dialog rather than surfacing the error.

Letting one error through

The widget is two small classes. The first extends the tags dropdown's autocomplete and overrides the method that handles a failed quick create. It inspects the error for the database driver's uniqueness violation marker and, if it finds it, rethrows. Anything else is passed to the parent implementation, which does the usual thing and offers a creation dialog.

The second class extends the tags field and swaps in that autocomplete. The registration spreads the tags descriptor and adds a styling class, so the field keeps the standard tags appearance.

The detail worth being precise about is where the check looks. It reads the debug information attached to the error and tests it for the constraint name the database driver produces. That is a string test against a server error payload, which is pragmatic rather than principled: it works because Odoo forwards that payload, and it would stop working if the payload were suppressed, at which point the widget would silently behave like plain tags.

Note also what the widget does not do. It does not produce a friendlier message, translate the constraint into business language, or prevent the attempt. It only stops the error being converted into a dialog, so what the user sees is Odoo's standard error presentation for a constraint violation.

Version compatibility

VersionStatusNotes
Odoo 20.0In developmentNot released. Byte-identical to Odoo 19 on the development branch.
Odoo 19.0VerifiedFirst version. Verified against the shipped source.
Odoo 18.0Not availableWidget does not exist. The field used the plain tags widget.
Odoo 17.0Not availableWidget does not exist.
Odoo 16.0Not availableWidget does not exist.

Upgrade note. The widget is new in Odoo 19. On Odoo 18 and earlier the barcodes field used the plain tags widget, so an upgrade gains the behavior with the standard inventory views and nothing needs migrating.

What is changing in Odoo 20

Odoo 20 is expected at Odoo Experience in Brussels, 24 to 26 September 2026. The development branch is unstable and this may still change; we re-verify the page after release.

Byte-identical. The file on the development branch matches Odoo 19 exactly, including the debug payload test. Nothing about this widget changes in Odoo 20.

Common problems and fixes

SymptomCause and fix
A duplicate barcode still opens a creation dialogThe error's debug payload did not contain the constraint marker the widget tests for. Check whether debug information is being suppressed on that deployment; the widget falls back to standard behavior without it.
The error message is not user friendlyThe widget only stops the error being converted into a dialog; it does not rewrite the message. Add a server-side constraint with a clear message if the wording matters.
Users can still create duplicatesThey are not duplicates as far as the database is concerned, for example differing by whitespace. Normalize the value server side before the constraint applies.
Quick create is unavailableAn inherited option disabled it. Remove no_quick_create if creating from typed text is wanted.
Missing widget errorThe stock module is not installed in that database. Install Inventory, or use the plain tags widget.

Barcode tags field vs the alternatives

WidgetBest forKey difference
many2many_barcode_tagsTag fields where a database uniqueness constraint is the likely reason a quick create failsRethrows uniqueness violations instead of falling back to a creation dialog
many2many_tagsMost tag fieldsOffers a creation dialog whenever a quick create fails, whatever the cause
many2one_barcodeScanning a single related recordA relation picker with scanning, not a tag list
many2many_tags_avatarTags representing peopleAvatars rather than plain tags, with standard error handling

Use the plain tags widget wherever quick create failures really are about missing data, which is most relations. Where a uniqueness constraint is the likely cause, either use this widget or disable quick create entirely, which avoids the situation rather than handling it.

Frequently asked questions

What does many2many_barcode_tags change?+
One thing. When creating a tag from typed text fails with a database uniqueness violation, the error is rethrown instead of being handled by falling back to a creation dialog.
Why does that matter for barcodes?+
Because a duplicate barcode is not a case of missing information. Opening a creation dialog invites the user to retry with the same value and fail again, less clearly.
How does it recognize the error?+
It inspects the error's debug payload for the database driver's uniqueness constraint marker. If that payload is absent, it falls back to the standard behavior.
Does it produce a nicer error message?+
No. It only stops the conversion into a dialog. The message is Odoo's standard presentation for a constraint violation.
Which versions have it?+
Odoo 19 onwards, and it is byte-identical on the Odoo 20 development branch.

Barcodes that scan to exactly one thing

Barcode design, unit of measure setup and the scanning flows on top of them decide whether your warehouse app speeds people up or slows them down. We implement Odoo Inventory and Barcode on versions 16 through 19.

Book a free consultation

How this page was produced

The overridden quick create error handling and the debug payload test were read from many2many_barcode_tags.js on the Odoo 19.0 branch, with the standard fallback behavior read from the shared autocomplete in web. The usage comes from stock/views/uom_uom_views.xml. Version coverage comes from the absence of the file on 16.0, 17.0 and 18.0, and a byte comparison against the public development branch. Spotted an error? Tell us and we will correct the page.