Example #1
0
 def addExpense(self):
     errorslist = self.validate()
     
     if errorslist:
         obj = {
             'errors': errorslist
         }
         return json.dumps(obj)
     
     expenseType = request.POST['expenseType']
     payTo = request.POST['payTo']
     expenseAmount = '-'+request.POST['expenseAmount']
     expenseDate = request.POST['expenseDate']
     contactType = request.POST['contactType']
     contactId = request.POST['contactId']
     companyId = request.environ.get("COMPANY_ID")
     now = datetime.datetime.today()
     curHour = now.hour
     curMin = now.minute
     curSec = now.second
     date = expenseDate.split('/')
     date = datetime.datetime(int(date[2]),int(date[0]),int(date[1]),curHour,curMin,curSec)
     
     if contactType == 'unit':
         leaseId = Lease.get_current_of_unit(contactId)
         if not leaseId:
             leaseId = None
         unitInfo = Unit.get_unit_info(contactId)
         propertyId = unitInfo[2]
         payTo = payTo.split('#')
         prop = payTo[0]
         prop = prop.strip()
         unit = payTo[1]
         payTo = prop + ' #' + unit
         
         Transaction.create(
                                 id=str(uuid.uuid1()),
                                 leaseid=leaseId,
                                 unitid=contactId,
                                 companyid=companyId,
                                 propertyid=propertyId,
                                 type=expenseType,
                                 name=payTo,
                                 amount=expenseAmount,
                                 date=date
                                 )
     elif contactType == 'property':
         Transaction.create(
                                 id=str(uuid.uuid1()),
                                 companyid=companyId,
                                 propertyid=contactId,
                                 type=expenseType,
                                 name=payTo,
                                 amount=expenseAmount,
                                 date=date
                                 )
     elif contactType == 'tenant':
         leaseId = Tenant_lease.get_lease_of_tenant(contactId)
         if not leaseId:
             leaseId = None
         record = Tenant.get_tenantInfo(contactId)
         if record:
             unitId = record[0]
             propertyId = record[1]
         else:
             unitId = None
             propertyId = None
         Transaction.create(
                                 id=str(uuid.uuid1()),
                                 leaseid=leaseId,
                                 unitid=unitId,
                                 companyid=companyId,
                                 propertyid=propertyId,
                                 type=expenseType,
                                 name=payTo,
                                 amount=expenseAmount,
                                 date=date
                                 )
     elif contactType == 'contact':
         Transaction.create(
                                 id=str(uuid.uuid1()),
                                 contactid=contactId,
                                 companyid=companyId,
                                 type=expenseType,
                                 name=payTo,
                                 amount=expenseAmount,
                                 date=date
                                 )
     else:
         Transaction.create(
                                 id=str(uuid.uuid1()),
                                 companyid=companyId,
                                 type=expenseType,
                                 name=payTo,
                                 amount=expenseAmount,
                                 date=date
                                 )
     return json.dumps('')