updates
This commit is contained in:
parent
f8e3ae67a2
commit
5d47a5b4cc
@ -17,7 +17,7 @@ from django.core.mail import EmailMultiAlternatives
|
|||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.contrib.auth.models import User, Group, Permission
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
@ -1319,4 +1319,13 @@ def log_email_status(task):
|
|||||||
if task.success:
|
if task.success:
|
||||||
logger.info(f"Email task for Schedule ID {task.args[0]} completed successfully. Result: {task.result}")
|
logger.info(f"Email task for Schedule ID {task.args[0]} completed successfully. Result: {task.result}")
|
||||||
else:
|
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}")
|
||||||
@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import secrets
|
import secrets
|
||||||
|
import logging
|
||||||
import datetime
|
import datetime
|
||||||
import requests
|
import requests
|
||||||
from decimal import Decimal
|
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.transactions import TransactionModel
|
||||||
from django_ledger.models.journal_entry import JournalEntryModel
|
from django_ledger.models.journal_entry import JournalEntryModel
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
import logging
|
from django_q.models import Schedule as DjangoQSchedule
|
||||||
from django_ledger.io import roles
|
from django_ledger.io import roles
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -223,13 +224,21 @@ def reserve_car(car, request):
|
|||||||
:return: Redirection to the car's detail page.
|
:return: Redirection to the car's detail page.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
reserved_until = timezone.now() + timezone.timedelta(hours=24)
|
# reserved_until = timezone.now() + timezone.timedelta(hours=24)
|
||||||
models.CarReservation.objects.create(
|
reserved_until = timezone.now() + timezone.timedelta(minutes=1)
|
||||||
|
reservation = models.CarReservation.objects.create(
|
||||||
car=car, reserved_by=request.user, reserved_until=reserved_until
|
car=car, reserved_by=request.user, reserved_until=reserved_until
|
||||||
)
|
)
|
||||||
car.status = models.CarStatusChoices.RESERVED
|
car.status = models.CarStatusChoices.RESERVED
|
||||||
car.save()
|
car.save()
|
||||||
# --- Logging for Success ---
|
# --- 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(
|
logger.info(
|
||||||
f"Car {car.pk} ('{car.id_car_make} {car.id_car_model}') reserved successfully "
|
f"Car {car.pk} ('{car.id_car_make} {car.id_car_model}') reserved successfully "
|
||||||
f"by user {request.user}. "
|
f"by user {request.user}. "
|
||||||
@ -1288,7 +1297,7 @@ def get_finance_data(estimate,dealer):
|
|||||||
)
|
)
|
||||||
discount = extra_info.data.get("discount", 0)
|
discount = extra_info.data.get("discount", 0)
|
||||||
discount = Decimal(discount)
|
discount = Decimal(discount)
|
||||||
|
|
||||||
additional_services = car.get_additional_services()
|
additional_services = car.get_additional_services()
|
||||||
discounted_price=(Decimal(car.marked_price) - discount)
|
discounted_price=(Decimal(car.marked_price) - discount)
|
||||||
vat_amount = discounted_price * vat.rate
|
vat_amount = discounted_price * vat.rate
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user