Beispiel #1
0
    def get(self, request, format=None):
        if not self.request.user.is_staff and not request.user.is_support:
            raise exceptions.PermissionDenied()

        customers = structure_models.Customer.objects.all()
        customers = invoices_filters.AccountingStartDateFilter().filter(
            request, customers, self)

        name = request.query_params.get('name', '')
        if name:
            customers = customers.filter(name__icontains=name)

        year = invoice_utils.get_current_year()
        month = invoice_utils.get_current_month()
        try:
            year = int(request.query_params.get('year', ''))
            month = int(request.query_params.get('month', ''))
        except ValueError:
            pass

        invoices = invoices_models.Invoice.objects.filter(
            customer__in=customers)
        invoices = invoices.filter(year=year, month=month)

        total = sum(invoice.total for invoice in invoices)
        return response.Response({'total': total}, status=status.HTTP_200_OK)
Beispiel #2
0
 def annotate_current_price(self, content_type):
     projects = Project.objects.all()
     year, month = get_current_year(), get_current_month()
     for project in projects:
         items = InvoiceItem.objects.filter(invoice__year=year,
                                            invoice__month=month,
                                            project_id=project.id)
         project.value = sum(item.price_current for item in items)
     return projects
Beispiel #3
0
 def update_total(self):
     current_year = invoices_utils.get_current_year()
     current_month = invoices_utils.get_current_month()
     self.total = self.get_total(current_year, current_month)