Просмотр исходного кода

Added vouchers to order history / Now tracking order within voucher application model

master
David Winterbottom 14 лет назад
Родитель
Сommit
4bf5ffb5c0

+ 6
- 1
oscar/checkout/core_views.py Просмотреть файл

123
             return order_models.ShippingAddress(**addr_data)
123
             return order_models.ShippingAddress(**addr_data)
124
         addr_id = self.co_data.user_address_id()
124
         addr_id = self.co_data.user_address_id()
125
         if addr_id:
125
         if addr_id:
126
-            return address_models.UserAddress._default_manager.get(pk=addr_id)
126
+            try:
127
+                return address_models.UserAddress._default_manager.get(pk=addr_id)
128
+            except address_models.UserAddress.DoesNotExist:
129
+                # This can happen if you reset all your tables and you still have
130
+                # session data that refers to addresses that no longer exist
131
+                pass
127
         return None
132
         return None
128
     
133
     
129
     def get_success_response(self):
134
     def get_success_response(self):

+ 8
- 6
oscar/offer/abstract_models.py Просмотреть файл

7
 
7
 
8
 from oscar.offer.managers import ActiveOfferManager
8
 from oscar.offer.managers import ActiveOfferManager
9
 
9
 
10
+SITE, VOUCHER, USER, SESSION = ("Site", "Voucher", "User", "Session")
10
 
11
 
11
 class AbstractConditionalOffer(models.Model):
12
 class AbstractConditionalOffer(models.Model):
12
     u"""
13
     u"""
24
     #     to apply this offer needs to be coded
25
     #     to apply this offer needs to be coded
25
     # (d) Session offers - these are temporarily available to a user after some trigger 
26
     # (d) Session offers - these are temporarily available to a user after some trigger 
26
     #     event.  Eg, users coming from some affiliate site get 10% off.     
27
     #     event.  Eg, users coming from some affiliate site get 10% off.     
27
-    SITE, VOUCHER, USER, SESSION = ("Site", "Voucher", "User", "Session")
28
     TYPE_CHOICES = (
28
     TYPE_CHOICES = (
29
         (SITE, "Site offer - available to all users"),
29
         (SITE, "Site offer - available to all users"),
30
         (VOUCHER, "Voucher offer - only available after entering the appropriate voucher code"),
30
         (VOUCHER, "Voucher offer - only available after entering the appropriate voucher code"),
33
     )
33
     )
34
     offer_type = models.CharField(_("Type"), choices=TYPE_CHOICES, default=SITE, max_length=128)
34
     offer_type = models.CharField(_("Type"), choices=TYPE_CHOICES, default=SITE, max_length=128)
35
 
35
 
36
-    condition = models.OneToOneField('offer.Condition')
37
-    benefit = models.OneToOneField('offer.Benefit')
36
+    condition = models.ForeignKey('offer.Condition')
37
+    benefit = models.ForeignKey('offer.Benefit')
38
 
38
 
39
     # Range of availability.  Note that if this is a voucher offer, then these
39
     # Range of availability.  Note that if this is a voucher offer, then these
40
     # dates are ignored and only the dates from the voucher are used to determine 
40
     # dates are ignored and only the dates from the voucher are used to determine 
215
         help_text="""This will be shown in the checkout and basket once the voucher is entered""")
215
         help_text="""This will be shown in the checkout and basket once the voucher is entered""")
216
     code = models.CharField(_("Code"), max_length=128, db_index=True, unique=True,
216
     code = models.CharField(_("Code"), max_length=128, db_index=True, unique=True,
217
         help_text="""Case insensitive / No spaces allowed""")
217
         help_text="""Case insensitive / No spaces allowed""")
218
-    offers = models.ManyToManyField('offer.ConditionalOFfer', related_name='vouchers')
218
+    offers = models.ManyToManyField('offer.ConditionalOFfer', related_name='vouchers', 
219
+                                    limit_choices_to={'offer_type': VOUCHER})
219
 
220
 
220
     SINGLE_USE, MULTI_USE, ONCE_PER_CUSTOMER = ('Single use', 'Multi-use', 'Once per customer')
221
     SINGLE_USE, MULTI_USE, ONCE_PER_CUSTOMER = ('Single use', 'Multi-use', 'Once per customer')
