Skip to content

Commit

Permalink
Merge pull request #20 from hivesolutions/dev_acaldas_order_csv
Browse files Browse the repository at this point in the history
Added order lines csv
  • Loading branch information
joamag committed Jun 9, 2016
2 parents e58d94e + 68ab57d commit 968dee3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/budy/controllers/api/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,49 @@ 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",
"product_id",
"quantity",
"size",
"scale",
"gender",
"line_total",
"currency",
"order_id",
"order_reference",
"order_total",
"order_status",
"account",
"date",
)]
for line in order.lines:
if not line.product: continue
line_s = (
line.id,
line.product.id,
line.product.product_id,
line.quantity,
line.size,
line.scale,
line.product.gender,
line.total,
line.currency,
order.id,
order.reference,
order.total,
order.status,
order.account.username,
order.created_d.strftime("%d/%m/%Y"),
)
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 @@ -655,6 +655,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 968dee3

Please sign in to comment.