def common_context(context, start, end): vendors = models.Supplier.objects.all() context["vendors"] = [{ 'name': v.name, 'transactions': sorted(list(Credit.objects.filter( account=v.account, entry__date__gte=start, entry__date__lte=end, entry__draft=False ) ) + list(Debit.objects.filter(account=v.account, entry__date__gte=start, entry__date__lte=end, entry__draft=False ) ), key=lambda x: x.entry.date), 'total': v.account.balance_over_period(start, end) } for v in vendors] start, end = encode_period(start, end) context.update({ 'start': start, 'end': end, })
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) start, end = encode_period(*extract_period(self.request.GET)) context.update({ 'start': start, 'end': end, 'date': datetime.date.today() }) return context
def common_context(context, start, end): jobs = InvoiceLine.objects.filter( Q(invoice__date__gte=start) & Q(invoice__date__lte=end) & Q(invoice__draft=False) & Q(invoice__status__in=['paid', 'invoice', 'paid-partially']) & Q(service__isnull=False)) revenue = sum([i.subtotal for i in jobs]) expenses = sum([i.service.cost_of_sale for i in jobs]) context['jobs_count'] = jobs.count() context['revenue'] = revenue context['expenses'] = expenses context['income'] = revenue - expenses start, end = encode_period(start, end) context.update({ 'start': start, 'end': end, 'date': datetime.date.today() })