This commit is contained in:
ismail 2025-06-01 14:16:02 +03:00
parent b8079ebf97
commit 5b4d6bf2b2
3 changed files with 33 additions and 27 deletions

View File

@ -578,7 +578,7 @@ path(
name="estimate_detail",
),
path("sales/estimates/create/", views.create_estimate, name="estimate_create"),
path("sales/estimates/create/<int:pk>/", views.create_estimate, name="estimate_create_from_opportunity"),
path("sales/estimates/create/<slug:slug>/", views.create_estimate, name="estimate_create_from_opportunity"),
path(
"sales/estimates/<uuid:pk>/estimate_mark_as/",
views.estimate_mark_as,

View File

@ -3592,7 +3592,7 @@ class EstimateListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
# @csrf_exempt
@login_required
@permission_required("django_ledger.add_estimatemodel", raise_exception=True)
def create_estimate(request, pk=None):
def create_estimate(request, slug=None):
"""
Creates a new estimate based on the provided data and saves it. This function processes
a POST request and expects a JSON payload containing details of the estimate such as
@ -3780,7 +3780,7 @@ def create_estimate(request, pk=None):
opportunity_id = data.get("opportunity_id")
if opportunity_id != "None":
opportunity = models.Opportunity.objects.get(pk=int(opportunity_id))
opportunity = models.Opportunity.objects.get(slug=opportunity_id)
opportunity.estimate = estimate
opportunity.save()
@ -3799,9 +3799,10 @@ def create_estimate(request, pk=None):
active=True
)
if pk:
opportunity = models.Opportunity.objects.get(pk=pk)
if slug:
opportunity = models.Opportunity.objects.get(slug=slug)
customer = opportunity.customer
form.fields['customer'].queryset = models.Customer.objects.filter(pk=customer.pk)
form.initial["customer"] = customer
car_list = (
@ -3842,7 +3843,7 @@ def create_estimate(request, pk=None):
}
for x in car_list
],
"opportunity_id": pk if pk else None,
"opportunity_id": slug if slug else None,
"customer_count": entity.get_customers().count(),
}
@ -5576,6 +5577,11 @@ class OpportunityDetailView(LoginRequiredMixin, DetailView):
context["tasks"] = models.Tasks.objects.filter(
content_type__model="opportunity", object_id=self.object.id
)
context["upcoming_events"] = {
"schedules": self.object.lead.get_all_schedules().filter(
scheduled_at__gt=timezone.now()
),
}
return context

View File

@ -15,7 +15,7 @@
{% if opportunity.estimate %}
<a class="dropdown-item" href="{% url 'estimate_detail' opportunity.estimate.pk %}">{{ _("View Quotation")}}</a>
{% else %}
<a class="dropdown-item" href="{% url 'estimate_create_from_opportunity' opportunity.pk %}">{{ _("Create Quotation")}}</a>
<a class="dropdown-item" href="{% url 'estimate_create_from_opportunity' opportunity.slug %}">{{ _("Create Quotation")}}</a>
{% endif %}
</li>
<li><a class="dropdown-item" href="{% url 'update_opportunity' opportunity.slug %}">Update Opportunity</a></li>
@ -77,26 +77,26 @@
<h4 class="mb-5 d-flex align-items-center"><span class="d-inline-block lh-sm me-1" data-feather="link" style="height:16px;width:16px;"></span> {{ _("Upcoming Events")}}</h4>
<div class="row g-3">
<div class="col-12">
<div class="mb-4">
<div class="d-flex flex-wrap justify-content-between mb-2">
<h5 class="mb-0 text-body-highlight me-2">{{ _("Estimate") }}</h5>
</div>
{% if opportunity.estimate %}
<a class="dropdown-item" href="{% url 'estimate_detail' opportunity.estimate.pk %}">{{ _("View Quotation")}}</a>
{% else %}
<p>{{ _("No Estimate") }}</p>
{% endif %}
</div>
<div class="mb-4">
<div class="d-flex flex-wrap justify-content-between mb-2">
<h5 class="mb-0 text-body-highlight me-2">{{ _("Invoice") }}</h5>
</div>
{% if opportunity.estimate.invoice %}
<a class="dropdown-item" href="{% url 'invoice_detail' opportunity.estimate.invoice.pk %}">{{ _("View Invoice")}}</a>
{% else %}
<p>{{ _("No Invoice") }}</p>
{% endif %}
</div>
{% for event in upcoming_events.schedules %}
<table class="table table-sm table-borderless mb-4">
<thead>
<tr>
<th scope="col">{{ _("Type") }}</th>
<th scope="col">{{ _("Purpose") }}</th>
<th scope="col">{{ _("Scheduled At") }}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ event.scheduled_type|capfirst }}</td>
<td>{{ event.purpose }}</td>
<td>{{ event.scheduled_at|naturaltime|capfirst }}</td>
</tr>
</tbody>
</table>
{% empty %}
<p>{{ _("No Invoice") }}</p>
{% endfor %}
</div>
</div>
</div>