Ejemplo n.º 1
0
    def __init__(self, context):
        """
        """
        pvm  = IProductVariantsManagement(context)
        shop = IShopManagement(context).getShop()
        
        self.context = context

        self.gross_prices = shop.getGrossPrices()
        self.has_variants = pvm.hasVariants()
        self.taxes = ITaxes(context)

        if self.has_variants:
            self.product_variant = \
                pvm.getSelectedVariant() or pvm.getDefaultVariant()
Ejemplo n.º 2
0
    def __init__(self, context):
        """
        """
        pvm = IProductVariantsManagement(context)
        shop = IShopManagement(context).getShop()

        self.context = context

        self.gross_prices = shop.getGrossPrices()
        self.has_variants = pvm.hasVariants()
        self.taxes = ITaxes(context)

        if self.has_variants:
            self.product_variant = \
                pvm.getSelectedVariant() or pvm.getDefaultVariant()
Ejemplo n.º 3
0
    def getPriceGross(self, property_id, option_id):
        """
        """
        shop = IShopManagement(self.context).getShop()
        tax_rate = ITaxes(self.context).getTaxRate()
        price = self._calcPrice(property_id, option_id)

        # The price entered is considered as gross price, so we simply
        # return it.
        if 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)
Ejemplo n.º 4
0
    def getPriceGross(self, property_id, option_id):
        """
        """
        shop     = IShopManagement(self.context).getShop()
        tax_rate = ITaxes(self.context).getTaxRate()
        price    = self._calcPrice(property_id, option_id)

        # The price entered is considered as gross price, so we simply
        # return it.
        if 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)
Ejemplo n.º 5
0
    def getPriceNet(self, property_id, option_id):
        """
        """
        # Get the tax rate for the product to which the property belongs.
        # Note: That means, the tax rate for the product's properties is the
        # same as for the product.
        shop = IShopManagement(self.context).getShop()
        tax_rate = ITaxes(self.context).getTaxRate()
        price = self._calcPrice(property_id, option_id)

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

        if 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
Ejemplo n.º 6
0
    def getPriceNet(self, property_id, option_id):
        """
        """
        # Get the tax rate for the product to which the property belongs.
        # Note: That means, the tax rate for the product's properties is the
        # same as for the product.
        shop     = IShopManagement(self.context).getShop()
        tax_rate = ITaxes(self.context).getTaxRate()
        price    = self._calcPrice(property_id, option_id)


        # The price entered is considered as gross price. So we have to 
        # calculate the net price first.
        
        if 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
Ejemplo n.º 7
0
class ProductTaxes(object):
    """Provides ITaxes for product content objects.
    """
    implements(ITaxes)
    adapts(IProduct)

    def __init__(self, context):
        """
        """
        self.context = context
        self.shop = IShopManagement(context).getShop()

    def getTaxRate(self):
        """
        """
        return self._calcTaxRateForProduct()

    def getTaxRateForCustomer(self):
        """
        """
        return self._calcTaxRateForCustomer()        

    def getTax(self, effective=True):
        """
        """
        if effective == True:
            return self._getEffectiveTax()
        else:
            return self._getStandardTax()
        
    def getTaxForCustomer(self, effective=True):
        """
        """
        if effective == True:
            return self._getEffectiveTaxForCustomer()
        else:
            return self._getStandardTaxForCustomer()

    def _getStandardTax(self):
        """Returns the standard tax of the product. Without taking care whether 
        the product is for sale or not. We need this in any case (whether the 
        product is for sale or not) to display the default price (e.g. stroked).
        """
        tax_rate = self._calcTaxRateForProduct()
        price = self.context.getPrice()
        
        if self.shop.getGrossPrices() == True:
            tax_abs = (tax_rate/(tax_rate+100)) * price
        else:
            tax_abs = price * (tax_rate/100)

        return tax_abs
        
    def _getStandardTaxForCustomer(self):
        """Returns the standard tax of the product and customer. Without taking 
        care whether the product is for sale or not. We need this in any case 
        (whether the  product is for sale or not) to display the default price 
        (e.g. stroked).
        """
        tax_product = self.getTax(effective=False)
        tax_rate_customer = self._calcTaxRateForCustomer()
        
        if self.shop.getGrossPrices() == True:
            price_net = self.context.getPrice() - tax_product
        else:
            price_net = self.context.getPrice()
        
        return (tax_rate_customer/100) * price_net

    def _getEffectiveTax(self):
        """Returns the effective tax of the product. This means it takes care 
        whether the product is for sale for not.
        """
        tax_rate = self._calcTaxRateForProduct()

        if self.context.getForSale() == True:
            price = self.context.getSalePrice()
        else:
            price = self.context.getPrice()

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

        return tax_abs
        
    def _getEffectiveTaxForCustomer(self):
        """Returns the effective tax of the product and customer. This means it
        takes care whether the product is for sale for not.
        """
        tax_product = self.getTax()
        tax_rate_customer = self._calcTaxRateForCustomer()

        if self.context.getForSale() == True:
            price_net = self.context.getSalePrice()
        else:
            price_net = self.context.getPrice()
        
        if self.shop.getGrossPrices() == True:
            price_net = price_net - tax_product
        
        return (tax_rate_customer/100) * price_net

    def _calcTaxRateForProduct(self):
        """Calculates the default tax for a given product.
        """
        # Returns the first tax rate, which is true. Taxes are sorted by 
        # position which is also the priority
        tm = ITaxManagement(self.shop)
        for tax in tm.getDefaultTaxes():
            if IValidity(tax).isValid(self.context) == True:
                return tax.getRate()

        return 0

    def _calcTaxRateForCustomer(self):
        """Calculates the special tax for a given product and customer.
        """
        
        # If the customer has a VAT registration and the shop has a VAT
        # registration, and his country ID is different to the shop's
        # country ID, then don't apply customer taxes (default taxes
        # still apply)
        customer = ICustomerManagement(self.shop).getAuthenticatedCustomer(createIfNotExist=False)
        if customer is not None:
            vatreg = customer.getVATRegistration()
        else:
            vatreg = None
        if not self.shop.__dict__.has_key('VATCountry') or self.shop.VATCountry == "None" or not vatreg or vatreg[:2] == self.shop.VATCountry:

            # 1. Try to find a Tax for actual Customer
            tm = ITaxManagement(self.shop)
            for tax in tm.getCustomerTaxes():
                if IValidity(tax).isValid(self.context) == True:
                    return tax.getRate()

        # 2. If nothing is found, returns the default tax for the product.
        return self._calcTaxRateForProduct()
