update the estimate details additionals
This commit is contained in:
parent
57aff69153
commit
baed1dd280
@ -1325,8 +1325,8 @@ 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
|
||||
total_services_amount = additional_services.get("total")
|
||||
|
||||
@ -5268,13 +5268,31 @@ class EstimateDetailView(LoginRequiredMixin, PermissionRequiredMixin, DetailView
|
||||
kwargs["invoice"] = invoice_obj
|
||||
try:
|
||||
car = estimate.get_itemtxs_data()[0].first().item_model.car
|
||||
selected_items = car.additional_services.filter(dealer=dealer)
|
||||
extra_info = models.ExtraInfo.objects.get(
|
||||
dealer=dealer,
|
||||
content_type=ContentType.objects.get_for_model(EstimateModel),
|
||||
object_id=estimate.pk
|
||||
)
|
||||
try:
|
||||
additionals = extra_info.data.get("additionals")
|
||||
if additionals:
|
||||
selected_items = models.AdditionalServices.objects.filter(dealer=dealer,pk__in=additionals)
|
||||
else:
|
||||
selected_items = []
|
||||
except Exception as e:
|
||||
selected_items = []
|
||||
if estimate.is_draft() or estimate.is_review():
|
||||
kwargs["grand_total"] = finance_data.get("final_price") + sum([x.price_ for x in selected_items])
|
||||
else:
|
||||
kwargs["grand_total"] = finance_data.get("grand_total")
|
||||
form = forms.AdditionalFinancesForm()
|
||||
form.fields["additional_finances"].queryset = form.fields[
|
||||
"additional_finances"
|
||||
].queryset.filter(dealer=dealer) #
|
||||
form.initial["additional_finances"] = selected_items
|
||||
kwargs["additionals_form"] = form
|
||||
kwargs["additional_finances"] = selected_items
|
||||
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
return super().get_context_data(**kwargs)
|
||||
@ -5439,8 +5457,9 @@ def update_estimate_additionals(request, dealer_slug, pk):
|
||||
estimate = get_object_or_404(EstimateModel, pk=pk)
|
||||
car = estimate.get_itemtxs_data()[0].first().item_model.car
|
||||
additionals = form.cleaned_data["additional_finances"]
|
||||
car.additional_services.set(additionals)
|
||||
# car.additional_services.set(additionals)
|
||||
additionals = [additional.pk for additional in additionals]
|
||||
|
||||
extra_info = models.ExtraInfo.objects.get(
|
||||
dealer=dealer,
|
||||
content_type=ContentType.objects.get_for_model(EstimateModel),
|
||||
@ -5448,11 +5467,6 @@ def update_estimate_additionals(request, dealer_slug, pk):
|
||||
)
|
||||
extra_info.data.update({"additionals": additionals})
|
||||
extra_info.save()
|
||||
# for i in additionals:
|
||||
|
||||
# if ex:
|
||||
# ex.delete()
|
||||
|
||||
car.save()
|
||||
messages.success(request, "Additional Finances updated successfully")
|
||||
return redirect("estimate_detail", dealer_slug=dealer_slug, pk=pk)
|
||||
@ -5609,7 +5623,7 @@ def estimate_mark_as(request, dealer_slug, pk):
|
||||
dealer = get_object_or_404(models.Dealer, slug=dealer_slug)
|
||||
estimate = get_object_or_404(EstimateModel, pk=pk)
|
||||
mark = request.GET.get("mark")
|
||||
print(mark)
|
||||
|
||||
if mark:
|
||||
if mark == "review":
|
||||
if not estimate.can_review():
|
||||
@ -5629,6 +5643,24 @@ def estimate_mark_as(request, dealer_slug, pk):
|
||||
# Reserve The Car
|
||||
car = estimate.get_itemtxs_data()[0].first().item_model.car
|
||||
reserve_car(car, request)
|
||||
extra_info = models.ExtraInfo.objects.get(
|
||||
dealer=dealer,
|
||||
content_type=ContentType.objects.get_for_model(EstimateModel),
|
||||
object_id=estimate.pk
|
||||
)
|
||||
try:
|
||||
additionals = extra_info.data.get("additionals")
|
||||
if additionals:
|
||||
selected_items = models.AdditionalServices.objects.filter(dealer=dealer,pk__in=additionals)
|
||||
else:
|
||||
selected_items = []
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
selected_items = []
|
||||
if selected_items:
|
||||
car.additional_services.clear()
|
||||
car.additional_services.set(selected_items)
|
||||
|
||||
messages.success(request, _("Quotation approved successfully"))
|
||||
return redirect("estimate_list", dealer_slug=dealer.slug)
|
||||
elif mark == "rejected":
|
||||
|
||||
@ -293,8 +293,9 @@
|
||||
<tr class="bg-body-secondary total-sum">
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="7">{% trans "Additional Services" %}</td>
|
||||
<td class="align-middle text-start fw-semibold">
|
||||
{% for service in data.additional_services.services %}
|
||||
<small><span class="fw-semibold">+ {{ service.0.name }} - {{ service.0.price_|floatformat }}<span class="icon-saudi_riyal"></span></span></small>
|
||||
|
||||
{% for service in additional_finances %}
|
||||
<small><span class="fw-semibold">+ {{ service.name }} - {{ service.price_|floatformat }}<span class="icon-saudi_riyal"></span></span></small>
|
||||
<br>
|
||||
{% endfor %}
|
||||
{% if estimate.is_draft %}
|
||||
@ -310,7 +311,7 @@
|
||||
<tr class="bg-body-secondary total-sum">
|
||||
<td class="align-middle ps-4 fw-bolder text-body-highlight" colspan="7">{% trans "Grand Total" %}</td>
|
||||
<td class="align-middle text-start fw-bolder">
|
||||
<span id="grand-total">{{ data.grand_total|floatformat }}<span class="icon-saudi_riyal"></span></span>
|
||||
<span id="grand-total">{{ grand_total|floatformat }}<span class="icon-saudi_riyal"></span></span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user