コード例 #1
0
ファイル: satchmo_discounts.py プロジェクト: dmvrtx/satchmo
def taxed_discount_line_unit_price(cartitem, discount):
    """Returns the discounted line unit_price for this cart item with taxes included."""
    price = untaxed_discount_line_unit_price(cartitem, discount)
    taxer = satchmo_tax._get_taxprocessor()
    price = price + taxer.by_price(cartitem.product.taxClass, price)

    return price
コード例 #2
0
ファイル: satchmo_discounts.py プロジェクト: hnejadi/xerobis
def taxed_discount_line_total(cartitem, discount):
    """Returns the discounted line total for this cart item with taxes included."""
    price = untaxed_discount_line_total(cartitem, discount)
    taxer = satchmo_tax._get_taxprocessor()
    price = price + taxer.by_price(cartitem.product.taxClass, price)
    
    return price
コード例 #3
0
def taxed_sale_price(product):
    """Returns the product unit price with the best auto discount applied and taxes included."""
    taxer = satchmo_tax._get_taxprocessor()
    price = untaxed_sale_price(product)
    price = price + taxer.by_product_and_price(
        product.taxClass, price, product=product)
    return price
コード例 #4
0
def taxed_discount_price(product, discount):
    """Returns the product price with the discount applied, and taxes included.

    Ex: product|discount_price:sale
    """
    price = untaxed_discount_price(product, discount)
    taxer = satchmo_tax._get_taxprocessor()
    return price + taxer.by_price(product.taxClass, price)
コード例 #5
0
ファイル: satchmo_discounts.py プロジェクト: dmvrtx/satchmo
def taxed_discount_price(product, discount):
    """Returns the product price with the discount applied, and taxes included.

    Ex: product|discount_price:sale
    """
    price = untaxed_discount_price(product, discount)
    taxer = satchmo_tax._get_taxprocessor()
    return price + taxer.by_price(product.taxClass, price)
コード例 #6
0
ファイル: forms.py プロジェクト: hnejadi/xerobis
def _get_shipping_choices(request, paymentmodule, cart, contact, default_view_tax=False):
    """Iterate through legal shipping modules, building the list for display to the user.
    
    Returns the shipping choices list, along with a dictionary of shipping choices, useful
    for building javascript that operates on shipping choices.
    """
    shipping_options = []
    shipping_dict = {}
    
    if not cart.is_shippable:
        methods = [shipping_method_by_key('NoShipping'),]
    else:
        methods = shipping_methods()
    
    for method in methods:
        method.calculate(cart, contact)
        if method.valid():
            template = lookup_template(paymentmodule, 'shipping/options.html')
            t = loader.get_template(template)
            shipcost = method.cost()
            shipping_tax = None
            taxed_shipping_price = None
            if config_value_safe('TAX','TAX_SHIPPING', False):
                shipping_tax = TaxClass.objects.get(title=config_value('TAX', 'TAX_CLASS'))
                taxer = _get_taxprocessor(request)
                total = shipcost + taxer.by_price(shipping_tax, shipcost)
                taxed_shipping_price = moneyfmt(total)
            c = RequestContext(request, {
                'amount': shipcost,
                'description' : method.description(),
                'method' : method.method(),
                'expected_delivery' : method.expectedDelivery(),
                'default_view_tax' : default_view_tax,
                'shipping_tax': shipping_tax,
                'taxed_shipping_price': taxed_shipping_price})
            shipping_options.append((method.id, t.render(c)))
            shipping_dict[method.id] = shipcost
    
    return shipping_options, shipping_dict
コード例 #7
0
ファイル: forms.py プロジェクト: mpango/satchmo
def _get_shipping_choices(request, paymentmodule, cart, contact, default_view_tax=False, order=None):
    """Iterate through legal shipping modules, building the list for display to the user.

    Returns the shipping choices list, along with a dictionary of shipping choices, useful
    for building javascript that operates on shipping choices.
    """
    shipping_options = []
    shipping_dict = {}
    rendered = {}
    if not order:
        try:
            order = Order.objects.from_request(request)
        except Order.DoesNotExist:
            pass

    discount = None
    if order:
        try:
            discount = Discount.objects.by_code(order.discount_code)
        except Discount.DoesNotExist:
            pass

    if not cart.is_shippable:
        methods = [shipping_method_by_key('NoShipping'),]
    else:
        methods = shipping_methods()

    tax_shipping = config_value_safe('TAX','TAX_SHIPPING', False)
    shipping_tax = None

    if tax_shipping:
        taxer = _get_taxprocessor(request)
        shipping_tax = TaxClass.objects.get(title=config_value('TAX', 'TAX_CLASS'))

    for method in methods:
        method.calculate(cart, contact)
        if method.valid():
            template = lookup_template(paymentmodule, 'shipping/options.html')
            t = loader.get_template(template)
            shipcost = finalcost = method.cost()

            if discount and order:
                order.shipping_cost = shipcost
                discount.calc(order)
                shipdiscount = discount.item_discounts.get('Shipping', 0)
            else:
                shipdiscount = 0

            # set up query to determine shipping price to show
            shipprice = Price()
            shipprice.price = shipcost
            shipadjust = PriceAdjustmentCalc(shipprice)
            if shipdiscount:
                shipadjust += PriceAdjustment('discount', _('Discount'), shipdiscount)

            satchmo_shipping_price_query.send(cart, adjustment=shipadjust)
            shipdiscount = shipadjust.total_adjustment()

            if shipdiscount:
                finalcost -= shipdiscount

            shipping_dict[method.id] = {'cost' : shipcost, 'discount' : shipdiscount, 'final' : finalcost}

            taxed_shipping_price = None
            if tax_shipping:
                taxcost = taxer.by_price(shipping_tax, finalcost)
                total = finalcost + taxcost
                taxed_shipping_price = moneyfmt(total)
                shipping_dict[method.id]['taxedcost'] = total
                shipping_dict[method.id]['tax'] = taxcost

            c = RequestContext(request, {
                'amount': finalcost,
                'description' : method.description(),
                'method' : method.method(),
                'expected_delivery' : method.expectedDelivery(),
                'default_view_tax' : default_view_tax,
                'shipping_tax': shipping_tax,
                'taxed_shipping_price': taxed_shipping_price})
            rendered[method.id] = t.render(c)

    #now sort by price, low to high
    sortme = [(value['cost'], key) for key, value in shipping_dict.items()]
    sortme.sort()

    shipping_options = [(key, rendered[key]) for cost, key in sortme]

    shipping_choices_query.send(sender=cart, cart=cart,
        paymentmodule=paymentmodule, contact=contact,
        default_view_tax=default_view_tax, order=order,
        shipping_options = shipping_options,
        shipping_dict = shipping_dict)
    return shipping_options, shipping_dict
コード例 #8
0
def _get_shipping_choices(request,
                          paymentmodule,
                          cart,
                          contact,
                          default_view_tax=False,
                          order=None):
    """Iterate through legal shipping modules, building the list for display to the user.

    Returns the shipping choices list, along with a dictionary of shipping choices, useful
    for building javascript that operates on shipping choices.
    """
    shipping_options = []
    shipping_dict = {}
    rendered = {}
    if not order:
        try:
            order = Order.objects.from_request(request)
        except Order.DoesNotExist:
            pass

    discount = None
    if order:
        try:
            discount = Discount.objects.by_code(order.discount_code)
        except Discount.DoesNotExist:
            pass

    if not cart.is_shippable:
        methods = [
            shipping_method_by_key('NoShipping'),
        ]
    else:
        methods = shipping_methods()

    tax_shipping = config_value_safe('TAX', 'TAX_SHIPPING', False)
    shipping_tax = None

    if tax_shipping:
        taxer = _get_taxprocessor(request)
        shipping_tax = TaxClass.objects.get(
            title=config_value('TAX', 'TAX_CLASS'))

    for method in methods:
        method.calculate(cart, contact)
        if method.valid(order=order):
            template = lookup_template(paymentmodule, 'shipping/options.html')
            t = loader.get_template(template)
            shipcost = finalcost = method.cost()

            if discount and order:
                order.shipping_cost = shipcost
                discount.calc(order)
                shipdiscount = discount.item_discounts.get('Shipping', 0)
            else:
                shipdiscount = 0

            # set up query to determine shipping price to show
            shipprice = Price()
            shipprice.price = shipcost
            shipadjust = PriceAdjustmentCalc(shipprice)
            if shipdiscount:
                shipadjust += PriceAdjustment('discount', _('Discount'),
                                              shipdiscount)

            satchmo_shipping_price_query.send(cart, adjustment=shipadjust)
            shipdiscount = shipadjust.total_adjustment()

            if shipdiscount:
                finalcost -= shipdiscount

            shipping_dict[method.id] = {
                'cost': shipcost,
                'discount': shipdiscount,
                'final': finalcost
            }

            taxed_shipping_price = None
            if tax_shipping:
                taxcost = taxer.by_price(shipping_tax, finalcost)
                total = finalcost + taxcost
                taxed_shipping_price = moneyfmt(total)
                shipping_dict[method.id]['taxedcost'] = total
                shipping_dict[method.id]['tax'] = taxcost

            c = RequestContext(
                request, {
                    'amount': finalcost,
                    'description': method.description(),
                    'method': method.method(),
                    'expected_delivery': method.expectedDelivery(),
                    'default_view_tax': default_view_tax,
                    'shipping_tax': shipping_tax,
                    'taxed_shipping_price': taxed_shipping_price
                })
            rendered[method.id] = t.render(c)

    #now sort by price, low to high
    sortme = [(value['cost'], key) for key, value in shipping_dict.items()]
    sortme.sort()

    shipping_options = [(key, rendered[key]) for cost, key in sortme]

    shipping_choices_query.send(sender=cart,
                                cart=cart,
                                paymentmodule=paymentmodule,
                                contact=contact,
                                default_view_tax=default_view_tax,
                                order=order,
                                shipping_options=shipping_options,
                                shipping_dict=shipping_dict)
    return shipping_options, shipping_dict
コード例 #9
0
ファイル: satchmo_discounts.py プロジェクト: hnejadi/xerobis
def taxed_sale_price(product):
    """Returns the product unit price with the best auto discount applied and taxes included."""
    taxer = satchmo_tax._get_taxprocessor()
    price = sale_price(product)
    price = price + taxer.by_price(product.taxClass, price)
    return price