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,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -165,11 +165,9 @@ def test_calc_due_date_skips_weekends_and_holidays():
|
||||
holidays=holidays,
|
||||
)
|
||||
|
||||
# Mon (12) -> holiday (ignored)
|
||||
# Tue (13) -> 1
|
||||
# Wed (14) -> 2
|
||||
# Thu (15) -> 3 ✅
|
||||
expected = datetime(2026, 1, 15, 10, 30)
|
||||
# Fri (9) + 3 calendar days -> Mon (12)
|
||||
# Mon (12) is a holiday -> adjust to Tue (13)
|
||||
expected = datetime(2026, 1, 13, 10, 30)
|
||||
|
||||
assert result == expected
|
||||
|
||||
|
||||
Reference in New Issue
Block a user