def add(data, db_session, username): logger.info(LogMsg.START, username) schema_validate(data,ITEM_ADD_SCHEMA_PATH) logger.debug(LogMsg.SCHEMA_CHECKED) book_id = data.get('book_id') person_id = data.get('person_id') if person_id is None: logger.error(LogMsg.DATA_MISSING, 'person_id') if is_book_in_library(person_id, book_id, db_session): logger.error(LogMsg.ALREADY_IS_IN_LIBRARY, {'book_id': book_id}) raise Http_error(409, Message.ALREADY_EXISTS) book = get_book(book_id, db_session) if book is None: logger.error(LogMsg.NOT_FOUND, {'book_id': book_id}) raise Http_error(404, Message.NOT_FOUND) if book.type.name in ONLINE_BOOK_TYPES : if data.get('count') > 1: logger.error(LogMsg.BOOK_ONLINE_TYPE_COUNT_LIMITATION) raise Http_error(400, Message.ONLINE_BOOK_COUNT_LIMITATION) content_id = book_has_content(book_id,'Original',db_session) if not content_id: logger.error(LogMsg.CONTENT_NOT_FOUND,{'book_id':book_id}) raise Http_error(404,Message.BOOK_HAS_NO_CONTENT) if not is_generated(content_id): logger.error(LogMsg.CONTENT_NOT_GENERATED, {'content_id': content_id}) raise Http_error(404, Message.BOOK_NOT_GENERATED) model_instance = OrderItem() populate_basic_data(model_instance, username) logger.debug(LogMsg.POPULATING_BASIC_DATA) model_instance.order_id = data.get('order_id') model_instance.book_id = book_id model_instance.count = data.get('count') # TODO discount not imposed yet model_instance.discount = data.get('discount', 0.0) model_instance.description = data.get('description') model_instance.price_detail = data.get('price_detail') model_instance.unit_price = get_book_price_internal(model_instance.book_id, db_session) logger.debug(LogMsg.ORDER_ITEM_UNIT_PRICE, model_instance.unit_price) model_instance.net_price = calc_net_price(model_instance.unit_price, model_instance.count, model_instance.discount) logger.debug(LogMsg.ORDER_ITEM_NET_PRICE, model_instance.net_price) db_session.add(model_instance) logger.info(LogMsg.END) return model_instance
def orderitem(request): current_user = request.user shopcart = ShopCart.objects.filter(user_id=current_user.id) schopcart = ShopCart.objects.filter(user_id=current_user.id) form = OrderForm(request.POST or None) form2 = OrderForm2(request.POST or None) total = 0 for rs in shopcart: total += rs.item.fiyat * rs.quantity if request.method == 'POST': if form.is_valid() and form2.is_valid(): # Send Credit card to bank, If the bank responds ok, continue, if not, show the error # .............. data = Order() data.first_name = form.cleaned_data[ 'first_name'] # get product quantity from form data.last_name = form.cleaned_data['last_name'] data.email = form.cleaned_data['email'] data.address = form2.cleaned_data['address'] data.city = form2.cleaned_data['city'] data.phone = form2.cleaned_data['phone'] data.user_id = current_user.id data.total = total data.ip = request.META.get('REMOTE_ADDR') ordercode = random.randint(100000000, 999999999) # ordercode= get_random_string(9).upper() # random cod data.code = ordercode data.save() for rs in shopcart: detail = OrderItem() detail.order_id = data.id # Order Id detail.item_id = rs.item_id detail.user_id = current_user.id detail.quantity = rs.quantity detail.beden = rs.beden detail.fiyat = rs.item.fiyat detail.save() return redirect(reverse('payment')) else: messages.warning(request, form.errors) return HttpResponseRedirect("/order/orderproduct") form = OrderForm() context = { 'shopcart': shopcart, 'total': total, 'form': form, 'form2': form2, 'schopcart': schopcart, } return render(request, 'order/order_form.html', context)
def add(data, db_session, username): logger.info(LogMsg.START, username) check_schema(['book_id', 'count', 'order_id', 'person_id'], data.keys()) logger.debug(LogMsg.SCHEMA_CHECKED) book_id = data.get('book_id') person_id = data.get('person_id') if person_id is None: logger.error(LogMsg.DATA_MISSING, 'person_id') if is_book_in_library(person_id, book_id, db_session): logger.error(LogMsg.ALREADY_IS_IN_LIBRARY, {'book_id': book_id}) raise Http_error(409, Message.ALREADY_EXISTS) book = get_book(book_id, db_session) if book is None: logger.error(LogMsg.NOT_FOUND, {'book_id': book_id}) raise Http_error(404, Message.NOT_FOUND) if book.type.name in ONLINE_BOOK_TYPES and data.get('count') > 1: logger.error(LogMsg.BOOK_ONLINE_TYPE_COUNT_LIMITATION) raise Http_error(400, Message.ONLINE_BOOK_COUNT_LIMITATION) model_instance = OrderItem() populate_basic_data(model_instance, username) logger.debug(LogMsg.POPULATING_BASIC_DATA) model_instance.order_id = data.get('order_id') model_instance.book_id = book_id model_instance.count = data.get('count') # TODO discount not imposed yet model_instance.discount = data.get('discount', 0.0) model_instance.description = data.get('description') model_instance.price_detail = data.get('price_detail') model_instance.unit_price = get_book_price_internal( model_instance.book_id, db_session) logger.debug(LogMsg.ORDER_ITEM_UNIT_PRICE, model_instance.unit_price) model_instance.net_price = calc_net_price(model_instance.unit_price, model_instance.count, model_instance.discount) logger.debug(LogMsg.ORDER_ITEM_NET_PRICE, model_instance.net_price) db_session.add(model_instance) logger.info(LogMsg.END) return model_instance
def create_order_from_express_paypal(nvp_dict): """ Create order in DB with ordered items """ #create order #create items #return order object order = Order() order.email = nvp_dict.get('email') order.b_first_name = nvp_dict.get('firstname') order.b_last_name = nvp_dict.get('lastname') order.b_address_countryname = nvp_dict.get('shiptocountryname') order.b_address_countrycode = nvp_dict.get('shiptocountrycode') order.b_address_zip = nvp_dict.get('shiptozip') order.b_address_state = nvp_dict.get('shiptostate') order.b_address_city = nvp_dict.get('shiptocity') order.b_address_street = nvp_dict.get('shiptostreet') \ + nvp_dict.get('shiptostreet2', "") order.shipping_address_flag = False order.status = order.NEW_ORDER order.paypal_transaction_id = nvp_dict.get('transactionid') order.save() item_ids = [(key, value) for key, value in nvp_dict.iteritems() if key.startswith("l_paymentrequest_0_number")] print item_ids for index, i in enumerate(item_ids): product = Prize.objects.get(pk=i[1]) order_item = OrderItem() order_item.order_id = order.id order_item.product = product order_item.number = product.number order_item.amount = nvp_dict.get('l_paymentrequest_0_amt' + str(index)) order_item.quantity = nvp_dict.get('l_paymentrequest_0_qty' + str(index)) order_item.save() return order
def save_order_items(nvp_dict, order): item_ids = [(key, value) for key, value in nvp_dict.iteritems() if key.startswith("l_paymentrequest_0_number")] print item_ids for index, i in enumerate(item_ids): product = Prize.objects.get(pk=i[1]) order_item = OrderItem() order_item.order_id = order.id order_item.product = product order_item.number = product.number order_item.name = product.name order_item.amount = nvp_dict.get('l_paymentrequest_0_amt' + str(index)) order_item.quantity = nvp_dict.get('l_paymentrequest_0_qty' + str(index)) order_item.size, order_item.color \ = get_size_and_color_from_paypal(nvp_dict.get('l_paymentrequest_0_desc' + str(index))) print nvp_dict.get('l_paymentrequest_0_desc' + str(index)) order_item.save()
def create_order_from_direct_paypal(nvp_dict): """ Create order in DB with ordered items """ #create order #create items #return order object """ <QueryDict: {u'l_paymentrequest_0_number0': [4], u's_countrycode': [u'AX'], u'b_state': [u'sdf'], u'card_first_name': [u'sdf'], u's_last_name': [u'sdf'], u's_street': [u'sdf'], u'acct': [u'4239530610456015'], u'l_paymentrequest_0_amt0': [32], u'l_paymentrequest_0_name0': [u'Raw Edge Design Letters Print Black Polyester VEST'], u's_city': [u'sdf'], u's_state': [u'sdf'], u'version': [u'116.0'], u's_countryname': [u'Aland Islands'], u'build': [u'16770825'], u'cvv2': [u'123'], u'b_street': [u'dd'], u'email': [u'*****@*****.**'], u'l_paymentrequest_0_qty0': [2], u'b_countrycode': [u'AU'], u'b_countryname': [u'Afghanistan'], u'timestamp': [u'2015-06-14T10:22:07Z'], u'currencycode': [u'USD'], u'card_last_name': [u'sdf'], u's_zip': [u'dsf'], u'paymentrequest_0_amt': [64.0], u'phone': [u'sdf'], u'b_country': [u'1'], u'cardyear': [u'2020'], u'transactionid': [u'06M899763J781091D'], u'amt': [u'64.00'], u's_first_name': [u'sdf'], u'cvv2match': [u'M'], u'cardmonth': [u'05'], u'ack': [u'Success'], u'b_city': [u'sdf'], u'creditcardtype': [u'visa'], u'b_last_name': [u'dddddd'], u'b_zip': [u'sdf'], u'avscode': [u'X'], u'b_first_name': [u'sads'], u'correlationid': [u'dba9b733e476']}> """ order = Order() order.email = nvp_dict.get('email') order.phone = nvp_dict.get('phone', "") order.b_first_name = nvp_dict.get('b_first_name') order.b_last_name = nvp_dict.get('b_last_name') order.b_address_countryname = nvp_dict.get('b_countryname') order.b_address_countrycode = nvp_dict.get('b_countrycode') order.b_address_zip = nvp_dict.get('b_zip') order.b_address_state = nvp_dict.get('b_state') order.b_address_city = nvp_dict.get('b_city') order.b_address_street = nvp_dict.get('b_street') order.s_first_name = nvp_dict.get('s_first_name', "") order.s_last_name = nvp_dict.get('s_last_name', "") order.s_address_countryname = nvp_dict.get('s_countryname', "") order.s_address_countrycode = nvp_dict.get('s_countrycode', "") order.s_address_zip = nvp_dict.get('s_zip', "") order.s_address_state = nvp_dict.get('s_state', "") order.s_address_city = nvp_dict.get('s_city', "") order.s_address_street = nvp_dict.get('s_street', "") order.status = order.NEW_ORDER order.paypal_transaction_id = nvp_dict.get('transactionid') order.save() item_ids = [(key, value) for key, value in nvp_dict.iteritems() if key.startswith("l_paymentrequest_0_number")] #print item_ids for index, i in enumerate(item_ids): product = Prize.objects.get(pk=i[1]) order_item = OrderItem() order_item.order_id = order.id order_item.product = product order_item.number = product.number order_item.amount = nvp_dict.get('l_paymentrequest_0_amt' + str(index)) order_item.quantity = nvp_dict.get('l_paymentrequest_0_qty' + str(index)) order_item.save() return order