def create_fake_order(discounts): user = User.query.order_by(func.random()).first() address = create_fake_address() status = random.choice(list(OrderStatusKinds)).value order_data = { "user_id": user.id, "shipping_address": address.full_address, "status": status, "token": str(uuid4()), } shipping_method = ShippingMethod.query.order_by(func.random()).first() order_data.update( { "shipping_method_name": shipping_method.title, "shipping_method_id": shipping_method.id, "shipping_price_net": shipping_method.price, } ) order = Order.create(**order_data) lines = create_order_lines(order, discounts, random.randrange(1, 5)) order.total_net = sum([line.get_total() for line in lines]) order.save() create_payment(order) return order
def checkout_note(): form = NoteForm(request.form) voucher_form = VoucherForm(request.form) cart = Cart.get_current_user_cart() address = ( UserAddress.get_by_id(cart.shipping_address_id) if cart.shipping_address_id else None ) shipping_method = ( ShippingMethod.get_by_id(cart.shipping_method_id) if cart.shipping_method_id else None ) if form.validate_on_submit(): order, msg = Order.create_whole_order(cart, form.note.data) if order: return redirect(order.get_absolute_url()) else: flash(msg, "warning") return redirect(url_for("checkout.cart_index")) return render_template( "checkout/note.html", form=form, address=address, voucher_form=voucher_form, shipping_method=shipping_method, )
def draft_order(id): order = Order.get_by_id(id) order.status = OrderStatusKinds.draft.value order.save() return render_template("order/detail.html", order=order)
def send_order(id): order = Order.get_by_id(id) order.status = OrderStatusKinds.shipped.value order.ship_status = ShipStatusKinds.delivered.value order.save() return render_template("order/detail.html", order=order)
def order_detail(id): order = Order.get_by_id(id) return render_template("order/detail.html", order=order)
def user(user_id): user = User.get_by_id(user_id) addresses = user.addresses orders = Order.get_user_orders(user_id) context = {"user": user, "addresses": addresses, "orders": orders} return render_template("user/detail.html", **context)
def index(): form = ChangePasswordForm(request.form) orders = Order.get_current_user_orders() return render_template("account/details.html", form=form, orders=orders)
def draft_order(id): order = Order.get_by_id(id) order.draft() return render_template("order/detail.html", order=order)
def send_order(id): order = Order.get_by_id(id) order.delivered() return render_template("order/detail.html", order=order)