Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions SoftLayer/CLI/account/orders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Order list account"""
# :license: MIT, see LICENSE for more details.

import click

from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.managers.account import AccountManager as AccountManager
from SoftLayer import utils


@click.command()
@click.option('--limit', '-l',
help='How many results to get in one api call',
default=100,
show_default=True)
@environment.pass_env
def cli(env, limit):
"""Order list account."""
manager = AccountManager(env.client)
orders = manager.get_account_all_billing_orders(limit)

order_table = formatting.Table(['Id', 'State', 'User', 'Date', 'Amount', 'Item'],
title="orders")
order_table.align = 'l'

for order in orders:
items = []
for item in order['items']:
items.append(item['description'])
create_date = utils.clean_time(order['createDate'], in_format='%Y-%m-%d', out_format='%Y-%m-%d')

order_table.add_row([order['id'], order['status'], order['userRecord']['username'], create_date,
order['orderTotalAmount'], utils.trim_to(' '.join(map(str, items)), 50)])
env.fout(order_table)
1 change: 1 addition & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
('account:billing-items', 'SoftLayer.CLI.account.billing_items:cli'),
('account:item-detail', 'SoftLayer.CLI.account.item_detail:cli'),
('account:cancel-item', 'SoftLayer.CLI.account.cancel_item:cli'),
('account:orders', 'SoftLayer.CLI.account.orders:cli'),

('virtual', 'SoftLayer.CLI.virt'),
('virtual:bandwidth', 'SoftLayer.CLI.virt.bandwidth:cli'),
Expand Down
47 changes: 47 additions & 0 deletions SoftLayer/fixtures/SoftLayer_Billing_Order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
getAllObjects = [{
'accountId': 123456,
'createDate': '2020-09-15T13:12:08-06:00',
'id': 112356450,
'modifyDate': '2020-09-15T13:13:13-06:00',
'status': 'COMPLETED',
'userRecordId': 987456321,
'userRecord': {
'username': 'test@test.com'
},
'items': [
{
'categoryCode': 'port_speed',
'description': '100 Mbps Private Network Uplink'
},
{
'categoryCode': 'service_port',
'description': '100 Mbps Private Uplink'
},
{
'categoryCode': 'public_port',
'description': '0 Mbps Public Uplink'
}
],
'orderApprovalDate': '2020-09-15T13:13:13-06:00',
'orderTotalAmount': '0'
},
{
'accountId': 123456,
'createDate': '2019-09-15T13:12:08-06:00',
'id': 645698550,
'modifyDate': '2019-09-15T13:13:13-06:00',
'status': 'COMPLETED',
'userRecordId': 987456321,
'userRecord': {
'username': 'test@test.com'
},
'items': [
{
'categoryCode': 'port_speed',
'description': '100 Mbps Private Network Uplink'
},

],
'orderApprovalDate': '2019-09-15T13:13:13-06:00',
'orderTotalAmount': '0'
}]
16 changes: 16 additions & 0 deletions SoftLayer/managers/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,19 @@ def cancel_item(self, identifier, reason="No longer needed", note=None):
note = "Cancelled by {} with the SLCLI".format(user.get('username'))

return self.client.call('Billing_Item', 'cancelItem', False, True, reason, note, id=identifier)

def get_account_all_billing_orders(self, limit=100, mask=None):
"""Gets all the topLevelBillingItems currently active on the account

:param string mask: Object Mask
:return: Billing_Item
"""

if mask is None:
mask = """
orderTotalAmount, userRecord,
initialInvoice[id,amount,invoiceTotalAmount],
items[description]
"""
return self.client.call('Billing_Order', 'getAllObjects',
limit=limit, mask=mask)
4 changes: 4 additions & 0 deletions docs/cli/account.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ Account Commands

.. click:: SoftLayer.CLI.account.cancel_item:cli
:prog: account cancel-item
:show-nested:

.. click:: SoftLayer.CLI.account.orders:cli
:prog: account orders
:show-nested:
7 changes: 6 additions & 1 deletion tests/CLI/modules/account_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@ def test_account_get_billing_item_detail(self):
def test_account_cancel_item(self):
result = self.run_command(['account', 'cancel-item', '12345'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem', identifier='12345')
self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem', identifier='12345')

def test_acccount_order(self):
result = self.run_command(['account', 'orders'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Billing_Order', 'getAllObjects')