]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
barcode logic: strip non-numeric characters from detected ASN string (#4379)
authorSebastian Porombka <queaker@users.noreply.github.com>
Tue, 17 Oct 2023 03:44:22 +0000 (05:44 +0200)
committerGitHub <noreply@github.com>
Tue, 17 Oct 2023 03:44:22 +0000 (03:44 +0000)
* legacy barcodes exist which still contain characters after the number. the current logic did not truncate them. instead, int() was called from the remaining string. this does not work in this case. it is therefore sufficient to continue processing numeric characters.

* lint

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
src/documents/barcodes.py

index 89d8c26850bfb8f8916e31d3aa38ea991a562735..cac02e3e973e946bca5b2d3f43cc071144195c42 100644 (file)
@@ -1,4 +1,5 @@
 import logging
+import re
 import tempfile
 from dataclasses import dataclass
 from pathlib import Path
@@ -100,6 +101,9 @@ class BarcodeReader:
             # remove the prefix and remove whitespace
             asn_text = asn_text[len(settings.CONSUMER_ASN_BARCODE_PREFIX) :].strip()
 
+            # remove non-numeric parts of the remaining string
+            asn_text = re.sub("[^0-9]", "", asn_text)
+
             # now, try parsing the ASN number
             try:
                 asn = int(asn_text)