fix due days to checkout
This commit is contained in:
@@ -27,7 +27,7 @@ from pydantic import (
|
||||
|
||||
from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client
|
||||
from config import DUE_DAYS, ORDER_TABLE
|
||||
from config import DUE_DAYS, ORDER_TABLE, USER_TABLE
|
||||
from routes.enrollments.enroll import Enrollment
|
||||
|
||||
router = Router()
|
||||
@@ -310,26 +310,27 @@ def _calc_due_date(
|
||||
holidays: set[date] | None = None,
|
||||
) -> datetime:
|
||||
holidays = holidays or set()
|
||||
current_dt = start_date
|
||||
|
||||
while business_days > 0:
|
||||
current_dt += timedelta(days=1)
|
||||
due_date = start_date + timedelta(days=business_days)
|
||||
|
||||
if current_dt.weekday() < 5 and current_dt.date() not in holidays:
|
||||
business_days -= 1
|
||||
while due_date.weekday() >= 5 or due_date.date() in holidays:
|
||||
due_date += timedelta(days=1)
|
||||
|
||||
return current_dt
|
||||
return due_date
|
||||
|
||||
|
||||
def _get_due_days(
|
||||
org_id: str | UUID4,
|
||||
default: int = DUE_DAYS,
|
||||
) -> int:
|
||||
return dyn.collection.get_item(
|
||||
KeyPair(
|
||||
pk=str(org_id),
|
||||
sk=SortKey('METADATA#BILLING', path_spec='due_days'),
|
||||
),
|
||||
raise_on_error=False,
|
||||
default=default,
|
||||
return int(
|
||||
dyn.collection.get_item(
|
||||
KeyPair(
|
||||
pk=str(org_id),
|
||||
sk=SortKey('METADATA#BILLING', path_spec='due_days'),
|
||||
table_name=USER_TABLE,
|
||||
),
|
||||
raise_on_error=False,
|
||||
default=default,
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user