コード例 #1
0
class VentaAreaListView(ListView):
    context_object_name = 'ventas'

    def dispatch(self, request, *args, **kwargs):
        self.form = PeriodoAreaForm(request.GET, prefix='venta-area')
        if self.form.is_valid():
            self.inicio = self.form.cleaned_data['inicio']
            self.fin = self.form.cleaned_data['fin']
            self.item_type = self.form.cleaned_data['area']

        return super(VentaAreaListView, self).dispatch(request, *args,
                                                       **kwargs)

    def get_queryset(self):
        return Venta.objects.filter(
            recibo__created__gte=self.inicio,
            recibo__created__lte=self.fin,
            recibo__nulo=False,
            item__item_type=self.item_type,
        )

    def get_context_data(self, **kwargs):
        context = super(VentaAreaListView, self).get_context_data(**kwargs)
        context['item_type'] = self.item_type
        context['inicio'] = self.inicio
        context['fin'] = self.fin
        context['total'] = self.get_queryset().aggregate(
            total=Sum('total'))['total']
        return context
コード例 #2
0
ファイル: views.py プロジェクト: luisdavid1962/hospicloud
class VentaAreaListView(ListView):
    context_object_name = 'ventas'

    def dispatch(self, request, *args, **kwargs):
        self.form = PeriodoAreaForm(request.GET, prefix='venta-area')
        if self.form.is_valid():
            self.inicio = self.form.cleaned_data['inicio']
            self.fin = self.form.cleaned_data['fin']
            self.item_type = self.form.cleaned_data['area']

        return super(VentaAreaListView, self).dispatch(request, *args, **kwargs)

    def get_queryset(self):
        return Venta.objects.filter(
            recibo__created__gte=self.inicio,
            recibo__created__lte=self.fin,
            recibo__nulo=False,
            item__item_type=self.item_type,
        )

    def get_context_data(self, **kwargs):
        context = super(VentaAreaListView, self).get_context_data(**kwargs)
        context['item_type'] = self.item_type
        context['inicio'] = self.inicio
        context['fin'] = self.fin
        context['total'] = sum(v.total() for v in self.object_list)
        return context