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
 import csv
1
 import csv
2
+from decimal import Decimal as D
2
 
3
 
3
 from django.db.models import get_model
4
 from django.db.models import get_model
4
 
5
 
7
 ReportCSVFormatter = get_class('dashboard.reports.reports', 'ReportCSVFormatter')
8
 ReportCSVFormatter = get_class('dashboard.reports.reports', 'ReportCSVFormatter')
8
 ReportHTMLFormatter = get_class('dashboard.reports.reports', 'ReportHTMLFormatter')
9
 ReportHTMLFormatter = get_class('dashboard.reports.reports', 'ReportHTMLFormatter')
9
 ConditionalOffer = get_model('offer', 'ConditionalOffer')
10
 ConditionalOffer = get_model('offer', 'ConditionalOffer')
11
+OrderDiscount = get_model('order', 'OrderDiscount')
10
 
12
 
11
 
13
 
12
 class OfferReportCSVFormatter(ReportCSVFormatter):
14
 class OfferReportCSVFormatter(ReportCSVFormatter):
28
     filename_template = 'dashboard/reports/partials/offer_report.html'
30
     filename_template = 'dashboard/reports/partials/offer_report.html'
29
 
31
 
30
 
32
 
31
-
32
 class OfferReportGenerator(ReportGenerator):
33
 class OfferReportGenerator(ReportGenerator):
33
-
34
     code = 'conditional-offers'
34
     code = 'conditional-offers'
35
     description = 'Offer performance'
35
     description = 'Offer performance'
36
 
36
 
40
     }
40
     }
41
 
41
 
42
     def generate(self):
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
 {% load currency_filters %}
2
 {% load currency_filters %}
3
 
3
 
4
 {% block report %}
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
     {% if page_obj %}
18
     {% if page_obj %}
18
         {% include "catalogue/partials/pagination.html" %}
19
         {% include "catalogue/partials/pagination.html" %}
19
     {% endif %}
20
     {% endif %}
21
+{% else %}
22
+	<p>No results found.</p>
23
+{% endif %}
20
 {% endblock %}
24
 {% endblock %}

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

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

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

2
 {% load currency_filters %}
2
 {% load currency_filters %}
3
 
3
 
4
 {% block report %}
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
     {% if page_obj %}
26
     {% if page_obj %}
26
         {% include "catalogue/partials/pagination.html" %}
27
         {% include "catalogue/partials/pagination.html" %}
27
     {% endif %}
28
     {% endif %}
29
+{% else %}
30
+	<p>No results found.</p>
31
+{% endif %}
28
 {% endblock %}
32
 {% endblock %}

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

4
 {% block report %}
4
 {% block report %}
5
 <table class="table table-striped table-bordered">
5
 <table class="table table-striped table-bordered">
6
     <tr>
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
         <th>Num lines</th>
9
         <th>Num lines</th>
11
         <th>Num items</th>
10
         <th>Num items</th>
12
         <th>Value</th>
11
         <th>Value</th>
15
     </tr>
14
     </tr>
16
     {% for basket in objects %}
15
     {% for basket in objects %}
17
     <tr>
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
         <td>{{ basket.num_lines }}</td>
19
         <td>{{ basket.num_lines }}</td>
22
         <td>{{ basket.num_items }}</td>
20
         <td>{{ basket.num_items }}</td>
23
         <td>{{ basket.total_incl_tax|currency }}</td>
21
         <td>{{ basket.total_incl_tax|currency }}</td>

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

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

Loading…
Cancel
Save