221
     USAGE_CHOICES = (
222
     USAGE_CHOICES = (
277
                     message = "You have already used this voucher in a previous order"
278
                     message = "You have already used this voucher in a previous order"
278
         return is_available, message
279
         return is_available, message
279
     
280
     
280
-    def record_usage(self, user):
281
+    def record_usage(self, order, user):
281
         u"""
282
         u"""
282
         Records a usage of this voucher in an order.
283
         Records a usage of this voucher in an order.
283
         """
284
         """
284
-        self.applications.create(voucher=self, user=user)
285
+        self.applications.create(voucher=self, order=order, user=user)
285
 
286
 
286
 
287
 
287
 class AbstractVoucherApplication(models.Model):
288
 class AbstractVoucherApplication(models.Model):
292
     # It is possible for an anonymous user to apply a voucher so we need to allow
293
     # It is possible for an anonymous user to apply a voucher so we need to allow
293
     # the user to be nullable
294
     # the user to be nullable
294
     user = models.ForeignKey('auth.User', blank=True, null=True)
295
     user = models.ForeignKey('auth.User', blank=True, null=True)
296
+    order = models.ForeignKey('order.Order')
295
     date_created = models.DateField(auto_now_add=True)
297
     date_created = models.DateField(auto_now_add=True)
296
 
298
 
297
     class Meta:
299
     class Meta:

+ 3
- 3
oscar/offer/admin.py Просмотреть файл

18
             'fields': ('name', 'code', 'usage', 'start_date', 'end_date')
18
             'fields': ('name', 'code', 'usage', 'start_date', 'end_date')
19
         }),
19
         }),
20
         ('Benefit', {
20
         ('Benefit', {
21
-            'fields': ('offers', 'free_shipping')
21
+            'fields': ('offers',)
22
         }),
22
         }),
23
         ('Usage', {
23
         ('Usage', {
24
             'fields': ('num_basket_additions', 'num_orders', 'total_discount')
24
             'fields': ('num_basket_additions', 'num_orders', 'total_discount')
27
     )
27
     )
28
     
28
     
29
 class VoucherApplicationAdmin(admin.ModelAdmin):
29
 class VoucherApplicationAdmin(admin.ModelAdmin):
30
-    list_display = ('voucher', 'user', 'date_created')
31
-    readonly_fields = ('voucher', 'user')        
30
+    list_display = ('voucher', 'user', 'order', 'date_created')
31
+    readonly_fields = ('voucher', 'user', 'order')        
32
     
32
     
33
 class ConditionalOfferAdmin(admin.ModelAdmin):
33
 class ConditionalOfferAdmin(admin.ModelAdmin):
34
     list_display = ('name', 'offer_type', 'start_date', 'end_date', 'condition', 'benefit', 'total_discount')
34
     list_display = ('name', 'offer_type', 'start_date', 'end_date', 'condition', 'benefit', 'total_discount')

+ 0
- 1
oscar/offer/fixtures/sample-voucher.json Просмотреть файл

47
         "pk": 1, 
47
         "pk": 1, 
48
         "model": "offer.voucher", 
48
         "model": "offer.voucher", 
49
         "fields": {
49
         "fields": {
50
-            "free_shipping": false, 
51
             "code": "BOOM", 
50
             "code": "BOOM", 
52
             "name": "Oscar voucher", 
51
             "name": "Oscar voucher", 
53
             "end_date": "2011-04-28", 
52
             "end_date": "2011-04-28", 

+ 5
- 0
oscar/order/abstract_models.py Просмотреть файл

432
     
432
     
433
     class Meta:
433
     class Meta:
434
         abstract = True
434
         abstract = True
435
+        
436
+    def description(self):
437
+        if self.voucher_code:
438
+            return self.voucher_code
439
+        return self.offer.name

+ 4
- 1
oscar/order/utils.py Просмотреть файл

120
         order_discount.save()
120
         order_discount.save()
121
         
121
         
122
     def _record_voucher_usage(self, order, voucher, user):
122
     def _record_voucher_usage(self, order, voucher, user):
123
-        voucher.record_usage(user)
123
+        u"""
124
+        Updates the models that care about this voucher.
125
+        """
126
+        voucher.record_usage(order, user)
124
         voucher.num_orders += 1
127
         voucher.num_orders += 1
125
         voucher.save()
128
         voucher.save()

+ 8
- 2
oscar/templates/customer/order.html Просмотреть файл

53
         <td><a href="{{ line.product.get_absolute_url }}">{{ line.description }}</a></td>
53
         <td><a href="{{ line.product.get_absolute_url }}">{{ line.description }}</a></td>
54
         <td>{{ line.product.stockrecord.availability }}</td>
54
         <td>{{ line.product.stockrecord.availability }}</td>
55
         <td>{{ line.quantity }}</td>
55
         <td>{{ line.quantity }}</td>
56
-        <td>{{ line.line_price_excl_tax|currency }}</td>
57
-        <td>{{ line.line_price_incl_tax|currency }}</td>
56
+        <td>{{ line.line_price_before_discounts_excl_tax|currency }}</td>
57
+        <td>{{ line.line_price_before_discounts_incl_tax|currency }}</td>
58
         <td>{{ line.shipping_status }}</td>
58
         <td>{{ line.shipping_status }}</td>
59
     </tr>
59
     </tr>
60
     {% endfor %}
60
     {% endfor %}
61
+    {% for discount in order.discounts.all %}
62
+    <tr>
63
+        <td colspan="4">{{ discount.description }}</td>
64
+        <td>-{{ discount.amount|currency }}</td>
65
+    </tr>
66
+    {% endfor %}
61
 </table>
67
 </table>
62
 
68
 
63
 <table>
69
 <table>

Загрузка…
Отмена
Сохранить