def redemption_request_due_date_escalation(*args, **kwargs):
    time = datetime.now()
    """
    send mail when due date is less than current date for redemption request
    """
    brand = kwargs.get("brand", None)
    args = [Q(due_date__lte=time), Q(resolution_flag=False), ~Q(status="Delivered")]
    redemption_request_obj = get_model("RedemptionRequest", brand).objects.filter(reduce(operator.and_, args))
    for redemption_request in redemption_request_obj:
        data = get_email_template("REDEMPTION_REQUEST_DUE_DATE_EXCEED_MAIL_TO_MANAGER", brand)
        data["newsubject"] = data["subject"].format(id=redemption_request.transaction_id)
        data["content"] = data["body"].format(
            transaction_id=redemption_request.transaction_id, status=redemption_request.status
        )
        escalation_list = get_model("UserProfile", brand).objects.filter(user__groups__name=Roles.REDEEMESCALATION)
        escalation_list_detail = utils.get_escalation_mailing_list(escalation_list)
        send_email_to_redeem_escaltion_group(data, escalation_list_detail)

        message = templates.get_template("LOYALTY_DUE_DATE_EXCEED_ESCALATION", brand).format(
            transaction_id=redemption_request.transaction_id, status=redemption_request.status
        )
        for phone_number in escalation_list_detail["sms"]:
            phone_number = utils.get_phone_number_format(phone_number)
            sms_log(brand, receiver=phone_number, action=AUDIT_ACTION, message=message)
            send_job_to_queue(
                send_loyalty_escalation_message,
                {"phone_number": phone_number, "message": message, "sms_client": settings.SMS_CLIENT},
            )
        redemption_request.resolution_flag = True
        redemption_request.save()
def create_context(email_template_name, feedback_obj, comment_obj=None):
    ''' feedback due date not defined when ticket is created'''
    if comment_obj:
        comment = comment_obj.comment
    else:
        comment = ""
    created_date = convert_utc_to_local_time(feedback_obj.created_date, True)
    try:
        assignee = feedback_obj.assignee.user_profile.user.username
    except:
        assignee = ""
    try:
        due_date = feedback_obj.due_date.strftime(DATE_FORMAT)
    except:
        due_date = ""
    if settings.BRAND == 'bajaj':
        type = feedback_obj.type
    else:
        type = "feedback"
    data = get_email_template(email_template_name, settings.BRAND)
    data['newsubject'] = data['subject'].format(id = feedback_obj.id)
    data['content'] = data['body'].format(id=feedback_obj.id, type = type, reporter = feedback_obj.reporter.user_profile.user.username, 
                                          message = feedback_obj.description, created_date = created_date, 
                                          assign_to = assignee ,  priority =  feedback_obj.priority, comment = comment,
                                          root_cause = feedback_obj.root_cause, resolution = feedback_obj.resolution,
                                          due_date = due_date, resolution_time=total_time_spent(feedback_obj))

    return data
def dfsc_customer_support(*args, **kwargs):
    brand = kwargs.get("brand", None)
    asc_obj = (
        get_model("AuthorizedServiceCenter", brand).objects.filter(user__state="MAH").select_related("user, user__user")
    )
    dealer_obj = get_model("Dealer", brand).objects.filter(user__state="MAH").select_related("user, user__user")

    data = get_email_template("CUSTOMER_SUPPORT_FOR_DFSC", brand)
    data["newsubject"] = data["subject"]
    data["content"] = data["body"]
    message = templates.get_template("CUSTOMER_SUPPORT_FOR_DFSC", brand)

    customer_support_helper(asc_obj, data, message)
    customer_support_helper(dealer_obj, data, message)
 def send_welcome_kit_mail_to_partner_retailer(self, welcome_kit_obj):
     '''Send mail to GP and LP when welcome Kit is assigned to them'''
     data = get_email_template('ASSIGNEE_WELCOME_KIT_MAIL_RETAILER', settings.BRAND)
     data['newsubject'] = data['subject'].format(id = welcome_kit_obj.transaction_id)
     url_link='http://bajaj.gladminds.co'
     data['content'] = data['body'].format(id=welcome_kit_obj.transaction_id,
                           created_date = welcome_kit_obj.created_date,
                           retailer_id = welcome_kit_obj.retailer.retailer_id,
                           retailer_name = welcome_kit_obj.retailer.retailer_name,
                           retailer_city = welcome_kit_obj.retailer.district,
                           retailer_state = welcome_kit_obj.retailer.user.state,
                     delivery_address = welcome_kit_obj.delivery_address,
                     url_link=url_link)
     partner_email_id=welcome_kit_obj.partner.user.user.email
     send_email_to_redemption_request_partner(data, partner_email_id)
     LOG.info('[send_welcome_kit_mail_to_partner]:{0}:: welcome kit request email sent'.format(
                                 partner_email_id))
 def send_mail_to_partner_for_retailer(self, redemption_obj):
     '''Send mail to GP and LP when redemption
        request is assigned to them for Retailer'''
     data = get_email_template('ASSIGNEE_REDEMPTION_MAIL_DETAIL_RETAILER', settings.BRAND)
     data['newsubject'] = data['subject'].format(id = redemption_obj.transaction_id)
     url_link='http://bajaj.gladminds.co'
     data['content'] = data['body'].format(id=redemption_obj.transaction_id,
                           created_date = redemption_obj.created_date,
                           retailer_id = redemption_obj.retailer.retailer_id,
                           retailer_name = redemption_obj.retailer.retailer_name,
                           retailer_city = redemption_obj.retailer.district,
                           retailer_state = redemption_obj.retailer.user.state,
                           product_id =  redemption_obj.product.product_id,
                           product_name =  redemption_obj.product.description,
                     delivery_address = redemption_obj.delivery_address,
                     url_link=url_link)
     partner_email_id=redemption_obj.partner.user.user.email
     send_email_to_redemption_request_partner(data, partner_email_id)
     LOG.error('[send_mail_to_partner]:{0}:: Redemption request email sent'.format(
                                 partner_email_id))