diff --git a/inventory/forms.py b/inventory/forms.py index 9f0f9dd5..3286cee3 100644 --- a/inventory/forms.py +++ b/inventory/forms.py @@ -432,25 +432,20 @@ class CarFinanceForm(forms.ModelForm): additional services associated with a car finance application. """ - # additional_finances = forms.ModelMultipleChoiceField( - # queryset=AdditionalServices.objects.all(), - # widget=forms.CheckboxSelectMultiple(attrs={"class": "form-check-input"}), - # required=False, - # ) + def clean(self): + cleaned_data = super().clean() + cost_price = cleaned_data.get("cost_price") + marked_price = cleaned_data.get("marked_price") + + if cost_price > marked_price: + raise forms.ValidationError({"cost_price": "Cost price should not be greater than marked price"}) + + return cleaned_data class Meta: model = CarFinance fields = ["cost_price","marked_price"] - # def save(self, commit=True): - # instance = super().save() - # try: - # instance.additional_services.set(self.cleaned_data["additional_finances"]) - # except KeyError: - # pass - # instance.save() - # return instance - class CarLocationForm(forms.ModelForm): """ @@ -1172,6 +1167,7 @@ class ScheduleForm(forms.ModelForm): scheduled_at = forms.DateTimeField( widget=DateTimeInput(attrs={"type": "datetime-local"}) ) + reminder = forms.BooleanField(help_text=_("Send a reminder?"),required=False) class Meta: model = Schedule diff --git a/inventory/views.py b/inventory/views.py index c80ab853..3335af8c 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -4912,10 +4912,19 @@ def update_estimate_discount(request, dealer_slug, pk): object_id=estimate.pk, ) discount_amount = request.POST.get("discount_amount", 0) + calculator = CarFinanceCalculator(estimate) + finance_data = calculator.get_finance_data() + if Decimal(discount_amount) >= finance_data.get('cars')[0]['marked_price']: + messages.error(request, _("Discount amount cannot be greater than marked price")) + return redirect("estimate_detail", dealer_slug=dealer_slug, pk=pk) + print(finance_data.get('cars')[0]['marked_price'] * Decimal('0.5')) + if Decimal(discount_amount) > finance_data.get('cars')[0]['marked_price'] * Decimal('0.5'): + messages.warning(request, _("Discount amount is greater than 50% of the marked price, proceed with caution.")) + else: + messages.success(request, _("Discount updated successfully")) extra_info.data.update({"discount": Decimal(discount_amount)}) extra_info.save() - messages.success(request, "Discount updated successfully") return redirect("estimate_detail", dealer_slug=dealer_slug, pk=pk) @@ -6535,6 +6544,7 @@ def schedule_event(request, dealer_slug, content_type, slug): form = forms.ScheduleForm(request.POST) if form.is_valid(): + reminder = form.cleaned_data['reminder'] instance = form.save(commit=False) instance.dealer = dealer instance.content_object = obj @@ -6581,20 +6591,21 @@ def schedule_event(request, dealer_slug, content_type, slug): created_by=request.user, activity_type=instance.scheduled_type, ) - scheduled_at_aware = timezone.make_aware(instance.scheduled_at, timezone.get_current_timezone()) if timezone.is_naive(instance.scheduled_at) else instance.scheduled_at + if reminder: + scheduled_at_aware = timezone.make_aware(instance.scheduled_at, timezone.get_current_timezone()) if timezone.is_naive(instance.scheduled_at) else instance.scheduled_at - reminder_time = scheduled_at_aware - timezone.timedelta(minutes=15) - # Only schedule if the reminder time is in the future - # Reminder emails are scheduled to be sent 15 minutes before the scheduled time - if reminder_time > timezone.now(): - DjangoQSchedule.objects.create( - name=f"send_schedule_reminder_email_to_{instance.scheduled_by.email}_for_{content_type}_with_PK_{instance.pk}", - func='inventory.tasks.send_schedule_reminder_email', - args=f'"{instance.pk}"', - schedule_type=DjangoQSchedule.ONCE, - next_run=reminder_time, - hook='inventory.tasks.log_email_status', - ) + reminder_time = scheduled_at_aware - timezone.timedelta(minutes=15) + # Only schedule if the reminder time is in the future + # Reminder emails are scheduled to be sent 15 minutes before the scheduled time + if reminder_time > timezone.now(): + DjangoQSchedule.objects.create( + name=f"send_schedule_reminder_email_to_{instance.scheduled_by.email}_for_{content_type}_with_PK_{instance.pk}", + func='inventory.tasks.send_schedule_reminder_email', + args=f'"{instance.pk}"', + schedule_type=DjangoQSchedule.ONCE, + next_run=reminder_time, + hook='inventory.tasks.log_email_status', + ) messages.success(request, _("Appointment Created Successfully")) return redirect(f'{content_type}_detail',dealer_slug=dealer_slug, slug=slug) @@ -9785,10 +9796,10 @@ def update_task(request, dealer_slug, pk): @permission_required("inventory.change_schedule", raise_exception=True) def update_schedule(request, dealer_slug, pk): task = get_object_or_404(models.Schedule, pk=pk) - if request.method == "POST": task.completed = False if task.completed else True task.save() + print("task") return render(request, "partials/task.html", {"task": task}) diff --git a/static/css/custom.css b/static/css/custom.css index 987242ff..fa1996f6 100644 --- a/static/css/custom.css +++ b/static/css/custom.css @@ -138,7 +138,8 @@ html[dir="rtl"] .form-icon-container .form-control { top: 50%; left: 50%; transform: translate(-50%, -50%); - z-index: 10; + z-index: 9999; + pointer-events: none; } #spinner-bg { @@ -150,11 +151,14 @@ html[dir="rtl"] .form-icon-container .form-control { background-color: rgba(255, 255, 255, 0.7); opacity: 0; transition: opacity 500ms ease-in; - z-index: 5; + visibility: hidden; + z-index: 10000; + pointer-events: none; } #spinner-bg.htmx-request { opacity: .8; + visibility: visible; } diff --git a/templates/base.html b/templates/base.html index 3e1e03c5..b875891d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -84,10 +84,10 @@ {% include "plans/expiration_messages.html" %} {% block period_navigation %} {% endblock period_navigation %} -
-
+
+
{% block customCSS %}{% endblock %} {% block content %}{% endblock content %} {% block customJS %}{% endblock %} diff --git a/templates/partials/task.html b/templates/partials/task.html index d09fc5b7..f5284b97 100644 --- a/templates/partials/task.html +++ b/templates/partials/task.html @@ -7,9 +7,10 @@
@@ -18,7 +19,7 @@
{{ task.scheduled_type|capfirst }}
{{ task.notes }} - {{ task.created_at|naturalday|capfirst }} + {{ task.scheduled_at|naturaltime|capfirst }} {% if task.completed %}