Beispiel #1
0
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())
    # TODO: this assumes that payment price is given as gross price, we have to add payment processor here
    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
        }
Beispiel #2
0
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.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
        }
Beispiel #3
0
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
        }
Beispiel #4
0
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)
Beispiel #5
0
def get_customer_tax_rate(request, product):
    """Returns the specfic customer tax for the current customer and product.
    """
    customer_tax = get_first_valid(request, CustomerTax.objects.all(), product)
    if customer_tax:
        return customer_tax.rate
    else:
        return _calc_product_tax_rate(request, product)
Beispiel #6
0
 def get_price(self):
     """
     Returns the stored price without any calculations.
     """
     from lfs.criteria import utils as criteria_utils
     price = criteria_utils.get_first_valid(
         self.request, self.shipping_method.prices.all())
     if price:
         return price.price
     return self.shipping_method.price
Beispiel #7
0
    def get_tax_rate(self):
        from lfs.criteria.utils import get_first_valid
        from lfs.customer_tax.models import CustomerTax

        customer_tax = get_first_valid(self.request, CustomerTax.objects.all(), self.shipping_method)
        if customer_tax:
            return customer_tax.rate
        if self.shipping_method.tax is None:
            return 0
        return self.shipping_method.tax.rate
Beispiel #8
0
    def get_tax_rate(self):
        from lfs.criteria.utils import get_first_valid
        from lfs.customer_tax.models import CustomerTax

        customer_tax = get_first_valid(self.request, CustomerTax.objects.all(), self.shipping_method)
        if customer_tax:
            return customer_tax.rate
        if self.shipping_method.tax is None:
            return 0
        return self.shipping_method.tax.rate
Beispiel #9
0
 def get_price(self):
     """
     Returns the stored price without any calculations.
     """
     from lfs.criteria import utils as criteria_utils
     price = criteria_utils.get_first_valid(self.request,
                                            self.shipping_method.prices.all())
     if price:
         return price.price
     return self.shipping_method.price
Beispiel #10
0
def get_customer_tax_rate(request, product):
    """Returns the specfic customer tax for the current customer and product.
    """
    if request and hasattr(request, 'cached_customer_tax_rate'):
        return getattr(request, 'cached_customer_tax_rate')
    customer_tax = get_first_valid(request, CustomerTax.objects.all(), product)
    if customer_tax:
        taxrate = customer_tax.rate
    else:
        taxrate = _calc_product_tax_rate(request, product)
    if request:
        setattr(request, 'cached_customer_tax_rate', taxrate)
    return taxrate
Beispiel #11
0
def get_customer_tax_rate(request, product):
    """Returns the specfic customer tax for the current customer and product.
    """
    cache_key = 'cached_customer_tax_rate_%s' % product.pk
    if request and hasattr(request, cache_key):
        return getattr(request, cache_key)
    customer_tax = get_first_valid(request, CustomerTax.objects.all(), product)
    if customer_tax:
        taxrate = customer_tax.rate
    else:
        taxrate = _calc_product_tax_rate(request, product)
    if request:
        setattr(request, cache_key, taxrate)
    return taxrate
Beispiel #12
0
    def get_tax_rate(self):
        from lfs.criteria.utils import get_first_valid
        from lfs.customer_tax.models import CustomerTax
        from django.core.cache import cache

        customer_tax = get_first_valid(self.request, CustomerTax.objects.all(), self.shipping_method)
        if customer_tax:
            return customer_tax.rate

        cache_key = 'shipping_method_tax_{}'.format(self.shipping_method.pk)
        tax_rate = cache.get(cache_key)
        if tax_rate is None:
            if self.shipping_method.tax_id is None:
                tax_rate = 0
            else:
                tax_rate = self.shipping_method.tax.rate
            cache.set(cache_key, tax_rate, 60)
        return tax_rate
Beispiel #13
0
    def get_tax_rate(self):
        from lfs.criteria.utils import get_first_valid
        from lfs.customer_tax.models import CustomerTax
        from django.core.cache import cache

        customer_tax = get_first_valid(self.request, CustomerTax.objects.all(), self.shipping_method)
        if customer_tax:
            return customer_tax.rate

        cache_key = 'shipping_method_tax_{}'.format(self.shipping_method.pk)
        tax_rate = cache.get(cache_key)
        if tax_rate is None:
            if self.shipping_method.tax_id is None:
                tax_rate = 0
            else:
                tax_rate = self.shipping_method.tax.rate
            cache.set(cache_key, tax_rate, 60)
        return tax_rate
Beispiel #14
0
def get_customer_tax_rate(request, product):
    """Returns the specfic customer tax for the current customer and product.
    """
    from lfs.customer_tax.models import CustomerTax
    cache_key = 'cached_customer_tax_rate_%s' % product.pk
    if request and hasattr(request, cache_key):
        return getattr(request, cache_key)

    all_cache_key = u'all_customer_taxes'
    customer_taxes = cache.get(all_cache_key)
    if customer_taxes is None:
        customer_taxes = CustomerTax.objects.all()
        cache.set(all_cache_key, customer_taxes)

    customer_tax = get_first_valid(request, customer_taxes, product)
    if customer_tax:
        taxrate = customer_tax.rate
    else:
        taxrate = _calc_product_tax_rate(request, product)
    if request:
        setattr(request, cache_key, taxrate)
    return taxrate
Beispiel #15
0
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)
Beispiel #16
0
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)
Beispiel #17
0
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)