Преглед изворни кода

Add alters_data attribute to all model functions that alter data

master
David Winterbottom пре 13 година
родитељ
комит
d0f19852da

+ 6
- 0
oscar/apps/basket/abstract_models.py Прегледај датотеку

150
             line.quantity += quantity
150
             line.quantity += quantity
151
             line.save()
151
             line.save()
152
         self._lines = None
152
         self._lines = None
153
+    add_product.alters_data = True
153
 
154
 
154
     def get_discounts(self):
155
     def get_discounts(self):
155
         if self.discounts is None:
156
         if self.discounts is None:
193
                                              line.quantity)
194
                                              line.quantity)
194
             existing_line.save()
195
             existing_line.save()
195
             line.delete()
196
             line.delete()
197
+    merge_line.alters_data = True
196
 
198
 
197
     def merge(self, basket, add_quantities=True):
199
     def merge(self, basket, add_quantities=True):
198
         """
200
         """
207
         basket.date_merged = now()
209
         basket.date_merged = now()
208
         basket.save()
210
         basket.save()
209
         self._lines = None
211
         self._lines = None
212
+    merge.alters_data = True
210
 
213
 
211
     def freeze(self):
214
     def freeze(self):
212
         """
215
         """
214
         """
217
         """
215
         self.status = self.FROZEN
218
         self.status = self.FROZEN
216
         self.save()
219
         self.save()
220
+    freeze.alters_data = True
217
 
221
 
218
     def thaw(self):
222
     def thaw(self):
219
         """
223
         """
221
         """
225
         """
222
         self.status = self.OPEN
226
         self.status = self.OPEN
223
         self.save()
227
         self.save()
228
+    thaw.alters_data = True
224
 
229
 
225
     def set_as_submitted(self):
230
     def set_as_submitted(self):
226
         """Mark this basket as submitted."""
231
         """Mark this basket as submitted."""
227
         self.status = self.SUBMITTED
232
         self.status = self.SUBMITTED
228
         self.date_submitted = now()
233
         self.date_submitted = now()
229
         self.save()
234
         self.save()
235
+    set_as_submitted.alters_data = True
230
 
236
 
231
     def set_as_tax_exempt(self):
237
     def set_as_tax_exempt(self):
232
         self.exempt_from_tax = True
238
         self.exempt_from_tax = True

+ 3
- 1
oscar/apps/catalogue/abstract_models.py Прегледај датотеку

375
         from oscar.apps.catalogue.categories import create_from_breadcrumbs
375
         from oscar.apps.catalogue.categories import create_from_breadcrumbs
376
         category = create_from_breadcrumbs(breadcrumb)
376
         category = create_from_breadcrumbs(breadcrumb)
377
 
377
 
378
-        temp = get_model('catalogue', 'ProductCategory')(category=category, product=self)
378
+        temp = get_model('catalogue', 'ProductCategory')(
379
+            category=category, product=self)
379
         temp.save()
380
         temp.save()
381
+    add_category_from_breadcrumbs.alters_data = True
380
 
382
 
381
     def attribute_summary(self):
383
     def attribute_summary(self):
382
         u"""Return a string of all of a product's attributes"""
384
         u"""Return a string of all of a product's attributes"""

+ 4
- 0
oscar/apps/customer/abstract_models.py Прегледај датотеку

158
     def archive(self):
158
     def archive(self):
159
         self.location = self.ARCHIVE
159
         self.location = self.ARCHIVE
160
         self.save()
160
         self.save()
161
+    archive.alters_data = True
161
 
162
 
162
     @property
163
     @property
163
     def is_read(self):
164
     def is_read(self):
231
         self.status = self.ACTIVE
232
         self.status = self.ACTIVE
232
         self.date_confirmed = now()
233
         self.date_confirmed = now()
233
         self.save()
234
         self.save()
235
+    confirm.alters_data = True
234
 
236
 
235
     def cancel(self):
237
     def cancel(self):
236
         self.status = self.CANCELLED
238
         self.status = self.CANCELLED
237
         self.date_cancelled = now()
239
         self.date_cancelled = now()
238
         self.save()
240
         self.save()
