Exemple #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)
Exemple #2
0
 def form_valid(self, form):
     data = form.cleaned_data
     name = data.get('name', None)
     #barcode = data.get('barcode', None)
     if name is not None:
         user = None
         try:
             user = User.objects.get(username=name)
         except:
             ldapobj = LDAPBackend()
             user = ldapobj.populate_user(name)
             if user is not None and not user.is_anonymous():
                 print("%s -> True" % name)
             else:
                 print("%s -> False" % name)
             user.save()
         account = None
         try:
             account = Account.objects.get(user=user)
         except:
             account = Account(user=user, balance=0)
         print("Creating %s" % user)
         #account.barcode = barcode
         account.save()
         messages.success(self.request, "Added %s" % user)
     return super(AccountCreateView, self).form_valid(form)
 def handle(self, *args, **kwargs):
     if len(args) <= 0:
         return
     for arg in args:
         ldapobj = LDAPBackend()
         user = ldapobj.populate_user(arg)
         if user is not None and not user.is_anonymous():
             self.stdout.write("%s -> True" % arg)
         else:
             self.stdout.write("%s -> False" % arg)
         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()