Skip to content

Commit 13502c3

Browse files
Merge pull request #1929 from caberos/issue1927
add a new command on order items-cancelation
2 parents fb14b43 + bbb60de commit 13502c3

File tree

7 files changed

+79
-0
lines changed

7 files changed

+79
-0
lines changed

SoftLayer/CLI/order/cancelation.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""List all cancelation."""
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 import utils
10+
11+
12+
@click.command(cls=SLCommand)
13+
@environment.pass_env
14+
def cli(env):
15+
"""List all account cancelations"""
16+
table = formatting.Table([
17+
'Case Number', 'Items', 'Created', 'Status', 'Requested by'])
18+
19+
manager = ordering.OrderingManager(env.client)
20+
cancelations = manager.get_all_cancelation()
21+
22+
for item in cancelations:
23+
table.add_row([item.get('ticketId'), item.get('itemCount'),
24+
utils.clean_time(item.get('createDate'),
25+
in_format='%Y-%m-%dT%H:%M:%S', out_format='%Y-%m-%d %H:%M'),
26+
item['status']['name'],
27+
item['user']['firstName'] + ' ' + item['user']['lastName']
28+
])
29+
30+
env.fout(table)

SoftLayer/CLI/routes.py

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

283284
('hardware', 'SoftLayer.CLI.hardware'),
284285
('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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
PRESET_MASK = '''id, name, keyName, description, prices[id, hourlyRecurringFee, recurringFee], locations'''
2020

2121

22+
# pylint: disable=R0904
2223
class OrderingManager(object):
2324
"""Manager to help ordering via the SoftLayer API.
2425
@@ -745,3 +746,12 @@ def delete_quote(self, quote_id):
745746
"""
746747

747748
return self.client['SoftLayer_Billing_Order_Quote'].deleteQuote(id=quote_id)
749+
750+
def get_all_cancelation(self, limit=50):
751+
"""returns the all cancelations, completed orders"""
752+
753+
mask = 'mask[id,itemCount,modifyDate,createDate,ticketId,' \
754+
'ticket[assignedUserId,id,' \
755+
'serviceProviderResourceId],status[name,id],user[id,firstName,lastName]]'
756+
return self.client.call('SoftLayer_Billing_Item_Cancellation_Request', 'getAllCancellationRequests',
757+
mask=mask, limit=limit)

docs/cli/ordering.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ Quotes
143143
:prog: order quote-delete
144144
:show-nested:
145145

146+
.. click:: SoftLayer.CLI.order.cancelation:cli
147+
:prog: order cancelation
148+
:show-nested:
149+
146150
Lookup
147151
======
148152
.. 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
@@ -905,3 +905,7 @@ def test_get_regions(self):
905905
def test_delete_quote(self):
906906
self.ordering.delete_quote(123)
907907
self.assert_called_with('SoftLayer_Billing_Order_Quote', 'deleteQuote')
908+
909+
def test_get_all_cancelations(self):
910+
self.ordering.get_all_cancelation()
911+
self.assert_called_with('SoftLayer_Billing_Item_Cancellation_Request', 'getAllCancellationRequests')

0 commit comments

Comments
 (0)