TimeZone Bug Fix

This commit is contained in:
2026-09-01 14:12:19 -05:00
parent df9958cb97
commit bf5566e911
2 changed files with 13 additions and 6 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ class Order(Base):
# When the order/ticket was created in the source system
source_created_at = Column(DateTime, nullable=True)
# When we pulled it into this app
imported_at = Column(DateTime, nullable=False, default=dt.datetime.utcnow)
imported_at = Column(DateTime, nullable=False, default=dt.datetime.now)
# When this ticket first transitioned into a fulfilled status - used
# for "fulfilled today" counts and as a rough audit trail. Set once,
# on the transition; not touched again while it stays fulfilled.
+12 -5
View File
@@ -102,6 +102,13 @@ def save_orders(orders: List[NormalizedOrder]) -> SaveResult:
what moves it into the Done pile. cancelled_at works the same way for
CANCELLED_STATUSES - it's what limits the Cancelled tab to "cancelled
today" rather than showing every cancelled ticket ever.
These get stamped with dt.datetime.now() (LOCAL time), not utcnow() -
deliberately, since every "is this today" check elsewhere compares
against dt.date.today() (also local). Mixing the two caused a real
bug: a ticket cancelled in the evening in a US timezone would get a
UTC timestamp that had already rolled into tomorrow, failing the
same-day check immediately and landing on Done instead of Cancelled.
"""
session = get_session()
new_count = 0
@@ -157,10 +164,10 @@ def save_orders(orders: List[NormalizedOrder]) -> SaveResult:
source_created_at=order["source_created_at"],
raw_data=order["raw_data"],
fulfilled_at=(
dt.datetime.utcnow() if status_in(new_status, fulfilled_statuses) else None
dt.datetime.now() if status_in(new_status, fulfilled_statuses) else None
),
cancelled_at=(
dt.datetime.utcnow() if status_in(new_status, cancelled_statuses) else None
dt.datetime.now() if status_in(new_status, cancelled_statuses) else None
),
)
)
@@ -178,11 +185,11 @@ def save_orders(orders: List[NormalizedOrder]) -> SaveResult:
if status_in(new_status, fulfilled_statuses) and not status_in(
old_status, fulfilled_statuses
):
existing.fulfilled_at = dt.datetime.utcnow()
existing.fulfilled_at = dt.datetime.now()
if status_in(new_status, cancelled_statuses) and not status_in(
old_status, cancelled_statuses
):
existing.cancelled_at = dt.datetime.utcnow()
existing.cancelled_at = dt.datetime.now()
existing.ticket_number = order.get("ticket_number")
existing.company = order.get("company", "Unknown")
@@ -265,7 +272,7 @@ def mark_shipstation_sent(ticket_number: str) -> None:
select(Order).where(Order.source == "jira", Order.ticket_number == ticket_number)
).scalar_one_or_none()
if order is not None:
order.shipstation_sent_at = dt.datetime.utcnow()
order.shipstation_sent_at = dt.datetime.now()
session.commit()
finally:
session.close()