Repository: softlayer/softlayer-python
Pull request #1901 (2023-04-06 20:35:54)

add a new option on account orders
[#issue1900](https://github.com/softlayer/softlayer-python/issues/1900)

![image](https://user-images.githubusercontent.com/22535437/230488767-01a34d6b-b11a-484a-8104-642082cfeceb.png)


![image](https://user-images.githubusercontent.com/22535437/230488712-e0773d5a-6626-44e7-855d-1371382eacae.png)



Patch:
diff --git a/SoftLayer/CLI/account/orders.py b/SoftLayer/CLI/account/orders.py
index 7dc291d7..f4cc1fa8 100644
--- a/SoftLayer/CLI/account/orders.py
+++ b/SoftLayer/CLI/account/orders.py
@@ -10,16 +10,34 @@
 from SoftLayer import utils
 
 
+def upgrade_table(upgrades):
+    """Formats a table for upgrade orders"""
+    table = formatting.Table(['Id', 'Maintance window', 'Status', 'Created Date',
+                              'Case'], title="Upgrade orders")
+    table.align['Subject'] = 'l'
+    table.align['Impacted Resources'] = 'l'
+    for upgrade in upgrades:
+        table.add_row([upgrade.get('id'),
+                       upgrade.get('maintenanceStartTimeUtc'),
+                       upgrade.get('statusId'),
+                       upgrade.get('createDate'),
+                       upgrade.get('ticketId') or '--'])
+    return table
+
+
 @click.command(cls=SLCommand)
 @click.option('--limit', '-l',
               help='How many results to get in one api call',
-              default=50,
+              default=100,
               show_default=True)
+@click.option('--upgrades', is_flag=True, default=False,
+              help="Show upgrades orders.")
 @environment.pass_env
-def cli(env, limit):
+def cli(env, limit, upgrades):
     """Lists account orders. Use `slcli order lookup <ID>` to find more details about a specific order."""
     manager = AccountManager(env.client)
     orders = manager.get_account_all_billing_orders(limit)
+    upgrade = manager.get_account_upgrade_orders(limit)
 
     order_table = formatting.Table(['Id', 'State', 'User', 'Date', 'Amount', 'Item'],
                                    title="orders")
@@ -34,3 +52,5 @@ def cli(env, limit):
         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)
+    if upgrades:
+        env.fout(upgrade_table(upgrade))
diff --git a/SoftLayer/fixtures/SoftLayer_Account.py b/SoftLayer/fixtures/SoftLayer_Account.py
index d8f7fc72..866af09f 100644
--- a/SoftLayer/fixtures/SoftLayer_Account.py
+++ b/SoftLayer/fixtures/SoftLayer_Account.py
@@ -1480,3 +1480,24 @@
         "name": "GettestProv12345",
         "uri": "http://test.com"
     }]
+
+getUpgradeRequests = [{
+    "createDate": "2023-03-01T19:39:51-06:00",
+    "id": 3237486,
+    "maintenanceStartTimeUtc": "2023-03-01T19:39:51-06:00",
+    "modifyDate": "2023-03-01T19:39:53-06:00",
+    "orderId": 103127604,
+    "statusId": 3,
+    "ticketId": 152510472,
+    "userId": 167758
+},
+    {
+        "createDate": "2023-02-27T19:41:26-06:00",
+        "id": 3229998,
+        "maintenanceStartTimeUtc": "2023-02-27T19:41:26-06:00",
+        "modifyDate": "2023-02-27T19:41:29-06:00",
+        "orderId": 103029352,
+        "statusId": 3,
+        "ticketId": 152452042,
+        "userId": 167758
+    }]
diff --git a/SoftLayer/managers/account.py b/SoftLayer/managers/account.py
index 7de4db36..a07312f9 100644
--- a/SoftLayer/managers/account.py
+++ b/SoftLayer/managers/account.py
@@ -416,3 +416,7 @@ def delete_provisioning(self, identifier):
         Returns: boolean
         """
         return self.client.call("SoftLayer_Provisioning_Hook", "deleteObject", id=identifier)
+
+    def get_account_upgrade_orders(self, limit=100):
+        """Gets upgrade order list"""
+        return self.client.call('SoftLayer_Account', 'getUpgradeRequests', limit=limit)


Test patch:
diff --git a/tests/CLI/modules/account_tests.py b/tests/CLI/modules/account_tests.py
index 71a4ad71..a158713f 100644
--- a/tests/CLI/modules/account_tests.py
+++ b/tests/CLI/modules/account_tests.py
@@ -174,3 +174,8 @@ def test_delete_provisioning_hook(self):
         result = self.run_command(['account', 'hook-delete', '123456'])
         self.assert_no_fail(result)
         self.assert_called_with('SoftLayer_Provisioning_Hook', 'deleteObject')
+
+    def test_order_upgrade(self):
+        result = self.run_command(['account', 'orders', '--upgrades'])
+        self.assert_no_fail(result)
+        self.assert_called_with('SoftLayer_Account', 'getUpgradeRequests')
diff --git a/tests/managers/account_tests.py b/tests/managers/account_tests.py
index a1a9f483..80ed7bc3 100644
--- a/tests/managers/account_tests.py
+++ b/tests/managers/account_tests.py
@@ -188,3 +188,7 @@ def test_create_provisioning_scripts(self):
     def test_delete_provisioning_scripts(self):
         self.manager.delete_provisioning(123456)
         self.assert_called_with("SoftLayer_Provisioning_Hook", "deleteObject")
+
+    def test_get_upgrades_orders(self):
+        self.manager.get_account_upgrade_orders()
+        self.assert_called_with("SoftLayer_Account", "getUpgradeRequests")