Пример #1
0
    def get(self, request, *args, **kwargs):
        if request.user.is_authenticated:

            bill_qs = BillModel.objects.for_entity_unpaid(
                entity_slug=self.kwargs['entity_slug'],
                user_model=request.user,
            ).select_related('ledger__entity')

            unit_slug = self.get_unit_slug()
            if unit_slug:
                bill_qs.filter(ledger__unit__slug__exact=unit_slug)

            net_summary = progressible_net_summary(bill_qs)
            entity_model = bill_qs.first().ledger.entity
            net_payables = {
                'entity_slug': self.kwargs['entity_slug'],
                'entity_name': entity_model.name,
                'net_payable_data': net_summary
            }

            if DJANGO_LEDGER_VALIDATE_SCHEMAS_AT_RUNTIME:
                try:
                    validate(instance=net_payables, schema=SCHEMA_NET_PAYABLES)
                except ValidationError as e:
                    return JsonResponse({
                        'message': f'Schema validation error. {e.message}'
                    }, status=500)

            return JsonResponse({
                'results': net_payables
            })

        return JsonResponse({
            'message': 'Unauthorized'
        }, status=401)
Пример #2
0
    def get(self, request, *args, **kwargs):
        if request.user.is_authenticated:
            invoice_qs = InvoiceModel.objects.for_entity_unpaid(
                entity_slug=self.kwargs['entity_slug'],
                user_model=request.user,
            ).select_related('ledger__entity')

            net_summary = progressible_net_summary(invoice_qs)
            entity_model = invoice_qs.first().ledger.entity
            net_receivable = {
                'entity_slug': self.kwargs['entity_slug'],
                'entity_name': entity_model.name,
                'net_receivable_data': net_summary
            }

            if DJANGO_LEDGER_VALIDATE_SCHEMAS_AT_RUNTIME:
                try:
                    validate(instance=net_receivable,
                             schema=SCHEMA_NET_RECEIVABLE)
                except ValidationError as e:
                    return JsonResponse(
                        {'message': f'Schema validation error. {e.message}'},
                        status=500)

            return JsonResponse({'results': net_receivable})

        return JsonResponse({'message': 'Unauthorized'}, status=401)
Пример #3
0
    def get(self, request, *args, **kwargs):
        if request.user.is_authenticated:
            invoice_qs = InvoiceModel.objects.for_entity_unpaid(
                entity_slug=self.kwargs['entity_slug'],
                user_model=request.user,
            )

            net_summary = progressible_net_summary(invoice_qs)

            return JsonResponse({
                'results': {
                    'entity_slug': self.kwargs['entity_slug'],
                    'net_receivable_data': net_summary
                }
            })

        return JsonResponse({'message': 'Unauthorized'}, status=401)