Skip to content

Commit

Permalink
inbound.py: make all datetime parsing aware of the timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
jdetaeye committed Feb 26, 2024
1 parent e680608 commit 8fff6fb
Showing 1 changed file with 49 additions and 10 deletions.
59 changes: 49 additions & 10 deletions frepple/controllers/inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,31 @@ def run(self):
st = elem.get("start")
if st:
try:
wo["start"] = datetime.strptime(st, "%Y-%m-%d %H:%M:%S")
wo["start"] = (
self.timezone.localize(
datetime.strptime(
st,
"%Y-%m-%d %H:%M:%S",
)
)
.astimezone(UTC)
.replace(tzinfo=None)
)
except Exception:
pass
nd = elem.get("end")
if st:
try:
wo["end"] = datetime.strptime(nd, "%Y-%m-%d %H:%M:%S")
wo["end"] = (
self.timezone.localize(
datetime.strptime(
nd,
"%Y-%m-%d %H:%M:%S",
)
)
.astimezone(UTC)
.replace(tzinfo=None)
)
except Exception:
pass
wo_data.append(wo)
Expand Down Expand Up @@ -209,13 +227,27 @@ def run(self):
quantity = float(elem.get("quantity"))
date_planned = elem.get("end")
if date_planned:
date_planned = datetime.strptime(
date_planned, "%Y-%m-%d %H:%M:%S"
date_planned = (
self.timezone.localize(
datetime.strptime(
date_planned,
"%Y-%m-%d %H:%M:%S",
)
)
.astimezone(UTC)
.replace(tzinfo=None)
)
date_ordered = elem.get("start")
if date_ordered:
date_ordered = datetime.strptime(
date_ordered, "%Y-%m-%d %H:%M:%S"
date_ordered = (
self.timezone.localize(
datetime.strptime(
date_ordered,
"%Y-%m-%d %H:%M:%S",
)
)
.astimezone(UTC)
.replace(tzinfo=None)
)

# Is that an update of an existing PO ?
Expand Down Expand Up @@ -390,12 +422,19 @@ def run(self):
continue

if date_shipping:
date_shipping = datetime.strptime(
date_shipping, "%Y-%m-%d %H:%M:%S"
date_shipping = (
self.timezone.localize(
datetime.strptime(
date_shipping,
"%Y-%m-%d %H:%M:%S",
)
)
.astimezone(UTC)
.replace(tzinfo=None)
)
else:
date_shipping = datetime.strptime(
datetime.now(), "%Y-%m-%d %H:%M:%S"
date_shipping = (
datetime.now().astimezone(UTC).replace(tzinfo=None)
)
if not hasattr(self, "stock_picking_dict"):
self.stock_picking_dict = {}
Expand Down

0 comments on commit 8fff6fb

Please sign in to comment.