Implement Details in CapDocument
This commit is contained in:
parent
d8cf10bfa9
commit
697edaefa3
3
TODO
3
TODO
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user