241
+    cancel.alters_data = True
239
 
242
 
240
     def close(self):
243
     def close(self):
241
         self.status = self.CLOSED
244
         self.status = self.CLOSED
242
         self.date_closed = now()
245
         self.date_closed = now()
243
         self.save()
246
         self.save()
247
+    close.alters_data = True
244
 
248
 
245
     def get_email_address(self):
249
     def get_email_address(self):
246
         if self.user:
250
         if self.user:

+ 1
- 0
oscar/apps/offer/models.py Прегледај датотеку

174
         self.num_orders += 1
174
         self.num_orders += 1
175
         self.total_discount += discount
175
         self.total_discount += discount
176
         self.save()
176
         self.save()
177
+    record_usage.alters_data = True
177
 
178
 
178
 
179
 
179
 class Condition(models.Model):
180
 class Condition(models.Model):

+ 2
- 0
oscar/apps/order/abstract_models.py Прегледај датотеку

78
                 line.status = self.cascade[self.status]
78
                 line.status = self.cascade[self.status]
79
                 line.save()
79
                 line.save()
80
         self.save()
80
         self.save()
81
+    set_status.alters_data = True
81
 
82
 
82
     @property
83
     @property
83
     def is_anonymous(self):
84
     def is_anonymous(self):
340
                                     'new_status': new_status, 'status': self.status})
341
                                     'new_status': new_status, 'status': self.status})
341
         self.status = new_status
342
         self.status = new_status
342
         self.save()
343
         self.save()
344
+    set_status.alters_data = True
343
 
345
 
344
     @property
346
     @property
345
     def category(self):
347
     def category(self):

+ 5
- 0
oscar/apps/partner/abstract_models.py Прегледај датотеку

123
             self.num_allocated = 0
123
             self.num_allocated = 0
124
         self.num_allocated += quantity
124
         self.num_allocated += quantity
125
         self.save()
125
         self.save()
126
+    allocate.alters_data = True
126
 
127
 
127
     def is_allocation_consumption_possible(self, quantity):
128
     def is_allocation_consumption_possible(self, quantity):
128
         return quantity <= min(self.num_allocated, self.num_in_stock)
129
         return quantity <= min(self.num_allocated, self.num_in_stock)
139
         self.num_allocated -= quantity
140
         self.num_allocated -= quantity
140
         self.num_in_stock -= quantity
141
         self.num_in_stock -= quantity
141
         self.save()
142
         self.save()
143
+    consume_allocation.alters_data = True
142
 
144
 
143
     def cancel_allocation(self, quantity):
145
     def cancel_allocation(self, quantity):
144
         # We ignore requests that request a cancellation of more than the amount already
146
         # We ignore requests that request a cancellation of more than the amount already
145
         # allocated.
147
         # allocated.
146
         self.num_allocated -= min(self.num_allocated, quantity)
148
         self.num_allocated -= min(self.num_allocated, quantity)
147
         self.save()
149
         self.save()
150
+    cancel_allocation.alters_data = True
148
 
151
 
149
     @property
152
     @property
150
     def net_stock_level(self):
153
     def net_stock_level(self):
169
         """
172
         """
170
         self.price_excl_tax = price
173
         self.price_excl_tax = price
171
         self.save()
174
         self.save()
175
+    set_discount_price.alters_data = True
172
 
176
 
173
     # Price retrieval methods - these default to no tax being applicable
177
     # Price retrieval methods - these default to no tax being applicable
174
     # These are intended to be overridden.
178
     # These are intended to be overridden.
271
     def close(self):
275
     def close(self):
272
         self.status = self.CLOSED
276
         self.status = self.CLOSED
273
         self.save()
277
         self.save()
278
+    close.alters_data = True
274
 
279
 
275
     def __unicode__(self):
280
     def __unicode__(self):
276
         return _('<stockalert for "%(stock)s" status %(status)s>') % {'stock': self.stockrecord, 'status': self.status}
281
         return _('<stockalert for "%(stock)s" status %(status)s>') % {'stock': self.stockrecord, 'status': self.status}

+ 49
- 25
oscar/apps/payment/models.py Прегледај датотеку

8
 
8
 
