Ejemplo n.º 1
0
 def handle(self, *args, **kwargs):
     for beerinst in BeerInst.objects.all():
         beerinst.reconcile_stock()
         beerinst.save()
     for user in User.objects.all():
         account = Account.objects.filter(user=user)
         if len(account) == 1:
             self.stdout.write("Reconciling %s ... " % user, ending="")
             # We have an account.
             account[0].reconcile()
             account[0].save()
             self.stdout.write("$ %s / due %s" % (account[0].balance_dollars, account[0].special_due))
         else:
             self.stdout.write("Creating %s" % user)
             account = Account(user=user, balance=0)
             account.save()
     caccounts = ClubAccount.objects.all()
     caccount = None
     if len(caccounts) == 0:
         caccount = ClubAccount()
     else:
         caccount = caccounts[0]
     caccount.reconcile()
     self.stdout.write("Beerclub assets cents %s" % caccount.balance)
     beerassetvalue = 0
     beerstocks = BeerInst.objects.filter(stock_total__gt=0)
     for beer in beerstocks:
         self.stdout.write("%s %s" % (beer.__unicode__(), beer.stock_value))
         beerassetvalue += beer.stock_value
     self.stdout.write("Beerclub beer stock value %s" % beerassetvalue)
Ejemplo n.º 2
0
    def get_context_data(self, **kwargs):
        context = super(StatsView, self).get_context_data(**kwargs)
        year_drinks = Drink.objects.filter(date__year=date.today().year)
        accounts = Account.objects.all()
        total_volume = Drink.objects.filter(date__year=date.today().year).aggregate(beerinst__volume=models.Sum('beerinst__volume'))['beerinst__volume']
        if total_volume is None:
            total_volume = 0
        ### Total volume
        total_ethanol = 0
        for drink in year_drinks:
            #total_volume += drink.beerinst.volume
            total_ethanol += drink.beerinst.volume_ethanol
        caccounts = ClubAccount.objects.all()
        caccount = None
        if len(caccounts) == 0:
            caccount = ClubAccount()
        else:
            caccount = caccounts[0]
        caccount.reconcile()
        context['caccount'] = caccount

        context['total_volume'] = total_volume / 1000.0
        context['total_ethanol'] = total_ethanol / 1000.0
        context['std_drinks'] = total_ethanol / 12.67

        context['top_five'] = sorted(accounts, key=lambda account: account.drinks_unique_had, reverse=True)[:5]
        #context['most_volume'] = sorted(accounts, key=lambda account: account.drinks_volume, reverse=True)[0]
        #context['most_volume_ethanol'] = sorted(accounts, key=lambda account: account.drinks_ethanol_volume, reverse=True)[0]
        return context
Ejemplo n.º 3
0
    def get_context_data(self, **kwargs):
        stat_year = date.today().year
        render_cash = True
        if 'year' in kwargs:
            stat_year = date(year=int(kwargs['year']), month=1, day=1).year
            render_cash = False
        context = super(StatsView, self).get_context_data(**kwargs)
        context['render_cash'] = render_cash
        year_drinks = Drink.objects.filter(date__year=stat_year)
        accounts = Account.objects.all()
        total_volume = Drink.objects.filter(date__year=stat_year).aggregate(beerinst__volume=models.Sum('beerinst__volume'))['beerinst__volume']
        if total_volume is None:
            total_volume = 0
        ### Total volume
        total_ethanol = 0
        for drink in year_drinks:
            #total_volume += drink.beerinst.volume
            total_ethanol += drink.beerinst.volume_ethanol
        caccounts = ClubAccount.objects.all()
        caccount = None
        if len(caccounts) == 0:
            caccount = ClubAccount()
        else:
            caccount = caccounts[0]
        caccount.reconcile()
        context['caccount'] = caccount

        context['total_volume'] = total_volume / 1000.0
        context['total_ethanol'] = total_ethanol / 1000.0
        context['std_drinks'] = total_ethanol / 12.67

        top_five_pre = sorted(accounts, key=lambda account: account.drinks_unique_had_year(stat_year), reverse=True)[:5]
        context['top_five'] = map(lambda account: '%s: %s %s' % (account.drinks_unique_had_year(stat_year), account.user.first_name, account.user.last_name), top_five_pre)
        #context['most_volume'] = sorted(accounts, key=lambda account: account.drinks_volume, reverse=True)[0]
        #context['most_volume_ethanol'] = sorted(accounts, key=lambda account: account.drinks_ethanol_volume, reverse=True)[0]
        context['year'] = stat_year
        return context