예제 #1
0
    def testGetTaxRateForCustomer(self):
        """
        """
        t = ITaxes(self.item1)
        self.assertEqual(t.getTaxRate(), 19.00)

        t = ITaxes(self.item2)
        self.assertEqual(t.getTaxRate(), 19.00)
예제 #2
0
    def testGetTaxRateForCustomer(self):
        """
        """
        t = ITaxes(self.item1)
        self.assertEqual(t.getTaxRate(), 19.00)

        t = ITaxes(self.item2)
        self.assertEqual(t.getTaxRate(), 19.00)
예제 #3
0
    def getTaxRateForCustomer(self):
        """
        """
        temp_payment_product = self._createTemporaryPaymentProduct()
        taxes = ITaxes(temp_payment_product)
        tax = taxes.getTaxRate()

        return tax
예제 #4
0
    def getTaxRateForCustomer(self):
        """
        """
        temp_payment_product = self._createTemporaryPaymentProduct()
        taxes = ITaxes(temp_payment_product)
        tax = taxes.getTaxRate()

        return tax
예제 #5
0
파일: taxes.py 프로젝트: viona/Easyshop
class CartItemTaxes:
    """Adapter which provides ITaxes for cart item content objects.
    """
    implements(ITaxes)
    adapts(ICartItem)

    def __init__(self, context):
        """
        """
        self.context = context

        # adapt Product to Taxes
        self.taxes = ITaxes(self.context.getProduct())

    def getTax(self):
        """Returns absolute tax.
        """
        price = IPrices(self.context).getPriceGross(with_discount=True)
        tax_rate = self.taxes.getTaxRate()

        tax = (tax_rate / (tax_rate + 100)) * price
        return tax

    def getTaxForCustomer(self):
        """Returns absolute tax for customer.
        """
        price = IPrices(self.context).getPriceGross(with_discount=True)
        tax_rate = self.taxes.getTaxRateForCustomer()

        tax = (tax_rate / (tax_rate + 100)) * price
        return tax

    def getTaxRate(self):
        """Returns tax rate
        """
        tax_rate = self.taxes.getTaxRate()
        return tax_rate

    def getTaxRateForCustomer(self):
        """Returns tax rate for a customer.
        """
        tax = self.taxes.getTaxRateForCustomer() * self.context.getAmount()
        return tax
예제 #6
0
파일: taxes.py 프로젝트: Easyshop/Easyshop
class CartItemTaxes:
    """Adapter which provides ITaxes for cart item content objects.
    """
    implements(ITaxes)
    adapts(ICartItem)
    
    def __init__(self, context):
        """
        """
        self.context = context

        # adapt Product to Taxes
        self.taxes = ITaxes(self.context.getProduct())

    def getTax(self):
        """Returns absolute tax.
        """
        price = IPrices(self.context).getPriceGross(with_discount=True)
        tax_rate = self.taxes.getTaxRate()
        
        tax  = (tax_rate/(tax_rate+100)) * price
        return tax
        
    def getTaxForCustomer(self):
        """Returns absolute tax for customer.
        """
        price = IPrices(self.context).getPriceGross(with_discount=True)
        tax_rate = self.taxes.getTaxRateForCustomer()

        tax = (tax_rate/(tax_rate+100)) * price
        return tax

    def getTaxRate(self):
        """Returns tax rate
        """
        tax_rate = self.taxes.getTaxRate()
        return tax_rate

    def getTaxRateForCustomer(self):
        """Returns tax rate for a customer.
        """
        tax = self.taxes.getTaxRateForCustomer() * self.context.getAmount()
        return tax        
예제 #7
0
 def testGetTaxRate(self):
     """
     """
     t = ITaxes(self.shop.products.product_1)
     self.assertEqual(t.getTaxRate(), 19.0)
