Skip to content

Commit d90cb04

Browse files
committed
between date filter
1 parent 01ae438 commit d90cb04

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

SoftLayer/CLI/billing/list.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,18 @@
1111

1212

1313
@click.command()
14-
@click.option('--frmdate', '-f', help='cost incurred from from_date')
15-
@click.option('--enddate', '-e',
14+
@click.option('--start_date', '-f', help='cost incurred from from_date')
15+
@click.option('--end_date', '-e',
1616
help='end date to consider, default is latest time stamp')
17-
@click.option('--group', '-g',
18-
help='grouping by a resource type e.g server, iscsi etc.')
19-
@click.option('--resource', '-r',
20-
help='shows only cost of the active/inactive resources',
21-
type=click.Choice(['active',
22-
'inactive']))
2317
@environment.pass_env
24-
def cli(env, frmdate, enddate, group, resource):
18+
def cli(env, start_date, end_date):
2519
"""List billing information for accounts."""
2620
billing = SoftLayer.BillingManager(env.client)
27-
from_date = frmdate
28-
to_date = enddate
29-
group_by = group
30-
resource_status = resource
21+
from_date = start_date
22+
to_date = end_date
3123
table = formatting.Table(['Order ID', 'Resource Name', 'Resource Type',
3224
'cost', 'create_date'])
33-
resources = billing.list_resources(from_date, to_date, group_by)
25+
resources = billing.list_resources(from_date, to_date)
3426

3527
for resource in resources:
3628
resource = utils.NestedDict(resource)

SoftLayer/managers/billing.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
:license: MIT, see LICENSE for more details.
77
"""
8-
from SoftLayer.utils import NestedDict, query_filter, IdentifierMixin, lookup
8+
from SoftLayer.utils import NestedDict, query_filter, query_filter_date, IdentifierMixin, lookup
99
import SoftLayer
1010
from calendar import monthrange
1111
from datetime import datetime, date, timedelta
@@ -41,7 +41,7 @@ def get_info(self):
4141
return result
4242

4343

44-
def list_resources(self, from_date=None, to_date=None, group_by=None, resource_status=None, **kwargs):
44+
def list_resources(self, from_date=None, to_date=None, **kwargs):
4545
""" Retrieve a list of all ordered resources along with their costing.
4646
4747
:param dict \\*\\*kwargs: response-level option (limit)
@@ -75,15 +75,15 @@ def list_resources(self, from_date=None, to_date=None, group_by=None, resource_s
7575
_filter['orders']['userRecordId'] = query_filter(user['id'])
7676
date_format = '%Y-%m-%d'
7777

78-
if from_date:
79-
from_date_filter = from_date + '*'
78+
if from_date and to_date:
79+
filter['orders']['createDate'] = query_filter_date(from_date, to_date)
80+
elif from_date:
81+
from_date_filter = '>=' + ' ' + from_date
8082
_filter['orders']['createDate'] = query_filter(from_date_filter)
81-
if to_date:
82-
to_date_filter = to_date + '*'
83+
elif to_date:
84+
to_date_filter = '<=' + ' ' + to_date
8385
_filter['orders']['createDate'] = query_filter(to_date_filter)
84-
if group_by:
85-
group_by_filter = '*' + group_by
86-
_filter['orders']['description'] = query_filter(group_by_filter)
86+
print _filter['orders']['createDate']
8787
orders = self.account.getOrders(filter=_filter.to_dict())
8888
total = 0.0
8989
result = []

SoftLayer/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ def query_filter(query):
112112
return {'operation': query}
113113

114114

115+
def query_filter_date(start, end):
116+
return {'operation': 'betweenDate',
117+
'options': [
118+
{'name': 'startDate', 'value': [start+' 0:0:0']},
119+
{'name': 'endDate', 'value': [end+' 0:0:0']}
120+
]
121+
}
122+
123+
115124
class IdentifierMixin(object):
116125
"""Mixin used to resolve ids from other names of objects.
117126

0 commit comments

Comments
 (0)