9
 class Transaction(models.Model):
9
 class Transaction(models.Model):
10
     """
10
     """
11
-    A transaction for payment sources which need a secondary 'transaction' to actually take the money
11
+    A transaction for payment sources which need a secondary 'transaction' to
12
+    actually take the money
12
 
13
 
13
-    This applies mainly to credit card sources which can be a pre-auth for the money.  A 'complete'
14
-    needs to be run later to debit the money from the account.
14
+    This applies mainly to credit card sources which can be a pre-auth for the
15
+    money.  A 'complete' needs to be run later to debit the money from the
16
+    account.
15
     """
17
     """
16
-    source = models.ForeignKey('payment.Source', related_name='transactions', verbose_name=_("Source"))
18
+    source = models.ForeignKey(
19
+        'payment.Source', related_name='transactions',
20
+        verbose_name=_("Source"))
17
 
21
 
18
     # We define some sample types
22
     # We define some sample types
19
     AUTHORISE, DEBIT, REFUND = 'Authorise', 'Debit', 'Refund'
23
     AUTHORISE, DEBIT, REFUND = 'Authorise', 'Debit', 'Refund'
24
     date_created = models.DateTimeField(_("Date Created"), auto_now_add=True)
28
     date_created = models.DateTimeField(_("Date Created"), auto_now_add=True)
25
 
29
 
26
     def __unicode__(self):
30
     def __unicode__(self):
27
-        return _("%(type)s of %(amount).2f") % {'type': self.txn_type, 'amount': self.amount}
31
+        return _("%(type)s of %(amount).2f") % {
32
+            'type': self.txn_type, 'amount': self.amount}
28
 
33
 
29
     class Meta:
34
     class Meta:
30
         verbose_name = _("Transaction")
35
         verbose_name = _("Transaction")
40
     multiple sources such as cheque, credit accounts, gift cards.  Each payment
45
     multiple sources such as cheque, credit accounts, gift cards.  Each payment
41
     source will have its own entry.
46
     source will have its own entry.
42
     """
47
     """
43
-    order = models.ForeignKey('order.Order', related_name='sources', verbose_name=_("Order"))
44
-    source_type = models.ForeignKey('payment.SourceType', verbose_name=_("Source Type"))
45
-    currency = models.CharField(_("Currency"), max_length=12, default=settings.OSCAR_DEFAULT_CURRENCY)
48
+    order = models.ForeignKey('order.Order',
49
+                              related_name='sources', verbose_name=_("Order"))
50
+    source_type = models.ForeignKey('payment.SourceType',
51
+                                    verbose_name=_("Source Type"))
52
+    currency = models.CharField(_("Currency"), max_length=12,
53
+                                default=settings.OSCAR_DEFAULT_CURRENCY)
46
 
54
 
47
     # Track the various amounts associated with this source
55
     # Track the various amounts associated with this source
48
-    amount_allocated = models.DecimalField(_("Amount Allocated"), decimal_places=2, max_digits=12, default=Decimal('0.00'))
49
-    amount_debited = models.DecimalField(_("Amount Debited"), decimal_places=2, max_digits=12, default=Decimal('0.00'))
50
-    amount_refunded = models.DecimalField(_("Amount Refunded"), decimal_places=2, max_digits=12, default=Decimal('0.00'))
51
-
52
-    # Reference number for this payment source.  This is often used to look up a
53
-    # transaction model for a particular payment partner.
54
-    reference = models.CharField(_("Reference"), max_length=128, blank=True, null=True)
56
+    amount_allocated = models.DecimalField(
57
+        _("Amount Allocated"), decimal_places=2, max_digits=12,
58
+        default=Decimal('0.00'))
59
+    amount_debited = models.DecimalField(
60
+        _("Amount Debited"), decimal_places=2, max_digits=12,
61
+        default=Decimal('0.00'))
62
+    amount_refunded = models.DecimalField(
63
+        _("Amount Refunded"), decimal_places=2, max_digits=12,
64
+        default=Decimal('0.00'))
65
+
66
+    # Reference number for this payment source.  This is often used to look up
67
+    # a transaction model for a particular payment partner.
68
+    reference = models.CharField(_("Reference"), max_length=128,
69
+                                 blank=True, null=True)
55
 