예제 #8
0
파일: prices.py 프로젝트: viona/Easyshop
class DiscountPrices:
    """Multia adapter which provides IPrices for discount content objects and 
    product.
    """
    implements(IPrices)
    adapts(IDiscount, ICartItem)

    # NOTE: We need the product additionally as we need to calculate taxes, as
    # the discount has the same tax rate as the related product.

    def __init__(self, discount, cart_item):
        """
        """
        self.discount = discount
        self.cart_item = cart_item
        self.product = cart_item.getProduct()
        self.taxes = ITaxes(self.product)
        self.shop = IShopManagement(self.product).getShop()

    def getPriceForCustomer(self):
        """
        """
        # If the discount is by percentage, we don't have to calc the tax for
        # the discount, because the discount is a part of the already calculated
        # price, hence we can do it here.

        if self.discount.getType() == "percentage":
            price = IPrices(self.cart_item).getPriceForCustomer()
            return price * (self.discount.getValue() / 100)
        else:
            tax_rate_for_customer = self.taxes.getTaxRateForCustomer()
            price_net = self.getPriceNet()

            # We take the net price and add the customer specific taxes.
            return price_net * ((tax_rate_for_customer + 100) / 100)

    def getPriceGross(self):
        """
        """
        if self.discount.getType() == "percentage":
            price = IPrices(self.cart_item).getPriceGross()
            return price * (self.discount.getValue() / 100)
        else:
            tax_rate = self.taxes.getTaxRate()
            price = self._calcTotalPrice()

            # The price entered is considered as gross price, so we simply
            # return it.
            if self.shop.getGrossPrices() == True:
                return price

            # The price entered is considered as net price. So we have to
            # calculate the gross price first.
            else:
                return price * ((tax_rate + 100) / 100)

    def getPriceNet(self):
        """
        """
        if self.discount.getType() == "percentage":
            price = IPrices(self.cart_item).getPriceNet()
            return price * (self.discount.getValue() / 100)
        else:
            tax_rate = self.taxes.getTaxRate()
            price = self._calcTotalPrice()

            # The price entered is considered as gross price. So we have to
            # calculate the net price first.

            if self.shop.getGrossPrices() == True:
                return price * (100 / (tax_rate + 100))

            # The price entered is considered as net price, so we simply return
            # it.
            else:
                return price

    def _calcTotalPrice(self):
        """
        """
        if self.discount.getBase() == "cart_item":
            return self.discount.getValue()
        else:
            return self.discount.getValue() * self.cart_item.getAmount()
예제 #9
0
파일: prices.py 프로젝트: Easyshop/Easyshop
class DiscountPrices:
    """Multia adapter which provides IPrices for discount content objects and 
    product.
    """
    implements(IPrices)
    adapts(IDiscount, ICartItem)
    
    # NOTE: We need the product additionally as we need to calculate taxes, as 
    # the discount has the same tax rate as the related product.
    
    def __init__(self, discount, cart_item):
        """
        """
        self.discount  = discount
        self.cart_item = cart_item
        self.product   = cart_item.getProduct()
        self.taxes     = ITaxes(self.product)
        self.shop      = IShopManagement(self.product).getShop()

    def getPriceForCustomer(self):
        """
        """
        # If the discount is by percentage, we don't have to calc the tax for 
        # the discount, because the discount is a part of the already calculated
        # price, hence we can do it here.
        
        if self.discount.getType() == "percentage":
            price = IPrices(self.cart_item).getPriceForCustomer()
            return price * (self.discount.getValue() / 100)
        else:
            tax_rate_for_customer = self.taxes.getTaxRateForCustomer()
            price_net = self.getPriceNet()
        
            # We take the net price and add the customer specific taxes.
            return price_net * ((tax_rate_for_customer+100)/100)

    def getPriceGross(self):
        """
        """
        if self.discount.getType() == "percentage":
            price = IPrices(self.cart_item).getPriceGross()
            return  price * (self.discount.getValue() / 100)
        else:
            tax_rate = self.taxes.getTaxRate()
            price = self._calcTotalPrice()

            # The price entered is considered as gross price, so we simply
            # return it.
            if self.shop.getGrossPrices() == True:
                return price                

            # The price entered is considered as net price. So we have to 
            # calculate the gross price first.
            else:
                return price * ((tax_rate+100)/100)

    def getPriceNet(self):
        """
        """
        if self.discount.getType() == "percentage":
            price = IPrices(self.cart_item).getPriceNet()
            return price * (self.discount.getValue() / 100)
        else:
            tax_rate = self.taxes.getTaxRate()
            price = self._calcTotalPrice()

            # The price entered is considered as gross price. So we have to 
            # calculate the net price first.
                
            if self.shop.getGrossPrices() == True:
                return price * (100/(tax_rate+100))
                
            # The price entered is considered as net price, so we simply return 
            # it.
            else:
                return price
            
    def _calcTotalPrice(self):
        """
        """
        if self.discount.getBase() == "cart_item":
            return self.discount.getValue()
        else:
            return self.discount.getValue() * self.cart_item.getAmount()