wyby sync: skip PIN collisions with foreign manual codes
Glutz codes are globally unique; a PIN already owned by another user (e.g. manually set temporary code) is skipped with a clear WARNING instead of failing the whole run. 41 tests green.
This commit is contained in:
@@ -119,6 +119,13 @@ class Sync:
|
||||
return c
|
||||
return None
|
||||
|
||||
def _pin_owner(self, pin):
|
||||
"""Any code row with this PIN value (codes are globally unique in Glutz)."""
|
||||
for c in self.codes:
|
||||
if str(c.get("code")) == str(pin):
|
||||
return c
|
||||
return None
|
||||
|
||||
# --- planning -------------------------------------------------------
|
||||
|
||||
def plan_booking(self, b, group_id, today):
|
||||
@@ -143,6 +150,14 @@ class Sync:
|
||||
desired_to = datetime.combine(b.end_date, time(23, 59, 59))
|
||||
row = self._code_row(uid, b.pin)
|
||||
if row is None:
|
||||
other = self._pin_owner(b.pin)
|
||||
if other is not None:
|
||||
self.skipped.append(
|
||||
f"{ctx} - PIN {b.pin} already exists for Glutz user id "
|
||||
f"{other['userId']} ({other.get('description') or 'no description'}) "
|
||||
"-> resolve manually, not touching foreign code"
|
||||
)
|
||||
return
|
||||
self.planned.append(
|
||||
(
|
||||
ctx,
|
||||
|
||||
Reference in New Issue
Block a user