This commit is contained in:
ismail 2025-08-21 16:51:26 +03:00
parent f8e3ae67a2
commit 5d47a5b4cc
2 changed files with 24 additions and 6 deletions

View File

@ -17,7 +17,7 @@ from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
from django.contrib.auth.models import User, Group, Permission
from inventory.models import DealerSettings, Dealer,Schedule,Notification
from inventory.models import DealerSettings, Dealer,Schedule,Notification,CarReservation,CarStatusChoices
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
@ -1319,4 +1319,13 @@ def log_email_status(task):
if task.success:
logger.info(f"Email task for Schedule ID {task.args[0]} completed successfully. Result: {task.result}")
else:
logger.error(f"Email task for Schedule ID {task.args[0]} failed. Error: {task.result}")
logger.error(f"Email task for Schedule ID {task.args[0]} failed. Error: {task.result}")
def remove_reservation_by_id(reservation_id):
try:
reservation = CarReservation.objects.get(pk=reservation_id)
reservation.car.status = CarStatusChoices.AVAILABLE
reservation.car.save()
reservation.delete()
except Exception as e:
logger.error(f"Error removing reservation with ID {reservation_id}: {e}")

View File

@ -1,5 +1,6 @@
import json
import secrets
import logging
import datetime
import requests
from decimal import Decimal
@ -27,7 +28,7 @@ from django.contrib.contenttypes.models import ContentType
from django_ledger.models.transactions import TransactionModel
from django_ledger.models.journal_entry import JournalEntryModel
from django.db import transaction
import logging
from django_q.models import Schedule as DjangoQSchedule
from django_ledger.io import roles
logger = logging.getLogger(__name__)
@ -223,13 +224,21 @@ def reserve_car(car, request):
:return: Redirection to the car's detail page.
"""
try:
reserved_until = timezone.now() + timezone.timedelta(hours=24)
models.CarReservation.objects.create(
# reserved_until = timezone.now() + timezone.timedelta(hours=24)
reserved_until = timezone.now() + timezone.timedelta(minutes=1)
reservation = models.CarReservation.objects.create(
car=car, reserved_by=request.user, reserved_until=reserved_until
)
car.status = models.CarStatusChoices.RESERVED
car.save()
# --- Logging for Success ---
DjangoQSchedule.objects.create(
name=f"remove_reservation_for_car_with_vin_{car.vin}",
func='inventory.tasks.remove_reservation_by_id',
args=reservation.pk,
schedule_type=DjangoQSchedule.ONCE,
next_run=reserved_until,
)
logger.info(
f"Car {car.pk} ('{car.id_car_make} {car.id_car_model}') reserved successfully "
f"by user {request.user}. "
@ -1288,7 +1297,7 @@ def get_finance_data(estimate,dealer):
)
discount = extra_info.data.get("discount", 0)
discount = Decimal(discount)
additional_services = car.get_additional_services()
discounted_price=(Decimal(car.marked_price) - discount)
vat_amount = discounted_price * vat.rate