コード例 #1
0
    def apply_shipping_offer(self, basket, method, offer):
        """
        Wrap a shipping method with an offer discount wrapper (as long as the
        shipping charge is non-zero).
        """
        # If the basket has qualified for shipping discount, wrap the shipping
        # method with a decorating class that applies the offer discount to the
        # shipping charge.
        charge = method.calculate(basket)
        if charge.excl_tax == D('0.00'):
            # No need to wrap zero shipping charges
            return method

        if charge.is_tax_known:
            return shipping_methods.TaxInclusiveOfferDiscount(method, offer)
        else:
            # When returning a tax exclusive discount, it is assumed
            # that this will be used to calculate taxes which will then
            # be assigned directly to the method instance.
            return shipping_methods.TaxExclusiveOfferDiscount(method, offer)
コード例 #2
0
ファイル: repository.py プロジェクト: wm3ndez/django-oscar
    def prime_method(self, basket, method):
        """
        Prime an individual method instance
        """
        method.set_basket(basket)

        # If the basket has a shipping offer, wrap the shipping method with a
        # decorating class that applies the offer discount to the shipping
        # charge.
        if basket.offer_applications.shipping_discounts:
            # We assume there is only one shipping discount available
            discount = basket.offer_applications.shipping_discounts[0]
            if method.charge_excl_tax > D('0.00'):
                if method.is_tax_known:
                    return methods.TaxInclusiveOfferDiscount(
                        method, discount['offer'])
                else:
                    # When returning a tax exclusive discount, it is assumed
                    # that this will be used to calculate taxes which will then
                    # be assigned directly to the method instance.
                    return methods.TaxExclusiveOfferDiscount(
                        method, discount['offer'])
        return method
コード例 #3
0
 def setUp(self):
     self.base_method = methods.FixedPrice(D('10.00'))
     offer = mock.Mock()
     offer.shipping_discount = mock.Mock(return_value=D('2.00'))
     self.method = methods.TaxExclusiveOfferDiscount(
         self.base_method, offer)