def add_gst(amount): try: return utils.add_gst(float(amount)) except TypeError: return '' except ValueError: return ''
def test_order_total(): nzhops = Supplier.objects.create(name="NZ Hops") cryer = Supplier.objects.create(name="Cryer") Surcharge.objects.filter(id=1).update(surcharge_percentage=4.7, order_surcharge=12.70) grain = Grain.objects.create(name="munich", unit_cost=12.3, unit_size="sack", supplier=cryer) hop = Hop.objects.create(name="saaz", unit_cost=34.4, unit_size="100g", supplier=nzhops) total = order_total_incl_gst([grain, hop], [5, 6]) expected_total = grain.unit_cost * 5 + hop.unit_cost * 6 expected_total *= 1.047 expected_total = add_gst(expected_total) expected_total += 12.70 assert_equal(round(expected_total, 3), round(total, 3))
def test_order_total_gst_excl(self): Surcharge.objects.get_or_create(id=1, surcharge_percentage=3.4, order_surcharge=11.80) supplier = Supplier.objects.create(name="testsupplier") order = UserOrder() order.user = User.objects.create_user("b") order.save() create_order_item(order, supplier, unit_cost=3.5, quantity=2) create_order_item(order, supplier, unit_cost=2.1, quantity=5) order.save() total = 3.5 * 2 + 2.1 * 5 total *= 1.034 total = add_gst(total) total += 11.80 assert_equal(total, order.total)
def total(self): from orders.utils import add_gst return add_gst(sum([o.total for o in self.order_items.all()])) + Surcharge.get_order_surcharge()
def total_incl_gst(self): from orders.utils import add_gst return "$%3.2f" % add_gst(self.total)