Subversion Repositories SmartDukaan

Rev

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

Rev 18664 Rev 18677
Line 150... Line 150...
150
    CreditTxnType.LOAN_CANCELLED : -1, 
150
    CreditTxnType.LOAN_CANCELLED : -1, 
151
    CreditTxnType.PAID : -1,
151
    CreditTxnType.PAID : -1,
152
    CreditTxnType.CORRECTION : -1
152
    CreditTxnType.CORRECTION : -1
153
}
153
}
154
 
154
 
-
 
155
creditorTicketSizeMap = {}
-
 
156
creditorDueDateMap = {}
155
 
157
 
156
stateIdMap = {}
158
stateIdMap = {}
157
def fetchStateMaster():
159
def fetchStateMaster():
158
    global stateIdMap
160
    global stateIdMap
159
    if stateIdMap:
161
    if stateIdMap:
Line 163... Line 165...
163
            glob_inventory_client = InventoryClient().get_client()
165
            glob_inventory_client = InventoryClient().get_client()
164
            stateIdMap = glob_inventory_client.getStateMaster()
166
            stateIdMap = glob_inventory_client.getStateMaster()
165
            return stateIdMap
167
            return stateIdMap
166
        except:
168
        except:
167
            print "Could not fetch"
169
            print "Could not fetch"
-
 
170
            
-
 
171
def fetchCreditorTicketSizeMap():
-
 
172
    global creditorTicketSizeMap
-
 
173
    allCreditors = Creditor.query.all()
-
 
174
    for creditor in allCreditors:
-
 
175
        creditorTicketSizeMap[creditor.id] = creditor.ticket_size
-
 
176
 
-
 
177
def fetchCreditorDueDateMap():
-
 
178
    global creditorDueDateMap
-
 
179
    allCreditors = Creditor.query.all()
-
 
180
    for creditor in allCreditors:
-
 
181
        creditorDueDateMap[creditor.id] = creditor.credit_due_days
-
 
182
 
168
 
183
 
