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 2 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
31 changes: 31 additions & 0 deletions SoftLayer/CLI/order/cancelation.py
@@ -0,0 +1,31 @@
"""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


@click.command(cls=SLCommand)
@environment.pass_env
def cli(env):
"""List all active quotes on an account"""
caberos marked this conversation as resolved.
Show resolved Hide resolved
table = formatting.Table([
'Case Number', 'Number Of Items Cancelled', 'Created', 'Status', 'Requested by'])
caberos marked this conversation as resolved.
Show resolved Hide resolved
table.align['Name'] = 'l'
table.align['Package Name'] = 'r'
table.align['Package Id'] = 'l'
caberos marked this conversation as resolved.
Show resolved Hide resolved

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

for item in cancelations:
table.add_row([item.get('ticketId'), item.get('itemCount'),
item.get('createDate'),
caberos marked this conversation as resolved.
Show resolved Hide resolved
item['status']['name'],
item['user']['firstName'] + ' ' + item['user']['lastName']
])

env.fout(table)
1 change: 1 addition & 0 deletions SoftLayer/CLI/routes.py
Expand Up @@ -278,6 +278,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"
}
}]
11 changes: 11 additions & 0 deletions SoftLayer/managers/ordering.py
Expand Up @@ -737,3 +737,14 @@ def get_regions(self, package_id, location=None):
if location:
_filter = {"regions": {"location": {"location": {"name": {"operation": location}}}}}
return self.client.call('SoftLayer_Product_Package', 'getRegions', id=package_id, filter=_filter)

def get_all_cancelation(self):
"""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,attachedHardware[id,hostname,domain],' \
'attachedVirtualGuests[id,hostname,domain],' \
'attachedDedicatedHosts[id,name],serviceProviderResourceId],' \
'status[name,id],user[id,firstName,lastName],' \
'items[billingItem[cancellationDate,categoryCode,pendingCancellationFlag]]]'
return self.client.call('SoftLayer_Billing_Item_Cancellation_Request', 'getAllCancellationRequests', mask=mask)
caberos marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions docs/cli/ordering.rst
Expand Up @@ -139,6 +139,10 @@ Quotes
:prog: order place-quote
: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 @@ -901,3 +901,7 @@ def test_get_items(self):
def test_get_regions(self):
self.ordering.get_regions(123)
self.assert_called_with('SoftLayer_Product_Package', 'getRegions')

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