Subversion Repositories SmartDukaan

Rev

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

Rev 21063 Rev 21090
Line 110... Line 110...
110
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
110
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
111
    WarehouseServiceException
111
    WarehouseServiceException
112
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part, \
112
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part, \
113
    mail_html
113
    mail_html
114
from shop2020.utils.Utils import to_py_date, to_java_date, \
114
from shop2020.utils.Utils import to_py_date, to_java_date, \
115
    getSyncOperatorsForRecharge
115
    getSyncOperatorsForRecharge, generate_random_code
116
from suds.client import Client
116
from suds.client import Client
-
 
117
from sqlalchemy.orm import aliased
117
 
118
 
118
 
119
 
119
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
120
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
120
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
121
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
121
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
122
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
Line 11422... Line 11423...
11422
        pmsa_agents.userId = userId
11423
        pmsa_agents.userId = userId
11423
        pmsa_agents.pmsa_id = pmsa.id
11424
        pmsa_agents.pmsa_id = pmsa.id
11424
        session.commit()
11425
        session.commit()
11425
    return True
11426
    return True
11426
 
11427
 
-
 
11428
def add_sales_associate(pmsa, referrerEmail, l1_userEmail):
-
 
11429
    d_pmsa = PMSA.query.filter(or_(PMSA.emailId == pmsa.emailId, PMSA.phone == pmsa.phone)).all()
-
 
11430
    if d_pmsa:
-
 
11431
        return "User with same phone or email already exists"
-
 
11432
    referrer = PMSA.get_by(emailId = referrerEmail, activated=True)
-
 
11433
    d_pmsa = PMSA()
-
 
11434
    d_pmsa.name = pmsa.name
-
 
11435
    d_pmsa.phone = pmsa.phone 
-
 
11436
    d_pmsa.emailId = pmsa.emailId
-
 
11437
    d_pmsa.address = pmsa.address
-
 
11438
    d_pmsa.state = pmsa.state
-
 
11439
    d_pmsa.level = pmsa.level
-
 
11440
    d_pmsa.activated = pmsa.activated
-
 
11441
    d_pmsa.pin = pmsa.pin
-
 
11442
    if referrerEmail != l1_userEmail:
-
 
11443
        if referrer is None or referrer.level != 'L2':
-
 
11444
            return "Not valid referrer"
-
 
11445
        l1_user = PMSA.get_by(id = referrer.l1_id)
-
 
11446
        if l1_user.emailId != l1_userEmail:
-
 
11447
            return "You are not authorized to refer"
-
 
11448
        d_pmsa.l2_id = referrer.id
-
 
11449
    else:
-
 
11450
        l1_user = referrer
-
 
11451
    d_pmsa.l1_id = l1_user.id
-
 
11452
    for i in range(0,5):
-
 
11453
        activation_code = "SA"+str(generate_random_code(8))
-
 
11454
        code_exists = PMSA.get_by(code=activation_code)
-
 
11455
        if not code_exists:
-
 
11456
            break
-
 
11457
        if i==4:
-
 
11458
            return "Activation code generation failed"
-
 
11459
    d_pmsa.code = activation_code
-
 
11460
    session.commit()
-
 
11461
    return "User added successfully.Activation Code %s"%(activation_code)
-
 
11462
 
-
 
11463
def search_pmsa(pmsaSearchFilter, associateEmail):
-
 
11464
    associate = PMSA.get_by(emailId = associateEmail)
-
 
11465
    query = session.query(PMSA).filter(PMSA.l1_id == associate.id)
-
 
11466
    if pmsaSearchFilter.name:
-
 
11467
        query = query.filter(PMSA.name == pmsaSearchFilter.name)
-
 
11468
    if pmsaSearchFilter.emailId:
-
 
11469
        query = query.filter(PMSA.emailId == pmsaSearchFilter.emailId)
-
 
11470
    if pmsaSearchFilter.phone:
-
 
11471
        query = query.filter(PMSA.phone == pmsaSearchFilter.phone)
-
 
11472
    if pmsaSearchFilter.code:
-
 
11473
        query = query.filter(PMSA.code == pmsaSearchFilter.code)
-
 
11474
    
-
 
11475
    if pmsaSearchFilter.l2_email:
-
 
11476
        referrer = PMSA.get_by(emailId = pmsaSearchFilter.l2_email)
-
 
11477
        if referrer:
-
 
11478
            query = query.filter(PMSA.l2_id == referrer.id)
-
 
11479
        else:
-
 
11480
            return []
-
 
11481
    return query.all()
11427
 
11482
 
-
 
11483
def get_pmsa_user(id, associateEmail):
-
 
11484
    associate = PMSA.get_by(emailId = associateEmail)
-
 
