Example #1
0
def commonthreadAddToCart(request, rug_name):
  from apps.seller.models.product import Product
  from apps.communication.views.email_class import Email
  from settings.people import operations_team

  rugs = {
    'opportunity':  [1860,],
    'coexistence':  [1861,],
    'mother':       [1862,],
    'motherland':   [1863,],
    'sacred':       [1864,],
    'identity':     [1865,],
  }

  try:
    buy_this_one = None
    for product_id in rugs[rug_name]:
      if not buy_this_one:
        product = Product.objects.get(id=product_id)
        if not product.is_sold:
          buy_this_one = product

    if buy_this_one:
      return HttpResponseRedirect(reverse('cart add', args=[buy_this_one.id]))
    else:
      email = Email(message=("%s rug is sold out!!!" % rug_name),
                    subject=("%s sold out" % rug_name))
      email.sendTo([person.email for person in operations_team])
      return HttpResponseRedirect(reverse('commonthread'))

  except:
    return HttpResponseRedirect(reverse('commonthread'))
Example #2
0
def cancelOrder(order):
  try:
    message = 'Cancel order %d, Confirmation# %d' % (order.id, order.checkout.id)
    email = Email(message=message)
    email.assignToOrder(order)
    email.sendTo([person.email for person in support_team])
    #todo: email customer

  except Exception as e:
    ExceptionHandler(e, "in order_events.cancelOrder")
Example #3
0
def createOrders(sender, instance, created, **kwargs):
  checkout = instance
  if (checkout.is_paid and #cart/checkout has been paid for
      checkout.cart.items.count() > 0 and #there are items in the cart
      checkout.orders.count() == 0): #there are no orders yet created

    from apps.public.models.order import Order
    for item in checkout.cart.items.all():
      if item.product.sold_at is not None:
        email = Email(message="customer was just charged for a product someone else already bought")
        email.sendTo([person.email for person in support_team])
      else:
        order = Order(
          checkout            = checkout,
          products_charge     = item.product.price,
          anou_charge         = item.product.anou_fee,
          shipping_charge     = item.product.shipping_cost,
          total_charge        = item.product.intl_price,
          seller_paid_amount  = item.product.price + item.product.shipping_cost
        )
        order.product = item.product
        order.save()
        item.product.sold_at = timezone.now()#todo: make this a post_save order to mark a product sold
        item.product.save()

    email = Email('order/created', checkout)
    email.assignToOrder(checkout.orders.first())
    email.sendTo(checkout.cart.email_with_name)
Example #4
0
def updateOrder(request):
  from django.utils import timezone

  if request.method == 'GET':
    order_id = request.GET.get('order_id')
    action = request.GET.get('action')
    order = Order.objects.get(id=order_id)

    if action == "seller paid":
      order.seller_paid_at = timezone.now()

      #SEND EMAIL WITH RECEIPT TO SELLER
      if order.seller.account.email:
        message = "%d: %s" % (order.product.id, order.seller_paid_receipt.original)
        email = Email(message=message, subject="$")
        email.assignToOrder(order)
        email.sendTo(order.seller.account.email)

      #SEND SMS TO SELLER
      if order.seller.account.phone:
        message = ("%d\r\n$\r\n%dD" %
                    (order.product.id, int(order.seller_paid_amount)))
        message += "\r\n"
        message += ("Aatik transfere %d D a votre compte pour les produit: %d" %
                    (order.seller_paid_amount, order.product.id))
        sendSMS(message, order.seller.account.phone)

    elif action == "add note": #requires order_id, note
      if request.GET.get('note'):
        timestamp = timezone.now()
        note = timestamp.strftime("%H:%M %d/%m/%y - ") + str(request.GET['note'])
        order.notes = order.notes if order.notes else ""
        order.notes += "\n" + note

    order.save()
    return HttpResponse(status=200)#OK

  else:
    return HttpResponse(status=402)#bad request, payment required
Example #5
0
def communicateOrderConfirmed(order, gimme_reply_sms=False):
  try:
    if DEBUG: sms_reply = '(shukran) order confirmed'
    else: sms_reply = 'shukran'

    #send email to buyer
    email = Email('order/confirmed', order)
    email.assignToOrder(order)
    email.sendTo(order.checkout.cart.email_with_name)

    if gimme_reply_sms:
      return sms_reply

    else:
      seller_phone = order.seller.phone
      sendSMSForOrder(sms_reply, seller_phone, order)

  except Exception as e:
    if DEBUG: return '(xata) ' + str(e)
    else:
      return 'xata'
      ExceptionHandler(e, "in order_events.communicateOrderConfimed")