Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a new command on order items-cancelation #1929

Merged
merged 9 commits into from May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions SoftLayer/CLI/order/cancelation.py
@@ -0,0 +1,30 @@
"""List all cancelation."""
# :license: MIT, see LICENSE for more details.
import click

from SoftLayer.CLI.command import SLCommand as SLCommand
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.managers import ordering
from SoftLayer import utils


@click.command(cls=SLCommand)
@environment.pass_env
def cli(env):
"""List all account cancelations"""
table = formatting.Table([
'Case Number', 'Items', 'Created', 'Status', 'Requested by'])

manager = ordering.OrderingManager(env.client)
cancelations = manager.get_all_cancelation()

for item in cancelations:
table.add_row([item.get('ticketId'), item.get('itemCount'),
utils.clean_time(item.get('createDate'),
in_format='%Y-%m-%dT%H:%M:%S', out_format='%Y-%m-%d %H:%M'),
item['status']['name'],
item['user']['firstName'] + ' ' + item['user']['lastName']
])

env.fout(table)
1 change: 1 addition & 0 deletions SoftLayer/CLI/routes.py
Expand Up @@ -279,6 +279,7 @@
('order:quote-save', 'SoftLayer.CLI.order.quote_save:cli'),
('order:quote', 'SoftLayer.CLI.order.quote:cli'),
('order:lookup', 'SoftLayer.CLI.order.lookup:cli'),
('order:cancelation', 'SoftLayer.CLI.order.cancelation:cli'),

('hardware', 'SoftLayer.CLI.hardware'),
('hardware:bandwidth', 'SoftLayer.CLI.hardware.bandwidth:cli'),
Expand Down
25 changes: 25 additions & 0 deletions SoftLayer/fixtures/SoftLayer_Billing_Item_Cancellation_Request.py
@@ -0,0 +1,25 @@
getAllCancellationRequests = [
{"createDate": "2023-04-20T06:53:17-06:00",
"id": 123456,
"ticketId": 147258,
"itemCount": 1,
"items": [
{
"billingItemId": 369852,
"id": 147852369,
"billingItem": {
"cancellationDate": "2023-05-03T22:59:59-06:00",
"categoryCode": "server",
}
}
],
"status": {
"id": 4,
"name": "Approved"
},
"user": {
"firstName": "CHRISTOPHER",
"id": 167758,
"lastName": "GALLO"
}
}]
10 changes: 10 additions & 0 deletions SoftLayer/managers/ordering.py
Expand Up @@ -19,6 +19,7 @@
PRESET_MASK = '''id, name, keyName, description, prices[id, hourlyRecurringFee, recurringFee], locations'''


# pylint: disable=R0904
class OrderingManager(object):
"""Manager to help ordering via the SoftLayer API.

Expand Down Expand Up @@ -745,3 +746,12 @@ def delete_quote(self, quote_id):
"""

return self.client['SoftLayer_Billing_Order_Quote'].deleteQuote(id=quote_id)

def get_all_cancelation(self, limit=50):
"""returns the all cancelations, completed orders"""

mask = 'mask[id,itemCount,modifyDate,createDate,ticketId,' \
caberos marked this conversation as resolved.
Show resolved Hide resolved
'ticket[assignedUserId,id,' \
'serviceProviderResourceId],status[name,id],user[id,firstName,lastName]]'
return self.client.call('SoftLayer_Billing_Item_Cancellation_Request', 'getAllCancellationRequests',
mask=mask, limit=limit)
4 changes: 4 additions & 0 deletions docs/cli/ordering.rst
Expand Up @@ -143,6 +143,10 @@ Quotes
:prog: order quote-delete
:show-nested:

.. click:: SoftLayer.CLI.order.cancelation:cli
:prog: order cancelation
:show-nested:

Lookup
======
.. click:: SoftLayer.CLI.order.lookup:cli
Expand Down
5 changes: 5 additions & 0 deletions tests/CLI/modules/order_tests.py
Expand Up @@ -415,6 +415,11 @@ def test_quote_list(self):
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getActiveQuotes')

def test_cancelation(self):
result = self.run_command(['order', 'cancelation'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Billing_Item_Cancellation_Request', 'getAllCancellationRequests')

def _get_order_items(self):
item1 = {'keyName': 'ITEM1', 'description': 'description1',
'itemCategory': {'categoryCode': 'cat1'},
Expand Down
4 changes: 4 additions & 0 deletions tests/managers/ordering_tests.py
Expand Up @@ -905,3 +905,7 @@ def test_get_regions(self):
def test_delete_quote(self):
self.ordering.delete_quote(123)
self.assert_called_with('SoftLayer_Billing_Order_Quote', 'deleteQuote')

def test_get_all_cancelations(self):
self.ordering.get_all_cancelation()
self.assert_called_with('SoftLayer_Billing_Item_Cancellation_Request', 'getAllCancellationRequests')