Skip to content

Commit 48306c4

Browse files
Merge pull request #1349 from caberos/issue1341
slcli account orders
2 parents 8a873b0 + 5dc7e95 commit 48306c4

File tree

6 files changed

+109
-1
lines changed

6 files changed

+109
-1
lines changed

SoftLayer/CLI/account/orders.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Order list account"""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
from SoftLayer.CLI import environment
7+
from SoftLayer.CLI import formatting
8+
from SoftLayer.managers.account import AccountManager as AccountManager
9+
from SoftLayer import utils
10+
11+
12+
@click.command()
13+
@click.option('--limit', '-l',
14+
help='How many results to get in one api call',
15+
default=100,
16+
show_default=True)
17+
@environment.pass_env
18+
def cli(env, limit):
19+
"""Order list account."""
20+
manager = AccountManager(env.client)
21+
orders = manager.get_account_all_billing_orders(limit)
22+
23+
order_table = formatting.Table(['Id', 'State', 'User', 'Date', 'Amount', 'Item'],
24+
title="orders")
25+
order_table.align = 'l'
26+
27+
for order in orders:
28+
items = []
29+
for item in order['items']:
30+
items.append(item['description'])
31+
create_date = utils.clean_time(order['createDate'], in_format='%Y-%m-%d', out_format='%Y-%m-%d')
32+
33+
order_table.add_row([order['id'], order['status'], order['userRecord']['username'], create_date,
34+
order['orderTotalAmount'], utils.trim_to(' '.join(map(str, items)), 50)])
35+
env.fout(order_table)

SoftLayer/CLI/routes.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
('account:billing-items', 'SoftLayer.CLI.account.billing_items:cli'),
2121
('account:item-detail', 'SoftLayer.CLI.account.item_detail:cli'),
2222
('account:cancel-item', 'SoftLayer.CLI.account.cancel_item:cli'),
23+
('account:orders', 'SoftLayer.CLI.account.orders:cli'),
2324

2425
('virtual', 'SoftLayer.CLI.virt'),
2526
('virtual:bandwidth', 'SoftLayer.CLI.virt.bandwidth:cli'),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
getAllObjects = [{
2+
'accountId': 123456,
3+
'createDate': '2020-09-15T13:12:08-06:00',
4+
'id': 112356450,
5+
'modifyDate': '2020-09-15T13:13:13-06:00',
6+
'status': 'COMPLETED',
7+
'userRecordId': 987456321,
8+
'userRecord': {
9+
'username': '[email protected]'
10+
},
11+
'items': [
12+
{
13+
'categoryCode': 'port_speed',
14+
'description': '100 Mbps Private Network Uplink'
15+
},
16+
{
17+
'categoryCode': 'service_port',
18+
'description': '100 Mbps Private Uplink'
19+
},
20+
{
21+
'categoryCode': 'public_port',
22+
'description': '0 Mbps Public Uplink'
23+
}
24+
],
25+
'orderApprovalDate': '2020-09-15T13:13:13-06:00',
26+
'orderTotalAmount': '0'
27+
},
28+
{
29+
'accountId': 123456,
30+
'createDate': '2019-09-15T13:12:08-06:00',
31+
'id': 645698550,
32+
'modifyDate': '2019-09-15T13:13:13-06:00',
33+
'status': 'COMPLETED',
34+
'userRecordId': 987456321,
35+
'userRecord': {
36+
'username': '[email protected]'
37+
},
38+
'items': [
39+
{
40+
'categoryCode': 'port_speed',
41+
'description': '100 Mbps Private Network Uplink'
42+
},
43+
44+
],
45+
'orderApprovalDate': '2019-09-15T13:13:13-06:00',
46+
'orderTotalAmount': '0'
47+
}]

SoftLayer/managers/account.py

+16
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,19 @@ def cancel_item(self, identifier, reason="No longer needed", note=None):
260260
note = "Cancelled by {} with the SLCLI".format(user.get('username'))
261261

262262
return self.client.call('Billing_Item', 'cancelItem', False, True, reason, note, id=identifier)
263+
264+
def get_account_all_billing_orders(self, limit=100, mask=None):
265+
"""Gets all the topLevelBillingItems currently active on the account
266+
267+
:param string mask: Object Mask
268+
:return: Billing_Item
269+
"""
270+
271+
if mask is None:
272+
mask = """
273+
orderTotalAmount, userRecord,
274+
initialInvoice[id,amount,invoiceTotalAmount],
275+
items[description]
276+
"""
277+
return self.client.call('Billing_Order', 'getAllObjects',
278+
limit=limit, mask=mask)

docs/cli/account.rst

+4
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ Account Commands
3434

3535
.. click:: SoftLayer.CLI.account.cancel_item:cli
3636
:prog: account cancel-item
37+
:show-nested:
38+
39+
.. click:: SoftLayer.CLI.account.orders:cli
40+
:prog: account orders
3741
:show-nested:

tests/CLI/modules/account_tests.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,9 @@ def test_account_get_billing_item_detail(self):
110110
def test_account_cancel_item(self):
111111
result = self.run_command(['account', 'cancel-item', '12345'])
112112
self.assert_no_fail(result)
113-
self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem', identifier='12345')
113+
self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem', identifier='12345')
114+
115+
def test_acccount_order(self):
116+
result = self.run_command(['account', 'orders'])
117+
self.assert_no_fail(result)
118+
self.assert_called_with('SoftLayer_Billing_Order', 'getAllObjects')

0 commit comments

Comments
 (0)