Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

from shop2020.clients.CRMClient import CRMClient
from shop2020.clients.UserClient import UserClient
from shop2020.thriftpy.crm.ttypes import SearchFilter, TicketCategory, Ticket, \
     Activity, TicketPriority, TicketStatus, ActivityType
from dtr.utils.utils import to_java_date,sendCrmProjectMailByDtr


def generateCrmTicket(customerFeedBack):
    sendCrmProjectMailByDtr(customerFeedBack)
    crmServiceClient = CRMClient().get_client() 
    userServiceClient = UserClient().get_client()   
    ticket = Ticket()
    activity = Activity()
    ticket.creatorId = 1
    user = userServiceClient.getUserByEmail(customerFeedBack.get('email'))
    if 'Return or replacement pending' in customerFeedBack.get('subject'):
        ticket.category = TicketCategory.PROFITMANDI_REFUND_PROBLEM
        ticket.priority = TicketPriority.HIGH
    elif 'Product Quality issue' in customerFeedBack.get('subject'):
        ticket.category = TicketCategory.PROFITMANDI_PRODUCT_ISSUE
        ticket.priority = TicketPriority.HIGH
    elif 'Delayed Delivery' in customerFeedBack.get('subject'):
        ticket.category = TicketCategory.PROFITMANDI_DELAYED_DELIVERY
        ticket.priority = TicketPriority.HIGH
    elif 'Technical issue at Profitmandi' in customerFeedBack.get('subject'):
        ticket.category = TicketCategory.PROFITMANDI_TECHNICAL_PROBLEM
        ticket.priority = TicketPriority.HIGH
    else:
        ticket.category = TicketCategory.PROFITMANDI_OTHER
        ticket.priority = TicketPriority.MEDIUM

    ticket.description = 'User Specified Subject :- '+ customerFeedBack.get('subject') + ' | ' +  customerFeedBack.get('message')
    ticket.customerEmailId = customerFeedBack.get('email')
    if user is not None and user.userId !=-1:
        ticket.customerId = user.userId
    ticket.assigneeId=57
    ticket.status = TicketStatus.OPEN
    ticket.openDate = to_java_date(customerFeedBack.get('created'))
    ticket.customerMobileNumber = customerFeedBack.get('mobile_number')
    ticket.customerName = customerFeedBack.get('customer_name')  
    activity.creatorId = 1
    activity.ticketAssigneeId = ticket.assigneeId
    activity.type = ActivityType.PROFITMANDI_CRM_APP_TICKET
    activity.description = 'User Specified Subject :- '+ customerFeedBack.get('subject') + ' | ' +  customerFeedBack.get('message')

    activity.ticketCategory = ticket.category
    activity.ticketDescription = ticket.description
    activity.ticketPriority = ticket.priority
    activity.ticketStatus = ticket.status
    activity.customerEmailId = customerFeedBack.get('email')
    if user is not None and user.userId !=-1:
        activity.customerId  = user.userId
    activity.customerName = customerFeedBack.get('customer_name')
    activity.customerMobileNumber = customerFeedBack.get('mobile_number')
    activity.creationTimestamp = ticket.openDate
    activity.customerEmailId= customerFeedBack.get('email')
    
    if not crmServiceClient.isAlive():
        crmServiceClient = CRMClient().get_client()
    
    ticketId = crmServiceClient.insertTicket(ticket, activity)
    
    if ticketId > 0:
        return True
    else:
        return False