def fill_single_list(request): productID = request.POST.get('productID', None) customer = request.POST.get('customer', None) create_time = request.POST.get('create_time', None) try: q = Purchase(productID=productID, customer = customer, process_step=1, product_name=Process.objects.filter(productID=productID)[0].product_name, create_time=create_time) q.save() except Exception, e: return comutils.baseresponse("system error", 500)
def fill_multiple_list(request): productID = request.POST.get('productID', None) customer = request.POST.get('customer', None) create_time = request.POST.get('create_time', None) product_name2 = request.POST.get('product_name2', None) try: q = Purchase(productID=productID, customer = customer, product_name=product_name2, process_step=2, create_time=create_time) q.save() except Exception, e: return comutils.baseresponse("system error", 500)
def new(request): if request.method == 'GET': return render_to_response( 'purchase/new.html', RequestContext( request, { 'purchase_active': 1, 'providers': get_providers(), 'stocks': get_stocks() })) else: data = request.POST.get('data') if not data: return failed_response('参数错误') else: all = json.loads(data) p = Purchase() p.provider = Provider.objects.get(id=all['supporter']) p.stock = Stock.objects.get(id=all['stock']) p.save() for item in all['detail']: pro = PurchaseDetail() pro.product = Product.objects.get(id=item['pid']) pro.num = int(item['pnum']) pro.price = float(item['pprice']) pro.save() p.detail.add(pro) p.save() return success_response('添加成功')
def create_transaction(request, product_id): purchase = Purchase() product = Product.objects.get(pk=product_id) purchase.product_id = product if request.method == 'POST': purchase.buyer_name = request.POST.get("name", "") purchase.quantity = request.POST.get("quantity", "") purchase.buyer_phone_number = request.POST.get("telephone", "") purchase.buyer_location = request.POST.get("location", "") purchase.product_id = Product.objects.get(pk=product_id) purchase.save() product.quantity = product.quantity - int(purchase.quantity) product.save() return redirect('home') return render(request, 'core/purchase/create_transaction.html', {'purchase': purchase});
def base(request): text={} try: if request.method == 'POST': dt=datetime.now().microsecond a=Purchase(number=str(dt), price=float(request.POST['ch'].replace(',','.')), status=False, body=request.POST['id']) a.save() except Exception: text['text']='ошибка' try: text['tov']=Product.objects.all() text['zak']=Purchase.objects.all() finally: return render_to_response('index.html',text,context_instance=RequestContext(request))
def purchase_stock(request): if request.method == 'POST': purchase = Purchase() date = request.POST.get('Date') billNo = request.POST.get('billNo') customer = request.POST.get('Customer_name') address = request.POST.get('Address') contact = request.POST.get('Contact') product_name = request.POST.get('Product_name') quantity = request.POST.get('Quantity') rate = request.POST.get('Rate') total = request.POST.get('Total') payment = request.POST.get('Payment') description = request.POST.get('Description') balance = request.POST.get('balance') mode = request.POST.get('Mode') purchase.save() return render(request, 'purchase_stock.html', {})
def create_purchase(request): if request.method == 'POST': form = CreatePurchaseForm(request.user, request.POST) if form.is_valid(): # TODO: Implement payment intent error handling payment_id = purchase_access.create_purchase( amount=form.cleaned_data.get('amount'), receipt_email=request.user.email, payment_method=form.cleaned_data.get('payment_method'), customer_id=request.user.profile.customer_id) payment = Purchase(purchase_id=payment_id, profile=request.user.profile) print(payment) payment.save() return redirect('home') else: if not Cards.objects.filter(profile=request.user.profile): return redirect('addcard') form = CreatePurchaseForm(request.user) return render(request, 'purchase/create_purchase.html', {'form': form})
def fake_order(token, pid): """ 测试刷单 :param pid: 产品id :param token: 用户token :return: """ now = datetime.now() order = now.strftime('%Y%m%d%H%M%S') + '{:0>4d}'.format(r.incr('today_order')) user = UserToken.objects.get_customer(token) product = Product.objects.get(pk=pid) amount = random.randint(1, 4) * product.min_purchase if int((product.sales_amount + amount) * 100 / product.funds_amount) > 70: products = Product.objects.filter(status=Product.STATUS_PUBLISHED) for pd in products: if pd.id != pid and int((pd.sales_amount + pd.min_purchase) * 100 / product.funds_amount) < 70: t = threading.Thread(target=fake_order, args=(token, pd.id)) t.start() break logger.info('product over 70: {}'.format(product.id)) return status = Purchase.TEST base_info = { 'order_no': order, 'customer': user, 'product': product, 'create_time': now.strftime('%Y-%m-%d %H:%M:%S'), 'amount': amount, 'terminal': Purchase.UNKNOWN, 'status': status, 'refund_status': False, 'refund_type': Purchase.TO_BANKCARD, 're_card_amount': amount, 're_balance_amount': 0 } purchase = Purchase(**base_info) purchase.save() logger.info('fake purchase: {}'.format(order)) tasks.increase_sales_amount.delay(purchase.product.id, amount)
def co_add(request): if request.user.type != 'purchase': return render(request,'confirm.html',{'message':'账号无权限'}) date = datetime.datetime.today() today = str(date.date())[2:7].replace('-', '') pur_id = 'CG02' + today sum = Purchase.objects.filter(purchaseid__contains=pur_id).count() pur_id = pur_id + '000' p_id = 'CG0'+str(int(pur_id[3:])+sum+1) purchasenum = request.POST.get('num') coid = request.POST.get('co_id') comp = Components.objects.get(coid=coid) coprice = comp.coprice sum_money = float(coprice) * float(purchasenum) purchase = Purchase(purchaseid=p_id,purchasenum=purchasenum,purchasestate='未采购',psumprice=sum_money, ptime=date) purchase.save() purchase_m = Purchase.objects.get(purchaseid=p_id) print(purchase_m) copurchase = CoPurchase(purchaseid=purchase_m,purchasenum=purchasenum,purchasestate='未采购',psumprice=sum_money, ptime=date,coid=comp) copurchase.save() url = reverse('purchase:co_unconfirmed') print(p_id) return redirect(url)
def purchase(self, user): """ 購入処理を実行する """ purchases = [] for item in self.items: ticket = item['ticket'] amount = item['amount'] # 売切れた場合はSOLD_OUTステータスに変更 if ticket.stock_amount() == amount: ticket.status = Ticket.STATUS_SOLD_OUT ticket.save() purchases.append( Purchase( ticket=ticket, user=user, amount=amount, )) Purchase.objects.bulk_create(purchases) self.delete_all()
def handleForm(request): user =request.user cart=Cart.objects.filter(cartUser__id=user.id) visa = Visa() order = Purchase() form = CheckoutForm(request.POST ) address_option =form.data['address_option'] print("adress option "+ address_option) # if form.is_valid(): # form.save() # print("test" +form.cleaned_data) order.cartUser =user order.city = form.data['city'] if address_option =='same': usr = Profile.objects.get(user__id=user.id) address = usr.address1 print(address) order.address = address else: address = form.data['shipping_address'] order.address = address order.address_details = form.data['address_details'] order.city = form.data['city'] payment =form.data['payment_option'] print(payment) if payment =='cash': order.cash = True order.visaInfo = None else: order.cash = False visa.card_owner = form.data.get('card_owner') visa.card_number = form.data.get('card_number') visa.card_expiry = form.data.get('card_expiry') visa.cvv = form.data.get('cvv') if form.data.get('save_card_info'): visa.save() # Cart.objects.filter(cartUser__id=user.id).delete() return render(request ,'orderReady.html', {'cart':cart, 'order':order,'payment':payment})
def handle(self, *args, **kwargs): existing_purchases = Purchase.objects.all() if existing_purchases: print("Records found. Deleting...") existing_purchases.delete() # Create 5000 purchase quantities with average of 7 purchase_quantities = generate_fixed_avg_list( self.min_quantity, self.max_quantity, self.average_quantity, self.total_purchases_required, ) # Distribute the purchases equally amongst all purchasers purchase_quantity_chunks = chunk_array(purchase_quantities, len(self.purchasers)) # Identify if there are any purchasers with same avg quantity same_average_indices = get_same_average_indices( purchase_quantity_chunks) # If there are any, move purchases(quantities) between those purchasers # so that their averages become different while same_average_indices: list_1_index = same_average_indices[0] list_2_index = same_average_indices[1] updated_list_1, updated_list_2 = rectify_same_average_by_shifting( purchase_quantity_chunks[list_1_index], purchase_quantity_chunks[list_2_index], ) purchase_quantity_chunks[list_1_index] = updated_list_1 purchase_quantity_chunks[list_2_index] = updated_list_2 same_average_indices = get_same_average_indices( purchase_quantity_chunks) purchase_objects = [] for purchaser_name in self.purchasers: purchase_quantities = purchase_quantity_chunks.pop() for purchase_quantity in purchase_quantities: purchase_objects.append( Purchase( purchaser_name=purchaser_name, quantity=purchase_quantity, created=get_random_date( self.purchases_start_datetime, # We leave 5 days for verification, dispatch and delivery self.purchases_end_datetime - timedelta(days=5), ))) Purchase.objects.bulk_create(purchase_objects) purchase_status_objs = [] for purchase in Purchase.objects.all(): purchase_progress = random.randint(1, 4) purchase_status_objs.append( PurchaseStatus( purchase=purchase, status=PurchaseStatusChoices.OPEN, created=purchase.created, )) if purchase_progress >= 1: verification_time = purchase.created + timedelta( # Between 1-5 hours seconds=random.randint(1 * 60 * 60, 5 * 60 * 60)) purchase_status_objs.append( PurchaseStatus( purchase=purchase, status=PurchaseStatusChoices.VERIFIED, created=verification_time, )) if purchase_progress == 2: # Between 1-3 days post creation dispatch_time = purchase.created + timedelta( seconds=random.randint(1 * 24 * 60 * 60, 3 * 24 * 60 * 60)) purchase_status_objs.append( PurchaseStatus( purchase=purchase, status=PurchaseStatusChoices.DISPATCHED, created=dispatch_time, )) # A purchase may have a delivered status without a dispatch status if purchase_progress == 3: dispatched = random.choice([True, False]) if dispatched: # Between 1-3 days post verification dispatch_time = purchase.created + timedelta( seconds=random.randint(1 * 24 * 60 * 60, 3 * 24 * 60 * 60)) purchase_status_objs.append( PurchaseStatus( purchase=purchase, status=PurchaseStatusChoices.DISPATCHED, created=dispatch_time, )) # If an item is not dispatched, it was probably picked up # right away delivery_time = dispatch_time + timedelta( # Between 0.5-2 days post dispatch seconds=random.randint( 0.5 * 24 * 60 * 60, 2 * 24 * 60 * 60)) if dispatched else verification_time + timedelta( # Between 15 - 45 min seconds=random.randint(15 * 60, 45 * 60)) purchase_status_objs.append( PurchaseStatus( purchase=purchase, status=PurchaseStatusChoices.DELIVERED, created=delivery_time, )) PurchaseStatus.objects.bulk_create(purchase_status_objs)