Subversion Repositories SmartDukaan

Rev

Rev 5802 | Rev 5807 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5802 Rev 5806
Line 48... Line 48...
48
import time
48
import time
49
import traceback
49
import traceback
50
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType
50
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType
51
from random import randrange
51
from random import randrange
52
from shop2020.clients.AlertClient import AlertClient
52
from shop2020.clients.AlertClient import AlertClient
-
 
53
import httplib
-
 
54
import urllib
53
logging.basicConfig(level=logging.DEBUG)
55
logging.basicConfig(level=logging.DEBUG)
54
 
56
 
55
 
57
 
56
PREPAID_SHIPPING_CUTOFF_TIME = 15
58
PREPAID_SHIPPING_CUTOFF_TIME = 15
57
COD_SHIPPING_CUTOFF_TIME = 12
59
COD_SHIPPING_CUTOFF_TIME = 12
Line 596... Line 598...
596
        print e
598
        print e
597
        return False
599
        return False
598
 
600
 
599
 
601
 
600
def __get_secret_code(order_id):
602
def __get_secret_code(order_id):
-
 
603
    __get_order_attribute_value(order_id, 'SECRET_CODE')
-
 
604
 
-
 
605
def __get_order_attribute_value(order_id, attribute_name):
601
    existingAttributes = Attribute.query.filter(Attribute.orderId == order_id).all()
606
    existingAttributes = Attribute.query.filter(Attribute.orderId == order_id).all()
602
    if existingAttributes :
607
    if existingAttributes :
603
        for existingAttribute in existingAttributes :
608
        for existingAttribute in existingAttributes :
604
            if existingAttribute.name == 'SECRET_CODE':
609
            if existingAttribute.name == attribute_name:
605
                return existingAttribute.value
610
                return existingAttribute.value
606
    return ""
611
    return ""
607
 
612
 
608
def get_order(order_id):
613
def get_order(order_id):
609
    order = Order.get_by(id=order_id)
614
    order = Order.get_by(id=order_id)
610
    if not order:
615
    if not order:
611
        raise TransactionServiceException(108, "no such order")
616
        raise TransactionServiceException(108, "no such order")
612
    
617
    
Line 1155... Line 1160...
1155
    order.status = OrderStatus.DELIVERY_SUCCESS
1160
    order.status = OrderStatus.DELIVERY_SUCCESS
1156
    order.statusDescription = "Order delivered"
1161
    order.statusDescription = "Order delivered"
1157
    update_trust_level(order)
1162
    update_trust_level(order)
1158
    session.commit()
1163
    session.commit()
1159
    
1164
    
-
 
1165
    if order.pickupStoreId:
-
 
1166
        __push_collection_to_hotspot(order, "SALE")
-
 
1167
    
1160
#    if order.pickupStoreId:
1168
#    if order.pickupStoreId:
1161
#        payment_client = PaymentClient().get_client()
1169
#        payment_client = PaymentClient().get_client()
1162
#        payment_client.createRefund(order.id, order.transaction.id, order.total_amount)
1170
#        payment_client.createRefund(order.id, order.transaction.id, order.total_amount)
1163
#        payment_client = PaymentClient().get_client()
1171
#        payment_client = PaymentClient().get_client()
1164
#        payment_client.partiallyCapturePayment(order.transaction.id, order.total_amount, xferBy, xferTxnId, now())
1172
#        payment_client.partiallyCapturePayment(order.transaction.id, order.total_amount, xferBy, xferTxnId, now())
Line 2199... Line 2207...
2199
    pdf.drawText(order_text)
2207
    pdf.drawText(order_text)
2200
    pdf.showPage()
2208
    pdf.showPage()
2201
    pdf.save()
2209
    pdf.save()
2202
    return filename
2210
    return filename
2203
 
2211
 
-
 
2212
def __push_collection_to_hotspot(order, type):
-
 
2213
    try:
-
 
2214
        logistics_client = LogisticsClient().get_client()
-
 
2215
        store = logistics_client.getPickupStore(order.pickupStoreId)
-
 
2216
        store_string = "<store>" + store.hotspotId + "</store>"
-
 
2217
        order_string = "<orderno>" + str(order.id) + "</orderno>"
-
 
2218
        collection_type = "<Type>" + type + "</Type>"
-
 
2219
        payment_mode = __get_order_attribute_value(order.id, "PAYMENT_MODE")
-
 
2220
        if type == "SALE":
-
 
2221
            amount = int(order.total_amount)
-
 
2222
            ts = order.delivery_timestamp
-
 
2223
        if type == "SALE RETURN":
-
 
2224
            amount = -int(order.total_amount)
-
 
2225
            ts = order.refund_timestamp
-
 
2226
        if payment_mode == "Cash":
-
 
2227
            cash_string = "<cash>" + str(amount) + "</cash>"
-
 
2228
            card_string = "<hdfc>0</hdfc>"
-
 
2229
        if payment_mode == "Card":
-
 
2230
            cash_string = "<cash>0</cash>"
-
 
2231
            card_string = "<hdfc>" + str(amount) + "</hdfc>"
-
 
2232
        date_string = "<date>" + ts.strftime("%Y%m%d") + "</date>"
-
 
2233
        time_string = "<time>" + ts.strftime("%H%M%S") + "</time>"
-
 
2234
        
-
 
2235
        conn = httplib.HTTPConnection("182.71.104.182")
-
 
2236
        XML="""
-
 
2237
        <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
-
 
2238
          <soap:Body>
-
 
2239
            <SaholicDataTransfer xmlns="http://tempuri.org/">
-
 
2240
        """
-
 
2241
        
-
 
2242
        XML = XML + store_string + order_string + collection_type + cash_string + card_string + date_string + time_string 
-
 
2243
        
-
 
2244
        footer = """
-
 
2245
            </SaholicDataTransfer>
-
 
2246
          </soap:Body>
-
 
2247
        </soap:Envelope>
-
 
2248
        """
-
 
2249
        XML = XML + footer
-
 
2250
        
-
 
2251
        params = urllib.urlencode({'op': 'SaholicDataTransfer'})
-
 
2252
        headers = { "Content-type": "text/xml", "Content-Length": "%d" % len(XML)}
-
 
2253
        conn.request("POST", "/loaddetect/Service.asmx?"+params, "", headers)
-
 
2254
        conn.send(XML)
-
 
2255
        response = conn.getresponse()
-
 
2256
        print response.status, response.reason
-
 
2257
        resp = response.read()
-
 
2258
        conn.close()
-
 
2259
        print resp
-
 
2260
        if "Saved Successfully" in resp:
-
 
2261
            return True
-
 
2262
        elif "Error in Saving Data" in resp:
-
 
2263
            return False
-
 
2264
        else: 
-
 
2265
            return False
-
 
2266
    except Exception as e:
-
 
2267
        print e
-
 
2268
        return False
-
 
2269
 
2204
def get_return_orders(warehouse_id, from_date, to_date):
2270
def get_return_orders(warehouse_id, from_date, to_date):
2205
    query = ReturnOrder.query.filter_by(processedStatus = False)
2271
    query = ReturnOrder.query.filter_by(processedStatus = False)
2206
    if warehouse_id != -1:
2272
    if warehouse_id != -1:
2207
        query = query.filter_by(warehouseId = warehouse_id)
2273
        query = query.filter_by(warehouseId = warehouse_id)
2208
    if from_date:
2274
    if from_date: