Skip to content

Commit 8ee1d1a

Browse files
caberoscaberos
authored andcommitted
add a new command on order items-cancelation
1 parent 5c08bac commit 8ee1d1a

File tree

7 files changed

+82
-0
lines changed

7 files changed

+82
-0
lines changed

SoftLayer/CLI/order/cancelation.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""List active quotes on an account."""
2+
# :license: MIT, see LICENSE for more details.
3+
import click
4+
5+
from SoftLayer.CLI.command import SLCommand as SLCommand
6+
from SoftLayer.CLI import environment
7+
from SoftLayer.CLI import formatting
8+
from SoftLayer.managers import ordering
9+
from SoftLayer.utils import clean_time
10+
11+
12+
@click.command(cls=SLCommand)
13+
@environment.pass_env
14+
def cli(env):
15+
"""List all active quotes on an account"""
16+
table = formatting.Table([
17+
'Case Number', 'Number Of Items Cancelled', 'Created', 'Status', 'Requested by'])
18+
table.align['Name'] = 'l'
19+
table.align['Package Name'] = 'r'
20+
table.align['Package Id'] = 'l'
21+
22+
manager = ordering.OrderingManager(env.client)
23+
cancelations = manager.get_all_cancelation()
24+
25+
for item in cancelations:
26+
table.add_row([item.get('ticketId'), item.get('itemCount'),
27+
item.get('createDate'),
28+
item['status']['name'],
29+
item['user']['firstName'] + ' ' + item['user']['lastName']
30+
])
31+
32+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@
278278
('order:quote-save', 'SoftLayer.CLI.order.quote_save:cli'),
279279
('order:quote', 'SoftLayer.CLI.order.quote:cli'),
280280
('order:lookup', 'SoftLayer.CLI.order.lookup:cli'),
281+
('order:cancelation', 'SoftLayer.CLI.order.cancelation:cli'),
281282

282283
('hardware', 'SoftLayer.CLI.hardware'),
283284
('hardware:bandwidth', 'SoftLayer.CLI.hardware.bandwidth:cli'),
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
getAllCancellationRequests = [
2+
{"createDate": "2023-04-20T06:53:17-06:00",
3+
"id": 123456,
4+
"ticketId": 147258,
5+
"itemCount": 1,
6+
"items": [
7+
{
8+
"billingItemId": 369852,
9+
"id": 147852369,
10+
"billingItem": {
11+
"cancellationDate": "2023-05-03T22:59:59-06:00",
12+
"categoryCode": "server",
13+
}
14+
}
15+
],
16+
"status": {
17+
"id": 4,
18+
"name": "Approved"
19+
},
20+
"user": {
21+
"firstName": "CHRISTOPHER",
22+
"id": 167758,
23+
"lastName": "GALLO"
24+
}
25+
}]

SoftLayer/managers/ordering.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,3 +737,14 @@ def get_regions(self, package_id, location=None):
737737
if location:
738738
_filter = {"regions": {"location": {"location": {"name": {"operation": location}}}}}
739739
return self.client.call('SoftLayer_Product_Package', 'getRegions', id=package_id, filter=_filter)
740+
741+
def get_all_cancelation(self):
742+
"""returns the all cancelations, completed orders"""
743+
744+
mask = 'mask[id,itemCount,modifyDate,createDate,ticketId,' \
745+
'ticket[assignedUserId,id,attachedHardware[id,hostname,domain],' \
746+
'attachedVirtualGuests[id,hostname,domain],' \
747+
'attachedDedicatedHosts[id,name],serviceProviderResourceId],' \
748+
'status[name,id],user[id,firstName,lastName],' \
749+
'items[billingItem[cancellationDate,categoryCode,pendingCancellationFlag]]]'
750+
return self.client.call('SoftLayer_Billing_Item_Cancellation_Request', 'getAllCancellationRequests', mask=mask)

docs/cli/ordering.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ Quotes
139139
:prog: order place-quote
140140
:show-nested:
141141

142+
.. click:: SoftLayer.CLI.order.cancelation:cli
143+
:prog: order cancelation
144+
:show-nested:
145+
142146
Lookup
143147
======
144148
.. click:: SoftLayer.CLI.order.lookup:cli

tests/CLI/modules/order_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ def test_quote_list(self):
415415
self.assert_no_fail(result)
416416
self.assert_called_with('SoftLayer_Account', 'getActiveQuotes')
417417

418+
def test_cancelation(self):
419+
result = self.run_command(['order', 'cancelation'])
420+
self.assert_no_fail(result)
421+
self.assert_called_with('SoftLayer_Billing_Item_Cancellation_Request', 'getAllCancellationRequests')
422+
418423
def _get_order_items(self):
419424
item1 = {'keyName': 'ITEM1', 'description': 'description1',
420425
'itemCategory': {'categoryCode': 'cat1'},

tests/managers/ordering_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,3 +901,7 @@ def test_get_items(self):
901901
def test_get_regions(self):
902902
self.ordering.get_regions(123)
903903
self.assert_called_with('SoftLayer_Product_Package', 'getRegions')
904+
905+
def test_get_all_cancelations(self):
906+
self.ordering.get_all_cancelation()
907+
self.assert_called_with('SoftLayer_Billing_Item_Cancellation_Request', 'getAllCancellationRequests')

0 commit comments

Comments
 (0)