-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! ✨(backend) add start and end date on order groups model
- Loading branch information
1 parent
b844aa3
commit b48a129
Showing
9 changed files
with
414 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Util to manage OrderGroup | ||
""" | ||
|
||
from django.utils import timezone | ||
|
||
|
||
def is_active(order_group): | ||
""" | ||
Determine the value of `is_active` of an OrderGroup object. If `start` nor `end` datetime | ||
fields are set, we return the value setted in the database. Otherwise when `start`, `end` | ||
or both datetime are setted, we should compare it to timezone.now() calculate if it's | ||
the window period to set `is_active`. | ||
""" | ||
if not order_group.start and not order_group.end: | ||
return order_group.is_active | ||
|
||
now = timezone.now() | ||
|
||
if order_group.start and order_group.end: | ||
return order_group.start <= now <= order_group.end | ||
if order_group.start: | ||
return now >= order_group.start | ||
if order_group.end: | ||
return now <= order_group.end | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.