def update_order(order: Order, send_order_summary=False) -> Order: if order.current_status is DRAFT: # update order_items based on order.draft_cart order_item_ids_processed = [] for cart_index_string, cart_item in order.draft_cart.items(): if not cart_index_string.startswith("i"): continue if 'item_id' not in cart_item: raise OrderException("missing item_id in cart item") if 'quantity' not in cart_item: raise OrderException("missing quantity in cart item") order_item = OrderItem.objects.none() if 'order_item_id' in cart_item: if cart_item['order_item_id'] in order_item_ids_processed: raise OrderException("duplicate order_item_id found") if cart_item['order_item_id']: order_item = OrderItem.objects.filter( id=cart_item['order_item_id']).first() if all([ not order_item, cart_item.get('item_id'), cart_item.get('quantity'), ]): order_item = OrderItem.objects.create( order=order, item_id=cart_item['item_id']) order_item.quantity = Decimal(cart_item['quantity']) if len(cart_item.get('note', "")): note = order_item.notes.first() if note: note.text = cart_item['note'] note.save() else: order_item.add_note(cart_item['note']) order_item.save() order_item_ids_processed.append(order_item.id) order.order_items.exclude(id__in=order_item_ids_processed).delete() order.save() if send_order_summary and order.is_ready_for_checkout: # send order summary to customer order.line_channel_membership.send_order_status(order) if order.current_status is PLACED and order.next_status is SHOP_CONFIRMED: pursue_shop_confirmation(order) return order
def post(self, **kwargs): ''' Send e-mail to user ordered a delivery and the admin ''' order_id = self.request.form.get('order_id') order = Order.get_id(int(order_id)) user = order[0].user language = self.get_locale() context = { 'user': user, 'order': order[0], 'info': order[1], 'language': language, 'format_currency': i18n.format_currency, } body = render_template('mail/order.html', **context) message = mail.EmailMessage() message.to = user.email message.body = body message.bcc = SHOP message.subject = SUBJECT_ORDER message.sender = SENDER message.reply_to = REPLY_TO if message.send(): logging.info(body) return Response('')
def get(self, order_id=None, **kwargs): order = Order.get_id(order_id) logging.warn(order) if order: self.form = OrderForm(obj=order[0]) context = { 'form': self.form, 'info': order[1], } return self.render_response('admin/orders/edit.html', **context)
def get(self, **kwargs): orders = Order.get_orders_by_user(self.auth_current_user) logging.info(orders) context = { 'orders': orders, } # if not admin: # enable set/change: # email, password return self.render_response('user/profile.html', **context)
def post(self, order_id=None, **kwargs): """Handle submitted form data""" # validate form if self.request.form.get('delivered') == 'on': delivered = True logging.warn(delivered) # saving edited order = Order.get_by_id(order_id) order.delivered = delivered if order.put(): return redirect('admin/shop/orders') return self.get(order_id)
def create(self, validated_data): order_list = validated_data.pop("orders") order_line = OrderLine.objects.create(**validated_data) while len(order_list) > 0: order_data = order_list.pop() order = Order(order_line=order_line, **order_data) item = Item.objects.get(pk=order.object_id) order.content_object = item order.price = item.price order.save() order_line.pay() return order_line
def get(self, **kwargs): ''' Send e-mail to user ordered a delivery and the admin ''' user = self.auth_current_user # todo: use real user order = Order.get_orders_by_user(user) context = { 'order': order, 'username': user.username, 'format_currency': i18n.format_currency, } body = render_template('mail/order.html', **context) message = mail.EmailMessage() message.to = user.email message.body = body message.subject = SUBJECT_ORDER message.sender = SENDER message.reply_to = REPLY_TO message.send() return Response(body)
def get(self, **kwargs): orders = Order.get_undelivered_orders() context = { 'orders': orders, } return self.render_response('admin/orders/index.html', **context)