| Line 562... |
Line 562... |
| 562 |
query = query.filter_by(is_or=False, is_std=False).filter(or_(Retailers.agent_id==self.agentId, Retailers.agent_id==None)).order_by(Retailers.is_elavated.desc(), -Retailers.agent_id)
|
562 |
query = query.filter_by(is_or=False, is_std=False).filter(or_(Retailers.agent_id==self.agentId, Retailers.agent_id==None)).order_by(Retailers.is_elavated.desc(), -Retailers.agent_id)
|
| 563 |
else:
|
563 |
else:
|
| 564 |
query = query.filter(Retailers.next_call_time<=datetime.now())
|
564 |
query = query.filter(Retailers.next_call_time<=datetime.now())
|
| 565 |
retailer = query.with_lockmode("update").first()
|
565 |
retailer = query.with_lockmode("update").first()
|
| 566 |
if retailer is not None:
|
566 |
if retailer is not None:
|
| 567 |
if isActivated(retailer.id):
|
- |
|
| 568 |
print retailer
|
- |
|
| 569 |
continue
|
- |
|
| 570 |
lgr.info( "retailer " +str(retailer.id))
|
567 |
lgr.info( "retailer " +str(retailer.id))
|
| 571 |
if status=="fresh":
|
568 |
if status=="fresh":
|
| 572 |
userquery = session.query(Users)
|
569 |
userquery = session.query(Users)
|
| 573 |
if retailer.contact2 is not None:
|
570 |
if retailer.contact2 is not None:
|
| 574 |
userquery = userquery.filter(Users.mobile_number.in_([retailer.contact1,retailer.contact2]))
|
571 |
userquery = userquery.filter(Users.mobile_number.in_([retailer.contact1,retailer.contact2]))
|
| Line 580... |
Line 577... |
| 580 |
lgr.info( "retailer.status " + retailer.status)
|
577 |
lgr.info( "retailer.status " + retailer.status)
|
| 581 |
session.commit()
|
578 |
session.commit()
|
| 582 |
continue
|
579 |
continue
|
| 583 |
retailer.status = 'assigned'
|
580 |
retailer.status = 'assigned'
|
| 584 |
else:
|
581 |
else:
|
| - |
|
582 |
if isActivated(retailer.id):
|
| - |
|
583 |
print "Retailer Already %d activated and marked onboarded"%(retailer.id)
|
| - |
|
584 |
continue
|
| 585 |
retailer.status = 'fassigned'
|
585 |
retailer.status = 'fassigned'
|
| 586 |
retailer.retry_count = 0
|
586 |
retailer.retry_count = 0
|
| 587 |
retailer.invalid_retry_count = 0
|
587 |
retailer.invalid_retry_count = 0
|
| 588 |
lgr.info( "Found Retailer " + str(retailer.id) + " with status " + status + " assigned to " + str(self.agentId))
|
588 |
lgr.info( "Found Retailer " + str(retailer.id) + " with status " + status + " assigned to " + str(self.agentId))
|
| 589 |
|
589 |
|
| Line 814... |
Line 814... |
| 814 |
self.callHistory.disposition_description = 'App link sent via' + self.callHistory.disposition_description + '. Followup again on ' + datetime.strftime(self.retailer.next_call_time, '%d/%m/%Y %H:%M:%S')
|
814 |
self.callHistory.disposition_description = 'App link sent via' + self.callHistory.disposition_description + '. Followup again on ' + datetime.strftime(self.retailer.next_call_time, '%d/%m/%Y %H:%M:%S')
|
| 815 |
addContactToRetailer(self.agentId, self.retailerId, self.smsNumber, self.callLater(), 'sms')
|
815 |
addContactToRetailer(self.agentId, self.retailerId, self.smsNumber, self.callLater(), 'sms')
|
| 816 |
session.commit()
|
816 |
session.commit()
|
| 817 |
return True
|
817 |
return True
|
| 818 |
def isActivated(retailerId):
|
818 |
def isActivated(retailerId):
|
| - |
|
819 |
retailerLink = session.query(RetailerLinks).filter_by(retailer_id=retailerId).first()
|
| - |
|
820 |
user = session.query(Users).filter_by(referrer=retailerLink.code).first()
|
| 819 |
try:
|
821 |
if user is None:
|
| 820 |
retailerLink = session.query(RetailerLinks).filter_by(retailer_id=retailerId).first()
|
822 |
mobileNumbers = list(session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailerId).all())
|
| 821 |
user = session.query(Users).filter_by(referrer=retailerLink.code).first()
|
823 |
user = session.query(Users).filter(Users.mobile_number.in_(mobileNumbers)).first()
|
| 822 |
if user is None:
|
824 |
if user is None:
|
| 823 |
mobileNumbers = list(session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailerId).all())
|
- |
|
| 824 |
user = session.query(Users).filter(Users.mobile_number.in_(mobileNumbers)).first()
|
825 |
return False
|
| 825 |
if user is None:
|
826 |
else:
|
| 826 |
return False
|
827 |
mapped_with = 'contact'
|
| 827 |
else:
|
828 |
else:
|
| 828 |
retailerLink.mapped_contact = user.mobile_number
|
829 |
mapped_with = 'code'
|
| 829 |
retailerLink.is_activated = True
|
830 |
retailerLink.mapped_with = mapped_with
|
| 830 |
retailerLink.user_id = user.id
|
831 |
retailerLink.user_id = user.id
|
| - |
|
832 |
retailer = session.query(Retailers).filter_by(id=retailerId)
|
| 831 |
return True
|
833 |
retailer.status = 'onboarded'
|
| 832 |
finally:
|
834 |
session.commit()
|
| 833 |
session.close()
|
835 |
session.close()
|
| - |
|
836 |
return True
|
| 834 |
|
837 |
|
| 835 |
class AddContactToRetailer():
|
838 |
class AddContactToRetailer():
|
| 836 |
def on_post(self,req,resp, agentId):
|
839 |
def on_post(self,req,resp, agentId):
|
| 837 |
agentId = int(agentId)
|
840 |
agentId = int(agentId)
|
| 838 |
try:
|
841 |
try:
|
| Line 974... |
Line 977... |
| 974 |
data[classkey] = obj.__class__.__name__
|
977 |
data[classkey] = obj.__class__.__name__
|
| 975 |
return data
|
978 |
return data
|
| 976 |
else:
|
979 |
else:
|
| 977 |
return obj
|
980 |
return obj
|
| 978 |
|
981 |
|
| 979 |
def getRetailerObj(retailer):
|
982 |
def getRetailerObj(retailer, otherContacts=None):
|
| 980 |
obj = Mock()
|
983 |
obj = Mock()
|
| 981 |
obj.title = retailer.title
|
984 |
obj.title = retailer.title
|
| - |
|
985 |
if otherContacts:
|
| - |
|
986 |
if retailer.contact1 is not None and retailer.contact1 not in otherContacts:
|
| 982 |
obj.contact1 = retailer.contact1
|
987 |
otherContacts.append(retailer.contact1)
|
| - |
|
988 |
if retailer.contact2 is not None and retailer.contact2 not in otherContacts:
|
| 983 |
obj.contact2 = retailer.contact2
|
989 |
otherContacts.append(retailer.contact2)
|
| 984 |
obj.address = retailer.address
|
990 |
obj.address = retailer.address_new if retailer.address_new is not None else retailer.address
|
| 985 |
obj.id = retailer.id
|
991 |
obj.id = retailer.id
|
| 986 |
obj.scheduled = (retailer.call_priority is not None)
|
992 |
obj.scheduled = (retailer.call_priority is not None)
|
| 987 |
return obj
|
993 |
return obj
|
| 988 |
|
994 |
|
| 989 |
def make_tiny(code):
|
995 |
def make_tiny(code):
|