Subversion Repositories SmartDukaan

Rev

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

Rev 2693 Rev 2764
Line 23... Line 23...
23
to = 'cnc.center@shop2020.in'
23
to = 'cnc.center@shop2020.in'
24
 
24
 
25
def process_pickup_records(provider):
25
def process_pickup_records(provider):
26
    try:
26
    try:
27
        filename = fetch_report(provider.name.upper() + ' PICKUP REPORT')
27
        filename = fetch_report(provider.name.upper() + ' PICKUP REPORT')
28
        pickup_details = read_pickup_report(filename)
28
        pickup_details, doa_pickup_details = read_pickup_report(filename)
29
        orders_not_picked_up = update_picked_orders(provider.id, pickup_details)
29
        orders_not_picked_up = update_picked_orders(provider.id, pickup_details)
-
 
30
        try:
30
        if orders_not_picked_up:
31
            if orders_not_picked_up:
31
            mismatch_file = "PickupMismatch.csv"
32
                mismatch_file = "PickupMismatch.csv"
32
            print "Some of our orders were not picked up. Printing report to:" + mismatch_file
33
                print "Some of our orders were not picked up. Printing report to:" + mismatch_file
33
            print_pickup_mismatch_report(mismatch_file, orders_not_picked_up)
34
                print_pickup_mismatch_report(mismatch_file, orders_not_picked_up)
-
 
35
                pickup_mismatch_part = get_attachment_part(mismatch_file)
-
 
36
                mail(from_user, from_pwd, to,\
-
 
37
                     "Order Pickup Mismatch for " + provider.name,\
-
 
38
                     "This is a system generated email.Please don't reply to it.",\
-
 
39
                     pickup_mismatch_part)
-
 
40
        except Exception:
-
 
41
            print "Some issue sending the mismatch report"
-
 
42
        
-
 
43
        doas_not_picked_up = update_picked_doas(provider.id, doa_pickup_details)
-
 
44
        try:
-
 
45
            if doas_not_picked_up:
-
 
46
                mismatch_file = "DoaPickupMismatch.csv"
-
 
47
                print "Some of our DOA orders were not picked up. Printing report to:" + mismatch_file
-
 
48
                print_pickup_mismatch_report(mismatch_file, doas_not_picked_up)
34
            pickup_mismatch_part = get_attachment_part(mismatch_file)
49
                pickup_mismatch_part = get_attachment_part(mismatch_file)
35
            mail(from_user, from_pwd, to,\
50
                mail(from_user, from_pwd, to,\
36
                 "Pickup Mismatch for " + provider.name,\
51
                     "DOA Pickup Mismatch for " + provider.name,\
37
                 "This is a system generated email.Please don't reply to it.",\
52
                     "This is a system generated email.Please don't reply to it.",\
38
                 pickup_mismatch_part)
53
                     pickup_mismatch_part)
-
 
54
        except Exception:
-
 
55
            print "Some issue sending the mismatch report"
39
    finally:
56
    finally:
40
        os.remove(filename)
57
        os.remove(filename)
41
 
58
 
42
def process_delivery_report(provider):
59
def process_delivery_report(provider):
43
    try:
60
    try:
Line 94... Line 111...
94
    print "Reading pickup report from:" + filename
111
    print "Reading pickup report from:" + filename
95
    workbook = xlrd.open_workbook(filename)
112
    workbook = xlrd.open_workbook(filename)
96
    sheet = workbook.sheet_by_index(0)
113
    sheet = workbook.sheet_by_index(0)
97
    num_rows = sheet.nrows
114
    num_rows = sheet.nrows
98
    picked_up_orders = {}
115
    picked_up_orders = {}
-
 
116
    picked_up_doas = {}
99
    for rownum in range(1, num_rows):
117
    for rownum in range(1, num_rows):
100
        unused_customer_code, awb, unused_ref_no, timeval, date = sheet.row_values(rownum)[0:5]
118
        unused_customer_code, awb, ref_no, timeval, date = sheet.row_values(rownum)[0:5]
101
        picked_up_orders[awb] = str(get_py_datetime(date, timeval))
119
        picked_up_orders[awb] = str(get_py_datetime(date, timeval))
-
 
120
        picked_up_doas[ref_no] = str(get_py_datetime(date, timeval))
102
    
121
    
103
    print "Picked up Orders:"
122
    print "Picked up Orders:"
104
    print picked_up_orders
123
    print picked_up_orders
105
    return picked_up_orders
124
    print picked_up_doas
-
 
125
    return picked_up_orders, picked_up_doas
106
 
126
 
107
def read_delivery_report(filename):
127
def read_delivery_report(filename):
108
    print "Reading delivery details from:" + filename
128
    print "Reading delivery details from:" + filename
109
    workbook = xlrd.open_workbook(filename)
129
    workbook = xlrd.open_workbook(filename)
110
    sheet = workbook.sheet_by_index(0)
130
    sheet = workbook.sheet_by_index(0)
Line 153... Line 173...
153
        orders_not_picked_up = txnClient.markOrdersAsPickedUp(provider_id, pickup_details)
173
        orders_not_picked_up = txnClient.markOrdersAsPickedUp(provider_id, pickup_details)
154
        return orders_not_picked_up
174
        return orders_not_picked_up
155
    except TransactionServiceException as tex:
175
    except TransactionServiceException as tex:
156
        print tex.message
176
        print tex.message
157
 
177
 
-
 
178
def update_picked_doas(provider_id, doa_pickup_details):
-
 
179
    txnClient = TransactionClient().get_client()
-
 
180
    try:
-
 
181
        doas_not_picked_up = txnClient.markDoasAsPickedUp(provider_id, doa_pickup_details)
-
 
182
        return doas_not_picked_up
-
 
183
    except TransactionServiceException as tex:
-
 
184
        print tex.message
-
 
185
 
158
def update_delivered_orders(provider_id, delivered_orders):
186
def update_delivered_orders(provider_id, delivered_orders):
159
    txnClient = TransactionClient().get_client()
187
    txnClient = TransactionClient().get_client()
160
    try:
188
    try:
161
        txnClient.markOrdersAsDelivered(provider_id, delivered_orders)
189
        txnClient.markOrdersAsDelivered(provider_id, delivered_orders)
162
    except TransactionServiceException as tex:
190
    except TransactionServiceException as tex: