signals(fix): error on course tracking
This commit is contained in:
1 file changed
+13
-14
+13
-14
@@ -126,21 +126,20 @@ def create_course_tracking(sender, instance, created, **kwargs):
|
|||||||
|
|
||||||
expected_end_date = start_date + timedelta(days=duration_days)
|
expected_end_date = start_date + timedelta(days=duration_days)
|
||||||
|
|
||||||
# Create course tracking with transaction
|
# Create course tracking without nested transaction
|
||||||
with transaction.atomic():
|
course_tracking = CourseTracking.objects.create(
|
||||||
course_tracking = CourseTracking.objects.create(
|
student=instance,
|
||||||
student=instance,
|
course=instance.course,
|
||||||
course=instance.course,
|
start_date=start_date,
|
||||||
start_date=start_date,
|
expected_end_date=expected_end_date,
|
||||||
expected_end_date=expected_end_date,
|
current_period=instance.current_period,
|
||||||
current_period=instance.current_period,
|
period_start_date=start_date,
|
||||||
period_start_date=start_date,
|
period_end_date=start_date
|
||||||
period_end_date=start_date
|
+ timedelta(days=180), # 6 months for first semester
|
||||||
+ timedelta(days=180), # 6 months for first semester
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# Force initial percentage calculation
|
# The model's save() method will handle the percentage calculation automatically
|
||||||
course_tracking.force_update_percentage()
|
# No need to manually call update_completion_percentage()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(
|
print(
|
||||||
|
|||||||
Reference in new issue
Block a user