diff --git a/inventory/urls.py b/inventory/urls.py index b8cfc8a0..fb78bc62 100644 --- a/inventory/urls.py +++ b/inventory/urls.py @@ -578,7 +578,7 @@ path( name="estimate_detail", ), path("sales/estimates/create/", views.create_estimate, name="estimate_create"), - path("sales/estimates/create//", views.create_estimate, name="estimate_create_from_opportunity"), + path("sales/estimates/create//", views.create_estimate, name="estimate_create_from_opportunity"), path( "sales/estimates//estimate_mark_as/", views.estimate_mark_as, diff --git a/inventory/views.py b/inventory/views.py index ecc13651..116b76c4 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -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 diff --git a/templates/crm/opportunities/opportunity_detail.html b/templates/crm/opportunities/opportunity_detail.html index d06821c1..2ade7690 100644 --- a/templates/crm/opportunities/opportunity_detail.html +++ b/templates/crm/opportunities/opportunity_detail.html @@ -15,7 +15,7 @@ {% if opportunity.estimate %} {{ _("View Quotation")}} {% else %} - {{ _("Create Quotation")}} + {{ _("Create Quotation")}} {% endif %}
  • Update Opportunity
  • @@ -77,26 +77,26 @@

    {{ _("Upcoming Events")}}

    -
    -
    -
    {{ _("Estimate") }}
    -
    - {% if opportunity.estimate %} - {{ _("View Quotation")}} - {% else %} -

    {{ _("No Estimate") }}

    - {% endif %} -
    -
    -
    -
    {{ _("Invoice") }}
    -
    - {% if opportunity.estimate.invoice %} - {{ _("View Invoice")}} - {% else %} -

    {{ _("No Invoice") }}

    - {% endif %} -
    + {% for event in upcoming_events.schedules %} + + + + + + + + + + + + + + + +
    {{ _("Type") }}{{ _("Purpose") }}{{ _("Scheduled At") }}
    {{ event.scheduled_type|capfirst }}{{ event.purpose }}{{ event.scheduled_at|naturaltime|capfirst }}
    + {% empty %} +

    {{ _("No Invoice") }}

    + {% endfor %}