Browse Source

Cleaned up report templates

master
David Winterbottom 13 years ago
parent
commit
fe4bcd5284

+ 20
- 4
oscar/apps/offer/reports.py View File

@@ -1,4 +1,5 @@
1 1
 import csv
2
+from decimal import Decimal as D
2 3
 
3 4
 from django.db.models import get_model
4 5
 
@@ -7,6 +8,7 @@ ReportGenerator = get_class('dashboard.reports.reports', 'ReportGenerator')
7 8
 ReportCSVFormatter = get_class('dashboard.reports.reports', 'ReportCSVFormatter')
8 9
 ReportHTMLFormatter = get_class('dashboard.reports.reports', 'ReportHTMLFormatter')
9 10
 ConditionalOffer = get_model('offer', 'ConditionalOffer')
11
+OrderDiscount = get_model('order', 'OrderDiscount')
10 12
 
11 13
 
12 14
 class OfferReportCSVFormatter(ReportCSVFormatter):
@@ -28,9 +30,7 @@ class OfferReportHTMLFormatter(ReportHTMLFormatter):
28 30
     filename_template = 'dashboard/reports/partials/offer_report.html'
29 31
 
30 32
 
31
-
32 33
 class OfferReportGenerator(ReportGenerator):
33
-
34 34
     code = 'conditional-offers'
35 35
     description = 'Offer performance'
36 36
 
@@ -40,5 +40,21 @@ class OfferReportGenerator(ReportGenerator):
40 40
     }
41 41
 
42 42
     def generate(self):
43
-        offers = ConditionalOffer._default_manager.all()
44
-        return self.formatter.generate_response(offers)
43
+        discounts = OrderDiscount._default_manager.filter(
44
+            order__date_placed__gte=self.start_date,
45
+            order__date_placed__lt=self.end_date
46
+        )
47
+        offer_discounts = {}
48
+        for discount in discounts:
49
+            if discount.offer_id not in offer_discounts:
50
+                try:
51
+                    offer = ConditionalOffer._default_manager.get(id=discount.offer_id)
52
+                except ConditionalOffer.DoesNotExist:
53
+                    continue
54
+                offer_discounts[discount.offer_id] = {
55
+                    'offer': offer,
56
+                    'total_discount': D('0.00')
57
+                }
58
+            offer_discounts[discount.offer_id]['total_discount'] += discount.amount
59
+
60
+        return self.formatter.generate_response(offer_discounts.values())

+ 16
- 12
oscar/templates/dashboard/reports/partials/offer_report.html View File

@@ -2,19 +2,23 @@
2 2
 {% load currency_filters %}
3 3
 
4 4
 {% block report %}
5
-<table class="table table-striped table-bordered">
6
-    <tr>
7
-        <th>Offer</th>
8
-        <th>Total discount</th>
9
-    </tr>
10
-    {% for offer in objects %}
11
-    <tr>
12
-        <td>{{ offer }}</td>
13
-        <td>{{ offer.total_discount }}</td>
14
-    </tr>
15
-    {% endfor %}
16
-</table>
5
+{% if objects %}
6
+	<table class="table table-striped table-bordered">
7
+		<tr>
8
+			<th>Offer</th>
9
+			<th>Total discount</th>
10
+		</tr>
11
+		{% for offer_discount in objects %}
12
+		<tr>
13
+			<td>{{ offer_discount.offer.name }}</td>
14
+			<td>{{ offer_discount.total_discount|currency }}</td>
15
+		</tr>
16
+		{% endfor %}
17
+	</table>
17 18
     {% if page_obj %}
18 19
         {% include "catalogue/partials/pagination.html" %}
19 20
     {% endif %}
21
+{% else %}
22
+	<p>No results found.</p>
23
+{% endif %}
20 24
 {% endblock %}

+ 2
- 6
oscar/templates/dashboard/reports/partials/open_basket_report.html View File

@@ -4,10 +4,8 @@
4 4
 {% block report %}
5 5
 <table class="table table-striped table-bordered">
6 6
     <tr>
7
-        <th>User ID</th>
8
-        <th>Name</th>
9 7
         <th>Email</th>
10
-        <th>Basket status</th>
8
+        <th>Name</th>
11 9
         <th>Num lines</th>
12 10
         <th>Num items</th>
13 11
         <th>Value</th>
@@ -16,10 +14,8 @@
16 14
     </tr>
