Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MBetterc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mbetter
MBetterc
Commits
b35eb9f0
Commit
b35eb9f0
authored
Jan 02, 2026
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Guarantee barcode uniqueness in the same fixture
parent
371b5832
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
5 deletions
+37
-5
barcode_utils.py
mbetterclient/utils/barcode_utils.py
+8
-2
routes.py
mbetterclient/web_dashboard/routes.py
+29
-3
No files found.
mbetterclient/utils/barcode_utils.py
View file @
b35eb9f0
...
...
@@ -313,13 +313,14 @@ def calculate_upce_check_digit(data: str) -> str:
return
data
+
str
(
check_digit
)
def
format_bet_id_for_barcode
(
bet_uuid
:
str
,
standard
:
str
)
->
str
:
def
format_bet_id_for_barcode
(
bet_uuid
:
str
,
standard
:
str
,
counter
:
int
=
0
)
->
str
:
"""
Format bet UUID for specific barcode standard
Args:
bet_uuid: Original bet UUID
standard: Target barcode standard
counter: Counter to add uniqueness when duplicates occur
Returns:
Formatted data suitable for the barcode standard
...
...
@@ -333,13 +334,18 @@ def format_bet_id_for_barcode(bet_uuid: str, standard: str) -> str:
if
standard
in
[
'code128'
,
'code39'
]:
# These support alphanumeric, use full UUID for maximum uniqueness
# Add counter to ensure uniqueness if needed
if
counter
>
0
:
clean_uuid
=
f
"{clean_uuid}_{counter}"
return
clean_uuid
elif
standard
in
[
'ean13'
,
'ean8'
,
'upca'
,
'upce'
,
'itf'
,
'codabar'
]:
# These require numeric data
# Convert hex UUID to numeric by taking hash
# Include counter in hash to ensure uniqueness
import
hashlib
hash_obj
=
hashlib
.
md5
(
bet_uuid
.
encode
())
hash_input
=
f
"{bet_uuid}_{counter}"
.
encode
()
hash_obj
=
hashlib
.
md5
(
hash_input
)
numeric_hash
=
str
(
int
(
hash_obj
.
hexdigest
()[:
12
],
16
))
if
standard
==
'ean13'
:
...
...
mbetterclient/web_dashboard/routes.py
View file @
b35eb9f0
...
...
@@ -4572,9 +4572,34 @@ def create_cashier_bet():
if
api_bp
.
db_manager
:
barcode_standard
=
api_bp
.
db_manager
.
get_config_value
(
'barcode.standard'
,
'none'
)
if
barcode_standard
and
barcode_standard
!=
'none'
:
# Format bet UUID for barcode
# Format bet UUID for barcode
, ensuring uniqueness within fixture
from
..utils.barcode_utils
import
format_bet_id_for_barcode
barcode_data
=
format_bet_id_for_barcode
(
bet_uuid
,
barcode_standard
)
from
..database.models
import
BetModel
# Try to generate unique barcode for this fixture
max_attempts
=
100
# Prevent infinite loop
counter
=
0
while
counter
<
max_attempts
:
barcode_data
=
format_bet_id_for_barcode
(
bet_uuid
,
barcode_standard
,
counter
)
# Check if this barcode already exists for the same fixture
existing_bet
=
session
.
query
(
BetModel
)
.
filter_by
(
barcode_data
=
barcode_data
,
barcode_standard
=
barcode_standard
,
fixture_id
=
fixture_id
)
.
first
()
if
not
existing_bet
:
# Unique barcode found
break
counter
+=
1
logger
.
debug
(
f
"Barcode collision detected for fixture {fixture_id}, trying counter {counter}"
)
if
counter
>=
max_attempts
:
logger
.
warning
(
f
"Could not generate unique barcode for bet {bet_uuid} in fixture {fixture_id} after {max_attempts} attempts"
)
barcode_data
=
None
# Fall back to no barcode
new_bet
=
BetModel
(
uuid
=
bet_uuid
,
...
...
@@ -5090,7 +5115,8 @@ def verify_barcode():
if
barcode_standard
:
query
=
query
.
filter_by
(
barcode_standard
=
barcode_standard
)
bet
=
query
.
first
()
# Order by creation date descending to get the latest bet in case of duplicates
bet
=
query
.
order_by
(
BetModel
.
created_at
.
desc
())
.
first
()
if
not
bet
:
return
jsonify
({
"error"
:
"Bet not found for this barcode"
}),
404
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment