Пример #1
0
def untaxed_discount_line_total(cartitem, discount):
    """Returns the discounted line total for this cart item"""
    price = cartitem.line_total
    if discount and discount.valid_for_product(cartitem.product):
        price = calc_by_percentage(price, discount.percentage)
    
    return price
Пример #2
0
def discount_line_total(cartitem, discount):
    """Returns the discounted line total for this cart item"""
    lt = cartitem.line_total
    if discount and discount.valid_for_product(cartitem.product):
        return calc_by_percentage(lt, discount.percentage)
    else:
        return lt
Пример #3
0
def sale_price(product):
    """Returns the product unit price with the best auto discount applied."""
    disc = find_best_auto_discount(product)
    price = product.unit_price
    if disc:
        return calc_by_percentage(price, disc.percentage)
    else:
        return price
Пример #4
0
def untaxed_sale_price(product):
    """Returns the product unit price with the best auto discount applied."""
    discount = find_best_auto_discount(product)
    price = product.unit_price
        
    if discount and discount.valid_for_product(cartitem.product):
        price = calc_by_percentage(price, disc.percentage)
    
    return price
Пример #5
0
def discount_price(product, discount):
    """Returns the product price with the discount applied.
    
    Ex: product|discount_price:sale
    """
    up = product.unit_price
    if discount and discount.valid_for_product(product):
        return calc_by_percentage(up, discount.percentage)
    else:
        return up
Пример #6
0
def untaxed_discount_saved(product, discount):
    """Returns the amount saved by the discount"""
    
    if discount and discount.valid_for_product(product):
        price = product.unit_price
        discounted = calc_by_percentage(price, discount.percentage)
        saved = price-discounted
        cents = Decimal("0.01")
        return saved.quantize(cents)
    else:
        return Decimal('0.00')
Пример #7
0
def discount_saved(product, discount):
    """Returns the amount saved by the discount"""
    
    if discount and discount.valid_for_product(product):
        price = product.unit_price
        discounted = calc_by_percentage(price, discount.percentage)
        saved = price-discounted
        cents = Decimal("0.01")
        return saved.quantize(cents)
    else:
        return Decimal('0.00')
Пример #8
0
def discount_saved(context, product, discount):
    """Returns the amount saved by the discount"""

    request = context.get("request")
    currency = currency_for_request(request)
    if discount and discount.valid_for_product(product):
        unit_price = convert_to_currency(product.unit_price, currency)
        discounted = calc_by_percentage(unit_price, discount.percentage)
        saved = unit_price - discounted
        cents = Decimal("0.01")
        price = saved.quantize(cents)
    else:
        price = Decimal("0.00")
    return money_format(price, currency)
Пример #9
0
def discount_price(context, product, discount):
    """Returns the product price with the discount applied.

    Ex: {% discount_price product sale %}
    """

    request = context.get("request")
    currency = currency_for_request(request)
    unit_price = convert_to_currency(product.unit_price, currency)

    if discount and discount.valid_for_product(product):
        price = calc_by_percentage(unit_price, discount.percentage)
    else:
        price = unit_price
    return money_format(price, currency)
Пример #10
0
def productvariation_details(product, include_tax, user, create=False):
    """Build the product variation details, for conversion to javascript.

    Returns variation detail dictionary built like so:
    details = {
        "OPTION_KEY" : {
            "SLUG": "Variation Slug",
            "PRICE" : {"qty" : "$price", [...]},
            "SALE" : {"qty" : "$price", [...]},
            "TAXED" : "$taxed price",   # omitted if no taxed price requested
            "QTY" : 1
        },
        [...]
    }
    """

    config = Config.objects.get_current()
    ignore_stock = config.no_stock_checkout
    discount = find_best_auto_discount(product)
    use_discount = discount and discount.percentage > 0

    if include_tax:
        taxer = get_taxprocessor(user)
        tax_class = product.taxClass

    details = {'SALE' : use_discount}
    
    curr = config_value('SHOP', 'CURRENCY')
    curr = curr.replace("_", " ")

    variations = ProductPriceLookup.objects.filter(parentid=product.id)
    if variations.count() == 0:
        if create:
            log.debug('Creating price lookup for %s', product)
            ProductPriceLookup.objects.smart_create_for_product(product)
            variations = ProductPriceLookup.objects.filter(parentid=product.id)
        else:
            log.warning('You must run satchmo_rebuild_pricing and add it to a cron-job to run every day, or else the product details will not work for product detail pages.')
    for detl in variations:
        key = detl.key
        if details.has_key(key):
            detail = details[key]
        else:
            detail = {}
            detail['SLUG'] = detl.productslug

            if not detl.active:
                qty = -1
            elif ignore_stock:
                qty = 10000
            else:
                qty = detl.items_in_stock

            detail['QTY'] = qty

            detail['PRICE'] = {}
            
            if use_discount:
                detail['SALE'] = {}
                
            if include_tax:
                detail['TAXED'] = {}
                if use_discount:
                    detail['TAXED_SALE'] = {}
                
            details[key] = detail
        
        price = detl.dynamic_price
        
        detail['PRICE'][detl.quantity] = moneyfmt(price, curr=curr)
        if use_discount:
            detail['SALE'][detl.quantity] = moneyfmt(calc_by_percentage(price, discount.percentage), curr=curr)
        
        if include_tax:
            tax_price = taxer.by_price(tax_class, price) + price
            detail['TAXED'][detl.quantity] = moneyfmt(tax_price, curr=curr)
            detail['TAXED_SALE'][detl.quantity] = moneyfmt(calc_by_percentage(tax_price, discount.percentage), curr=curr)
                
    return details