Skip to content

Commit

Permalink
Merge d60059f into c32442f
Browse files Browse the repository at this point in the history
  • Loading branch information
Afonso Neves Caldas committed Jun 8, 2016
2 parents c32442f + d60059f commit c25f737
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/budy/controllers/api/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,35 @@ def cancel(self, key):
redirect_url = redirect_url,
order = order
)

@appier.route("/api/orders/<str:key>/lines.csv", "GET")
@appier.ensure(token = "admin")
def lines_csv(self, key):
order = budy.Order.get(key = key)
lines_s = [(
"id",
"product",
"quantity",
"size",
"scale",
"total",
"currency",
"country"
)]
for line in order.lines:
if not line.product: continue
line_s = (
line.id,
line.product.id,
line.quantity,
line.size,
line.scale,
line.total,
line.currency,
line.country
)
lines_s.append(line_s)

result = appier.serialize_csv(lines_s, delimiter = ",")
self.content_type("text/csv")
return result
8 changes: 8 additions & 0 deletions src/budy/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,14 @@ def fix_store_s(self):
self.store = self.account.store
self.save()

@appier.link(name = "Export Lines CSV")
def lines_csv_url(self, absolute = False):
return appier.get_app().url_for(
"order_api.lines_csv",
key = self.key,
absolute = absolute
)

@property
def payable(self):
return self.total
Expand Down

0 comments on commit c25f737

Please sign in to comment.