70
 
56
     # A customer-friendly label for the source, eg XXXX-XXXX-XXXX-1234
71
     # A customer-friendly label for the source, eg XXXX-XXXX-XXXX-1234
57
     label = models.CharField(_("Label"), max_length=128, blank=True, null=True)
72
     label = models.CharField(_("Label"), max_length=128, blank=True, null=True)
82
                 self._create_transaction(*txn)
97
                 self._create_transaction(*txn)
83
 
98
 
84
     def balance(self):
99
     def balance(self):
85
-        return self.amount_allocated - self.amount_debited + self.amount_refunded
100
+        return (self.amount_allocated - self.amount_debited +
101
+                self.amount_refunded)
86
 
102
 
87
-    def create_deferred_transaction(self, txn_type, amount, reference=None, status=None):
103
+    def create_deferred_transaction(self, txn_type, amount, reference=None,
104
+                                    status=None):
88
         """
105
         """
89
         Register the data for a transaction that can't be created yet due to FK
106
         Register the data for a transaction that can't be created yet due to FK
90
-        constraints.  This happens at checkout where create an payment source and a
91
-        transaction but can't save them until the order model exists.
107
+        constraints.  This happens at checkout where create an payment source
108
+        and a transaction but can't save them until the order model exists.
92
         """
109
         """
93
         if self.deferred_txns is None:
110
         if self.deferred_txns is None:
94
             self.deferred_txns = []
111
             self.deferred_txns = []
95
         self.deferred_txns.append((txn_type, amount, reference, status))
112
         self.deferred_txns.append((txn_type, amount, reference, status))
96
 
113
 
