Exemplo n.º 1
0
def salesbro_tax_handler(request, order_form):
    """
    Default tax handler - called immediately after the handler defined
    by ``SHOP_HANDLER_BILLING_SHIPPING``. Implement your own and
    specify the path to import it from via the setting
    ``SHOP_HANDLER_TAX``. This function will typically contain any tax
    calculation where the tax amount can then be set using the function
    ``cartridge.shop.utils.set_tax``. The Cart object is also
    accessible via ``request.cart``
    """
    total = request.cart.total_price()

    # To implement PST would need to do the following
    # - Keep track of GST total_price (all things)
    # - Keep track fo PST total_price (no Ticket or TicketOptions)
    # - Need a new calculation for discount
    # - Change gst and pst calculation

    if 'discount_code' in request.session:
        discount_code = DiscountCode.objects.get(code=request.session['discount_code'])
        discount = request.cart.calculate_discount(discount_code)
        total -= discount

    # pst = total * Decimal(0.07)
    gst = total * Decimal(0.05)

    # tax = math.ceil(pst*100 + gst*100)/100
    tax = math.ceil(gst*100)/100

    set_tax(request, "GST", tax)
Exemplo n.º 2
0
def personalization_pricing(request, order_form, order):
    set_personalization_cost(request, 0)
    personalized_count = sum([item.personalization_price * item.quantity for item in order.items.iterator() if item.personalization and item.personalization.embroidery_type <> 1 and hasattr(item, 'personalization_price')])
    if personalized_count:
        set_personalization_cost(request, personalized_count)
    item_total = sum([item.total_price for item in order.items.iterator()])
    set_tax(request, _("Tax"), (Decimal(request.session.get('personalization_total', '0.0')) + item_total) * Decimal(.06))
    set_shipping(request, _("Flat rate shipping"),
        settings.SHOP_DEFAULT_SHIPPING_VALUE)
Exemplo n.º 3
0
def tax_handler(request, order_form):
    """
    Calculates Tax
    """
    tax = Decimal(0)
    cart = Cart.objects.from_request(request)
    for item in cart.items.all():
        variation = ProductVariation.objects.get(sku=item.sku)
        if not variation.tax_exempt:
            tax += item.unit_price * Decimal(Settings.get_setting('SHOP_DEFAULT_TAX_RATE'))
    set_tax(request, "GST 5%", tax)
Exemplo n.º 4
0
def default_tax_handler(request, order_form):
    """
    Default tax handler - called immediately after the handler defined
    by ``SHOP_HANDLER_BILLING_SHIPPING``. Implement your own and
    specify the path to import it from via the setting
    ``SHOP_HANDLER_TAX``. This function will typically contain any tax
    calculation where the tax amount can then be set using the function
    ``cartridge.shop.utils.set_tax``. The Cart object is also
    accessible via ``request.cart``
    """
    set_tax(request, _("Tax"), 0)
Exemplo n.º 5
0
def default_tax_handler(request, order_form):
    """
    Default tax handler - called immediately after the handler defined
    by ``SHOP_HANDLER_BILLING_SHIPPING``. Implement your own and
    specify the path to import it from via the setting
    ``SHOP_HANDLER_TAX``. This function will typically contain any tax
    calculation where the tax amount can then be set using the function
    ``cartridge.shop.utils.set_tax``. The Cart object is also
    accessible via ``request.cart``
    """
    set_tax(request, _("Tax"), 0)
Exemplo n.º 6
0
    def test_set_tax(self):
        """
        Regression test to ensure that set_tax still sets the appropriate
        session variables.
        """

        tax_type = 'Tax for Testing'
        tax_total = 56.65

        class request:
            session = {}

        set_tax(request, tax_type, tax_total)
        self.assertEqual(request.session.get("tax_type"), str(tax_type))
        self.assertEqual(request.session.get("tax_total"), str(tax_total))
Exemplo n.º 7
0
    def test_set_tax(self):
        """
        Regression test to ensure that set_tax still sets the appropriate
        session variables.
        """

        tax_type = "Tax for Testing"
        tax_total = 56.65

        class request:
            session = {}

        set_tax(request, tax_type, tax_total)
        self.assertEqual(request.session.get("tax_type"), str(tax_type))
        self.assertEqual(request.session.get("tax_total"), str(tax_total))
Exemplo n.º 8
0
def personalization_pricing(request, order_form, order):
    set_personalization_cost(request, 0)
    personalized_count = sum([
        item.personalization_price * item.quantity
        for item in order.items.iterator()
        if item.personalization and item.personalization.embroidery_type <> 1
        and hasattr(item, 'personalization_price')
    ])
    if personalized_count:
        set_personalization_cost(request, personalized_count)
    item_total = sum([item.total_price for item in order.items.iterator()])
    set_tax(request, _("Tax"),
            (Decimal(request.session.get('personalization_total', '0.0')) +
             item_total) * Decimal(.06))
    set_shipping(request, _("Flat rate shipping"),
                 settings.SHOP_DEFAULT_SHIPPING_VALUE)
Exemplo n.º 9
0
    def test_set_tax(self):
        '''
        Regression test to ensure that set_tax still sets the appropriate
        session variables.
        '''
        from cartridge.shop.utils import set_tax

        tax_type = 'Tax for Testing'
        tax_total = 56.65

        class request:
            session = {}

        set_tax(request, tax_type, tax_total)

        assert request.session.get('tax_type') == tax_type, \
            'tax_type not set with set_tax'
        assert request.session.get('tax_total') == tax_total, \
            'tax_total not set with set_tax'
Exemplo n.º 10
0
    def test_set_tax(self):
        '''
        Regression test to ensure that set_tax still sets the appropriate
        session variables.
        '''
        from cartridge.shop.utils import set_tax

        tax_type = 'Tax for Testing'
        tax_total = 56.65

        class request:
            session = {}

        set_tax(request, tax_type, tax_total)

        assert request.session.get('tax_type') == tax_type, \
            'tax_type not set with set_tax'
        assert request.session.get('tax_total') == tax_total, \
            'tax_total not set with set_tax'
Exemplo n.º 11
0
def default_tax_handler(request, order_form):
    """
    Default tax handler - called immediately after the handler defined
    by ``SHOP_HANDLER_BILLING_SHIPPING``. Implement your own and
    specify the path to import it from via the setting
    ``SHOP_HANDLER_TAX``. This function will typically contain any tax
    calculation where the tax amount can then be set using the function
    ``cartridge.shop.utils.set_tax``. The Cart object is also
    accessible via ``request.cart``
    """
    settings.clear_cache()
    if settings.SHOP_DEFAULT_TAX_RATE:
        locale.setlocale(locale.LC_NUMERIC, str(settings.SHOP_CURRENCY_LOCALE))
        tax_rate = settings.SHOP_DEFAULT_TAX_RATE
        if settings.SHOP_TAX_INCLUDED:
            tax = request.cart.total_price() - (
                request.cart.total_price() /
                decimal.Decimal(1 + tax_rate / 100))
            tax_type = _("Incl.") + " " + f"{tax_rate:n}" + "% " + _("VAT")
        else:
            tax = request.cart.total_price() * decimal.Decimal(tax_rate / 100)
            tax_type = _("VAT") + " (" + f"{tax_rate:n}" + "%)"
        set_tax(request, tax_type, f"{tax:.2f}")