Sfoglia il codice sorgente

Remove comments and change exception names

master
Viggodevries 2 anni fa
parent
commit
627298822b

+ 2
- 18
src/oscar/apps/basket/abstract_models.py Vedi File

727
 
727
 
728
     def __init__(self, *args, **kwargs):
728
     def __init__(self, *args, **kwargs):
729
         super().__init__(*args, **kwargs)
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
         self.discounts = LineDiscountRegistry(self)
730
         self.discounts = LineDiscountRegistry(self)
734
 
731
 
735
     class Meta:
732
     class Meta:
789
                     "when tax-inclusive discounts are already applied"
786
                     "when tax-inclusive discounts are already applied"
790
                 )
787
                 )
791
         self.discounts.discount(discount_value, affected_quantity, incl_tax, offer)
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
     def consume(self, quantity, offer=None):
790
     def consume(self, quantity, offer=None):
796
         """
791
         """
883
 
878
 
884
     @_discount_incl_tax.setter
879
     @_discount_incl_tax.setter
885
     def _discount_incl_tax(self, value):
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
     @property
883
     @property
889
     @deprecated
884
     @deprecated
892
 
887
 
893
     @_discount_excl_tax.setter
888
     @_discount_excl_tax.setter
894
     def _discount_excl_tax(self, value):
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
     @property
892
     @property
898
     def has_discount(self):
893
     def has_discount(self):
909
     @property
904
     @property
910
     def discount_value(self):
905
     def discount_value(self):
911
         return self.discounts.total
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
     # pylint: disable=W0201
908
     # pylint: disable=W0201
917
     @property
909
     @property
986
             return round_half_up(
978
             return round_half_up(
987
                 self.line_price_excl_tax_incl_discounts / self._tax_ratio
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
         return self.line_price_incl_tax
982
         return self.line_price_incl_tax
999
 
983
 

+ 4
- 6
src/oscar/apps/basket/utils.py Vedi File

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

+ 2
- 0
src/oscar/apps/order/utils.py Vedi File

248
     def create_line_discount_models(self, order, order_line, basket_line):
248
     def create_line_discount_models(self, order, order_line, basket_line):
249
         for discount in basket_line.discounts:
249
         for discount in basket_line.discounts:
250
             order_discount = order.discounts.filter(offer_id=discount.offer.id).first()
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
             if order_discount:
253
             if order_discount:
252
                 order_line.discounts.create(
254
                 order_line.discounts.create(
253
                     order_discount=order_discount,
255
                     order_discount=order_discount,

Loading…
Annulla
Salva