97
-    def _create_transaction(self, txn_type, amount, reference=None, status=None):
114
+    def _create_transaction(self, txn_type, amount, reference=None,
115
+                            status=None):
98
         Transaction.objects.create(source=self,
116
         Transaction.objects.create(source=self,
99
                                    txn_type=txn_type,
117
                                    txn_type=txn_type,
100
                                    amount=amount,
118
                                    amount=amount,
107
         """
125
         """
108
         self.amount_allocated += amount
126
         self.amount_allocated += amount
109
         self.save()
127
         self.save()
110
-        self._create_transaction(Transaction.AUTHORISE, amount, reference, status)
128
+        self._create_transaction(
129
+            Transaction.AUTHORISE, amount, reference, status)
130
+    allocate.alters_data = True
111
 
131
 
112
     def debit(self, amount=None, reference=None, status=None):
132
     def debit(self, amount=None, reference=None, status=None):
113
         """
133
         """
118
         self.amount_debited += amount
138
         self.amount_debited += amount
119
         self.save()
139
         self.save()
120
         self._create_transaction(Transaction.DEBIT, amount, reference, status)
140
         self._create_transaction(Transaction.DEBIT, amount, reference, status)
141
+    debit.alters_data = True
121
 
142
 
122
     def refund(self, amount, reference=None, status=None):
143
     def refund(self, amount, reference=None, status=None):
123
         """
144
         """
126
         self.amount_refunded += amount
147
         self.amount_refunded += amount
127
         self.save()
148
         self.save()
128
         self._create_transaction(Transaction.REFUND, amount, reference, status)
149
         self._create_transaction(Transaction.REFUND, amount, reference, status)
150
+    refund.alters_data = True
129
 
151
 
130
     @property
152
     @property
131
     def amount_available_for_refund(self):
153
     def amount_available_for_refund(self):
143
     or an internal source such as a managed account.i
165
     or an internal source such as a managed account.i
144
     """
166
     """
145
     name = models.CharField(_("Name"), max_length=128)
167
     name = models.CharField(_("Name"), max_length=128)
146
-    code = models.SlugField(_("Code"), max_length=128, help_text=_("""This is used within
147
-        forms to identify this source type"""))
168
+    code = models.SlugField(_("Code"), max_length=128,
169
+       help_text=_("This is used within forms to identify this source type"))
148
 
170
 
149
     class Meta:
171
     class Meta:
150
         verbose_name = _("Source Type")
172
         verbose_name = _("Source Type")
160
 
182
 
161
 
183
 
162
 class Bankcard(models.Model):
184
 class Bankcard(models.Model):
163
-    user = models.ForeignKey('auth.User', related_name='bankcards', verbose_name=_("User"))
185
+    user = models.ForeignKey('auth.User', related_name='bankcards',
186
+                             verbose_name=_("User"))
164
     card_type = models.CharField(_("Card Type"), max_length=128)
187
     card_type = models.CharField(_("Card Type"), max_length=128)
165
     name = models.CharField(_("Name"), max_length=255)
188
     name = models.CharField(_("Name"), max_length=255)
166
     number = models.CharField(_("Number"), max_length=32)
189
     number = models.CharField(_("Number"), max_length=32)
167
     expiry_date = models.DateField(_("Expiry Date"))
190
     expiry_date = models.DateField(_("Expiry Date"))
168
 
191
 
169
     # For payment partners who are storing the full card details for us
192
     # For payment partners who are storing the full card details for us
170
-    partner_reference = models.CharField(_("Partner Reference"), max_length=255, null=True, blank=True)
193
+    partner_reference = models.CharField(
194
+        _("Partner Reference"), max_length=255, null=True, blank=True)
171
 
195
 
172
     class Meta:
196
     class Meta:
173
         verbose_name = _("Bankcard")
197
         verbose_name = _("Bankcard")

+ 4
- 3
oscar/apps/promotions/models.py Прегледај датотеку

37
     def record_click(self):
37
     def record_click(self):
38
         self.clicks += 1
38
         self.clicks += 1
39
         self.save()
39
         self.save()
40
+    record_click.alters_data = True
40
 
41
 
41
 
42
 
42
 class PagePromotion(LinkedPromotion):
43
 class PagePromotion(LinkedPromotion):
156
 
157
 
157
 class Image(AbstractPromotion):
158
 class Image(AbstractPromotion):
158
     """
159
     """
159
-    An image promotion is simply a named image which has an optional 
160
+    An image promotion is simply a named image which has an optional
160
     link to another part of the site (or another site).
161
     link to another part of the site (or another site).
161
-    
162
+
162
     This can be used to model both banners and pods.
163
     This can be used to model both banners and pods.
163
     """
164
     """
164
     _type = 'Image'
165
     _type = 'Image'
179
 class MultiImage(AbstractPromotion):
180
 class MultiImage(AbstractPromotion):
180
     """
181
     """
181
     A multi-image promotion is simply a collection of image promotions
182
     A multi-image promotion is simply a collection of image promotions
182
-    that are rendered in a specific way.  This models things like 
183
+    that are rendered in a specific way.  This models things like
183
     rotating banners.
184
     rotating banners.
184
     """
185
     """
185
     _type = 'Multi-image'
186
     _type = 'Multi-image'

+ 42
- 32
oscar/apps/shipping/models.py Прегледај датотеку

13
     description = models.TextField(_("Description"), blank=True)
13
     description = models.TextField(_("Description"), blank=True)
14
 
14
 
15
     # We allow shipping methods to be linked to a specific set of countries
15
     # We allow shipping methods to be linked to a specific set of countries
16
-    countries = models.ManyToManyField('address.Country', null=True, blank=True, verbose_name=_("Countries"))
16
+    countries = models.ManyToManyField('address.Country', null=True,
17
+                                       blank=True, verbose_name=_("Countries"))
17
 
18
 
18
     _basket = None
19
     _basket = None
19
 
20
 
22
         verbose_name = _("Shipping Method")
23
         verbose_name = _("Shipping Method")
23
         verbose_name_plural = _("Shipping Methods")
24
         verbose_name_plural = _("Shipping Methods")
24
 
25
 
25
-
26
     def save(self, *args, **kwargs):
26
     def save(self, *args, **kwargs):
27
         if not self.code:
27
         if not self.code:
28
             self.code = slugify(self.name)
28
             self.code = slugify(self.name)
30
 
30
 
31
     def __unicode__(self):
31
     def __unicode__(self):
32
         return self.name
32
         return self.name
33
-    
33
+
34
     def set_basket(self, basket):
34
     def set_basket(self, basket):
35
         self._basket = basket
35
         self._basket = basket
36
 
36
 
38
 class OrderAndItemCharges(ShippingMethod):
38
 class OrderAndItemCharges(ShippingMethod):
39
     """
39
     """
40
     Standard shipping method
40
     Standard shipping method
41
-    
42
-    This method has two components: 
41
+
42
+    This method has two components:
43
     * a charge per order
43
     * a charge per order
44
     * a charge per item
44
     * a charge per item
45
-    
46
-    Many sites use shipping logic which fits into this system.  However, for more
47
-    complex shipping logic, a custom shipping method object will need to be provided
48
-    that subclasses ShippingMethod.
45
+
46
+    Many sites use shipping logic which fits into this system.  However, for
47
+    more complex shipping logic, a custom shipping method object will need to
48
+    be provided that subclasses ShippingMethod.
49
     """
49
     """
50
-    price_per_order = models.DecimalField(_("Price per order"), decimal_places=2, max_digits=12, default=D('0.00'))
51
-    price_per_item = models.DecimalField(_("Price per item"), decimal_places=2, max_digits=12, default=D('0.00'))
52
-    
50
+    price_per_order = models.DecimalField(
51
+        _("Price per order"), decimal_places=2, max_digits=12,
52
+        default=D('0.00'))
53
+    price_per_item = models.DecimalField(
54
+        _("Price per item"), decimal_places=2, max_digits=12,
55
+        default=D('0.00'))
56
+
53
     # If basket value is above this threshold, then shipping is free
57
     # If basket value is above this threshold, then shipping is free
54
-    free_shipping_threshold = models.DecimalField(_("Free Shipping"), decimal_places=2, max_digits=12, blank=True, null=True)
55
-    
58
+    free_shipping_threshold = models.DecimalField(
59
+        _("Free Shipping"), decimal_places=2, max_digits=12, blank=True,
60
+        null=True)
61
+
56
     _basket = None
62
     _basket = None
57
 
63
 
58
     class Meta:
64
     class Meta:
61
 
67
 
62
     def set_basket(self, basket):
68
     def set_basket(self, basket):
63
         self._basket = basket
69
         self._basket = basket
64
-    
70
+
65
     def basket_charge_incl_tax(self):
71
     def basket_charge_incl_tax(self):
66
         """
72
         """
67
         Return basket total including tax
73
         Return basket total including tax
69
         if self.free_shipping_threshold != None and \
75
         if self.free_shipping_threshold != None and \
70
                 self._basket.total_incl_tax >= self.free_shipping_threshold:
76
                 self._basket.total_incl_tax >= self.free_shipping_threshold:
71
             return D('0.00')
77
             return D('0.00')
72
-        
78
+
73
         charge = self.price_per_order
79
         charge = self.price_per_order
74
         for line in self._basket.lines.all():
80
         for line in self._basket.lines.all():
75
             charge += line.quantity * self.price_per_item
81
             charge += line.quantity * self.price_per_item
76
         return charge
82
         return charge
77
-    
83
+
78
     def basket_charge_excl_tax(self):
84
     def basket_charge_excl_tax(self):
79
         """
85
         """
80
-        Return basket total excluding tax.  
81
-        
86
+        Return basket total excluding tax.
87
+
82
         Default implementation assumes shipping is tax free.
88
         Default implementation assumes shipping is tax free.
83
         """
89
         """
84
         return self.basket_charge_incl_tax()
90
         return self.basket_charge_incl_tax()
85
 
91
 
86
 
92
 
87
 class WeightBased(ShippingMethod):
93
 class WeightBased(ShippingMethod):
88
-    upper_charge = models.DecimalField(_("Upper Charge"), decimal_places=2, max_digits=12, null=True,
89
-                                      help_text=_("""This is the charge when the
90
-                                       weight of the basket is greater than all
91
-                                      the weight bands"""))
94
+    upper_charge = models.DecimalField(
95
+        _("Upper Charge"), decimal_places=2, max_digits=12, null=True,
96
+        help_text=_("This is the charge when the weight of the basket "
97
+                    "is greater than all the weight bands"""))
92
 
98
 
93
     weight_attribute = 'weight'
99
     weight_attribute = 'weight'
94
-    default_weight = models.DecimalField(_("Default Weight"), decimal_places=2, max_digits=12, default=D('0.00'),
95
-                        help_text=_("""Default product weight in Kg when no
96
-                                        weight attribute is defined"""))
100
+    default_weight = models.DecimalField(
101
+        _("Default Weight"), decimal_places=2, max_digits=12,
102
+        default=D('0.00'),
103
+        help_text=_("Default product weight in Kg when no weight attribute "
104
+                    "is defined"))
97
 
105
 
98
     class Meta:
106
     class Meta:
99
         verbose_name = _("Weight-based Shipping Method")
107
         verbose_name = _("Weight-based Shipping Method")
100
         verbose_name_plural = _("Weight-based Shipping Methods")
108
         verbose_name_plural = _("Weight-based Shipping Methods")
101
 
109
 
102
     def basket_charge_incl_tax(self):
110
     def basket_charge_incl_tax(self):
103
-        weight = Scales(attribute_code=self.weight_attribute, default_weight=self.default_weight).weigh_basket(self._basket)
111
+        weight = Scales(attribute_code=self.weight_attribute,
112
+                        default_weight=self.default_weight).weigh_basket(
113
+                            self._basket)
104
         band = self.get_band_for_weight(weight)
114
         band = self.get_band_for_weight(weight)
105
         if not band:
115
         if not band:
106
             if self.bands.all().count() > 0 and self.upper_charge:
116
             if self.bands.all().count() > 0 and self.upper_charge:
108
             else:
118
             else:
109
                 return D('0.00')
119
                 return D('0.00')
110
         return band.charge
120
         return band.charge
111
-    
121
+
112
     def basket_charge_excl_tax(self):
122
     def basket_charge_excl_tax(self):
113
         return self.basket_charge_incl_tax()
123
         return self.basket_charge_incl_tax()
114
-        
124
+
115
     def get_band_for_weight(self, weight):
125
     def get_band_for_weight(self, weight):
116
         """
126
         """
117
         Return the weight band for a given weight
127
         Return the weight band for a given weight
133
                                                 limit will be determine by the
143
                                                 limit will be determine by the
134
                                                 other weight bands"""))
144
                                                 other weight bands"""))
