Commits

Andres Vargas committed 515fb55

change the url when the order its empty

Comments (0)

Files changed (3)

dineromail/dineromail_settings.py

 from django.utils.translation import ugettext as _
 from django.conf import settings
+from decimal import Decimal
 
 DINEROMAIL_ACCOUNT_NUMBER = getattr(settings,"DINEROMAIL_ACCOUNT_NUMBER", "0")
+DINEROMAIL_PAYMEND_LIMIT = getattr(settings,"DINEROMAIL_PAYMEND_LIMIT", Decimal("2000"))
 
 MEXICO = 4
 ARGENTINA = 1

dineromail/lfs/utils.py

 
 #others
 import urllib
+from decimal import Decimal
+
+def __get_price(order):
+    price = Decimal("0")
+    str_item = ""
+    for index, item in enumerate(order.items.all()):
+        str_item += " " + item.product_name
+        price =  Decimal( str(item.product_price_net)) + Decimal(str(item.product_tax))
+        #dineromail commision and shipping cost
+    price += Decimal(str(order.payment_price)) + Decimal(str(order.payment_tax))  + Decimal(str(order.shipping_price))
+    return price, str_item
 
 
 def lfs_generate_url( order = None, request = None):
         shop = get_default_shop()
         current_site = Site.objects.get(id=settings.SITE_ID)
         last_index = 1
-        str_item =""
-        price  = 0
-        # adding items to dineromail cart
-        for index, item in enumerate(order.items.all()):
-            str_item += " " + item.product_name
-            price =  item.product_price_net + item.product_tax
-        #dineromail commision and shipping cost
-        price += order.payment_price + order.payment_tax  + order.shipping_price
-
-        #buyer info
+        price, str_item  = __get_price(order)
+                #buyer info
         p["usr_nombre"] = order.customer_firstname
         p["usr_apellido"] = order.customer_lastname
         p["usr_email"] = order.customer_email
         p["NombreItem"] = str_item
         p["PrecioItem"] ="%.2f" % price
         # configuration
-  #      if shop.image:
-  #         p["image_url"]= "http://"+ current_site.domain + settings.MEDIA_URL + shop.image.url
-#        p["DireccionExito"] ="http://"+ current_site.domain + reverse("lfs_thank_you")
- #       p["DireccionFracaso"] = "http://"+ current_site.domain + reverse("lfs_checkout_dispatcher")
+        if shop.image:
+           p["image_url"]= "http://"+ current_site.domain + settings.MEDIA_URL + shop.image.url
+        p["DireccionExito"] ="http://"+ current_site.domain + reverse("lfs_thank_you")
+        p["DireccionFracaso"] = "http://"+ current_site.domain + reverse("lfs_checkout_dispatcher")
         t = Transaction.objects.create(content_object=order)
         p["trx_id"] = "t-%s-%s" % (t.id,order.id)
         #uri = urllib.urlencode(p)

dineromail/lfs/views.py

-from utils import lfs_generate_url
+from utils import lfs_generate_url,__get_price
+from  dineromail.dineromail_settings import DINEROMAIL_PAYMEND_LIMIT
+
 from django.utils.translation import ugettext as _
+from django.core.urlresolvers import reverse
+
+from decimal import Decimal
+
 # called on lfs/payment/utils.py +101
 def process(request,order):
     """Processes the payment depending on the selected payment method. Returns
         message.
      """
     accepted = True
-    next_url = lfs_generate_url(request = request, order=order)
-    position = 0
+    position = "payment_method"
     paid = False
-    submited = True
-    message =""
-    if not next_url:
-        message = _("No se pudo generar orden")
-        submited, paid, accepted  = False, False, False
-    return {'accepted':accepted, 'next-url':next_url, 'paid':paid,'submited':submited,
+    submited = False
+    message ="-----"
+    next_url = None
+    if order:
+        price,t = __get_price(order)
+        if price > DINEROMAIL_PAYMEND_LIMIT:
+            message = _("Sobrepasa el limite de pago $ %(limit)s permitido: https://mx.dineromail.com/tyc 7.1" % {'limit': DINEROMAIL_PAYMEND_LIMIT} )
+            accepted, submited, paid  = False, False, False
+        else:
+            next_url = lfs_generate_url(request = request, order=order)
+            if not next_url:
+                message = _("No se pudo generar orden")
+                submited, paid, accepted  = False, False, False
+    else:
+        next_url = reverse("lfs_cart")
+        submited, paid, accepted  = False, False, True
+    d= {'accepted':accepted, 'next-url':next_url, 'paid':paid,'submited':submited,
             "message": message, 'message-position':position }
+    return d
 
 # called on lfs/payment/utils.py +131
 def get_next_url(order):