def _collect_inventory(self): while True: val = raw_input("barcode, SHOW or 'END'. # ") if val == 'END': return elif val == 'SHOW': for sto in StockTake.objects.all(): print(sto) else: beerinst_pack = BeerInst.objects.filter(barcode_pack=val).first() beerinst_sing = BeerInst.objects.filter(barcode=val).first() if beerinst_pack is not None: st = StockTake(beerinst=beerinst_pack, quantity=beerinst_pack.quantity_pack) st.clean() st.save() print(st) last = st elif beerinst_sing is not None: st = StockTake(beerinst=beerinst_sing, quantity=1) st.clean() st.save() print(st) last = st else: print('NO SUCH BEER')
def _coalesce(self): # Get the set of all beerinsts referenced by for bi in BeerInst.objects.all(): quantity = StockTake.objects.filter(beerinst=bi).aggregate(quantity=models.Sum('quantity'))['quantity'] if quantity > 0: StockTake.objects.filter(beerinst=bi).delete() st = StockTake(beerinst=bi, quantity=quantity) st.clean() st.save()