169
delhi_pincodes = ['110001','110002','110003','110004','110005','110006','110007','110008','110009','110010','110011','110012','110013','110014','110015',\
184
delhi_pincodes = ['110001','110002','110003','110004','110005','110006','110007','110008','110009','110010','110011','110012','110013','110014','110015',\
170
                '110016','110017','110018','110019','110020','110021','110022','110023','110024','110025','110026','110027','110028','110029','110030',\
185
                '110016','110017','110018','110019','110020','110021','110022','110023','110024','110025','110026','110027','110028','110029','110030',\
171
                '110031','110032','110033','110034','110035','110037','110038','110041','110042','110044','110045','110046','110047','110048','110049',\
186
                '110031','110032','110033','110034','110035','110037','110038','110041','110042','110044','110045','110046','110047','110048','110049',\
172
                '110051','110052','110053','110054','110055','110056','110057','110058','110059','110060','110061','110062','110063','110064','110065',\
187
                '110051','110052','110053','110054','110055','110056','110057','110058','110059','110060','110061','110062','110063','110064','110065',\
Line 8996... Line 9011...
8996
    us_query = UserSanction.query
9011
    us_query = UserSanction.query
8997
    if userId:
9012
    if userId:
8998
        us_query = us_query.filter(UserSanction.user_id == userId)
9013
        us_query = us_query.filter(UserSanction.user_id == userId)
8999
    if creditorId:
9014
    if creditorId:
9000
        us_query = us_query.filter(UserSanction.creditor_id == creditorId)
9015
        us_query = us_query.filter(UserSanction.creditor_id == creditorId)
-
 
9016
        
9001
    return us_query.all()
9017
    allSanctions = us_query.all()
-
 
9018
    returnMap = {}
-
 
9019
    for sanction in allSanctions:
-
 
9020
        ticket_size = -1
-
 
9021
        if creditorTicketSizeMap.has_key(sanction.creditor_id):
-
 
9022
            ticket_size = creditorTicketSizeMap.get(sanction.creditor_id)
-
 
9023
        else:
-
 
9024
            fetchCreditorTicketSizeMap()
-
 
9025
            ticket_size = creditorTicketSizeMap.get(sanction.creditor_id)
-
 
9026
        
-
 
9027
        if returnMap.has_key(sanction.creditor_id):
-
 
9028
            creditorMap = returnMap.get(sanction.creditor_id)
-
 
9029
            creditorMap['TicketSize'] = ticket_size
-
 
9030
            if creditorMap.has_key('Sanctions'):
-
 
9031
                sanctionsList = creditorMap.get('Sanctions')
-
 
9032
                sanctionsList.append(sanction)
-
 
9033
                creditorMap['Sanctions'] = sanctionsList
-
 
9034
            else:
-
 
9035
                sanctionsList =[]
-
 
9036
                sanctionsList.append(sanction)
-
 
9037
                creditorMap['Sanctions'] = sanctionsList
-
 
9038
            returnMap[sanction.creditor_id] = creditorMap
-
 
9039
        else:
-
 
9040
            creditorMap
-
 
9041
            creditorMap['TicketSize'] = ticket_size
-
 
9042
            sanctionsList =[]
-
 
9043
            sanctionsList.append(sanction)
-
 
9044
            creditorMap['Sanctions'] = sanctionsList
-
 
9045
            returnMap[sanction.creditor_id] = creditorMap
-
 
9046
                    
-
 
9047
    return returnMap
9002
 
9048
 
9003
def update_user_sanction(userSanction):
9049
def update_user_sanction(userSanction):
9004
    userS = UserSanction.get_by(id=userSanction.id)
9050
    userS = UserSanction.get_by(id=userSanction.id)
9005
    if userS is None:
9051
    if userS is None:
9006
        return False
9052
        return False
Line 9087... Line 9133...
9087
                loanHistoryRec.creditor_id = creditorId
9133
                loanHistoryRec.creditor_id = creditorId
9088
                loanHistoryRec.payment_id = paymentId
9134
                loanHistoryRec.payment_id = paymentId
9089
                loanHistoryRec.amount = creditTxn.amount * loanTxnMultplierMap.get(creditTxn.credit_type)
9135
                loanHistoryRec.amount = creditTxn.amount * loanTxnMultplierMap.get(creditTxn.credit_type)
9090
                loanHistoryRec.credit_type = CreditTxnType._VALUES_TO_NAMES[creditTxn.credit_type]
9136
                loanHistoryRec.credit_type = CreditTxnType._VALUES_TO_NAMES[creditTxn.credit_type]
9091
                loanHistoryRec.loan_id = creditTxn.loan_id
9137
                loanHistoryRec.loan_id = creditTxn.loan_id
-
 
9138
                if creditorDueDateMap.has_key(creditorId):
-
 
9139
                    due_days = creditorDueDateMap.get(creditorId)
9092
                loanHistoryRec.due_date = datetime.datetime.now()+timedelta(days=30)
9140
                    loanHistoryRec.due_date = datetime.datetime.now()+timedelta(days=due_days)
-
 
9141
                else:
-
 
9142
                    fetchCreditorDueDateMap()
-
 
9143
                    due_days = creditorDueDateMap.get(creditorId)
-
 
9144
                    loanHistoryRec.due_date = datetime.datetime.now()+timedelta(days=due_days)
9093
        else:
9145
        else:
9094
            logging.info("Error: Entry already existed for "+str(paymentId) + " Shipping Id:- "+str(creditTxns[0].shipping_id) +" Credit Txn Type:- "+CreditTxnType._VALUES_TO_NAMES[creditTxn.credit_type]+ " in Credit History ")
9146
            logging.info("Error: Entry already existed for "+str(paymentId) + " Shipping Id:- "+str(creditTxns[0].shipping_id) +" Credit Txn Type:- "+CreditTxnType._VALUES_TO_NAMES[creditTxn.credit_type]+ " in Credit History ")
9095
            raise TransactionServiceException(227, "Error: Entry already existed for "+str(paymentId) + " Shipping Id:- "+str(creditTxns[0].shipping_id) +" Credit Txn Type:- "+CreditTxnType._VALUES_TO_NAMES[creditTxn.credit_type]+ " in Credit History ")
9147
            raise TransactionServiceException(227, "Error: Entry already existed for "+str(paymentId) + " Shipping Id:- "+str(creditTxns[0].shipping_id) +" Credit Txn Type:- "+CreditTxnType._VALUES_TO_NAMES[creditTxn.credit_type]+ " in Credit History ")
9096
    session.commit()   
9148
    session.commit()   
9097
    return True
9149
    return True
Line 9185... Line 9237...
9185
                loanHistoryRec.payment_id = paymentId
9237
                loanHistoryRec.payment_id = paymentId
9186
                loanHistoryRec.amount = loanTxn.amount * loanTxnMultplierMap.get(loanTxn.credit_type)
9238
                loanHistoryRec.amount = loanTxn.amount * loanTxnMultplierMap.get(loanTxn.credit_type)
9187
                loanHistoryRec.credit_type = CreditTxnType._VALUES_TO_NAMES[loanTxn.credit_type]
9239
                loanHistoryRec.credit_type = CreditTxnType._VALUES_TO_NAMES[loanTxn.credit_type]
9188
                loanHistoryRec.loan_id = loanTxn.loan_id
9240
                loanHistoryRec.loan_id = loanTxn.loan_id
9189
                if loanTxn.credit_type in [CreditTxnType.LOAN]:
9241
                if loanTxn.credit_type in [CreditTxnType.LOAN]:
-
 
9242
                    if creditorDueDateMap.has_key(creditorId):
-
 
9243
                        due_days = creditorDueDateMap.get(creditorId)
9190
                    loanHistoryRec.due_date = datetime.datetime.now()+timedelta(days=30)
9244
                        loanHistoryRec.due_date = datetime.datetime.now()+timedelta(days=due_days)
-
 
9245
                    else:
-
 
9246
                        fetchCreditorDueDateMap()
-
 
9247
                        due_days = creditorDueDateMap.get(creditorId)
-
 
9248
                        loanHistoryRec.due_date = datetime.datetime.now()+timedelta(days=due_days)
9191
                if loanTxn.credit_type in [CreditTxnType.CORRECTION]:
9249
                if loanTxn.credit_type in [CreditTxnType.CORRECTION]:
9192
                    loanRec = LoanHistory.get_by(payment_id=paymentId,loan_id=loanTxn.loan_id, credit_type='LOAN')
9250
                    loanRec = LoanHistory.get_by(payment_id=paymentId,loan_id=loanTxn.loan_id, credit_type='LOAN')
9193
                    loanRec.updated = datetime.datetime.now()
9251
                    loanRec.updated = datetime.datetime.now()
9194
                    userSanction.loan = userSanction.loan + (loanTxn.amount * loanTxnMultplierMap.get(loanTxn.credit_type))
9252
                    userSanction.loan = userSanction.loan + (loanTxn.amount * loanTxnMultplierMap.get(loanTxn.credit_type))
9195
            else:
9253
            else: