def recover_coupon_info(data):
    customer_id = data['customerId']
    logger.info('UCN for customer {0} requested by User {1}'.format(customer_id, data['current_user']))
    coupon_data = utils.get_coupon_info(data)
    if coupon_data:
        ucn_recovery_obj = utils.upload_file(data, coupon_data.unique_service_coupon)
        send_recovery_email_to_admin(ucn_recovery_obj, coupon_data)
        message = 'UCN for customer {0} is {1}.'.format(customer_id,
                                                    coupon_data.unique_service_coupon)
        return {'status': True, 'message': message}
    else:
        message = 'No coupon in progress for customerID {0}.'.format(customer_id) 
        return {'status': False, 'message': message}
def recover_coupon_info(data):
    customer_id = data['customerId']
    logger.info('UCN for customer {0} requested by User {1}'.format(customer_id, data['current_user']))
    coupon_data = utils.get_coupon_info(data)
    if coupon_data:
        user_obj = models.UserProfile.objects.get(user=data['current_user'])
        file_obj = data['job_card']
        customer_id = data['customerId']
        reason = data['reason']
        file_obj.name = get_file_name(data, file_obj)
        destination = settings.JOBCARD_DIR.format('bajajib')
        bucket = settings.JOBCARD_BUCKET
        path = utils.upload_file(destination, bucket, file_obj, logger_msg="JobCard")
        ucn_recovery_obj = models.UCNRecovery(reason=reason, user=user_obj,
                                        customer_id=customer_id, file_location=path,
                                        unique_service_coupon=coupon_data.unique_service_coupon)
        ucn_recovery_obj.save()
        send_recovery_email_to_admin(ucn_recovery_obj, coupon_data)
        message = 'UCN for customer {0} is {1}.'.format(customer_id,
                                                    coupon_data.unique_service_coupon)
        return {'status': True, 'message': message}
    else:
        message = 'No coupon in progress for customerID {0}.'.format(customer_id) 
        return {'status': False, 'message': message}
 def test_get_coupon_info(self):  
     request = RequestObject(user='******', data={
                             'customerId': 'SAP001', 'vin': 'VINXXX001'}, file={'jobCard': ''})
     result = get_coupon_info(request.POST)
     self.assertEqual(30,result.valid_days)