示例#1
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        entity_model = self.object
        context['page_title'] = entity_model.name
        context['header_title'] = entity_model.name
        context['header_subtitle'] = _('Dashboard')
        context['header_subtitle_icon'] = 'mdi:monitor-dashboard'

        context[
            'pnl_chart_id'] = f'djl-entity-pnl-chart-{randint(10000, 99999)}'
        context['pnl_chart_endpoint'] = reverse(
            'django_ledger:entity-json-pnl',
            kwargs={'entity_slug': self.kwargs['entity_slug']})
        context[
            'payables_chart_id'] = f'djl-entity-payables-chart-{randint(10000, 99999)}'
        context['payables_chart_endpoint'] = reverse(
            'django_ledger:entity-json-net-payables',
            kwargs={'entity_slug': self.kwargs['entity_slug']})
        context[
            'receivables_chart_id'] = f'djl-entity-receivables-chart-{randint(10000, 99999)}'
        context['receivables_chart_endpoint'] = reverse(
            'django_ledger:entity-json-net-receivables',
            kwargs={'entity_slug': self.kwargs['entity_slug']})

        context['from_date'] = self.get_from_date()
        context['to_date'] = self.get_to_date()
        set_default_entity(self.request, entity_model)
        context = self.get_entity_digest(context)

        # Unpaid Bills for Dashboard
        context['bills'] = self.get_unpaid_bills_qs()

        # Unpaid Invoices for Dashboard
        context['invoices'] = self.get_unpaid_invoices_qs()
        return context
示例#2
0
 def get(self, *args, **kwargs):
     response = super().get(*args, **kwargs)
     request = getattr(self, 'request')
     try:
         entity_model = getattr(self, 'object')
         if entity_model and isinstance(entity_model, EntityModel):
             set_default_entity(request, entity_model)
     except AttributeError:
         pass
     return response
示例#3
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        entity_model = self.object
        context['page_title'] = entity_model.name
        context['header_title'] = entity_model.name
        context['header_subtitle'] = _('Dashboard')
        context['header_subtitle_icon'] = 'mdi:monitor-dashboard'

        end_date = get_end_date_from_session(entity_slug=entity_model.slug,
                                             request=self.request)
        context['date_filter'] = end_date

        set_default_entity(self.request, entity_model)

        context[
            'pnl_chart_id'] = f'djl-entity-pnl-chart-{randint(10000, 99999)}'
        context['pnl_chart_endpoint'] = reverse(
            'django_ledger:entity-json-pnl',
            kwargs={'entity_slug': self.kwargs['entity_slug']})

        context[
            'payables_chart_id'] = f'djl-entity-payables-chart-{randint(10000, 99999)}'
        context['payables_chart_endpoint'] = reverse(
            'django_ledger:entity-json-net-payables',
            kwargs={'entity_slug': self.kwargs['entity_slug']})

        context[
            'receivables_chart_id'] = f'djl-entity-receivables-chart-{randint(10000, 99999)}'
        context['receivables_chart_endpoint'] = reverse(
            'django_ledger:entity-json-net-receivables',
            kwargs={'entity_slug': self.kwargs['entity_slug']})

        # DIGEST PHASE ---
        by_period = self.request.GET.get('by_period')
        digest = entity_model.digest(user_model=self.request.user,
                                     to_date=end_date,
                                     by_period=True if by_period else False,
                                     process_ratios=True,
                                     process_roles=True,
                                     process_groups=True)
        context.update(digest)

        # Unpaid Bills for Dashboard
        context['bills'] = BillModel.objects.for_entity_unpaid(
            user_model=self.request.user,
            entity_slug=self.kwargs['entity_slug']).select_related(
                'vendor').order_by('due_date')

        # Unpaid Invoices for Dashboard
        context['invoices'] = InvoiceModel.objects.for_entity_unpaid(
            user_model=self.request.user,
            entity_slug=self.kwargs['entity_slug']).select_related(
                'customer').order_by('due_date')
        return context
示例#4
0
 def post(self, request, *args, **kwargs):
     form = EntityFilterForm(request.POST, user_model=request.user)
     session_key = get_default_entity_session_key()
     if form.is_valid():
         entity_model = form.cleaned_data['entity_model']
         self.url = reverse('django_ledger:entity-detail',
                            kwargs={'entity_slug': entity_model.slug})
         set_default_entity(request, entity_model)
     else:
         try:
             del self.request.session[session_key]
         finally:
             self.url = reverse('django_ledger:entity-list')
     return super().post(request, *args, **kwargs)