def create(self, data): t = super(ApproTransactionSerializer, self).create(data) stockitem_map = {} total = 0 for i in data["items"]: buyitem = i["buyitem"] qty = i["qty"] priceobj, _ = BuyItemPrice.objects.get_or_create(bar=t.bar, buyitem=buyitem) if "price" in i: priceobj.price = i["price"] / qty priceobj.save() total += i["price"] else: total += priceobj.price * qty try: stockitem = StockItem.objects.get(bar=t.bar, details=buyitem.details) if stockitem.id not in stockitem_map: stockitem_map[stockitem.id] = {'stockitem': stockitem, 'delta': 0} stockitem_map[stockitem.id]['delta'] += qty * buyitem.itemqty except: t.delete() raise Http404("Stockitem does not exist") for x in stockitem_map.values(): x['stockitem'].create_operation(delta=x['delta'], unit='buy', transaction=t) t.accountoperation_set.create( target=get_default_account(t.bar), delta=-total) return t
def create(self, data): t = super(BarInvestmentTransactionSerializer, self).create(data) t.accountoperation_set.create( target=get_default_account(t.bar), delta=-data["amount"]) t.transactiondata_set.create( label='motive', data=data["motive"]) return t
def create(self, data): t = super(WithdrawTransactionSerializer, self).create(data) t.accountoperation_set.create( target=data["account"], delta=-data["amount"]) t.accountoperation_set.create( target=get_default_account(t.bar), delta=-data["amount"]) return t
def create(self, data): t = super(DepositTransactionSerializer, self).create(data) t.accountoperation_set.create( target=data["account"], delta=data["amount"]) t.accountoperation_set.create( target=get_default_account(t.bar), delta=data["amount"]) t.moneyflow = data["amount"] t.save() return t
def create(self, data): t = super(RefundTransactionSerializer, self).create(data) t.accountoperation_set.create( target=data["account"], delta=data["amount"]) t.accountoperation_set.create( target=get_default_account(t.bar), delta=data["amount"]) t.transactiondata_set.create( label='motive', data=data["motive"]) t.moneyflow = data["amount"] t.save() return t
def setUpClass(self): super(ApproSerializerTests, self).setUpClass() self.bar_account = get_default_account(self.bar)
def setUpClass(self): super(DepositSerializerTests, self).setUpClass() self.bar_account = get_default_account(self.bar) self.wrong_bar_account = get_default_account(self.wrong_bar)