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 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 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)