Ejemplo n.º 8
0
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()
Ejemplo n.º 9
0
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()
Ejemplo n.º 10
0
class ProductTaxes(object):
    """Provides ITaxes for product content objects.
    """
    implements(ITaxes)
    adapts(IProduct)

    def __init__(self, context):
        """
        """
        self.context = context
        self.shop = IShopManagement(context).getShop()

    def getTaxRate(self):
        """
        """
        return self._calcTaxRateForProduct()

    def getTaxRateForCustomer(self):
        """
        """
        return self._calcTaxRateForCustomer()

    def getTax(self, effective=True):
        """
        """
        if effective == True:
            return self._getEffectiveTax()
        else:
            return self._getStandardTax()

    def getTaxForCustomer(self, effective=True):
        """
        """
        if effective == True:
            return self._getEffectiveTaxForCustomer()
        else:
            return self._getStandardTaxForCustomer()

    def _getStandardTax(self):
        """Returns the standard tax of the product. Without taking care whether 
        the product is for sale or not. We need this in any case (whether the 
        product is for sale or not) to display the default price (e.g. stroked).
        """
        tax_rate = self._calcTaxRateForProduct()
        price = self.context.getPrice()

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

        return tax_abs

    def _getStandardTaxForCustomer(self):
        """Returns the standard tax of the product and customer. Without taking 
        care whether the product is for sale or not. We need this in any case 
        (whether the  product is for sale or not) to display the default price 
        (e.g. stroked).
        """
        tax_product = self.getTax(effective=False)
        tax_rate_customer = self._calcTaxRateForCustomer()

        if self.shop.getGrossPrices() == True:
            price_net = self.context.getPrice() - tax_product
        else:
            price_net = self.context.getPrice()

        return (tax_rate_customer / 100) * price_net

    def _getEffectiveTax(self):
        """Returns the effective tax of the product. This means it takes care 
        whether the product is for sale for not.
        """
        tax_rate = self._calcTaxRateForProduct()

        if self.context.getForSale() == True:
            price = self.context.getSalePrice()
        else:
            price = self.context.getPrice()

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

        return tax_abs

    def _getEffectiveTaxForCustomer(self):
        """Returns the effective tax of the product and customer. This means it
        takes care whether the product is for sale for not.
        """
        tax_product = self.getTax()
        tax_rate_customer = self._calcTaxRateForCustomer()

        if self.context.getForSale() == True:
            price_net = self.context.getSalePrice()
        else:
            price_net = self.context.getPrice()

        if self.shop.getGrossPrices() == True:
            price_net = price_net - tax_product

        return (tax_rate_customer / 100) * price_net

    def _calcTaxRateForProduct(self):
        """Calculates the default tax for a given product.
        """
        # Returns the first tax rate, which is true. Taxes are sorted by
        # position which is also the priority
        tm = ITaxManagement(self.shop)
        for tax in tm.getDefaultTaxes():
            if IValidity(tax).isValid(self.context) == True:
                return tax.getRate()

        return 0

    def _calcTaxRateForCustomer(self):
        """Calculates the special tax for a given product and customer.
        """

        # If the customer has a VAT registration and the shop has a VAT
        # registration, and his country ID is different to the shop's
        # country ID, then don't apply customer taxes (default taxes
        # still apply)
        customer = ICustomerManagement(
            self.shop).getAuthenticatedCustomer(createIfNotExist=False)
        if customer is not None:
            vatreg = customer.getVATRegistration()
        else:
            vatreg = None
        if not self.shop.__dict__.has_key(
                'VATCountry'
        ) or self.shop.VATCountry == "None" or not vatreg or vatreg[:
                                                                    2] == self.shop.VATCountry:

            # 1. Try to find a Tax for actual Customer
            tm = ITaxManagement(self.shop)
            for tax in tm.getCustomerTaxes():
                if IValidity(tax).isValid(self.context) == True:
                    return tax.getRate()

        # 2. If nothing is found, returns the default tax for the product.
        return self._calcTaxRateForProduct()