Require club cards in cashier enrollment and restore ticket owners
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -5,6 +5,38 @@ ACCOUNT = re.compile(r"(?<![\w-])(?:[0-9]{2}(?:[- ][0-9]{2}){6}|[0-9]{14})(?![\w
|
||||
CARD = re.compile(r"[0-9]{1,50}")
|
||||
|
||||
|
||||
def card_account_entry(value):
|
||||
"""Validate an explicit card/account pair, including a 14-digit card."""
|
||||
from .account_utils import format_account_number
|
||||
parts = value.strip().split(maxsplit=1)
|
||||
if len(parts) != 2 or not CARD.fullmatch(parts[0]) or not ACCOUNT.fullmatch(parts[1]):
|
||||
raise ValueError("Для каждого счёта обязательна клубная карта. Формат: КАРТА СЧЁТ, например 0007 11-22-33-44-55-66-77.")
|
||||
return f"{parts[0]} {format_account_number(parts[1])}"
|
||||
|
||||
|
||||
def parse_cashier_records(text):
|
||||
# Keep the existing table/Viposnova formats, but never accept an unbound row.
|
||||
entries, errors = [], []
|
||||
if not any(line.strip().lower().startswith("viposnova") for line in text.splitlines()):
|
||||
lines = [line.strip() for line in text.splitlines() if line.strip()]
|
||||
try:
|
||||
entries = [card_account_entry(line) for line in lines]
|
||||
except ValueError:
|
||||
entries = []
|
||||
if not entries:
|
||||
entries, errors = parse_account_records(text)
|
||||
checked = []
|
||||
for entry in entries:
|
||||
try:
|
||||
pair = card_account_entry(entry)
|
||||
except ValueError as error:
|
||||
errors.append(str(error))
|
||||
continue
|
||||
if pair not in checked:
|
||||
checked.append(pair)
|
||||
return checked, list(dict.fromkeys(errors))
|
||||
|
||||
|
||||
def parse_account_records(text):
|
||||
from .account_utils import format_account_number
|
||||
lines = [line.strip() for line in text.splitlines() if line.strip()]
|
||||
|
||||
Reference in New Issue
Block a user