Subversion Repositories SmartDukaan

Rev

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

Rev 15613 Rev 15662
Line 550... Line 550...
550
                return retailer
550
                return retailer
551
        retailer.status = ASSIGN_MAP.get(status)
551
        retailer.status = ASSIGN_MAP.get(status)
552
        lgr.info( "getRetryRetailer " + str(retailer.id))
552
        lgr.info( "getRetryRetailer " + str(retailer.id))
553
        return retailer
553
        return retailer
554
            
554
            
-
 
555
    def getNotActiveRetailer(self):
-
 
556
        try:
-
 
557
            user = session.query(Users).filter_by(activated=0).filter_by(status=1).filter(Users.mobile_number != None).filter(~Users.mobile_number.like("0%")).order_by(Users.created.desc()).with_lockmode("update").first()
-
 
558
            if user is None: 
-
 
559
                return None
-
 
560
            else:
-
 
561
                retailerContact = session.query(RetailerContacts).filter_by(mobile_number=user.mobile_number).first()
-
 
562
                if retailerContact is not None:
-
 
563
                    retailer = session.query(Retailers).filter_by(id=retailerContact.retailer_id).first()
-
 
564
                else:
-
 
565
                    retailer = session.query(Retailers).filter_by(contact1=user.mobile_number).first()
-
 
566
                    if retailer is None:
-
 
567
                        retailer = session.query(Retailers).filter_by(contact2=user.mobile_number).first()
-
 
568
                        if retailer is None:
-
 
569
                            retailer = Retailers()
-
 
570
                            retailer.contact1 = user.mobile_number
-
 
571
                            retailer.status = 'assigned'
-
 
572
                user.status = 2
-
 
573
                session.commit()
-
 
574
                print "retailer id", retailer.id
-
 
575
                retailer.contact = user.mobile_number
-
 
576
                return retailer
-
 
577
        finally:
-
 
578
            session.close()
-
 
579
            
555
    def getNewRetailer(self,failback=True):
580
    def getNewRetailer(self,failback=True):
-
 
581
        retailer = self.getNotActiveRetailer()
-
 
582
        if retailer is not None:
-
 
583
            return retailer
556
        retry = True
584
        retry = True
557
        retailer = None 
585
        retailer = None 
558
        try:
586
        try:
559
            while(retry):
587
            while(retry):
560
                lgr.info( "Calltype " + self.callType)
588
                lgr.info( "Calltype " + self.callType)
Line 680... Line 708...
680
        alreadyUser = self.alReadyUser
708
        alreadyUser = self.alReadyUser
681
        verifiedLinkSent = self.verifiedLinkSent
709
        verifiedLinkSent = self.verifiedLinkSent
682
        onboarded = self.onboarded
710
        onboarded = self.onboarded
683
        self.address = jsonReq.get('address')
711
        self.address = jsonReq.get('address')
684
        self.retailerId = int(jsonReq.get('retailerid'))
712
        self.retailerId = int(jsonReq.get('retailerid'))
685
        self.smsNumber = jsonReq.get('smsnumber') 
713
        self.smsNumber = jsonReq.get('smsnumber').strip().lstrip("0") 
686
        try:
714
        try:
687
            self.retailer = session.query(Retailers).filter_by(id=self.retailerId).first()
715
            self.retailer = session.query(Retailers).filter_by(id=self.retailerId).first()
688
            if self.address:
716
            if self.address:
689
                self.retailer.address_new = self.address
717
                self.retailer.address_new = self.address
690
            self.callDisposition = jsonReq.get('calldispositiontype')
718
            self.callDisposition = jsonReq.get('calldispositiontype')
Line 1043... Line 1071...
1043
        return obj
1071
        return obj
1044
    
1072
    
1045
def getRetailerObj(retailer, otherContacts1=None, callType=None):
1073
def getRetailerObj(retailer, otherContacts1=None, callType=None):
1046
    print "before otherContacts1",otherContacts1
1074
    print "before otherContacts1",otherContacts1
1047
    otherContacts = [] if otherContacts1 is None else otherContacts1
1075
    otherContacts = [] if otherContacts1 is None else otherContacts1
1048
    print "afotherContacts1",otherContacts
1076
    print "after otherContacts1",otherContacts
1049
    obj = Mock()
1077
    obj = Mock()
1050
    obj.title = retailer.title
1078
    obj.title = retailer.title
1051
    obj.id = retailer.id
1079
    obj.id = retailer.id
1052
    if retailer.contact1 is not None and retailer.contact1 not in otherContacts:
1080
    if retailer.contact1 is not None and retailer.contact1 not in otherContacts:
1053
        otherContacts.append(retailer.contact1)
1081
        otherContacts.append(retailer.contact1)
Line 1057... Line 1085...
1057
    obj.contact1 = None if len(otherContacts)==0 else otherContacts[0]
1085
    obj.contact1 = None if len(otherContacts)==0 else otherContacts[0]
1058
    if obj.contact1 is not None:
1086
    if obj.contact1 is not None:
1059
        obj.contact2 = None if len(otherContacts)==1 else otherContacts[1]
1087
        obj.contact2 = None if len(otherContacts)==1 else otherContacts[1]
1060
    obj.scheduled = (retailer.call_priority is not None)
1088
    obj.scheduled = (retailer.call_priority is not None)
1061
    obj.status = retailer.status
1089
    obj.status = retailer.status
-
 
1090
    if hasattr(retailer, 'contact'):
-
 
1091
        obj.contact = retailer.contact
1062
    if callType == 'onboarding':
1092
    if callType == 'onboarding':
1063
        try:
1093
        try:
1064
            userId, activatedTime = session.query(RetailerLinks.user_id, RetailerLinks.activated).filter(RetailerLinks.retailer_id==retailer.id).first()
1094
            userId, activatedTime = session.query(RetailerLinks.user_id, RetailerLinks.activated).filter(RetailerLinks.retailer_id==retailer.id).first()
1065
            activated, = session.query(Users.activation_time).filter(Users.id==userId).first()
1095
            activated, = session.query(Users.activation_time).filter(Users.id==userId).first()
1066
            if activated is not None:
1096
            if activated is not None:
Line 1148... Line 1178...
1148
        resp.body = dumps(result)
1178
        resp.body = dumps(result)
1149
 
1179
 
1150
 
1180
 
1151
 
1181
 
1152
def main():
1182
def main():
1153
    tagActivatedReatilers()
1183
    #tagActivatedReatilers()
-
 
1184
    a = RetailerDetail()
-
 
1185
    retailer = a.getNotActiveRetailer()
-
 
1186
    otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
-
 
1187
    print json.dumps(todict(getRetailerObj(retailer, otherContacts, 'fresh')), encoding='utf-8')
1154
    #print make_tiny("AA")
1188
    #print make_tiny("AA")
1155
    
1189
    
1156
if __name__ == '__main__':
1190
if __name__ == '__main__':
1157
    main()
1191
    main()
1158
        
1192
        
1159
1193