Implement Details in CapDocument

This commit is contained in:
Lucas Verney 2016-09-29 17:28:39 -04:00
parent d8cf10bfa9
commit 697edaefa3
2 changed files with 32 additions and 10 deletions

3
TODO
View File

@ -1,5 +1,4 @@
* history (Detail) vs Bill? * Bills vs Details?
* Bill._url?
* Update modules? * Update modules?
* amazon.com is buggy * amazon.com is buggy

View File

@ -6,16 +6,39 @@ def to_cozy(document):
Export a CapDocument object to JSON, to pass it to Cozy instance. Export a CapDocument object to JSON, to pass it to Cozy instance.
""" """
# Fetch the list of subscriptions # Fetch the list of subscriptions
subscriptions = list(document.iter_subscription()) try:
# Return a formatted dict with all the infos subscriptions = list(document.iter_subscription())
return { except NotImplementedError:
"subscriptions": [ # List of subscriptions subscriptions = None
clean_object(subscription) for subscription in subscriptions # Fetch and clean the list of bills
], try:
"bills": { # List of bills for each subscription assert(subscriptions)
bills = {
subscription.id: [ subscription.id: [
clean_object(bill) for bill in document.iter_bills(subscription) clean_object(bill) for bill in document.iter_documents(subscription)
] ]
for subscription in subscriptions for subscription in subscriptions
} }
except (NotImplementedError, AssertionError):
bills = None
# Fetch and clean the list of history bills (detailed consumption)
try:
assert(subscriptions)
detailed_bills = {
subscription.id: [
clean_object(detailed_bill)
for detailed_bill in document.get_details(subscription)
]
for subscription in subscriptions
}
except (NotImplementedError, AssertionError):
detailed_bills = None
# Return a formatted dict with all the infos
ret = {
"subscriptions": [ # Clean the subscriptions list
clean_object(subscription) for subscription in subscriptions
],
"bills": bills,
"detailed_bills": detailed_bills
} }
return ret