def post(self):
        tOrderKey = self.request.get('orderid')

        #logging.debug("tOrderKey: " + tOrderKey)

        tPaOrder = PaOrder()
        tPaOrder = PaOrder.get(tOrderKey)

        tUser = users.get_current_user()
        tAgent = Agent().GetAgentByEmail(str(tUser.email()))

        if (tPaOrder.paOrderDeliver == False and tPaOrder.paOrderLock == False
                and tAgent.agentIsEnabled == True):
            tGoldAmount = tPaOrder.paAmountInt

            tGoldAmountLong = tGoldAmount
            tGoldAmount = tGoldAmount / 1000000

            if (tAgent.agentGoldSupply == None):
                tAgent.agentGoldSupply = 0

            tCommission = tGoldAmount * 0.05 + 0.50

            tAgent.agentGoldSupply = int(
                tAgent.agentGoldSupply) - int(tGoldAmountLong)
            tAgent.agentCurrentCommission = tAgent.agentCurrentCommission + tCommission
            tAgent.agentTotalCommission = tAgent.agentTotalCommission + tCommission

            tAgentOrders = tAgent.agentOrders  #Add order to agent pa orders
            tAgentOrders.append(tOrderKey)
            tAgent.agentOrders = tAgentOrders

            tAgent.agentCurrentOrderTotal = tAgent.agentCurrentOrderTotal + 1

            tAgentKey = tAgent.put()

            tPaOrder.paDeliveryAgent = str(tAgent.agentId)
            tPaOrder.paDeliveryAgentNick = tAgent.agentNickName
            tPaOrder.paOrderDeliver = True
            tPaOrder.paOrderLock = True
            tKey = tPaOrder.put()

            #logging.debug("Delivery by Agent: " + str(tAgentKey))
            #logging.debug("Delivery of Order: " + str(tKey))

            self.response.headers[
                'Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
            self.response.headers['Content-Type'] = 'Content-Type: plain/text'
            self.response.out.write("Order Delivered")
        else:
            #logging.debug('Attempted to Deliver ' + tOrderKey + " by Agent " + tAgent.agentId)
            self.response.headers[
                'Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
            self.response.headers['Content-Type'] = 'Content-Type: plain/text'
            self.response.out.write("Order Not Deliverable")
 def post(self):
     tOrderKey = self.request.get('orderid')
     
     #logging.debug("tOrderKey: " + tOrderKey)
     
     tPaOrder = PaOrder()
     tPaOrder = PaOrder.get(tOrderKey)
     
     tUser = users.get_current_user()
     tAgent = Agent().GetAgentByEmail(str(tUser.email()))
     
     if (tPaOrder.paOrderDeliver == False and tPaOrder.paOrderLock == False and tAgent.agentIsEnabled == True):
         tGoldAmount = tPaOrder.paAmountInt
         
         tGoldAmountLong = tGoldAmount
         tGoldAmount = tGoldAmount / 1000000
         
         if (tAgent.agentGoldSupply == None):
             tAgent.agentGoldSupply = 0
         
         tCommission = tGoldAmount * 0.05 + 0.50
         
         tAgent.agentGoldSupply = int(tAgent.agentGoldSupply) - int(tGoldAmountLong)
         tAgent.agentCurrentCommission = tAgent.agentCurrentCommission + tCommission
         tAgent.agentTotalCommission = tAgent.agentTotalCommission + tCommission
         
         tAgentOrders = tAgent.agentOrders #Add order to agent pa orders
         tAgentOrders.append(tOrderKey)
         tAgent.agentOrders = tAgentOrders           
         
         tAgent.agentCurrentOrderTotal = tAgent.agentCurrentOrderTotal + 1
         
         tAgentKey = tAgent.put()
         
         tPaOrder.paDeliveryAgent = str(tAgent.agentId)
         tPaOrder.paDeliveryAgentNick = tAgent.agentNickName
         tPaOrder.paOrderDeliver = True
         tPaOrder.paOrderLock = True
         tKey = tPaOrder.put()
         
         #logging.debug("Delivery by Agent: " + str(tAgentKey))
         #logging.debug("Delivery of Order: " + str(tKey))
         
         self.response.headers['Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
         self.response.headers['Content-Type'] = 'Content-Type: plain/text'
         self.response.out.write("Order Delivered")
     else:
         #logging.debug('Attempted to Deliver ' + tOrderKey + " by Agent " + tAgent.agentId)
         self.response.headers['Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
         self.response.headers['Content-Type'] = 'Content-Type: plain/text'
         self.response.out.write("Order Not Deliverable")    
 def post(self):
     tOrderKey = self.request.get('orderid')
     tAgentGold = self.request.get('agentgold')
     
     #logging.debug("tOrderKey: " + tOrderKey)
     #logging.debug("tAgentGold: " + tAgentGold)
     tOrder = Order()
     tOrder = Order.get(tOrderKey)
     tUser = users.get_current_user()
     tAgent = Agent().GetAgentByEmail(str(tUser.email()))
     
     if (tOrder.orderDeliver == "" or tOrder.orderDeliver == 'False' and tOrder.orderLocked != 'True' and tAgent.agentIsEnabled == True):
             
         tGoldAmount = tOrder.orderQuantity
         tPromoCode = ""
         tPromoCode = tOrder.orderPromotionalCode
         tPromo = Promo()
         tPromoCode = tPromoCode.lower()
         tReferCode = tOrder.orderReferralCode
         tCustomerLookup = CustomerHandler()
         tCustomer = Customer()
         
         tCustomer = Customer().get(str(tOrder.orderCustomer))
         # Promo codes get unlimited uses per customer
         # tUsedBonus = Order.GetCustomerPromoCodes(tCustomer.customerPaypalId)
         # tUsedBonus = tCustomer.customerUsedBonus
         # logging.debug("Customer used bonuses: " + str(tUsedBonus))
         # logging.debug("Order Promo Code: " + str(tPromoCode))
         tUsedBonus = [] 
         
         try:
             tPromo = Promo.GetPromoByCode(tPromoCode)
             # logging.debug(str(tPromo.promoGoldAmount))
             # logging.debug(str(tPromo.promoPercentage))
             # logging.debug(str(tPromo.promoIsActive))
             
             if ((tPromo.promoIsActive) and (tPromo.promoUses <= tPromo.promoLimit)):
                 if (tPromo.promoLimit != 0):
                     tPromo.promoUses = tPromo.promoUses + 1
                 
                 if((tPromoCode in tUsedBonus) == True):
                     tPercentBonus = 0.0
                 else:
                     tPercentBonus = float(tGoldAmount) * tPromo.promoPercentage
                     #tUsedBonus.append(tPromoCode)
                     
                 tGoldAmount = tGoldAmount + tPercentBonus
                 tGoldAmount = tGoldAmount + tPromo.promoGoldAmount
                 tTotalBonusFloat = tPercentBonus + tPromo.promoGoldAmount
                 tOrder.orderBonusQuantity = int(tTotalBonusFloat)     
         except:
             tOrder.orderBonusQuantity = 0
             
         tGoldAmountLong = tGoldAmount
         tGoldAmount = tGoldAmount / 1000000
         
         tOrderValue = float(tOrder.orderCost)
         
         #if(tOrder.orderIsGenerated == True):
             #tGoldAmountLong = 0
             #tGoldAmount = 0
         
             
         tStockManager = StockManager()
         tStockManager.LoadAccounts()            
         tStockManager.PlaceOrder(tGoldAmountLong * -1, tOrder.orderGoldType)            
                         
         #if tOrder.orderGoldType == '07':
             #tStockAccountManager.Set07Stock(int(tGoldAmountLong * -1))
         #else:
             #tStockAccountManager.SetEOCStock(int(tGoldAmountLong * -1))
                         
         tCommission = float(tOrderValue) * 0.05 + 0.50
         
         if tCommission >= 10.0:
             tCommission = 10.0                           
             
         tAgent.agentCurrentCommission = float(tAgent.agentCurrentCommission + tCommission)
         tAgent.agentTotalCommission = float(tAgent.agentTotalCommission + tCommission)                
         
         tAgentOrders = tAgent.agentOrders
         tAgentOrders.append(tOrderKey)
         tAgent.agentOrders = tAgentOrders
         tAgentKey = tAgent.put()
         tOrder.orderDeliveryAgent = str(tAgent.agentId)
         tOrder.orderAgent = str(tAgentKey)
         tOrder.orderDeliver = 'True'
         tKey = tOrder.put()
         
         #logging.debug("Delivery by Agent: " + str(tAgentKey))
         #logging.debug("Delivery of Order: " + str(tKey))
         
         #taskqueue.add(url='/calcreferral', countdown = 1, params={'key' : str(tKey) } )
         
         self.response.headers['Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
         self.response.headers['Content-Type'] = 'Content-Type: plain/text'
         self.response.out.write("Order Delivered")
     else:
         #logging.debug('Attempted to Deliver ' + tOrderKey + " by Agent " + tAgent.agentId)
         self.response.headers['Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
         self.response.headers['Content-Type'] = 'Content-Type: plain/text'
         self.response.out.write("Order Not Deliverable")
示例#4
0
    def GetContext(self):
        tContext = {}
        tAgent = Agent()
        tAgentHandler = AgentHandler()
        tOrders = []
        tOrder = Order()
        tUser = self.USER

        tAgentQuery = Agent().all()
        tAgentQuery.filter('agentOnline', True)
        tAgents = tAgentQuery.fetch(100)
        if (len(tAgents) > 0):
            tContext['agentnum'] = len(tAgents)
            tContext['agents'] = tAgents
        try:
            tAgent = Agent().GetAgentByEmail(str(tUser.email()))
        except:
            pass
        if (tAgent.agentId == 'No Agent'):
            tAgent.agentCurrentCommission = 0.0
            tAgent.agentTotalCommission = 0.0
            tAgent.agentOrders = []
            tAgent.agentId = str(tUser.email())
            tAgent.agentGoldSupply = 0
            tAgent.agentOnline = False
            tAgent.put()

        if (tAgent.agentGoldSupply == None):
            tAgent.agentGoldSupply = 0

        tOrderQuery = PaOrder.all()
        tOrderQuery.filter("paDeliveryAgent", tAgent.agentId)
        tOrderQuery.order("-paDateDelivered")
        tOrdersRaw = tOrderQuery.fetch(50)

        tAgentDonorsQuery = DonorRecord.all()
        tAgentDonorsQuery.filter('donorAgent', tAgent.agentId)
        tAgentDonorsQuery.order('-donorDate')
        tAgentDonations = tAgentDonorsQuery.fetch(20)

        for o in tOrdersRaw:
            tOrder = o
            if (tOrder != None):
                tOrders.append(tOrder)

        #tGoldSupply = tAgent.agentGoldSupply

        logging.debug('Original eoc ' + str(tAgent.agentGoldSupplyEoc))
        logging.debug('Original 07 ' + str(tAgent.agentGoldSupply07))

        tEocString = NumberToGp.ConvertIntToBet(tAgent.agentGoldSupplyEoc)
        t07String = NumberToGp.ConvertIntToBet(tAgent.agentGoldSupply07)

        logging.debug('Stringed version eoc ' + tEocString)
        logging.debug('Stringed version 07 ' + t07String)

        #tAgent.__setattr__('agentGoldSupplyEocString', tEocString)
        #tAgent.__setattr__('agentGoldSupply07String', t07String)

        tContext['agent'] = tAgent
        tContext['gpeocstring'] = str(tEocString)
        tContext['gp07string'] = str(t07String)
        #tContext['agentgold'] = locale.format("%d", int(tGoldSupply), grouping = True)
        tContext['orders'] = tOrders
        tContext['agentcomm'] = locale.format("%0.2f",
                                              tAgent.agentCurrentCommission,
                                              grouping=True)
        tContext['agenttotal'] = locale.format("%0.2f",
                                               tAgent.agentTotalCommission,
                                               grouping=True)
        tContext['donations'] = tAgentDonations
        return tContext
示例#5
0
    def post(self):
        tOrderKey = self.request.get('orderid')
        tAgentGold = self.request.get('agentgold')

        #logging.debug("tOrderKey: " + tOrderKey)
        #logging.debug("tAgentGold: " + tAgentGold)
        tOrder = Order()
        tOrder = Order.get(tOrderKey)
        tUser = users.get_current_user()
        tAgent = Agent().GetAgentByEmail(str(tUser.email()))

        if (tOrder.orderDeliver == "" or tOrder.orderDeliver == 'False'
                and tOrder.orderLocked != 'True'
                and tAgent.agentIsEnabled == True):

            tGoldAmount = tOrder.orderQuantity
            tPromoCode = ""
            tPromoCode = tOrder.orderPromotionalCode
            tPromo = Promo()
            tPromoCode = tPromoCode.lower()
            tReferCode = tOrder.orderReferralCode
            tCustomerLookup = CustomerHandler()
            tCustomer = Customer()

            tCustomer = Customer().get(str(tOrder.orderCustomer))
            # Promo codes get unlimited uses per customer
            # tUsedBonus = Order.GetCustomerPromoCodes(tCustomer.customerPaypalId)
            # tUsedBonus = tCustomer.customerUsedBonus
            # logging.debug("Customer used bonuses: " + str(tUsedBonus))
            # logging.debug("Order Promo Code: " + str(tPromoCode))
            tUsedBonus = []

            try:
                tPromo = Promo.GetPromoByCode(tPromoCode)
                # logging.debug(str(tPromo.promoGoldAmount))
                # logging.debug(str(tPromo.promoPercentage))
                # logging.debug(str(tPromo.promoIsActive))

                if ((tPromo.promoIsActive)
                        and (tPromo.promoUses <= tPromo.promoLimit)):
                    if (tPromo.promoLimit != 0):
                        tPromo.promoUses = tPromo.promoUses + 1

                    if ((tPromoCode in tUsedBonus) == True):
                        tPercentBonus = 0.0
                    else:
                        tPercentBonus = float(
                            tGoldAmount) * tPromo.promoPercentage
                        #tUsedBonus.append(tPromoCode)

                    tGoldAmount = tGoldAmount + tPercentBonus
                    tGoldAmount = tGoldAmount + tPromo.promoGoldAmount
                    tTotalBonusFloat = tPercentBonus + tPromo.promoGoldAmount
                    tOrder.orderBonusQuantity = int(tTotalBonusFloat)
            except:
                tOrder.orderBonusQuantity = 0

            tGoldAmountLong = tGoldAmount
            tGoldAmount = tGoldAmount / 1000000

            tOrderValue = float(tOrder.orderCost)

            #if(tOrder.orderIsGenerated == True):
            #tGoldAmountLong = 0
            #tGoldAmount = 0

            tStockManager = StockManager()
            tStockManager.LoadAccounts()
            tStockManager.PlaceOrder(tGoldAmountLong * -1,
                                     tOrder.orderGoldType)

            #if tOrder.orderGoldType == '07':
            #tStockAccountManager.Set07Stock(int(tGoldAmountLong * -1))
            #else:
            #tStockAccountManager.SetEOCStock(int(tGoldAmountLong * -1))

            tCommission = float(tOrderValue) * 0.05 + 0.50

            if tCommission >= 10.0:
                tCommission = 10.0

            tAgent.agentCurrentCommission = float(
                tAgent.agentCurrentCommission + tCommission)
            tAgent.agentTotalCommission = float(tAgent.agentTotalCommission +
                                                tCommission)

            tAgentOrders = tAgent.agentOrders
            tAgentOrders.append(tOrderKey)
            tAgent.agentOrders = tAgentOrders
            tAgentKey = tAgent.put()
            tOrder.orderDeliveryAgent = str(tAgent.agentId)
            tOrder.orderAgent = str(tAgentKey)
            tOrder.orderDeliver = 'True'
            tKey = tOrder.put()

            #logging.debug("Delivery by Agent: " + str(tAgentKey))
            #logging.debug("Delivery of Order: " + str(tKey))

            #taskqueue.add(url='/calcreferral', countdown = 1, params={'key' : str(tKey) } )

            self.response.headers[
                'Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
            self.response.headers['Content-Type'] = 'Content-Type: plain/text'
            self.response.out.write("Order Delivered")
        else:
            #logging.debug('Attempted to Deliver ' + tOrderKey + " by Agent " + tAgent.agentId)
            self.response.headers[
                'Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
            self.response.headers['Content-Type'] = 'Content-Type: plain/text'
            self.response.out.write("Order Not Deliverable")