def test_includes_hourly_report_with_orders(self): create_order( total=prices.Price('GBP', excl_tax=D('34.05'), tax=D('0.00'))) create_order( total=prices.Price('GBP', excl_tax=D('21.90'), tax=D('0.00'))) report = IndexView().get_hourly_report() self.assertEqual(len(report['order_total_hourly']), 12) self.assertEqual(len(report['y_range']), 11) self.assertEqual(report['max_revenue'], D('60'))
def calculate(self, basket): base_charge = self.method.calculate(basket) discount = self.offer.shipping_discount(base_charge.excl_tax) excl_tax = base_charge.excl_tax - discount return prices.Price( currency=base_charge.currency, excl_tax=excl_tax)
def calculate(self, basket): if (self.free_shipping_threshold is not None and basket.total_incl_tax >= self.free_shipping_threshold): return prices.Price( currency=basket.currency, excl_tax=D('0.00'), incl_tax=D('0.00')) charge = self.price_per_order for line in basket.lines.all(): if line.product.is_shipping_required: charge += line.quantity * self.price_per_item # Zero tax is assumed... return prices.Price( currency=basket.currency, excl_tax=charge, incl_tax=charge)
def calculate(self, basket, shipping_charge, **kwargs): excl_tax = basket.total_excl_tax + shipping_charge.excl_tax if basket.is_tax_known and shipping_charge.is_tax_known: incl_tax = basket.total_incl_tax + shipping_charge.incl_tax else: incl_tax = None return prices.Price(currency=basket.currency, excl_tax=excl_tax, incl_tax=incl_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 shipping_charge = prices.Price(currency=basket.currency, excl_tax=D('5.00')) total = self.calculator.calculate(basket, shipping_charge) self.assertIsInstance(total, prices.Price) self.assertEqual(D('10.00') + D('5.00'), total.excl_tax) self.assertFalse(total.is_tax_known)
def calculate(self, basket): # Note, when weighing the basket, we don't check whether the item # requires shipping or not. It is assumed that if something has a # weight, then it requires shipping. scale = Scale(attribute_code=self.weight_attribute, default_weight=self.default_weight) weight = scale.weigh_basket(basket) charge = self.get_charge(weight) # Zero tax is assumed... return prices.Price( currency=basket.currency, excl_tax=charge, incl_tax=charge)
def skip_unless_payment_is_required(self, request): # Check to see if payment is actually required for this order. shipping_address = self.get_shipping_address(request.basket) shipping_method = self.get_shipping_method(request.basket, shipping_address) if shipping_method: shipping_charge = shipping_method.calculate(request.basket) else: # It's unusual to get here as a shipping method should be set by # the time this skip-condition is called. In the absence of any # other evidence, we assume the shipping charge is zero. shipping_charge = prices.Price(currency=request.basket.currency, excl_tax=D('0.00'), tax=D('0.00')) total = self.get_order_totals(request.basket, shipping_charge) if total.excl_tax == D('0.00'): raise exceptions.PassedSkipCondition( url=reverse('checkout:preview'))
def calculate(self, basket): return prices.Price( currency=basket.currency, excl_tax=self.charge_excl_tax, incl_tax=self.charge_incl_tax)
def calculate(self, basket): # If the charge is free then tax must be free (musn't it?) and so we # immediately set the tax to zero return prices.Price( currency=basket.currency, excl_tax=D('0.00'), tax=D('0.00'))