Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OD-18685_Feature_Request_Minimum_age_restriction_to_use_Date_of_Birth_(DOB) #1184

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import org.apache.cayenne.exp.ExpressionFactory
import org.apache.cayenne.query.Ordering
import org.apache.cayenne.query.SelectQuery

import java.time.Period

import static ish.common.types.ConfirmationStatus.DO_NOT_SEND
import static ish.common.types.ConfirmationStatus.NOT_SENT
import ish.common.types.EnrolmentStatus
Expand Down Expand Up @@ -232,7 +234,17 @@ class CheckoutController {
Integer minAge = courseClass.minStudentAge
Integer maxAge = courseClass.maxStudentAge

if ((minAge != null && studentAge < minAge) || (maxAge != null && studentAge > maxAge)) {
// Calculate the student's age at the start of future classes (only for WITH_SESSION class type). This student cannot enroll today because he is too young, but this student will have a birthday before the class starts.
// And when the class starts his age will pass age restrictions. Therefore, today we must allow such students to enroll in the class. And the same case with maxStudentAge. OD-18685.
LocalDate startDateClass = LocalDateUtils.dateToValue(courseClass.startDateTime)
Integer studentAgeWhenClassStarted = null
if (!courseClass.isHybrid && !courseClass.isDistantLearningCourse && startDateClass != null && startDateClass > LocalDate.now()) {
studentAgeWhenClassStarted = Period.between(contact.getBirthDate(), startDateClass).years
} else {
studentAgeWhenClassStarted = studentAge
}

if ((minAge != null && studentAgeWhenClassStarted < minAge) || (maxAge != null && studentAgeWhenClassStarted > maxAge)) {
result << new CheckoutValidationErrorDTO(nodeId: contact.id, itemId: dto.classId, itemType: SaleTypeDTO.CLASS, error: "$contact.fullName is unable to enrol in this class. They do not meet the age requirements")
}
}
Expand Down
Loading