Advertisement
Guest User

Untitled

a guest
Dec 26th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.88 KB | None | 0 0
  1. class ClientData(models.Model):
  2.  
  3.     ApiKey = models.CharField(max_length=256)
  4.     ApiSecretKey = models.CharField(max_length=256)
  5.     FirstName = models.CharField(max_length=50)
  6.     LastName = models.CharField(max_length=50)
  7.     MobilePhone = models.CharField(max_length=11,unique=True)
  8.     TransactionPin = models.CharField(max_length=4)
  9.     Dni = models.CharField(max_length=20,unique=True)
  10.     DniTypeChoice = {
  11.         ('1', 'V'),
  12.         ('2', 'E'),
  13.         ('3', 'J'),
  14.         ('4', 'P'),
  15.         ('5', 'G'),
  16.     }
  17.     DniType = models.CharField(max_length=1,
  18.                                choices=DniTypeChoice)
  19.     Country = models.ForeignKey(Country)
  20.     State = models.ForeignKey(State)
  21.     City = models.ForeignKey(City)
  22.     Address = models.CharField(max_length=500)
  23.     Email = models.EmailField(max_length=100,unique=True)
  24.     Company = models.CharField(max_length=100)
  25.  
  26.     CompanySectorChoice = {
  27.         ('1', 'Salud y Bienestar'),
  28.         ('2', 'Alimentos y bebidas'),
  29.         ('3', 'Casa y Oficina'),
  30.         ('4', 'Ropa y Accesorios'),
  31.         ('5', 'Entretenimiento y/o actividades recreativas'),
  32.         ('6', 'Transportacion'),
  33.         ('7', 'Alojamiento'),
  34.         ('8', 'Recaudacion de fondos'),
  35.         ('9', 'Venta al menudeo'),
  36.         ('10', 'Servicios Profesionales'),
  37.         ('11', 'Organizaciones civiles'),
  38.     }
  39.     CompanySector = models.CharField(max_length=2,
  40.                                      choices=CompanySectorChoice,
  41.                                      default=1)
  42.     Username = models.CharField(max_length=15, unique=True)
  43.     Password = models.CharField(max_length=128)
  44.     RegisterDate = models.DateTimeField(auto_now_add=True)
  45.     LastSeenDate = models.DateTimeField(auto_now_add=True)
  46.     IpAddress = models.CharField(max_length=255,default="0")
  47.     Balance = models.DecimalField(max_digits=9, decimal_places=2)
  48.     android_token = models.CharField(max_length=250,default="0")
  49.     ios_token = models.CharField(max_length=250,default="0")
  50.  
  51.  
  52.     ClientStatus = (
  53.         ('1', 'Auditando'),
  54.         ('2', 'Activa'),
  55.         ('3', 'Inactiva'),
  56.         ('4', 'Bloqueada'),
  57.     )
  58.     Status = models.CharField(max_length=1,
  59.                               choices=ClientStatus,
  60.                               default=2)
  61.  
  62.     def __unicode__(self):
  63.         return self.FirstName + ' ' + self.LastName
  64.  
  65.     def available_balance(self):
  66.         return self.Balance
  67.  
  68.     # Check Client Balance
  69.     def check_balance(self, amount, fee):
  70.         available_amount = float(self.Balance)
  71.         if amount != 0:
  72.             if amount > 0:
  73.                 if available_amount >= (amount + fee):
  74.                     return True
  75.                 else:
  76.                     return False
  77.             else:
  78.                 return False
  79.         else:
  80.             return False
  81.  
  82.     # Add Amount to Balance
  83.     def deposit(self, amount):
  84.         self.Balance = (self.Balance + amount)
  85.         self.save()
  86.  
  87.     # Subtract Amount from Balance
  88.     def withdraw(self, amount):
  89.         self.Balance = (self.Balance - amount)
  90.         self.save()
  91.  
  92.  
  93.     def daily_limit(self, amount_limit):
  94.  
  95.         try:
  96.             today = datetime.datetime.today()
  97.             TransactionObject = Client_Transaction.objects.filter(
  98.             ClientData=self,
  99.             TransactionDate__year=today.year,
  100.             TransactionDate__month=today.month,
  101.             TransactionDate__day=today.day).aggregate(Sum('Amount'))
  102.  
  103.             if TransactionObject['Amount__sum'] <= amount_limit or TransactionObject['Amount__sum'] == None:
  104.                 return True
  105.             else:
  106.                 return False
  107.         except:
  108.             return False
  109.  
  110.     def my_contacts(self):
  111.         try:
  112.             Contacts = ClientContactList.objects.filter(Client=self)
  113.             return Contacts
  114.         except ClientContactList.DoesNotExist:
  115.             return  None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement