-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added overview and export written off orders
- Loading branch information
1 parent
eb71637
commit 9269ca8
Showing
6 changed files
with
869 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from collections import defaultdict | ||
from django.db.models import Sum | ||
|
||
def get_writeoff_products(event, writeoff_purchases): | ||
writeoff_products = writeoff_purchases.filter(order__event=event) \ | ||
.values('order__writeoff_category__name', 'product') \ | ||
.annotate(total_amount=Sum('amount'), total_price=Sum('price')) \ | ||
.order_by('order__writeoff_category__name', 'product') | ||
|
||
# Group writeoffs by category | ||
grouped_writeoff_products = defaultdict(lambda: {'products': [], 'total_amount': 0, 'total_price': 0}) | ||
|
||
# calculate total product amount and total price per category | ||
for product in writeoff_products: | ||
category_name = product['order__writeoff_category__name'] | ||
grouped_writeoff_products[category_name]['products'].append(product) | ||
grouped_writeoff_products[category_name]['total_amount'] += product['total_amount'] | ||
grouped_writeoff_products[category_name]['total_price'] += product['total_price'] | ||
|
||
# Convert defaultdict to a regular dict for easier template use | ||
return dict(grouped_writeoff_products) |
Binary file not shown.
Oops, something went wrong.