11485
    pmsa = PMSA.get_by(id=id)
-
 
11486
    if pmsa.l1_id != associate.id:
-
 
11487
        return None 
-
 
11488
    l2_user_email = ""
-
 
11489
    if pmsa.l2_id:
-
 
11490
        l2_user = PMSA.get_by(id=pmsa.l2_id)
-
 
11491
        l2_user_email = l2_user.emailId
-
 
11492
    return pmsa, associate.emailId, l2_user_email
-
 
11493
 
-
 
11494
def update_pmsa_user(pmsa, associateEmail):
-
 
11495
    d_pmsa = PMSA.query.filter(or_(PMSA.emailId == pmsa.emailId, PMSA.phone == pmsa.phone)).all()
-
 
11496
    if not d_pmsa or (len(d_pmsa)==1 and d_pmsa[0].id == pmsa.id):
-
 
11497
        n_pmsa = PMSA.get_by(id=pmsa.id)
-
 
11498
        associate = PMSA.get_by(emailId = associateEmail)
-
 
11499
        if n_pmsa.l1_id != associate.id:
-
 
11500
            return "You dont have permission to edit this user"
-
 
11501
        n_pmsa.name = pmsa.name
-
 
11502
        n_pmsa.phone = pmsa.phone 
-
 
11503
        n_pmsa.emailId = pmsa.emailId
-
 
11504
        n_pmsa.address = pmsa.address
-
 
11505
        n_pmsa.state = pmsa.state
-
 
11506
        n_pmsa.activated = pmsa.activated
-
 
11507
        n_pmsa.pin = pmsa.pin
-
 
11508
        session.commit()
-
 
11509
        return "User updated successfully"
-
 
11510
    return "User with same email or phone exists"
-
 
11511
 
-
 
11512
def get_pending_pmsa(associateEmail):
-
 
11513
    associate = PMSA.get_by(emailId = associateEmail)
-
 
11514
    query = session.query(PMSA).filter(PMSA.l1_id == associate.id).filter(PMSA.activated == False)
-
 
11515
    return query.all()
11428
 
11516
 
-
 
11517
def get_pmsa_users(associateEmail):
-
 
11518
    associate = PMSA.get_by(emailId = associateEmail)
-
 
11519
    query = session.query(PMSA).filter(PMSA.l1_id == associate.id).order_by(desc(PMSA.createdAt))
-
 
11520
    return query.all()
-
 
11521
    
-
 
11522
def get_stats_for_associates(associateEmail):
-
 
11523
    a = PMSA.get_by(emailId = associateEmail)
-
 
11524
    if a is None:
-
 
11525
        return [0,0,0,0,0]
-
 
11526
    l2 = session.query(PMSA.id).filter(PMSA.l1_id == a.id).filter(PMSA.level == "L2").count()
-
 
11527
    l3 = session.query(PMSA.id).filter(PMSA.l1_id == a.id).filter(PMSA.level == "L3").count()
-
 
11528
    not_activated = session.query(PMSA.id).filter(PMSA.l1_id == a.id).filter(PMSA.activated == False).count()
-
 
11529
    total = session.query(PMSA.id).filter(PMSA.l1_id == a.id).count()
-
 
11530
    return [l2,l3,total,not_activated,total-not_activated]
-
 
11531
    
-
 
11532
    
11429
if __name__ == '__main__':
11533
if __name__ == '__main__':
11430
    #DataService.initialize()
11534
    #DataService.initialize()
11431
    get_billed_orders_for_manifest_gen(7441, 2, True)
11535
    get_billed_orders_for_manifest_gen(7441, 2, True)
11432
#    ordersmap = {'911319502886601':1544266,'911319502890314':1544266,'x911319502903141':1544269,'x911319502916655':1544269,'x911319502950985':1544269,'x911319502836309':1544269,'x911319502972369':1544269,'x911319502950860':1544269,'x911319502918313':1544269,
11536
#    ordersmap = {'911319502886601':1544266,'911319502890314':1544266,'x911319502903141':1544269,'x911319502916655':1544269,'x911319502950985':1544269,'x911319502836309':1544269,'x911319502972369':1544269,'x911319502950860':1544269,'x911319502918313':1544269,
11433
#                 'x911319502943436':1544269,'x911319502928056':1544269,'x911319502838263':1544269,'911319502794144':1544269,'x911319502821616':1544269,'x911319502974746':1544269,'x911319502821442':1544269,'x911319502903984':1544269,'x911319502820980':1544269,
11537
#                 'x911319502943436':1544269,'x911319502928056':1544269,'x911319502838263':1544269,'911319502794144':1544269,'x911319502821616':1544269,'x911319502974746':1544269,'x911319502821442':1544269,'x911319502903984':1544269,'x911319502820980':1544269,