def setUp(self): self.non_discount_methods = [ methods.Free(), methods.FixedPrice(D('10.00'), D('10.00')), OrderAndItemCharges(price_per_order=D('5.00'), price_per_item=D('1.00')) ]
def build_submission(): basket = factories.create_basket() # Ensure taxes aren't set by default basket.strategy = strategy.US() # Ensure partner has an address partner = basket.lines.all()[0].stockrecord.partner G(partner_models.PartnerAddress, partner=partner) shipping_address = G(models.ShippingAddress, phone_number='') shipping_method = methods.FixedPrice(D('0.99')) shipping_charge = shipping_method.calculate(basket) calculator = calculators.OrderTotalCalculator() total = calculator.calculate(basket, shipping_charge) return { 'user': None, 'basket': basket, 'shipping_address': shipping_address, 'shipping_method': shipping_method, 'shipping_charge': shipping_charge, 'order_total': total, 'order_kwargs': {}, 'payment_kwargs': {}}
class Repository(repository.Repository): # We default to just fixed price shipping. methods = [ shipping_methods.FixedPrice( D(settings.OSCAR_FIXED_PRICE_SHIPPING_CHG_EXCL_TAX), D(settings.OSCAR_FIXED_PRICE_SHIPPING_CHG_INCL_TAX)) ]
def test_returns_correct_totals_when_tax_is_known(self): basket = mock.Mock() basket.total_excl_tax = D('10.00') basket.total_incl_tax = D('12.00') basket.is_tax_known = True method = methods.FixedPrice(D('5.00'), D('5.50')) total = self.calculator.calculate(basket, method) self.assertIsInstance(total, prices.Price) self.assertEqual(D('10.00') + D('5.00'), total.excl_tax) self.assertTrue(total.is_tax_known) self.assertEqual(D('12.00') + D('5.50'), total.incl_tax) self.assertEqual(D('2.00') + D('0.50'), total.tax)
def test_returns_correct_totals_when_tax_is_not_known(self): basket = mock.Mock() basket.total_excl_tax = D('10.00') basket.is_tax_known = False method = methods.FixedPrice(D('5.00')) total = self.calculator.calculate(basket, method) self.assertIsInstance(total, prices.Price) self.assertEqual(D('10.00') + D('5.00'), total.excl_tax) self.assertFalse(total.is_tax_known) with self.assertRaises(AttributeError): total.incl_tax with self.assertRaises(AttributeError): total.tax
def setUp(self): self.method = methods.FixedPrice( charge_excl_tax=D('10.00'), charge_incl_tax=D('12.00')) basket = Basket() self.charge = self.method.calculate(basket)
def setUp(self): self.method = methods.FixedPrice(D('10.00')) basket = Basket() self.charge = self.method.calculate(basket)
def setUp(self): self.base_method = methods.FixedPrice(D('10.00'), D('12.00')) offer = mock.Mock() offer.shipping_discount = mock.Mock(return_value=D('5.00')) self.method = methods.TaxInclusiveOfferDiscount( self.base_method, offer)
class Repository(object): """ Repository class responsible for returning ShippingMethod objects for a given user, basket etc """ # We default to just free shipping. Customise this class and override this # property to add your own shipping methods. This should be a list of # instantiated shipping methods. # 캠퍼 수정 (override) # methods = (shipping_methods.Free(),) # 3달러로 규정하자 methods = (shipping_methods.FixedPrice(3000, 3000), ) # methods = (shipping_methods.Free(),) # API def get_shipping_methods(self, basket, shipping_addr=None, **kwargs): """ Return a list of all applicable shipping method instances for a given basket, address etc. """ # shipping이 필요 없다면 (DVD 같은 것들) if not basket.is_shipping_required(): # Special case! Baskets that don't require shipping get a special # shipping method. return [shipping_methods.NoShippingRequired()] # 이용할 수 잇는 method 불러오기 methods = self.get_available_shipping_methods( basket=basket, shipping_addr=shipping_addr, **kwargs) # 장바구니에 shipping_할인이 있으면 적용 if basket.has_shipping_discounts: methods = self.apply_shipping_offers(basket, methods) return methods def get_default_shipping_method(self, basket, shipping_addr=None, **kwargs): """ Return a 'default' shipping method to show on the basket page to give the customer an indication of what their order will cost. """ shipping_methods = self.get_shipping_methods( basket, shipping_addr=shipping_addr, **kwargs) if len(shipping_methods) == 0: raise ImproperlyConfigured( _("You need to define some shipping methods")) # Assume first returned method is default return shipping_methods[0] # Helpers def get_available_shipping_methods(self, basket, shipping_addr=None, **kwargs): """ Return a list of all applicable shipping method instances for a given basket, address etc. This method is intended to be overridden. KAMPER OVERRIDE 수정 """ return self.methods def apply_shipping_offers(self, basket, methods): """ Apply shipping offers to the passed set of methods """ # We default to only applying the first shipping discount. offer = basket.shipping_discounts[0]['offer'] return [ self.apply_shipping_offer(basket, method, offer) for method in methods ] 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)
def setUp(self): self.method = methods.FixedPrice( D('10.00'), D('12.00')) basket = Basket() self.method.set_basket(basket)
class Repository(_Repository): methods = (shipping_methods.FixedPrice(10000, 11000), )