def get_shipping_costs(request, shipping_method): """Returns a dictionary with the shipping price and tax for the passed request and shipping method. The format of the dictionary is: {"price" : 0.0, "tax" : 0.0} """ if shipping_method is None: return { "price": 0.0, "tax": 0.0 } try: tax_rate = shipping_method.tax.rate except AttributeError: tax_rate = 0.0 price = criteria_utils.get_first_valid(request, shipping_method.prices.all()) if price is None: price = shipping_method.get_price_gross(request) tax = shipping_method.get_tax(request) return { "price": price, "tax": tax } else: tax = (tax_rate / (tax_rate + 100)) * price.price return { "price": price.price, "tax": tax }
def get_shipping_costs(request, shipping_method): """Returns a dictionary with the shipping price and tax for the passed request and shipping method. The format of the dictionary is: {"price" : 0.0, "tax" : 0.0} """ if shipping_method is None: return {"price": 0.0, "tax": 0.0} try: tax_rate = shipping_method.tax.rate except AttributeError: tax_rate = 0.0 price = criteria_utils.get_first_valid(request, shipping_method.prices.all()) if price is None: price = shipping_method.get_price_gross(request) tax = shipping_method.get_tax(request) return {"price": price, "tax": tax} else: tax = (tax_rate / (tax_rate + 100)) * price.price return {"price": price.price, "tax": tax}
def get_payment_costs(request, payment_method): """ Returns the payment price and tax for the given request. """ if payment_method is None: return { "price": 0.0, "tax": 0.0 } try: tax_rate = payment_method.tax.rate except AttributeError: tax_rate = 0.0 price = criteria_utils.get_first_valid(request, payment_method.prices.all()) if price is None: price = payment_method.price tax = (tax_rate / (tax_rate + 100)) * price return { "price": price, "tax": tax } else: tax = (tax_rate / (tax_rate + 100)) * price.price return { "price": price.price, "tax": tax }
def get_default_shipping_method(request): """Returns the default shipping method for the passed request. At the moment is this the first valid shipping method, but this could be made more explicit in future. """ active_shipping_methods = ShippingMethod.objects.filter(active=True) return criteria_utils.get_first_valid(request, active_shipping_methods)
def get_payment_costs(request, payment_method): """ Returns the payment price and tax for the given request. """ if payment_method is None: return {"price": 0.0, "tax": 0.0} try: tax_rate = payment_method.tax.rate except AttributeError: tax_rate = 0.0 price = criteria_utils.get_first_valid(request, payment_method.prices.all()) if price is None: price = payment_method.price tax = (tax_rate / (tax_rate + 100)) * price return {"price": price, "tax": tax} else: tax = (tax_rate / (tax_rate + 100)) * price.price return {"price": price.price, "tax": tax}
def get_first_valid_shipping_method(request, product=None): """Returns the valid shipping method with the highest priority. """ active_shipping_methods = ShippingMethod.objects.filter(active=True) return criteria_utils.get_first_valid(request, active_shipping_methods, product)
def get_default_payment_method(request): """ Returns the default payment method for given request. """ active_payment_methods = PaymentMethod.objects.filter(active=True) return criteria_utils.get_first_valid(request, active_payment_methods)