Переглянути джерело

Remove comments and change exception names

master
Viggodevries 2 роки тому
джерело
коміт
627298822b

+ 2
- 18
src/oscar/apps/basket/abstract_models.py Переглянути файл

@@ -727,9 +727,6 @@ class AbstractLine(models.Model):
727 727
 
728 728
     def __init__(self, *args, **kwargs):
729 729
         super().__init__(*args, **kwargs)
730
-        # Instance variables used to persist discount information
731
-        # self._discount_excl_tax = D("0.00")
732
-        # self._discount_incl_tax = D("0.00")
733 730
         self.discounts = LineDiscountRegistry(self)
734 731
 
735 732
     class Meta:
@@ -789,8 +786,6 @@ class AbstractLine(models.Model):
789 786
                     "when tax-inclusive discounts are already applied"
790 787
                 )
791 788
         self.discounts.discount(discount_value, affected_quantity, incl_tax, offer)
792
-        # self.discounts.append((discount_value, affected_quantity, incl_tax, offer))
793
-        # self.consume(affected_quantity, offer=offer)
794 789
 
795 790
     def consume(self, quantity, offer=None):
796 791
         """
@@ -883,7 +878,7 @@ class AbstractLine(models.Model):
883 878
 
884 879
     @_discount_incl_tax.setter
885 880
     def _discount_incl_tax(self, value):
886
-        raise Exception("_discount_incl_tax kan je niet setten")
881
+        raise Exception("You can not set _discount_incl_tax")
887 882
 
888 883
     @property
889 884
     @deprecated
@@ -892,7 +887,7 @@ class AbstractLine(models.Model):
892 887
 
893 888
     @_discount_excl_tax.setter
894 889
     def _discount_excl_tax(self, value):
895
-        raise Exception("_discount_excl_tax kan je niet setten")
890
+        raise Exception("You can not set _discount_excl_tax")
896 891
 
897 892
     @property
898 893
     def has_discount(self):
@@ -909,9 +904,6 @@ class AbstractLine(models.Model):
909 904
     @property
910 905
     def discount_value(self):
911 906
         return self.discounts.total
912
-        # return sum([discount[0] for discount in self.discounts], 0)
913
-        # Only one of the incl- and excl- discounts should be non-zero
914
-        # return max(self._discount_incl_tax, self._discount_excl_tax)
915 907
 
916 908
     # pylint: disable=W0201
917 909
     @property
@@ -986,14 +978,6 @@ class AbstractLine(models.Model):
986 978
             return round_half_up(
987 979
                 self.line_price_excl_tax_incl_discounts / self._tax_ratio
988 980
             )
989
-            # return max(0, self.line_price_incl_tax - (excl_tax_discounts / self._tax_ratio).quantize(D("0.01"), ROUND_HALF_DOWN))
990
-            # return max(0, self.line_price_incl_tax - round_half_up(excl_tax_discounts / self._tax_ratio))
991
-            # return max(
992
-            #     0,
993
-            #     round_half_up(
994
-            #         (self.line_price_excl_tax - excl_tax_discounts) / self._tax_ratio
995
-            #     ),
996
-            # )
997 981
 
998 982
         return self.line_price_incl_tax
999 983
 

+ 4
- 6
src/oscar/apps/basket/utils.py Переглянути файл

@@ -9,6 +9,10 @@ from oscar.core.decorators import deprecated
9 9
 Applicator = get_class("offer.applicator", "Applicator")
10 10
 ConditionalOffer = get_model("offer", "ConditionalOffer")
11 11
 
12
+DiscountApplication = namedtuple(
13
+    "DiscountApplication", ["amount", "quantity", "incl_tax", "offer"]
14
+)
15
+
12 16
 
13 17
 class BasketMessageGenerator(object):
14 18
     new_total_template_name = "oscar/basket/messages/new_total.html"
@@ -116,7 +120,6 @@ class LineOfferConsumer(object):
116 120
         basket line is consumed for *any* offer, else only for the
117 121
         specified offer.
118 122
         """
119
-        # raise Exception("viggo is henk")
120 123
         if offer:
121 124
             self._cache(offer)
122 125
             available = self.available(offer)
@@ -202,11 +205,6 @@ class LineOfferConsumer(object):
202 205
         return max_affected_items - self.num_consumed(offer)
203 206
 
204 207
 
205
-DiscountApplication = namedtuple(
206
-    "DiscountApplication", ["amount", "quantity", "incl_tax", "offer"]
207
-)
208
-
209
-
210 208
 class LineDiscountRegistry(LineOfferConsumer):
211 209
     def __init__(self, line):
212 210
         super().__init__(line)

+ 2
- 0
src/oscar/apps/order/utils.py Переглянути файл

@@ -248,6 +248,8 @@ class OrderCreator(object):
248 248
     def create_line_discount_models(self, order, order_line, basket_line):
249 249
         for discount in basket_line.discounts:
250 250
             order_discount = order.discounts.filter(offer_id=discount.offer.id).first()
251
+            # If we are unable to find the discount we do not care, the total amount is still saved on the discount model,
252
+            # these models are only created so we know how much discount was given per line for each offer
251 253
             if order_discount:
252 254
                 order_line.discounts.create(
253 255
                     order_discount=order_discount,

Завантаження…
Відмінити
Зберегти