Subversion Repositories SmartDukaan

Rev

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

Rev 3475 Rev 3476
Line 1... Line 1...
1
#!/usr/bin/python 
1
#!/usr/bin/python
2
 
2
 
3
import time
3
import time
4
import datetime
4
import datetime
5
import optparse
5
import optparse
6
import sys
6
import sys
7
import csv
7
import csv
8
import xlrd
8
import xlrd
-
 
9
import traceback
9
 
10
 
10
if __name__ == '__main__' and __package__ is None:
11
if __name__ == '__main__' and __package__ is None:
11
    import os
12
    import os
12
    sys.path.insert(0, os.getcwd())
13
    sys.path.insert(0, os.getcwd())
13
 
14
 
Line 27... Line 28...
27
        filename = fetch_report(provider.name.upper() + ' PICKUP REPORT')
28
        filename = fetch_report(provider.name.upper() + ' PICKUP REPORT')
28
        pickup_details, doa_pickup_details = read_pickup_report(filename)
29
        pickup_details, doa_pickup_details = read_pickup_report(filename)
29
        orders_not_picked_up = update_picked_orders(provider.id, pickup_details)
30
        orders_not_picked_up = update_picked_orders(provider.id, pickup_details)
30
        try:
31
        try:
31
            if orders_not_picked_up:
32
            if orders_not_picked_up:
32
                mismatch_file = "PickupMismatch.csv"
33
                mismatch_file = "/tmp/PickupMismatch.csv"
33
                print "Some of our orders were not picked up. Printing report to:" + mismatch_file
34
                print "Some of our orders were not picked up. Printing report to:" + mismatch_file
34
                print_pickup_mismatch_report(mismatch_file, orders_not_picked_up)
35
                print_pickup_mismatch_report(mismatch_file, orders_not_picked_up)
35
                pickup_mismatch_part = get_attachment_part(mismatch_file)
36
                pickup_mismatch_part = [get_attachment_part(mismatch_file)]
36
                mail(from_user, from_pwd, to,\
37
                mail(from_user, from_pwd, to,\
37
                     "Order Pickup Mismatch for " + provider.name,\
38
                     "Order Pickup Mismatch for " + provider.name,\
38
                     "This is a system generated email.Please don't reply to it.",\
39
                     "This is a system generated email.Please don't reply to it.",\
39
                     pickup_mismatch_part)
40
                     pickup_mismatch_part)
40
        except Exception:
41
        except Exception:
41
            print "Some issue sending the mismatch report"
42
            print "Some issue sending the mismatch report"
-
 
43
            traceback.print_exc()
42
        
44
        
43
        doas_not_picked_up = update_picked_doas(provider.id, doa_pickup_details)
45
        doas_not_picked_up = update_picked_doas(provider.id, doa_pickup_details)
44
        try:
46
        try:
45
            if doas_not_picked_up:
47
            if doas_not_picked_up:
46
                mismatch_file = "DoaPickupMismatch.csv"
48
                mismatch_file = "/tmp/DoaPickupMismatch.csv"
47
                print "Some of our DOA orders were not picked up. Printing report to:" + mismatch_file
49
                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)
50
                print_pickup_mismatch_report(mismatch_file, doas_not_picked_up)
49
                pickup_mismatch_part = [get_attachment_part(mismatch_file)]
51
                pickup_mismatch_part = [get_attachment_part(mismatch_file)]
50
                mail(from_user, from_pwd, to,\
52
                mail(from_user, from_pwd, to,\
51
                     "DOA Pickup Mismatch for " + provider.name,\
53
                     "DOA Pickup Mismatch for " + provider.name,\
52
                     "This is a system generated email.Please don't reply to it.",\
54
                     "This is a system generated email.Please don't reply to it.",\
53
                     pickup_mismatch_part)
55
                     pickup_mismatch_part)
54
        except Exception:
56
        except Exception:
55
            print "Some issue sending the mismatch report"
57
            print "Some issue sending the mismatch report"
-
 
58
            traceback.print_exc()
56
    finally:
59
    finally:
57
        os.remove(filename)
60
        os.remove(filename)
58
 
61
 
59
def process_delivery_report(provider):
62
def process_delivery_report(provider):
60
    try:
63
    try:
Line 68... Line 71...
68
            
71
            
69
            mail(from_user, from_pwd, to,\
72
            mail(from_user, from_pwd, to,\
70
                 "Returned Orders Report for " + provider.name,\
73
                 "Returned Orders Report for " + provider.name,\
71
                 "This is a system generated email.Please don't reply to it.",\
74
                 "This is a system generated email.Please don't reply to it.",\
72
                 [])
75
                 [])
-
 
76
    except:
-
 
77
        print "Some issue sending the returned orders report"
-
 
78
        traceback.print_exc()
73
    finally:
79
    finally:
74
        os.remove(filename)
80
        os.remove(filename)
75
 
81
 
76
def process_non_delivery_report(provider):
82
def process_non_delivery_report(provider):
77
    try:
83
    try: