| Line 7... |
Line 7... |
| 7 |
from dtr.storage import Mongo
|
7 |
from dtr.storage import Mongo
|
| 8 |
from dtr.storage.DataService import Retailers, Users, CallHistory, RetryConfig, \
|
8 |
from dtr.storage.DataService import Retailers, Users, CallHistory, RetryConfig, \
|
| 9 |
RetailerLinks, Activation_Codes, Agents, Agent_Roles, AgentLoginTimings, \
|
9 |
RetailerLinks, Activation_Codes, Agents, Agent_Roles, AgentLoginTimings, \
|
| 10 |
FetchDataHistory, RetailerContacts, Orders, OnboardedRetailerChecklists,\
|
10 |
FetchDataHistory, RetailerContacts, Orders, OnboardedRetailerChecklists,\
|
| 11 |
RetailerAddresses, Pincodeavailability, app_offers, appmasters, user_app_cashbacks, user_app_installs,\
|
11 |
RetailerAddresses, Pincodeavailability, app_offers, appmasters, user_app_cashbacks, user_app_installs,\
|
| 12 |
Postoffices, UserCrmCallingData
|
12 |
Postoffices, UserCrmCallingData, CallHistoryCrm
|
| 13 |
from dtr.storage.Mongo import get_mongo_connection
|
13 |
from dtr.storage.Mongo import get_mongo_connection
|
| 14 |
from dtr.storage.Mysql import fetchResult
|
14 |
from dtr.storage.Mysql import fetchResult
|
| 15 |
from dtr.utils import FetchLivePrices, DealSheet as X_DealSheet, \
|
15 |
from dtr.utils import FetchLivePrices, DealSheet as X_DealSheet, \
|
| 16 |
UserSpecificDeals
|
16 |
UserSpecificDeals
|
| 17 |
from dtr.utils.utils import getLogger,encryptMessage,decryptMessage,\
|
17 |
from dtr.utils.utils import getLogger,encryptMessage,decryptMessage,\
|
| Line 1636... |
Line 1636... |
| 1636 |
user.counter=1
|
1636 |
user.counter=1
|
| 1637 |
user.modified = datetime.now()
|
1637 |
user.modified = datetime.now()
|
| 1638 |
session.commit()
|
1638 |
session.commit()
|
| 1639 |
resp.body = json.dumps(todict(getUserObject(user)), encoding='utf-8')
|
1639 |
resp.body = json.dumps(todict(getUserObject(user)), encoding='utf-8')
|
| 1640 |
session.close()
|
1640 |
session.close()
|
| - |
|
1641 |
|
| - |
|
1642 |
def on_post(self, req, resp):
|
| - |
|
1643 |
returned = False
|
| - |
|
1644 |
self.agentId = req.get_param("agent_id")
|
| - |
|
1645 |
project_name = req.get_param("project_name")
|
| - |
|
1646 |
if project_name == 'accessories':
|
| - |
|
1647 |
jsonReq = json.loads(req.stream.read(), encoding='utf-8')
|
| - |
|
1648 |
lgr.info( "Request ----\n" + str(jsonReq))
|
| - |
|
1649 |
self.jsonReq = jsonReq
|
| - |
|
1650 |
callLaterAccs = self.callLaterAccs
|
| - |
|
1651 |
accsDisposition = self.accsDisposition
|
| - |
|
1652 |
self.userId = int(jsonReq.get('user_id'))
|
| - |
|
1653 |
try:
|
| - |
|
1654 |
self.user = session.query(UserCrmCallingData).filter_by(id=self.userId).first()
|
| - |
|
1655 |
self.callDisposition = jsonReq.get('calldispositiontype')
|
| - |
|
1656 |
self.callHistoryCrm = CallHistoryCrm()
|
| - |
|
1657 |
self.callHistoryCrm.agent_id=self.agentId
|
| - |
|
1658 |
self.callHistoryCrm.project_id = 1
|
| - |
|
1659 |
self.callHistoryCrm.call_disposition = self.callDisposition
|
| - |
|
1660 |
self.callHistoryCrm.user_id=self.userId
|
| - |
|
1661 |
self.callHistoryCrm.call_type=self.callType
|
| - |
|
1662 |
self.callHistoryCrm.duration_sec = int(jsonReq.get("callduration"))
|
| - |
|
1663 |
self.callHistoryCrm.disposition_comments = jsonReq.get('calldispositioncomments')
|
| - |
|
1664 |
self.callHistoryCrm.call_time = datetime.strptime(jsonReq.get("calltime"), '%d/%m/%Y %H:%M:%S')
|
| - |
|
1665 |
self.callHistoryCrm.mobile_number = jsonReq.get('number')
|
| - |
|
1666 |
|
| - |
|
1667 |
dispositionMap = { 'call_later':callLaterAccs,
|
| - |
|
1668 |
'ringing_no_answer':callLaterAccs,
|
| - |
|
1669 |
'not_reachable':callLaterAccs,
|
| - |
|
1670 |
'switch_off':callLaterAccs,
|
| - |
|
1671 |
'technical_issue':accsDisposition,
|
| - |
|
1672 |
'pricing_issue':accsDisposition,
|
| - |
|
1673 |
'shipping_issue':accsDisposition,
|
| - |
|
1674 |
'internet_issue':accsDisposition,
|
| - |
|
1675 |
'checking_price':accsDisposition,
|
| - |
|
1676 |
'order_process':accsDisposition,
|
| - |
|
1677 |
'placed_order':accsDisposition,
|
| - |
|
1678 |
'place_order':accsDisposition
|
| - |
|
1679 |
}
|
| - |
|
1680 |
returned = dispositionMap[jsonReq.get('calldispositiontype')]()
|
| - |
|
1681 |
finally:
|
| - |
|
1682 |
session.close()
|
| 1641 |
|
1683 |
|
| - |
|
1684 |
if returned:
|
| - |
|
1685 |
resp.body = "{\"result\":\"success\"}"
|
| - |
|
1686 |
else:
|
| - |
|
1687 |
resp.body = "{\"result\":\"failed\"}"
|
| - |
|
1688 |
|
| - |
|
1689 |
def accsDisposition(self):
|
| - |
|
1690 |
self.user.status='done'
|
| - |
|
1691 |
self.user.user_available = 1
|
| - |
|
1692 |
self.user.disposition=self.callDisposition
|
| - |
|
1693 |
self.user.modified = datetime.now()
|
| - |
|
1694 |
if self.callDisposition == 'technical_issue':
|
| - |
|
1695 |
self.callHistoryCrm.disposition_description='Technical issue at Profitmandi'
|
| - |
|
1696 |
elif self.callDisposition == 'pricing_issue':
|
| - |
|
1697 |
self.callHistoryCrm.disposition_description='Pricing Issue(High)'
|
| - |
|
1698 |
elif self.callDisposition == 'shipping_issue':
|
| - |
|
1699 |
self.callHistoryCrm.disposition_description='Shipping charges related issue'
|
| - |
|
1700 |
elif self.callDisposition == 'internet_issue':
|
| - |
|
1701 |
self.callHistoryCrm.disposition_description='Internet issue at user end'
|
| - |
|
1702 |
elif self.callDisposition == 'checking_price':
|
| - |
|
1703 |
self.callHistoryCrm.disposition_description='Checking price'
|
| - |
|
1704 |
elif self.callDisposition == 'order_process':
|
| - |
|
1705 |
self.callHistoryCrm.disposition_description='Order Process inquery'
|
| - |
|
1706 |
elif self.callDisposition == 'placed_order':
|
| - |
|
1707 |
self.callHistoryCrm.disposition_description='Placed Order from Different Account'
|
| - |
|
1708 |
elif self.callDisposition == 'place_order':
|
| - |
|
1709 |
self.callHistoryCrm.disposition_description='Will Place Order'
|
| - |
|
1710 |
session.commit()
|
| - |
|
1711 |
return True
|
| - |
|
1712 |
|
| - |
|
1713 |
def callLaterAccs(self):
|
| - |
|
1714 |
self.user.call_priority = None
|
| - |
|
1715 |
if self.callDisposition == 'call_later':
|
| - |
|
1716 |
if self.callHistoryCrm.disposition_description is not None:
|
| - |
|
1717 |
self.user.next_call_time = datetime.strptime(self.callHistory.disposition_description, '%d/%m/%Y %H:%M:%S')
|
| - |
|
1718 |
self.callHistoryCrm.disposition_description = 'User requested to call on ' + self.callHistoryCrm.disposition_description
|
| - |
|
1719 |
else:
|
| - |
|
1720 |
self.user.next_call_time = self.callHistoryCrm.call_time + timedelta(days=1)
|
| - |
|
1721 |
self.callHistoryCrm.disposition_description = 'Call scheduled on ' + datetime.strftime(self.user.next_call_time, '%d/%m/%Y %H:%M:%S')
|
| - |
|
1722 |
else:
|
| - |
|
1723 |
if self.callDisposition == 'ringing_no_answer':
|
| - |
|
1724 |
if self.user.disposition == 'ringing_no_answer':
|
| - |
|
1725 |
self.user.retry_count += 1
|
| - |
|
1726 |
else:
|
| - |
|
1727 |
self.user.disposition = 'ringing_no_answer'
|
| - |
|
1728 |
self.user.retry_count = 1
|
| - |
|
1729 |
else:
|
| - |
|
1730 |
if self.user.disposition == 'ringing_no_answer':
|
| - |
|
1731 |
pass
|
| - |
|
1732 |
else:
|
| - |
|
1733 |
self.user.disposition = 'not_reachable'
|
| - |
|
1734 |
self.user.retry_count += 1
|
| - |
|
1735 |
self.user.invalid_retry_count += 1
|
| - |
|
1736 |
|
| - |
|
1737 |
retryConfig = session.query(RetryConfig).filter_by(call_type=self.callType, disposition_type=self.retailer.disposition, retry_count=self.retailer.retry_count).first()
|
| - |
|
1738 |
if retryConfig is not None:
|
| - |
|
1739 |
self.user.next_call_time = self.callHistoryCrm.call_time + timedelta(minutes = retryConfig.minutes_ahead)
|
| - |
|
1740 |
self.callHistory.disposition_description = 'Call scheduled on ' + datetime.strftime(self.retailer.next_call_time, '%d/%m/%Y %H:%M:%S')
|
| - |
|
1741 |
else:
|
| - |
|
1742 |
self.user.status = 'failed'
|
| - |
|
1743 |
self.callHistoryCrm.disposition_description = 'Call failed as all attempts exhausted'
|
| - |
|
1744 |
|
| - |
|
1745 |
session.commit()
|
| - |
|
1746 |
return True
|
| - |
|
1747 |
|
| 1642 |
def insertUserCrmData(project_id):
|
1748 |
def insertUserCrmData(project_id):
|
| 1643 |
if project_id==1:
|
1749 |
if project_id==1:
|
| 1644 |
getCartDetailsUser()
|
1750 |
getCartDetailsUser()
|
| 1645 |
|
1751 |
|
| 1646 |
def getCartDetailsUser():
|
1752 |
def getCartDetailsUser():
|
| Line 1687... |
Line 1793... |
| 1687 |
d_sorted = sorted(zip(userMasterMap.values(), userMasterMap.keys()))
|
1793 |
d_sorted = sorted(zip(userMasterMap.values(), userMasterMap.keys()))
|
| 1688 |
counter=0
|
1794 |
counter=0
|
| 1689 |
for i in d_sorted:
|
1795 |
for i in d_sorted:
|
| 1690 |
if counter==2:
|
1796 |
if counter==2:
|
| 1691 |
break
|
1797 |
break
|
| 1692 |
userCheck = session.query(UserCrmCallingData).filter_by(user_id=i[1]).filter(UserCrmCallingData.user_available==1).filter(UserCrmCallingData.modified<=(datetime.now().date()-timedelta(days=3))).filter(UserCrmCallingData.project_id!=1).first()
|
1798 |
userCheck = session.query(UserCrmCallingData).filter_by(user_id=i[1]).filter(UserCrmCallingData.modified<=(datetime.now().date()-timedelta(days=3))).filter(UserCrmCallingData.project_id!=1 or UserCrmCallingData.user_available==1).first()
|
| 1693 |
if userCheck is None:
|
1799 |
if userCheck is None:
|
| 1694 |
counter=counter+1
|
1800 |
counter=counter+1
|
| 1695 |
print i[0],i[1],counter
|
1801 |
print i[0],i[1],counter
|
| 1696 |
userId=i[1]
|
1802 |
userId=i[1]
|
| 1697 |
userMasterData = UserCrmCallingData()
|
1803 |
userMasterData = UserCrmCallingData()
|