Exemplo n.º 1
0
 def _user_balance(self, valuta):
     q = self.profilebalance_set.filter(
         valuta=Valuta.objects.filter(value=valuta),
         profile=self,
         cancel=False,
         confirm=True)
     if not q:
         return _Zero
     _c1 = q.filter(accept=True).count()
     _c2 = q.aggregate(Sum('value')).get('value__sum') or _Zero
     md5key = strmd5sum("_user_balance" + str(q.count()) + str(valuta) +
                        str(self.pk) + str(_c1) + str(_c2))
     b = cache.get(md5key)
     if b is None:
         balance_plus = sum(
             q.filter(action="+", accept=True).distinct().extra(select={
                 'total':
                 """
                         CASE
                             WHEN users_profilebalance.min_commission and (users_profilebalance.value * users_profilebalance.commission / 100) < users_profilebalance.min_commission THEN users_profilebalance.value - users_profilebalance.min_commission
                             WHEN users_profilebalance.max_commission > 0 and (users_profilebalance.value * users_profilebalance.commission / 100) > users_profilebalance.max_commission THEN users_profilebalance.value - users_profilebalance.max_commission
                             ELSE (users_profilebalance.value * (1 - users_profilebalance.commission / 100))
                         END
                         """
             }, ).only('id').values_list('total', flat=True)) or _Zero
         balance_plus = normalized(balance_plus, where="DOWN")
         balance_minus = q.filter(action="-").distinct().aggregate(
             total=Sum('value')).get('total') or _Zero
         balance_minus = normalized(balance_minus, where="DOWN")
         b = balance_plus - balance_minus
         cache.set(md5key, b)
     return b
Exemplo n.º 2
0
 def calc(self, amount, rate, ttype, totext=None):
     amount = D(amount)
     rate = D(rate)
     total = normalized(amount * rate, where="DOWN")
     if ttype == 'sale':
         _amo = total
         pos = self.right
     else:
         _amo = amount
         pos = self.left
     commission = normalized(_amo * self.commission / D(100))
     if totext:
         return floatformat(total, -8), floatformat(commission, -8), pos
     return total, commission, pos
Exemplo n.º 3
0
 def w_transaction(self):
     if self.action == "+":
         value = self.value
     elif self.action == "-":
         value = normalized(self.value - self._commission_debit,
                            where="DOWN")
     return "%s %s" % (floatformat(value, -8), self.valuta)
Exemplo n.º 4
0
 def total_admin(self):
     v = normalized(self.value - self._commission_debit, where="DOWN")
     return floatformat(v, -8)
Exemplo n.º 5
0
 def _total(self):
     if self.action == "+":
         return normalized(self.value - self._commission_debit,
                           where="DOWN")
     elif self.action == "-":
         return self.value
Exemplo n.º 6
0
 def _debit_right(self):
     # usd
     #return self._total
     # 600
     return normalized(self._total - self._commission_debit, where="DOWN")
Exemplo n.º 7
0
 def _debit_left(self):
     # btc
     # 427
     #return self._total
     return normalized(self._total - self._commission_debit, where="DOWN")
Exemplo n.º 8
0
 def total(self):
     return normalized(self._total - self._commission_debit, where="DOWN")
Exemplo n.º 9
0
 def commiss(self):
     return floatformat(normalized(self._commission_debit), -8)