135
     charge = models.DecimalField(_("Charge"), decimal_places=2, max_digits=12)
145
     charge = models.DecimalField(_("Charge"), decimal_places=2, max_digits=12)
136
-    
146
+
137
     @property
147
     @property
138
     def weight_from(self):
148
     def weight_from(self):
139
         lower_bands = self.method.bands.filter(
149
         lower_bands = self.method.bands.filter(
141
         if not lower_bands:
151
         if not lower_bands:
142
             return D('0.00')
152
             return D('0.00')
143
         return lower_bands[0].upper_limit
153
         return lower_bands[0].upper_limit
144
-    
154
+
145
     @property
155
     @property
146
     def weight_to(self):
156
     def weight_to(self):
147
         return self.upper_limit
157
         return self.upper_limit
148
-    
158
+
149
     class Meta:
159
     class Meta:
150
         ordering = ['upper_limit']
160
         ordering = ['upper_limit']
151
         verbose_name = _("Weight Band")
161
         verbose_name = _("Weight Band")

+ 2
- 0
oscar/apps/voucher/abstract_models.py Прегледај датотеку

112
             self.applications.create(voucher=self, order=order)
112
             self.applications.create(voucher=self, order=order)
113
         self.num_orders += 1
113
         self.num_orders += 1
114
         self.save()
114
         self.save()
115
+    record_usage.alters_data = True
115
 
116
 
116
     def record_discount(self, discount):
117
     def record_discount(self, discount):
117
         """
118
         """
119
         """
120
         """
120
         self.total_discount += discount
121
         self.total_discount += discount
121
         self.save()
122
         self.save()
123
+    record_discount.alters_data = True
122
 
124
 
123
     @property
125
     @property
124
     def benefit(self):
126
     def benefit(self):

Loading…
Откажи
Сачувај