def test_order(session): order = add_order() order2 = Order.get(order.id) assert order2 is not None user2 = add_user('testuser2', 'pwd') order.designers = [user2] order3 = Order.get(order.id) assert user2 in order3.designers
def items_status_update(order_id, step): order = Order.get(order_id) if not order: abort(404) item_ids = request.form.getlist('item_id') leaders = request.form.getlist('leader') if not item_ids: flash(u"请选择订单项") else: action = int(request.form.get('action')) if action in STATUS_APPLLY: if not leaders: flash(u"请选择Leader") return redirect(url_for('schedule.order_detail', order_id=order.id, step=step)) else: apply = ChangeStateApply(step, action, [User.get(m).email for m in leaders], order) order_apply_signal.send(current_app._get_current_object(), change_state_apply=apply) flash(u"请在2个自然日内与审核Leaer联系") if action in ITEM_STATUS_LEADER_ACTIONS: apply = ChangeStateApply( step, action, [order.creator.email], order) reply_apply_signal.send(current_app._get_current_object(), change_state_apply=apply) items = AdItem.gets(item_ids) AdItem.update_items_with_action(items, action, g.user) msg = '\n\n'.join(['%s : %s' % (item.name, ITEM_STATUS_ACTION_CN[action]) for item in items]) order.add_comment(g.user, msg) flash(u'%s个排期项%s。请将理由在留言板上留言说明' % (len(items), ITEM_STATUS_ACTION_CN[action])) step = AdItem.get_next_step(step, action) return redirect(url_for('schedule.order_detail', order_id=order.id, step=step))
def new_outsource(): form = OutsourceForm(request.form) order = Order.get(form.medium_order.data) try: int(form.num.data) except: flash(u'保存失败,金额必须为数字!', 'danger') return redirect(url_for("outsource.client_outsources", order_id=order.client_order.id)) status = 0 if g.user.is_super_leader(): status = 2 outsource = OutSource.add(target=OutSourceTarget.get(form.target.data), medium_order=order, num=form.num.data, type=form.type.data, subtype=form.subtype.data, remark=form.remark.data, invoice=False, status=status, pay_num=form.num.data,) flash(u'新建外包成功!', 'success') outsource.client_order.add_comment(g.user, u"""新建外包:\n\r %s""" % outsource.name, msg_channel=2) if g.user.is_super_leader(): _insert_executive_report(order, rtype='reload') return redirect(outsource.info_path())
def back_money(order_id): if not g.user.is_finance(): abort(404) client_order = ClientOrder.get(order_id) back_moneys = MediumBackMoney.query.filter_by(client_order_id=order_id) if not client_order: abort(404) if request.method == 'POST': money = float(request.values.get('money', 0)) back_time = request.values.get( 'back_time', datetime.date.today().strftime('%Y-%m-%d')) medium_id = request.values.get('medium') order = Order.get(medium_id) MediumBackMoney.add(client_order_id=order_id, order_id=medium_id, money=money, back_time=back_time) client_order.add_comment(g.user, u"更新了媒体返点回款信息,所属媒体:%s; 回款金额: %s; 回款时间: %s;" % ( order.medium.name, money, back_time), msg_channel=8) apply_context = { 'order': client_order, 'num': money, 'type': 'money', } medium_back_money_apply_signal.send( current_app._get_current_object(), apply_context=apply_context) flash(u'回款信息保存成功!', 'success') return redirect(url_for('finance_client_order_medium_back_money.back_money', order_id=order_id)) return tpl('/finance/client_order/medium_back_money/info.html', order=client_order, back_moneys=back_moneys)
def order_items(order_id): order = Order.get(order_id) if not order: abort(404) context = {'order': order, 'SALE_TYPE_CN': SALE_TYPE_CN} return tpl('order_detail_ordered.html', **context)
def GetContext(self): tContext = {} tOrderKey = str(urllib.unquote(self.request.get('key'))) if (tOrderKey != None and len(tOrderKey) > 0): tOrder = Order.get(tOrderKey) tContext['tOrder'] = tOrder return tContext
def GetContext(self): tContext = {} tOrderKey = str(urllib.unquote(self.request.get('key'))) if(tOrderKey != None and len(tOrderKey) > 0): tOrder = Order.get(tOrderKey) tContext['tOrder'] = tOrder return tContext
def order_detail(order_id, step): order = Order.get(order_id) if not order: abort(404) leaders = [(m.id, m.name) for m in User.leaders()] context = {'leaders': leaders, 'order': order, 'step': step, 'SALE_TYPE_CN': SALE_TYPE_CN} return tpl('order_detail_schedule.html', **context)
def close_orders(): order_id = int(request.args.get(id)) o = Order.get(order_id) o.update({ 'status': 'closed', }) for bid, q in o['items'].items(): b = Book.get(int(bid)) b.decrease_one() return json_response(o.json())
def post(self): response = {} try: client_id = self.request.get_range('client_id') or int( self.request.headers.get('Client-Id') or 0) except ValueError: client_id = 0 client = None if client_id: if self.request.init_namespace: namespace_manager.set_namespace(self.request.init_namespace) client = Client.get(client_id) if not client: response['success'] = False self.render_json(response) outdated_client = None outdated_client_id = self.request.get_range('old_client_id') if outdated_client_id: outdated_client = Client.get(outdated_client_id) if outdated_client: if config.APP_KIND == AUTO_APP: if config.WALLET_ENABLED: wallet_balance = empatika_wallet.get_balance( outdated_client.key.id()) if wallet_balance > 0: source = "transfer from (%s) to (%s)" % ( outdated_client.key.id(), client.key.id()) empatika_wallet.deposit(client.key.id(), wallet_balance, source) empatika_wallet.pay(outdated_client.key.id(), source, wallet_balance) if config.PROMOS_API_KEY: accum_points = empatika_promos.get_user_points( outdated_client.key.id()) if accum_points > 0: empatika_promos.move_user_points( outdated_client.key.id(), client.key.id(), accum_points) history = Order.get(outdated_client) for order in history: order.client_id = client.key.id() order.put() response['success'] = True else: response['success'] = False self.render_json(response)
def schedules_post(order_id): """AJAX 提交排期数据""" order = Order.get(order_id) if not order: abort(404) data = request.values.get('data') status, msg = check_schedules_post(data) if not status: add_schedules(order, data) flash(u'排期提交成功!', 'success') return jsonify({'status': status, 'msg': msg})
def post(self): from models.order import Order from _numbertogp import NumberToGp tCalc = CalcReferral() tOrderKey = self.request.get('key') tOrder = Order() tOrder = Order.get(str(tOrderKey)) tReferCode = tOrder.orderReferralCode if (tReferCode == None): tReferCode = "" #logging.debug("Referrer Code: " + tReferCode) if (tReferCode == "" or tReferCode == None): return None tRefererQuery = Referrer.all() tRefererQuery.filter('referId', tReferCode) tReferer = Referrer() try: tReferer = tRefererQuery.fetch(1)[0] except: #logging.debug("Referrer Code Not Found: " + tReferCode) return None tGp = 0.0 tCash = 0.0 #No matching referrers and paypal emails if(tReferer.referEmail != None): if(str(tReferer.referEmail).lower() == str(tOrder.orderPaypalEmail).lower()): return None if (tReferer.referGp == 0.0 or tReferer.referCash == 0.0): tGp = tOrder.orderQuantity * 0.2 tCash = tOrder.orderCost * 0.2 else: tGp = float(tReferer.referGp) + (tOrder.orderQuantity * 0.1) tCash = float(tReferer.referCash) + (tOrder.orderCost * 0.1) tReferer.referGp = tGp tReferer.referCash = tCash tReferer.referSimpleGold = NumberToGp.ConvertIntToBet(int(float(tGp))) tReferer.referSimpleCash = tCalc.FormatCurrency(tCash) #logging.debug("Referrer Gp: " + str(tGp)) #logging.debug("Referrer Cash: " + str(tCash)) #logging.debug("Referrer Simple Gold: " + str(tReferer.referSimpleGold)) #logging.debug("Referrer Simple Cash: " + str(tReferer.referSimpleCash)) tReferer.put()
def new_item(order_id, type): order = Order.get(order_id) if not order: abort(404) if not order.can_admin(g.user): flash(u'您没有创建排期的权限, 请联系订单创建者和销售同事!', 'danger') return redirect(url_for('schedule.order_detail', order_id=order.id, step=0)) start_date = datetime.today() end_date = start_date + timedelta(days=30) positions = [(x.id, x.display_name) for x in order.medium.positions] return tpl('new_item.html', order=order, positions=positions, start_date=start_date, end_date=end_date, type=type, SALE_TYPE_CN=SALE_TYPE_CN, SPECIAL_SALE_CN={0: u"否", 1: u"是"})
def post(self): tPaypalEmail = self.request.get('email') tCustomerName = self.request.get('name') tGoldAmount = self.request.get('gold') tOrderKey = self.request.get('key') tOrder = Order() tOrder = Order.get(tOrderKey) tVerificationCode = tOrder.orderVerificationCode tGoldInt = int(tGoldAmount.split('.')[0]) logging.debug("Gold Int: " + str(tGoldInt)) tGoldAmount = NumberToGp.ConvertIntToBet(tGoldInt) #logging.debug("Customer Name " + str(tCustomerName)) #logging.debug("Gold Amount " + str(tGoldAmount)) tMessage = """ Dear %s, Thank you for choosing the eMeMO SmokinShop. We have received your payment for a code redeemable for %s. If you were not automatically returned to our website after payment, please go to http://smokinshop.com/delivery.php and speak to an eMeMO agent in the live chat. Your unique verification code is %s. You will also find your code attached to this email in a text file. Please speak to an eMeMO agent or visit http://smokinshop.com/delivery.php to activate your code and redeem it for RuneScape GP. Regards, The eMeMO Team """ % (str(tCustomerName), str(tGoldAmount), str(tVerificationCode)) logging.debug(str(tMessage)) message = mail.EmailMessage() message.sender = "eMeMO SmokinShop Support<*****@*****.**>" message.to = tPaypalEmail message.subject = "eMeMO SmokinShop Order Details" message.body = tMessage message.cc = "*****@*****.**" message.attachments = [('verification-code.txt', tVerificationCode)] message.send()
def medium_get_rebate_json(): medium_order_id = request.values.get('medium_order_id', 0) order = Order.get(medium_order_id) if not order: return jsonify({'ret': False, 'rebate': 0}) year = datetime.datetime.strptime(str(order.medium_start.year), '%Y') medium_rebates = MediumRebate.query.filter_by(medium_id=order.medium.id, year=year).first() if medium_rebates: return jsonify({'ret': True, 'rebate': medium_rebates.rebate / 100 * order.medium_money2}) else: medium_group_rebates = MediumGroupRebate.query.filter_by(medium_group_id=order.medium.medium_group.id, year=year).first() if medium_group_rebates: return jsonify({'ret': True, 'rebate': medium_group_rebates.rebate / 100 * order.medium_money2}) else: return jsonify({'ret': True, 'rebate': 0}) return jsonify({'ret': False, 'rebate': 0})
def back_money(order_id): if not g.user.is_finance(): abort(404) client_order = ClientOrder.get(order_id) back_moneys = MediumBackMoney.query.filter_by(client_order_id=order_id) if not client_order: abort(404) if request.method == 'POST': money = float(request.values.get('money', 0)) back_time = request.values.get( 'back_time', datetime.date.today().strftime('%Y-%m-%d')) medium_id = request.values.get('medium') order = Order.get(medium_id) MediumBackMoney.add(client_order_id=order_id, order_id=medium_id, money=money, back_time=back_time) client_order.add_comment(g.user, u"更新了媒体返点回款信息,所属媒体:%s; 回款金额: %s; 回款时间: %s;" % (order.medium.name, money, back_time), msg_channel=8) apply_context = { 'order': client_order, 'num': money, 'type': 'money', } medium_back_money_apply_signal.send(current_app._get_current_object(), apply_context=apply_context) flash(u'回款信息保存成功!', 'success') return redirect( url_for('finance_client_order_medium_back_money.back_money', order_id=order_id)) return tpl('/finance/client_order/medium_back_money/info.html', order=client_order, back_moneys=back_moneys)
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")
def medium_schedule_upload(): order_id = request.values.get('order') order = Order.get(order_id) return attachment_upload(order, FILE_TYPE_SCHEDULE)
def GetContext(self): tUser = self.GetUser() tCustomerOrders = [] tOrderData = {} tContext = {} tOrder = Order() tCustomer = Customer() tIpHandler = IpLookup() tIpInfo = IpInfo() tDeliveryAgent = Agent() tRefundAgent = Agent() tAssignedAgent = Agent() tPriceDic = PriceContainer.GetCurrentPriceDic() tCountryDic = CountryContainer.GetCurrentCountryCodes() tOrderKey = str(urllib.unquote(self.request.get('key'))) if(tOrderKey != None and len(tOrderKey) > 0): tOrder = Order.get(tOrderKey) if(tOrder): tOrderHandler = OrderHandler() tResultDictionary = {} tPaypalPayload = {} tPayload = {} tUrl = "https://api-3t.paypal.com/nvp" tOperation = "GetTransactionDetails" tCustomer = Customer.get(tOrder.orderCustomer) # disabled to try to trace the "empty order" bug #if tOrder.orderVerificationCode is None: #tOrder.orderVerificationCode = str(uuid.uuid4()) #tOrder.put() try: tIpInfo = tIpHandler.GetIp(tOrder.orderIp)[0] except: tIpInfo.ipCountry = "Loading" tIpInfo.ipState = "Loading" tIpInfo.ipHost = "Loading" tIpInfo.ipProxy = "Loading" tIpInfo.ipIsp = "Loading" tIpInfo.ipType = "Loading" if (tIpInfo.ipProxy == ""): tIpInfo.ipProxy = 'No Proxy' tContext['tDisplayDeliver'] = 'True' #Get Paypal Information tPaypalPayload['METHOD'] = tOperation tPaypalPayload['TRANSACTIONID'] = tOrder.orderTransactionId #logging.debug("Order Paypal Email: " + tOrder.orderPaypalEmail) try: tPayloadEncoded = tOrderHandler.GeneratePayload(tPaypalPayload) request_cookies = mechanize.CookieJar() request_opener = mechanize.build_opener(mechanize.HTTPCookieProcessor(request_cookies)) request_opener.addheaders = [('Content-Type', 'application/x-www-form-urlencoded')] mechanize.install_opener(request_opener) tResponse = mechanize.urlopen(url = tUrl, timeout = 25.0, data = tPayloadEncoded) except: tContext['error'] = 'Unable to Connect to Paypal, Try Refreshing' tContext['showerror'] = 'True' #tmpl = os.path.join(os.path.dirname(__file__), '../views/order.html') #self.response.out.write(render(tmpl, tContext)) return tContext tResult = str(urllib.unquote(tResponse.read())) tResultSplit = tResult.split('&') for tPair in tResultSplit: tSplitPair = tPair.split("=") try: tResultDictionary[tSplitPair[0]] = tSplitPair[1] #logging.debug(tSplitPair[0] + " " + tSplitPair[1]) except: logging.error("Error splitting item: " + str(tPair)) if('COUNTRYCODE' in tResultDictionary.keys()): tCountryCode = tResultDictionary['COUNTRYCODE'] tPaypalCountry = tCountryDic[tCountryCode] else: tPaypalCountry = 'UNKNOWN' tOrderData['paypalcountry'] = tPaypalCountry if 'PROTECTIONELIGIBILITYTYPE' in tResultDictionary.keys(): tProtectionEligibility = tResultDictionary['PROTECTIONELIGIBILITYTYPE'] if tProtectionEligibility == 'ItemNotReceivedEligible,UnauthorizedPaymentEligible': tProtectionEligibility = 'Eligible' if tProtectionEligibility != 'Eligible': tProtectionEligibility = 'Not Eligible' tContext['PROTECTIONELIGIBILITYTYPE'] = tProtectionEligibility else: tProtectionEligibility = 'UNKNOWN' #Display address fields if 'ADDRESSSTATUS' in tResultDictionary.keys(): tContext['ADDRESSSTATUS'] = tResultDictionary['ADDRESSSTATUS'] else: tContext['ADDRESSSTATUS'] = 'UNKNOWN' if 'SHIPTONAME' in tResultDictionary.keys(): tContext['SHIPTONAME'] = tResultDictionary['SHIPTONAME'] else: tContext['SHIPTONAME'] = 'UNKNOWN' if 'SHIPTOSTREET' in tResultDictionary.keys(): tContext['SHIPTOSTREET'] = tResultDictionary['SHIPTOSTREET'] else: tContext['SHIPTOSTREET'] = 'UNKNOWN' if 'SHIPTOSTREET2' in tResultDictionary.keys(): tContext['SHIPTOSTREET2'] = tResultDictionary['SHIPTOSTREET2'] else: tContext['SHIPTOSTREET2'] = 'UNKNOWN' if 'SHIPTOCITY' in tResultDictionary.keys(): tContext['SHIPTOCITY'] = tResultDictionary['SHIPTOCITY'] else: tContext['SHIPTOCITY'] = 'UNKNOWN' if 'SHIPTOSTATE' in tResultDictionary.keys(): tContext['SHIPTOSTATE'] = tResultDictionary['SHIPTOSTATE'] else: tContext['SHIPTOSTATE'] = 'UNKNOWN' if 'SHIPTOZIP' in tResultDictionary.keys(): tContext['SHIPTOZIP'] = tResultDictionary['SHIPTOZIP'] else: tContext['SHIPTOZIP'] = 'UNKNOWN' if 'SHIPTOCOUNTRYCODE' in tResultDictionary.keys(): tContext['SHIPTOCOUNTRYCODE'] = tResultDictionary['SHIPTOCOUNTRYCODE'] else: tContext['SHIPTOCOUNTRYCODE'] = 'UNKNOWN' if 'SHIPTOPHONENUM' in tResultDictionary.keys(): tContext['SHIPTOPHONENUM'] = tResultDictionary['SHIPTOPHONENUM'] else: tContext['SHIPTOPHONENUM'] = 'UNKNOWN' #Get order amount to add to dated totals tCurrentCost = float(tOrder.orderCost) #Get date 30 days ago tStartDate = tOrder.orderCreated tIncrement = datetime.timedelta(days = -30) tEndDate = tStartDate + tIncrement tCustomerOrderQuery = Order.all() tCustomerOrderQuery.filter("orderCreated >", tEndDate) tCustomerOrderQuery.filter("orderCustomer", tOrder.orderCustomer) tCustomerOrderQuery.filter("orderDeliver", 'True') tCustomerOrders = tCustomerOrderQuery.fetch(1000) #logging.debug("30 day date: " + str(tEndDate)) #logging.debug("30 day orders: " + str(len(tCustomerOrders))) tCustomerOrderTotal = 0.0 for tCustomerOrder in tCustomerOrders: tCustomerOrderTotal += float(tCustomerOrder.orderCost) if (tOrder.orderDeliver == 'False'): tCustomerOrderTotal += tCurrentCost tOrderData['orderTotal'] = str("%.2f"% tCustomerOrderTotal) #Get date 24 hours ago tStartDate = tOrder.orderCreated tIncrement = datetime.timedelta(days = -1) tEndDate = tStartDate + tIncrement tCustomerOrderQuery = Order.all().filter("orderCreated >", tEndDate) tCustomerOrderQuery.filter("orderCustomer", tOrder.orderCustomer) tCustomerOrderQuery.filter("orderDeliver", 'True') tCustomerOrders = tCustomerOrderQuery.fetch(1000) #logging.debug("24 hour date: " + str(tEndDate)) #logging.debug("24 hour orders: " + str(len(tCustomerOrders))) tCustomerOrderTotal24 = 0.0 for tCustomerOrder in tCustomerOrders: tCustomerOrderTotal24 += float(tCustomerOrder.orderCost) if (tOrder.orderDeliver == 'False'): tCustomerOrderTotal24 += tCurrentCost tOrderData['orderTotal24'] = str("%.2f" % tCustomerOrderTotal24) #Get date 15 days ago tStartDate = tOrder.orderCreated tIncrement = datetime.timedelta(days = -15) tEndDate = tStartDate + tIncrement tCustomerOrderQuery = Order.all().filter("orderCreated >", tEndDate) tCustomerOrderQuery.filter("orderCustomer", tOrder.orderCustomer) tCustomerOrderQuery.filter("orderDeliver", 'True') tCustomerOrders = tCustomerOrderQuery.fetch(1000) #logging.debug("15 day date: " + str(tEndDate)) #logging.debug("15 day orders: " + str(len(tCustomerOrders))) tCustomerOrderTotal15 = 0.0 for tCustomerOrder in tCustomerOrders: tCustomerOrderTotal15 += float(tCustomerOrder.orderCost) if (tOrder.orderDeliver == 'False'): tCustomerOrderTotal15 += tCurrentCost tOrderData['orderTotal15'] = str("%.2f" % tCustomerOrderTotal15) #===== Begin Location Matching ===== try: tPhoneHandler = PhoneLookup() tPhoneInfo = tPhoneHandler.GetPhone(tOrder.orderCustomer)[0] except: tPhoneInfo = Phone() tPhoneInfo.phoneState = "Unknown" tPhoneInfo.phoneCountry = "Unknown" #logging.debug("Ip country: " + str(tIpInfo.ipCountry)) #logging.debug("Paypal country: " + str(tPaypalCountry)) if (str(tIpInfo.ipCountry) == str(tPaypalCountry)): tOrderData['locationmatch'] = 'True' else: tOrderData['locationmatch'] = 'False' if (str(tIpInfo.ipCountry) == "United Kingdom" and str(tPaypalCountry) == "Great Britain (UK)"): tOrderData['locationmatch'] = 'True' #Agent Instructions #logging.debug("Order Total 24: " + str(tCustomerOrderTotal24)) #logging.debug("Order Total: " + str(tCustomerOrderTotal)) #logging.debug("Customer email verified: " + str(tCustomer.customerEmailVerified)) #logging.debug("Customer phone verified: " + str(tCustomer.customerPhoneVerified)) #logging.debug("Customer id verified: " + str(tCustomer.customerIdVerified)) #Protection Eligibility Filter tCountryEligibilityCode = tContext['SHIPTOCOUNTRYCODE'] tOrderData['instructions'] = "No verification required" # default value if tCountryEligibilityCode in ('US', 'UK', 'CA', 'GB'): if tOrder.orderCost > 10: if tProtectionEligibility == 'Eligible': if tCustomerOrderTotal24 > 1000.0 or tCustomerOrderTotal > 4000.0: tOrderData['instructions'] = "<span style='color:red'>$$$ Call Corowns $$$</span>" else: # not payment eligible tOrderData['instructions'] = "<span style='color:red'>Refund - No Seller Protection</span>" tContext['tDisplayDeliver'] = 'False' else: # international customer #if( tCustomerOrderTotal24 < 30.0 and tCustomerOrderTotal < 60.0): if tIpInfo.ipType == "Corporate": tOrderData['instructions'] = tOrderData['instructions'] + "<br /><span style='color:red'>Refer to PA - Corporate IP</span>" tOrderData['tDisplayDeliver'] = 'False' if (tIpInfo.ipProxy): if ("Confirmed proxy server" == tIpInfo.ipProxy): tOrderData['instructions'] = tOrderData['instructions'] + "<br /><span style='color:red'>Refer to PA - Proxy</span>" tContext['tDisplaydeliver'] = 'False' if tCustomerOrderTotal24 > 200.0 or tCustomerOrderTotal > 400.0: tOrderData['instructions'] = "<span style='color:red'>Refer to PA - Limit Exceeded</span>" tOrderData['tDisplayDeliver'] = 'False' elif tCustomerOrderTotal24 > 90.0 or tCustomerOrderTotal > 180.0: if tCustomer.customerIdVerified != True: tOrderData['instructions'] = "<span style='color:red'>Verify Photo ID</span>" elif tCustomerOrderTotal24 > 30.0 or tCustomerOrderTotal > 60.0: if tCustomer.customerPhoneVerified != True: tOrderData['instructions'] = "<span style='color:red'>Verify Phone Number</span>" if(tOrderData['locationmatch'] != 'True'): tOrderData['instructions'] = tOrderData['instructions'] + "<br /><span style='color:red'>Verify Country Match</span>" #logging.debug("Order Data Instructions: " + str(tOrderData['instructions'])) #logging.debug("Location Match" + str(tOrderData['locationmatch'])) tCustomerOrderQuery = db.GqlQuery("SELECT * FROM Order WHERE orderCustomer = '" + tOrder.orderCustomer + "'") tTotalCustomerOrders = [] tTotalCustomerOrders = tCustomerOrderQuery.fetch(50) for tCustomerOrder in tTotalCustomerOrders: if (tCustomerOrder.orderChargeback == True): tChargeBack = True else: tChargeBack = False tOrderData['chargeback'] = tChargeBack if (tChargeBack) else False tOrderData['chargeback'] = str(tOrderData['chargeback']) tIpChargebacks = tIpHandler.GetChargebacks(tOrder.orderIp) tOrderData['ipchargeback'] = len(tIpChargebacks) try: tTotalBonusString = NumberToGp.ConvertIntToBet(int(tOrder.orderBonusQuantity)) #logging.debug("Total Bonus String " + tTotalBonusString) except: tTotalBonusString = "" if (tCustomer.customerIsPaBlacklisted == True): tOrderData['instructions'] = tOrderData['instructions'] + "<br /><span style='color:red'>Refer to PA - Blacklist</span>" tContext['tDisplayDeliver'] = 'False' if (tCustomer.customerIsGlobalBlacklisted == True): tOrderData['instructions'] = tOrderData['instructions'] + "<br /><span style='color:red'>Do Not Deliver - Blacklist</span>" tContext['tDisplayDeliver'] = 'False' #normalize unicode try: tSimpleGold = unicodedata.normalize("NFC", tOrder.orderSimpleGoldAmount).encode("ascii", "ignore") except: tSimpleGold = tOrder.orderSimpleGoldAmount #logging.debug(str(tPriceDic[tSimpleGold])) #logging.debug(str(tOrder.orderCost)) tCurrentEocPrices = PriceContainer.GetCurrentPriceDic() tCurrent07Prices = PriceContainer.GetCurrentPriceDic07() #logging.debug(str(tCurrent07Prices)) #logging.debug(str(tCurrentEocPrices)) tSkip07 = False tValidOrder = False if tOrder.orderSimpleGoldAmount in tCurrentEocPrices.keys(): if str(tOrder.orderCost) == str(tCurrentEocPrices[tOrder.orderSimpleGoldAmount]): tOrder.orderGoldType = 'eoc' tSkip07 = True tValidOrder = True if not tSkip07: if tOrder.orderSimpleGoldAmount in tCurrent07Prices.keys(): if str(tOrder.orderCost) == str(tCurrent07Prices[tOrder.orderSimpleGoldAmount]): tOrder.orderGoldType = '07' tValidOrder = True #logging.debug("skip07 {}".format(tSkip07)) #logging.debug("valid {}".format(tValidOrder)) #logging.debug("order simple gold amount {}".format(tOrder.orderSimpleGoldAmount)) #logging.debug("order value {}".format(tOrderData['orderTotal'])) #logging.debug("gold type {}".format(tContext['gold_type'])) if not tValidOrder: tOrderData['instructions'] = tOrderData['instructions'] + '<br /><span style="color:red">Do Not Deliver - Bad Payment</span>' #tOrderData['tDisplayDeliver'] = 'False' #tOrder.orderLocked = 'True' #tOrder.put() #logging.debug(str(tOrder.orderIsGenerated)) if(tOrder.orderIsGenerated == True): tOrder.orderLocked = 'False' tOrder.orderIsRefunded = 'False' tOrder.orderDeliver = 'False' tOrderData['tDisplayDeliver'] = 'True' try: tDeliveryAgent = Agent.GetAgentByEmail(tOrder.orderDeliveryAgent) tContext['tDeliveryAgent'] = tDeliveryAgent except: pass try: tAssignedAgent = Agent.GetAgentByEmail(tOrder.orderAssignedAgent) tContext['tAssignedAgent'] = tAssignedAgent except: pass try: tRefundAgent = Agent.GetAgentByEmail(tOrder.orderRefundAgent) tContext['tRefundAgent'] = tRefundAgent except: pass tOrderData['bonus'] = tTotalBonusString tOrderData['phoneverified'] = str(tCustomer.customerPhoneVerified) tOrderData['emailverified'] = str(tCustomer.customerEmailVerified) tOrderData['idverified'] = str(tCustomer.customerIdVerified) tContext['tOrder'] = tOrder tContext['tOrderData'] = tOrderData tContext['tCustomer'] = tCustomer tContext['tIpInfo'] = tIpInfo tContext['tPhoneInfo'] = tPhoneInfo if ((tOrder.orderDeliveryAgent == "" or tOrder.orderDeliveryAgent == None) and tOrder.orderDeliver == 'True'): tAgentKey = tOrder.orderAgent tAgentId = Agent() tAgentId = Agent.get(tAgentKey) tOrder.orderDeliveryAgent = str(tAgentId.agentId) #logging.debug(str(tOrderData)) return tContext
def medium_contract_upload(): order_id = request.values.get('order') order = Order.get(order_id) return attachment_upload(order, FILE_TYPE_CONTRACT)
def finish_medium_order_upload(): order_id = request.values.get('order') order = Order.get(order_id) return attachment_upload(order, FILE_TYPE_FINISH)
def outsource(outsource_id): type = request.values.get('type', '') if type == 'douban': outsource = DoubanOutSource.get(outsource_id) else: outsource = OutSource.get(outsource_id) if not outsource: abort(404) if type == 'douban': form = DoubanOutsourceForm(request.form) else: form = OutsourceForm(request.form) outsource.target = OutSourceTarget.get(form.target.data) if type == 'douban': outsource.douban_order = DoubanOrder.get(form.douban_order.data) else: outsource.medium_order = Order.get(form.medium_order.data) try: int(form.num.data) except: flash(u'保存失败,金额必须为数字!', 'danger') return redirect(outsource.info_path()) outsource.num = form.num.data outsource.type = form.type.data outsource.subtype = form.subtype.data outsource.remark = form.remark.data outsource.invoice = True outsource.pay_num = form.num.data outsource.save() flash(u'保存成功!', 'success') if type == "douban": outsource.douban_order.add_comment(g.user, u"更新了外包:\n\r%s" % outsource.name, msg_channel=2) else: outsource.client_order.add_comment(g.user, u"更新了外包:\n\r%s" % outsource.name, msg_channel=2) if type == 'douban': order = outsource.douban_order else: order = outsource.medium_order.client_order if outsource.status not in [0, 4]: to_users = order.direct_sales + order.agent_sales + \ [order.creator, g.user] + order.operater_users try: outsource_apply_user = User.outsource_leaders_email( order.agent_sales[0]) except: outsource_apply_user = [] if outsource.status in [1, 2, 5]: to_users_name = ','.join( [k.name for k in order.operater_users] + [k.name for k in order.agent_sales]) elif outsource.status == 3: to_users += User.finances() to_users_name = ','.join( [k.name for k in User.finances()] + [k.name for k in order.operater_users]) to_emails = list( set([x.email for x in to_users] + [k.email for k in outsource_apply_user])) title = u'【费用报备】%s-%s-%s' % (order.contract or u'无合同号', order.jiafang_name, u'修改外包信息') apply_context = {"sender": g.user, "to": to_emails, "action_msg": u'修改外包信息', "msg": '', "order": order, "title": title, "to_users": to_users_name, "outsources": [outsource]} outsource_apply_signal.send( current_app._get_current_object(), context=apply_context) return redirect(outsource.info_path())
def export_schedule(order_id): order = Order.get(order_id) filename = ("%s-%s.xls" % (order.name, datetime.now().strftime('%Y%m%d%H%M%S'))).encode('utf-8') xls = Excel().write_excle(order.excel_table) response = get_download_response(xls, filename) return response
def medium_order_files(order_id): co = Order.get(order_id) return tpl("order_files.html", order=co)
def step_5(context): order = Order.get(Order.order_id == context.order_id) # assert hasattr(order, 'producer_id') is False assert order.producer_id is None
def get(self, id): self.write(Order.get(id))
async def start(self) -> List[Entry]: order = Order.get(id=self.order_id) return self.respond(data=self.Response(result=order))
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")
def step_4(context, name): order = Order.get(Order.order_id == context.order_id) producer = Producer.get(Producer.name == name) assert order.producer_id == producer
def update_orders(): data = request.get_json() order_id = data.pop('id') o = Order.get(order_id) o.update(data) return json_response(o.json())
def step_6(context, status): order = Order.get(Order.order_id == context.order_id) assert order.order_status == status
def GetContext(self): tUser = self.GetUser() tCustomerOrders = [] tOrderData = {} tContext = {} tOrder = Order() tCustomer = Customer() tIpHandler = IpLookup() tIpInfo = IpInfo() tDeliveryAgent = Agent() tRefundAgent = Agent() tAssignedAgent = Agent() tPriceDic = PriceContainer.GetCurrentPriceDic() tCountryDic = CountryContainer.GetCurrentCountryCodes() tOrderKey = str(urllib.unquote(self.request.get('key'))) if (tOrderKey != None and len(tOrderKey) > 0): tOrder = Order.get(tOrderKey) if (tOrder): tOrderHandler = OrderHandler() tResultDictionary = {} tPaypalPayload = {} tPayload = {} tUrl = "https://api-3t.paypal.com/nvp" tOperation = "GetTransactionDetails" tCustomer = Customer.get(tOrder.orderCustomer) # disabled to try to trace the "empty order" bug #if tOrder.orderVerificationCode is None: #tOrder.orderVerificationCode = str(uuid.uuid4()) #tOrder.put() try: tIpInfo = tIpHandler.GetIp(tOrder.orderIp)[0] except: tIpInfo.ipCountry = "Loading" tIpInfo.ipState = "Loading" tIpInfo.ipHost = "Loading" tIpInfo.ipProxy = "Loading" tIpInfo.ipIsp = "Loading" tIpInfo.ipType = "Loading" if (tIpInfo.ipProxy == ""): tIpInfo.ipProxy = 'No Proxy' tContext['tDisplayDeliver'] = 'True' #Get Paypal Information tPaypalPayload['METHOD'] = tOperation tPaypalPayload['TRANSACTIONID'] = tOrder.orderTransactionId #logging.debug("Order Paypal Email: " + tOrder.orderPaypalEmail) try: tPayloadEncoded = tOrderHandler.GeneratePayload(tPaypalPayload) request_cookies = mechanize.CookieJar() request_opener = mechanize.build_opener( mechanize.HTTPCookieProcessor(request_cookies)) request_opener.addheaders = [ ('Content-Type', 'application/x-www-form-urlencoded') ] mechanize.install_opener(request_opener) tResponse = mechanize.urlopen(url=tUrl, timeout=25.0, data=tPayloadEncoded) except: tContext[ 'error'] = 'Unable to Connect to Paypal, Try Refreshing' tContext['showerror'] = 'True' #tmpl = os.path.join(os.path.dirname(__file__), '../views/order.html') #self.response.out.write(render(tmpl, tContext)) return tContext tResult = str(urllib.unquote(tResponse.read())) tResultSplit = tResult.split('&') for tPair in tResultSplit: tSplitPair = tPair.split("=") try: tResultDictionary[tSplitPair[0]] = tSplitPair[1] #logging.debug(tSplitPair[0] + " " + tSplitPair[1]) except: logging.error("Error splitting item: " + str(tPair)) if ('COUNTRYCODE' in tResultDictionary.keys()): tCountryCode = tResultDictionary['COUNTRYCODE'] tPaypalCountry = tCountryDic[tCountryCode] else: tPaypalCountry = 'UNKNOWN' tOrderData['paypalcountry'] = tPaypalCountry if 'PROTECTIONELIGIBILITYTYPE' in tResultDictionary.keys(): tProtectionEligibility = tResultDictionary[ 'PROTECTIONELIGIBILITYTYPE'] if tProtectionEligibility == 'ItemNotReceivedEligible,UnauthorizedPaymentEligible': tProtectionEligibility = 'Eligible' if tProtectionEligibility != 'Eligible': tProtectionEligibility = 'Not Eligible' tContext['PROTECTIONELIGIBILITYTYPE'] = tProtectionEligibility else: tProtectionEligibility = 'UNKNOWN' #Display address fields if 'ADDRESSSTATUS' in tResultDictionary.keys(): tContext['ADDRESSSTATUS'] = tResultDictionary['ADDRESSSTATUS'] else: tContext['ADDRESSSTATUS'] = 'UNKNOWN' if 'SHIPTONAME' in tResultDictionary.keys(): tContext['SHIPTONAME'] = tResultDictionary['SHIPTONAME'] else: tContext['SHIPTONAME'] = 'UNKNOWN' if 'SHIPTOSTREET' in tResultDictionary.keys(): tContext['SHIPTOSTREET'] = tResultDictionary['SHIPTOSTREET'] else: tContext['SHIPTOSTREET'] = 'UNKNOWN' if 'SHIPTOSTREET2' in tResultDictionary.keys(): tContext['SHIPTOSTREET2'] = tResultDictionary['SHIPTOSTREET2'] else: tContext['SHIPTOSTREET2'] = 'UNKNOWN' if 'SHIPTOCITY' in tResultDictionary.keys(): tContext['SHIPTOCITY'] = tResultDictionary['SHIPTOCITY'] else: tContext['SHIPTOCITY'] = 'UNKNOWN' if 'SHIPTOSTATE' in tResultDictionary.keys(): tContext['SHIPTOSTATE'] = tResultDictionary['SHIPTOSTATE'] else: tContext['SHIPTOSTATE'] = 'UNKNOWN' if 'SHIPTOZIP' in tResultDictionary.keys(): tContext['SHIPTOZIP'] = tResultDictionary['SHIPTOZIP'] else: tContext['SHIPTOZIP'] = 'UNKNOWN' if 'SHIPTOCOUNTRYCODE' in tResultDictionary.keys(): tContext['SHIPTOCOUNTRYCODE'] = tResultDictionary[ 'SHIPTOCOUNTRYCODE'] else: tContext['SHIPTOCOUNTRYCODE'] = 'UNKNOWN' if 'SHIPTOPHONENUM' in tResultDictionary.keys(): tContext['SHIPTOPHONENUM'] = tResultDictionary[ 'SHIPTOPHONENUM'] else: tContext['SHIPTOPHONENUM'] = 'UNKNOWN' #Get order amount to add to dated totals tCurrentCost = float(tOrder.orderCost) #Get date 30 days ago tStartDate = tOrder.orderCreated tIncrement = datetime.timedelta(days=-30) tEndDate = tStartDate + tIncrement tCustomerOrderQuery = Order.all() tCustomerOrderQuery.filter("orderCreated >", tEndDate) tCustomerOrderQuery.filter("orderCustomer", tOrder.orderCustomer) tCustomerOrderQuery.filter("orderDeliver", 'True') tCustomerOrders = tCustomerOrderQuery.fetch(1000) #logging.debug("30 day date: " + str(tEndDate)) #logging.debug("30 day orders: " + str(len(tCustomerOrders))) tCustomerOrderTotal = 0.0 for tCustomerOrder in tCustomerOrders: tCustomerOrderTotal += float(tCustomerOrder.orderCost) if (tOrder.orderDeliver == 'False'): tCustomerOrderTotal += tCurrentCost tOrderData['orderTotal'] = str("%.2f" % tCustomerOrderTotal) #Get date 24 hours ago tStartDate = tOrder.orderCreated tIncrement = datetime.timedelta(days=-1) tEndDate = tStartDate + tIncrement tCustomerOrderQuery = Order.all().filter("orderCreated >", tEndDate) tCustomerOrderQuery.filter("orderCustomer", tOrder.orderCustomer) tCustomerOrderQuery.filter("orderDeliver", 'True') tCustomerOrders = tCustomerOrderQuery.fetch(1000) #logging.debug("24 hour date: " + str(tEndDate)) #logging.debug("24 hour orders: " + str(len(tCustomerOrders))) tCustomerOrderTotal24 = 0.0 for tCustomerOrder in tCustomerOrders: tCustomerOrderTotal24 += float(tCustomerOrder.orderCost) if (tOrder.orderDeliver == 'False'): tCustomerOrderTotal24 += tCurrentCost tOrderData['orderTotal24'] = str("%.2f" % tCustomerOrderTotal24) #Get date 15 days ago tStartDate = tOrder.orderCreated tIncrement = datetime.timedelta(days=-15) tEndDate = tStartDate + tIncrement tCustomerOrderQuery = Order.all().filter("orderCreated >", tEndDate) tCustomerOrderQuery.filter("orderCustomer", tOrder.orderCustomer) tCustomerOrderQuery.filter("orderDeliver", 'True') tCustomerOrders = tCustomerOrderQuery.fetch(1000) #logging.debug("15 day date: " + str(tEndDate)) #logging.debug("15 day orders: " + str(len(tCustomerOrders))) tCustomerOrderTotal15 = 0.0 for tCustomerOrder in tCustomerOrders: tCustomerOrderTotal15 += float(tCustomerOrder.orderCost) if (tOrder.orderDeliver == 'False'): tCustomerOrderTotal15 += tCurrentCost tOrderData['orderTotal15'] = str("%.2f" % tCustomerOrderTotal15) #===== Begin Location Matching ===== try: tPhoneHandler = PhoneLookup() tPhoneInfo = tPhoneHandler.GetPhone(tOrder.orderCustomer)[0] except: tPhoneInfo = Phone() tPhoneInfo.phoneState = "Unknown" tPhoneInfo.phoneCountry = "Unknown" #logging.debug("Ip country: " + str(tIpInfo.ipCountry)) #logging.debug("Paypal country: " + str(tPaypalCountry)) if (str(tIpInfo.ipCountry) == str(tPaypalCountry)): tOrderData['locationmatch'] = 'True' else: tOrderData['locationmatch'] = 'False' if (str(tIpInfo.ipCountry) == "United Kingdom" and str(tPaypalCountry) == "Great Britain (UK)"): tOrderData['locationmatch'] = 'True' #Agent Instructions #logging.debug("Order Total 24: " + str(tCustomerOrderTotal24)) #logging.debug("Order Total: " + str(tCustomerOrderTotal)) #logging.debug("Customer email verified: " + str(tCustomer.customerEmailVerified)) #logging.debug("Customer phone verified: " + str(tCustomer.customerPhoneVerified)) #logging.debug("Customer id verified: " + str(tCustomer.customerIdVerified)) #Protection Eligibility Filter tCountryEligibilityCode = tContext['SHIPTOCOUNTRYCODE'] tOrderData[ 'instructions'] = "No verification required" # default value if tCountryEligibilityCode in ('US', 'UK', 'CA', 'GB'): if tOrder.orderCost > 10: if tProtectionEligibility == 'Eligible': if tCustomerOrderTotal24 > 1000.0 or tCustomerOrderTotal > 4000.0: tOrderData[ 'instructions'] = "<span style='color:red'>$$$ Call Corowns $$$</span>" else: # not payment eligible tOrderData[ 'instructions'] = "<span style='color:red'>Refund - No Seller Protection</span>" tContext['tDisplayDeliver'] = 'False' else: # international customer #if( tCustomerOrderTotal24 < 30.0 and tCustomerOrderTotal < 60.0): if tIpInfo.ipType == "Corporate": tOrderData['instructions'] = tOrderData[ 'instructions'] + "<br /><span style='color:red'>Refer to PA - Corporate IP</span>" tOrderData['tDisplayDeliver'] = 'False' if (tIpInfo.ipProxy): if ("Confirmed proxy server" == tIpInfo.ipProxy): tOrderData['instructions'] = tOrderData[ 'instructions'] + "<br /><span style='color:red'>Refer to PA - Proxy</span>" tContext['tDisplaydeliver'] = 'False' if tCustomerOrderTotal24 > 200.0 or tCustomerOrderTotal > 400.0: tOrderData[ 'instructions'] = "<span style='color:red'>Refer to PA - Limit Exceeded</span>" tOrderData['tDisplayDeliver'] = 'False' elif tCustomerOrderTotal24 > 90.0 or tCustomerOrderTotal > 180.0: if tCustomer.customerIdVerified != True: tOrderData[ 'instructions'] = "<span style='color:red'>Verify Photo ID</span>" elif tCustomerOrderTotal24 > 30.0 or tCustomerOrderTotal > 60.0: if tCustomer.customerPhoneVerified != True: tOrderData[ 'instructions'] = "<span style='color:red'>Verify Phone Number</span>" if (tOrderData['locationmatch'] != 'True'): tOrderData['instructions'] = tOrderData[ 'instructions'] + "<br /><span style='color:red'>Verify Country Match</span>" #logging.debug("Order Data Instructions: " + str(tOrderData['instructions'])) #logging.debug("Location Match" + str(tOrderData['locationmatch'])) tCustomerOrderQuery = db.GqlQuery( "SELECT * FROM Order WHERE orderCustomer = '" + tOrder.orderCustomer + "'") tTotalCustomerOrders = [] tTotalCustomerOrders = tCustomerOrderQuery.fetch(50) for tCustomerOrder in tTotalCustomerOrders: if (tCustomerOrder.orderChargeback == True): tChargeBack = True else: tChargeBack = False tOrderData['chargeback'] = tChargeBack if (tChargeBack) else False tOrderData['chargeback'] = str(tOrderData['chargeback']) tIpChargebacks = tIpHandler.GetChargebacks(tOrder.orderIp) tOrderData['ipchargeback'] = len(tIpChargebacks) try: tTotalBonusString = NumberToGp.ConvertIntToBet( int(tOrder.orderBonusQuantity)) #logging.debug("Total Bonus String " + tTotalBonusString) except: tTotalBonusString = "" if (tCustomer.customerIsPaBlacklisted == True): tOrderData['instructions'] = tOrderData[ 'instructions'] + "<br /><span style='color:red'>Refer to PA - Blacklist</span>" tContext['tDisplayDeliver'] = 'False' if (tCustomer.customerIsGlobalBlacklisted == True): tOrderData['instructions'] = tOrderData[ 'instructions'] + "<br /><span style='color:red'>Do Not Deliver - Blacklist</span>" tContext['tDisplayDeliver'] = 'False' #normalize unicode try: tSimpleGold = unicodedata.normalize( "NFC", tOrder.orderSimpleGoldAmount).encode("ascii", "ignore") except: tSimpleGold = tOrder.orderSimpleGoldAmount #logging.debug(str(tPriceDic[tSimpleGold])) #logging.debug(str(tOrder.orderCost)) tCurrentEocPrices = PriceContainer.GetCurrentPriceDic() tCurrent07Prices = PriceContainer.GetCurrentPriceDic07() #logging.debug(str(tCurrent07Prices)) #logging.debug(str(tCurrentEocPrices)) tSkip07 = False tValidOrder = False if tOrder.orderSimpleGoldAmount in tCurrentEocPrices.keys(): if str(tOrder.orderCost) == str( tCurrentEocPrices[tOrder.orderSimpleGoldAmount]): tOrder.orderGoldType = 'eoc' tSkip07 = True tValidOrder = True if not tSkip07: if tOrder.orderSimpleGoldAmount in tCurrent07Prices.keys(): if str(tOrder.orderCost) == str( tCurrent07Prices[tOrder.orderSimpleGoldAmount]): tOrder.orderGoldType = '07' tValidOrder = True #logging.debug("skip07 {}".format(tSkip07)) #logging.debug("valid {}".format(tValidOrder)) #logging.debug("order simple gold amount {}".format(tOrder.orderSimpleGoldAmount)) #logging.debug("order value {}".format(tOrderData['orderTotal'])) #logging.debug("gold type {}".format(tContext['gold_type'])) if not tValidOrder: tOrderData['instructions'] = tOrderData[ 'instructions'] + '<br /><span style="color:red">Do Not Deliver - Bad Payment</span>' #tOrderData['tDisplayDeliver'] = 'False' #tOrder.orderLocked = 'True' #tOrder.put() #logging.debug(str(tOrder.orderIsGenerated)) if (tOrder.orderIsGenerated == True): tOrder.orderLocked = 'False' tOrder.orderIsRefunded = 'False' tOrder.orderDeliver = 'False' tOrderData['tDisplayDeliver'] = 'True' try: tDeliveryAgent = Agent.GetAgentByEmail( tOrder.orderDeliveryAgent) tContext['tDeliveryAgent'] = tDeliveryAgent except: pass try: tAssignedAgent = Agent.GetAgentByEmail( tOrder.orderAssignedAgent) tContext['tAssignedAgent'] = tAssignedAgent except: pass try: tRefundAgent = Agent.GetAgentByEmail(tOrder.orderRefundAgent) tContext['tRefundAgent'] = tRefundAgent except: pass tOrderData['bonus'] = tTotalBonusString tOrderData['phoneverified'] = str(tCustomer.customerPhoneVerified) tOrderData['emailverified'] = str(tCustomer.customerEmailVerified) tOrderData['idverified'] = str(tCustomer.customerIdVerified) tContext['tOrder'] = tOrder tContext['tOrderData'] = tOrderData tContext['tCustomer'] = tCustomer tContext['tIpInfo'] = tIpInfo tContext['tPhoneInfo'] = tPhoneInfo if ((tOrder.orderDeliveryAgent == "" or tOrder.orderDeliveryAgent == None) and tOrder.orderDeliver == 'True'): tAgentKey = tOrder.orderAgent tAgentId = Agent() tAgentId = Agent.get(tAgentKey) tOrder.orderDeliveryAgent = str(tAgentId.agentId) #logging.debug(str(tOrderData)) return tContext