Beispiel #1
0
    def get_queryset(self, *args, **kwargs):
        """
        Pretty much like the one in apps.client.views
        """
        date = self.request.GET.get("month", None)
        resource_type = self.request.GET.get("type", None)

        query = Q()

        # Split and get year and month
        if date:
            month, year = self.split_date_tokens(date)
            if resource_type == "prospection":
                query = query & Q(visitation_date__month=month, visitation_date__year=year)
            else:
                query = query & Q(created_date__month=month, created_date__year=year)
        else:
            months_to_check = get_reverse_months_header()
            query = query & self.get_date_query(months_to_check, resource_type=resource_type)
            
        # This is a bit patchy 
        # TODO: Fix it up a little. Perhaps break it up into another function?
        if resource_type == "prospection":
            self.template_name = "prospection/ajax/prospection_detail_table.html"
            return Prospection.objects.filter(query)
        else:
            return self.model.objects.filter(query)
Beispiel #2
0
    def get(self, request):
        # Get every client that has a signature date of today 'till 4 months in the future
        months = get_reverse_months_header()
        
        # Check if the user is a Vendedor. If the user is a vendedor only
        # show this user the clients that belong to him
        if request.user.groups.filter(name="Ventas").count():
            clients = Client.objects.filter(prospection__salesperson__pk=request.user.pk)
        else:
            clients = Client.objects.all()
        

        object_dict = dict()
        for c in CLIENT_STATUS:
            object_dict[c[0]] = clients.filter(status=unicode(c[1]))

        object_dict = sorted(object_dict.iteritems(), key=operator.itemgetter(0))

        new_object_dict = dict()
        for c in TOTAL_INCOME_BUCKET:
            new_object_dict[c[1]] = clients.filter(prospection__total_income=c[0])

        new_object_dict = sorted(new_object_dict.iteritems(), key=operator.itemgetter(0))

        return self.render_to_response({
            "months": months,
            "object_dict": object_dict,
            "new_object_dict": new_object_dict
        })
Beispiel #3
0
    def get_context_data(self, *args, **kwargs):
        """
        Render a table with two rows, one containing prospections and one containing new clients
        """
        context = super(ListView, self).get_context_data(*args, **kwargs)
        # Now arrange everything neatly in rows
        context["months"] = get_reverse_months_header()
        clientes = SortedDict()
        clientes["prospecciones"] = Prospection.objects.all().exclude(client__isnull=False)
        clientes["clientes"] = Client.objects.all().exclude(status="Firmado")

        context["object_list"] = clientes
        return context