17 15
     {% for basket in objects %}
18 16
     <tr>
19
-        <td>{{ basket.owner_id }}</td>
20
-        <td>{{ basket.owner.get_full_name }}</td>
21 17
         <td>{{ basket.owner.email }}</td>
22
-        <td>{{ basket.status }}</td>
18
+        <td>{{ basket.owner.get_full_name|default:"-" }}</td>
23 19
         <td>{{ basket.num_lines }}</td>
24 20
         <td>{{ basket.num_items }}</td>
25 21
         <td>{{ basket.total_incl_tax|currency }}</td>

+ 24
- 20
oscar/templates/dashboard/reports/partials/order_report.html View File

@@ -2,27 +2,31 @@
2 2
 {% load currency_filters %}
3 3
 
4 4
 {% block report %}
5
-<table class="table table-striped table-bordered">
6
-    <tr>
7
-        <th>Order number</th>
8
-        <th>User</th>
9
-        <th>Total incl. tax</th>
10
-        <th>Date placed</th>
11
-        <th></th>
12
-    </tr>
13
-    {% for order in objects %}
14
-    <tr>
15
-        <td>{{ order.number }}</td>
16
-        <td>{{ order.user }}</td>
17
-        <td>{{ order.total_incl_tax|currency }}</td>
18
-        <td>{{ order.date_placed }}</td>
19
-        <td>
20
-            <a class="btn btn-info" href="{% url dashboard:order-detail order.number %}">View</a>
21
-        </td>
22
-    </tr>
23
-    {% endfor %}
24
-</table>
5
+{% if objects %}
6
+	<table class="table table-striped table-bordered">
7
+		<tr>
8
+			<th>Order number</th>
9
+			<th>User</th>
10
+			<th>Total incl. tax</th>
11
+			<th>Date placed</th>
12
+			<th></th>
13
+		</tr>
14
+		{% for order in objects %}
15
+		<tr>
16
+			<td>{{ order.number }}</td>
17
+			<td>{{ order.user }}</td>
18
+			<td>{{ order.total_incl_tax|currency }}</td>
19
+			<td>{{ order.date_placed }}</td>
20
+			<td>
21
+				<a class="btn btn-info" href="{% url dashboard:order-detail order.number %}">View</a>
22
+			</td>
23
+		</tr>
24
+		{% endfor %}
25
+	</table>
25 26
     {% if page_obj %}
26 27
         {% include "catalogue/partials/pagination.html" %}
27 28
     {% endif %}
29
+{% else %}
30
+	<p>No results found.</p>
31
+{% endif %}
28 32
 {% endblock %}

+ 4
- 6
oscar/templates/dashboard/reports/partials/submitted_basket_report.html View File

@@ -4,9 +4,8 @@
4 4
 {% block report %}
5 5
 <table class="table table-striped table-bordered">
6 6
     <tr>
7
-        <th>User ID</th>
8
-        <th>User</th>
9
-        <th>Basket status</th>
7
+        <th>Email</th>
8
+        <th>Name</th>
10 9
         <th>Num lines</th>
11 10
         <th>Num items</th>
12 11
         <th>Value</th>
@@ -15,9 +14,8 @@
15 14
     </tr>
16 15
     {% for basket in objects %}
17 16
     <tr>
18
-        <td>{{ basket.owner_id|default:"-" }}</td>
19
-        <td>{{ basket.owner }}</td>
20
-        <td>{{ basket.status }}</td>
17
+        <td>{{ basket.owner.email }}</td>
18
+        <td>{{ basket.owner.get_full_name|default:"-" }}</td>
21 19
         <td>{{ basket.num_lines }}</td>
22 20
         <td>{{ basket.num_items }}</td>
23 21
         <td>{{ basket.total_incl_tax|currency }}</td>

+ 1
- 1
oscar/templates/dashboard/reports/partials/voucher_report.html View File

@@ -14,7 +14,7 @@
14 14
         <td>{{ voucher.code }}</td>
15 15
         <td>{{ voucher.num_basket_additions }}</td>
16 16
         <td>{{ voucher.num_orders }}</td>
17
-        <td>{{ voucher.total_discount }}</td>
17
+        <td>{{ voucher.total_discount|currency }}</td>
18 18
     </tr>
19 19
     {% endfor %}
20 20
 </table>

Loading…
Cancel
Save