Exemple #1
0
    def testGetTaxForCustomer(self):
        """
        """
        t = ITaxes(self.item1)
        tax = "%.2f" % t.getTaxForCustomer()
        self.assertEqual(tax, "7.03")

        t = ITaxes(self.item2)
        tax = "%.2f" % t.getTaxForCustomer()
        self.assertEqual(tax, "9.10")
    def testGetTaxForCustomer(self):
        """
        """
        t = ITaxes(self.item1)
        tax = "%.2f" % t.getTaxForCustomer()
        self.assertEqual(tax, "7.03")

        t = ITaxes(self.item2)
        tax = "%.2f" % t.getTaxForCustomer()
        self.assertEqual(tax, "9.10")
Exemple #3
0
    def getTaxForCustomer(self):
        """
        """
        temp_payment_product = self._createTemporaryPaymentProduct()
        taxes = ITaxes(temp_payment_product)
        tax = taxes.getTaxForCustomer()

        return tax
    def getTaxForCustomer(self):
        """
        """
        temp_payment_product = self._createTemporaryPaymentProduct()
        taxes = ITaxes(temp_payment_product)        
        tax = taxes.getTaxForCustomer()

        return tax
Exemple #5
0
    def getTaxForCustomer(self):
        """
        """
        im = IItemManagement(self.context)
        if im.hasItems() == False:
            return 0.0

        tax = 0.0
        for cart_item in im.getItems():
            taxes = ITaxes(cart_item)
            tax += taxes.getTaxForCustomer()

        # Get shop
        shop = IShopManagement(self.context).getShop()

        # Shipping
        tax += IShippingPriceManagement(shop).getTaxForCustomer()

        # Payment
        tax += IPaymentPriceManagement(shop).getTaxForCustomer()

        return tax
Exemple #6
0
    def getTaxForCustomer(self):
        """
        """
        im = IItemManagement(self.context)
        if im.hasItems() == False:
            return 0.0
        
        tax = 0.0
        for cart_item in im.getItems():
            taxes = ITaxes(cart_item)
            tax += taxes.getTaxForCustomer()

        # Get shop
        shop = IShopManagement(self.context).getShop()
        
        # Shipping
        tax += IShippingPriceManagement(shop).getTaxForCustomer()
        
        # Payment
        tax += IPaymentPriceManagement(shop).getTaxForCustomer()
        
        return tax
Exemple #7
0
    def _addItemFromCartItem(self, id, cart_item):
        """Sets the item by given cart item.
        """        
        self.context.manage_addProduct["easyshop.core"].addOrderItem(id=str(id))
        new_item = getattr(self.context, str(id))

        # set product quantity        
        new_item.setProductQuantity(cart_item.getAmount())
                
        # Set product prices & taxes
        product_taxes  = ITaxes(cart_item.getProduct())
        product_prices = IPrices(cart_item.getProduct())
        item_prices = IPrices(cart_item)
        item_taxes  = ITaxes(cart_item)
        
        new_item.setTaxRate(product_taxes.getTaxRateForCustomer())
        new_item.setProductTax(product_taxes.getTaxForCustomer())
        
        new_item.setProductPriceGross(product_prices.getPriceForCustomer())
        new_item.setProductPriceNet(product_prices.getPriceNet())

        # Set item prices & taxes
        new_item.setTax(item_taxes.getTaxForCustomer())
        new_item.setPriceGross(item_prices.getPriceForCustomer())
        new_item.setPriceNet(item_prices.getPriceNet())

        # Discount
        discount = IDiscountsCalculation(cart_item).getDiscount()
        if discount is not None:
            new_item.setDiscountDescription(discount.Title())

            dp = getMultiAdapter((discount, cart_item))
            new_item.setDiscountGross(dp.getPriceForCustomer())
            new_item.setDiscountNet(dp.getPriceNet())
        
        # Set product
        product = cart_item.getProduct()
        new_item.setProduct(product)

        # Set product name and id
        data = IData(product).asDict()
        new_item.setProductTitle(data["title"])
        new_item.setArticleId(data["article_id"])

        # Set properties
        properties = []
        pm = IPropertyManagement(product)
        for selected_property in cart_item.getProperties():

            # Get the price
            property_price = pm.getPriceForCustomer(
                selected_property["id"], 
                selected_property["selected_option"])

            # By default we save the titles of the properties and selected 
            # options In this way they are kept if the title of a property or 
            # option will be changed after the product has been bought.
            titles = getTitlesByIds(
                product,
                selected_property["id"], 
                selected_property["selected_option"])

            # If we don't find the property or option we ignore the property. 
            # This can only happen if the property has been deleted after a 
            # product has been added to the cart. In this case we don't want the 
            # property at all (I think).
            if titles is None:
                continue
                                    
            properties.append({
                "title" : titles["property"],
                "selected_option" : titles["option"],
                "price" : str(property_price),
            })
                            
        new_item.setProperties(properties)
 def testGetTaxForCustomer(self):
     """
     """
     t = ITaxes(self.shop.products.product_1)
     self.assertEqual("%.2f" % t.getTaxForCustomer(), "1.85")
Exemple #9
0
    def _addItemFromCartItem(self, id, cart_item):
        """Sets the item by given cart item.
        """
        self.context.manage_addProduct["easyshop.core"].addOrderItem(
            id=str(id))
        new_item = getattr(self.context, str(id))

        # set product quantity
        new_item.setProductQuantity(cart_item.getAmount())

        # Set product prices & taxes
        product_taxes = ITaxes(cart_item.getProduct())
        product_prices = IPrices(cart_item.getProduct())
        item_prices = IPrices(cart_item)
        item_taxes = ITaxes(cart_item)

        new_item.setTaxRate(product_taxes.getTaxRateForCustomer())
        new_item.setProductTax(product_taxes.getTaxForCustomer())

        new_item.setProductPriceGross(product_prices.getPriceForCustomer())
        new_item.setProductPriceNet(product_prices.getPriceNet())

        # Set item prices & taxes
        new_item.setTax(item_taxes.getTaxForCustomer())
        new_item.setPriceGross(item_prices.getPriceForCustomer())
        new_item.setPriceNet(item_prices.getPriceNet())

        # Discount
        discount = IDiscountsCalculation(cart_item).getDiscount()
        if discount is not None:
            new_item.setDiscountDescription(discount.Title())

            dp = getMultiAdapter((discount, cart_item))
            new_item.setDiscountGross(dp.getPriceForCustomer())
            new_item.setDiscountNet(dp.getPriceNet())

        # Set product
        product = cart_item.getProduct()
        new_item.setProduct(product)

        # Set product name and id
        data = IData(product).asDict()
        new_item.setProductTitle(data["title"])
        new_item.setArticleId(data["article_id"])

        # Set properties
        properties = []
        pm = IPropertyManagement(product)
        for selected_property in cart_item.getProperties():

            # Get the price
            property_price = pm.getPriceForCustomer(
                selected_property["id"], selected_property["selected_option"])

            # By default we save the titles of the properties and selected
            # options In this way they are kept if the title of a property or
            # option will be changed after the product has been bought.
            titles = getTitlesByIds(product, selected_property["id"],
                                    selected_property["selected_option"])

            # If we don't find the property or option we ignore the property.
            # This can only happen if the property has been deleted after a
            # product has been added to the cart. In this case we don't want the
            # property at all (I think).
            if titles is None:
                continue

            properties.append({
                "title": titles["property"],
                "selected_option": titles["option"],
                "price": str(property_price),
            })

        new_item.setProperties(properties)
Exemple #10
0
class ProductPrices(object):
    """Provides IPrices for product content object.
    """
    implements(IPrices)
    adapts(IProduct)

    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()
                                   
    def getPriceForCustomer(self, effective=True, variant_price=True):
        """
        """
        if self.has_variants and variant_price and \
           self.product_variant.getPrice() != 0:
            return IPrices(self.product_variant).getPriceForCustomer(effective)
        else:
            if effective == True:
                return self._getEffectivePriceForCustomer()
            else:
                return self._getStandardPriceForCustomer()
            
    def getPriceNet(self, effective=True, variant_price=True):
        """
        """
        if self.has_variants and variant_price and \
           self.product_variant.getPrice() != 0:
            return IPrices(self.product_variant).getPriceNet(effective)
        else:
            if effective == True:
                return self._getEffectivePriceNet()
            else:
                return self._getStandardPriceNet()

    def getPriceGross(self, effective=True, variant_price=True):
        """
        """
        if self.has_variants and variant_price and \
           self.product_variant.getPrice() != 0:
            return IPrices(self.product_variant).getPriceGross(effective)
        else:
            if effective == True:
                return self._getEffectivePriceGross()
            else:
                return self._getStandardPriceGross()

    # Effective Price
    def _getEffectivePriceForCustomer(self):
        """Returns the effective price for customer, dependend of the product 
        is for sale or not.
        """
        tax_abs_customer = self.taxes.getTaxForCustomer()
        return self._getEffectivePriceNet() + tax_abs_customer

    def _getEffectivePriceNet(self):
        """Returns the effective price for customer, dependend of the product 
        is for sale or not.
        """
        if self.context.getForSale() == True:
            price = self.context.getSalePrice()
        else:
            price = self.context.getPrice()
        
        if self.gross_prices == True:
            return price - self.taxes.getTax()
        else:
            return price

    def _getEffectivePriceGross(self):
        """Returns the effective price for customer, dependend of the product 
        is for sale or not.
        """
        if self.context.getForSale() == True:
            price = self.context.getSalePrice()
        else:
            price = self.context.getPrice()
            
        if self.gross_prices == True:
            return price
        else:
            return price + self.taxes.getTax()

    # Standard Price
    def _getStandardPriceForCustomer(self):
        """Returns always the standard price, independent of the product is for 
        sale or not. We need this in any case to display the standard price 
        (e.g. stroked).
        """
        tax_abs_customer = self.taxes.getTaxForCustomer(False)
        return self._getStandardPriceNet() + tax_abs_customer

    def _getStandardPriceNet(self):
        """Returns always the standard price, independent of the product is for 
        sale or not. We need this in any case to display the standard price 
        (e.g. stroked).
        """
        if self.gross_prices == True:
            return self.context.getPrice() - self.taxes.getTax(False)
        else:
            return self.context.getPrice()

    def _getStandardPriceGross(self):
        """Returns always the standard price, independent of the product is for 
        sale or not. We need this in any case to display the standard price 
        (e.g. stroked).
        """
        if self.gross_prices == True:
            return self.context.getPrice()
        else:
            return self.context.getPrice() + self.taxes.getTax(False)
Exemple #11
0
class ProductPrices(object):
    """Provides IPrices for product content object.
    """
    implements(IPrices)
    adapts(IProduct)

    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()

    def getPriceForCustomer(self, effective=True, variant_price=True):
        """
        """
        if self.has_variants and variant_price and \
           self.product_variant.getPrice() != 0:
            return IPrices(self.product_variant).getPriceForCustomer(effective)
        else:
            if effective == True:
                return self._getEffectivePriceForCustomer()
            else:
                return self._getStandardPriceForCustomer()

    def getPriceNet(self, effective=True, variant_price=True):
        """
        """
        if self.has_variants and variant_price and \
           self.product_variant.getPrice() != 0:
            return IPrices(self.product_variant).getPriceNet(effective)
        else:
            if effective == True:
                return self._getEffectivePriceNet()
            else:
                return self._getStandardPriceNet()

    def getPriceGross(self, effective=True, variant_price=True):
        """
        """
        if self.has_variants and variant_price and \
           self.product_variant.getPrice() != 0:
            return IPrices(self.product_variant).getPriceGross(effective)
        else:
            if effective == True:
                return self._getEffectivePriceGross()
            else:
                return self._getStandardPriceGross()

    # Effective Price
    def _getEffectivePriceForCustomer(self):
        """Returns the effective price for customer, dependend of the product 
        is for sale or not.
        """
        tax_abs_customer = self.taxes.getTaxForCustomer()
        return self._getEffectivePriceNet() + tax_abs_customer

    def _getEffectivePriceNet(self):
        """Returns the effective price for customer, dependend of the product 
        is for sale or not.
        """
        if self.context.getForSale() == True:
            price = self.context.getSalePrice()
        else:
            price = self.context.getPrice()

        if self.gross_prices == True:
            return price - self.taxes.getTax()
        else:
            return price

    def _getEffectivePriceGross(self):
        """Returns the effective price for customer, dependend of the product 
        is for sale or not.
        """
        if self.context.getForSale() == True:
            price = self.context.getSalePrice()
        else:
            price = self.context.getPrice()

        if self.gross_prices == True:
            return price
        else:
            return price + self.taxes.getTax()

    # Standard Price
    def _getStandardPriceForCustomer(self):
        """Returns always the standard price, independent of the product is for 
        sale or not. We need this in any case to display the standard price 
        (e.g. stroked).
        """
        tax_abs_customer = self.taxes.getTaxForCustomer(False)
        return self._getStandardPriceNet() + tax_abs_customer

    def _getStandardPriceNet(self):
        """Returns always the standard price, independent of the product is for 
        sale or not. We need this in any case to display the standard price 
        (e.g. stroked).
        """
        if self.gross_prices == True:
            return self.context.getPrice() - self.taxes.getTax(False)
        else:
            return self.context.getPrice()

    def _getStandardPriceGross(self):
        """Returns always the standard price, independent of the product is for 
        sale or not. We need this in any case to display the standard price 
        (e.g. stroked).
        """
        if self.gross_prices == True:
            return self.context.getPrice()
        else:
            return self.context.getPrice() + self.taxes.getTax(False)
Exemple #12
0
 def testGetTaxForCustomer(self):
     """
     """
     t = ITaxes(self.cart)
     tax = "%.2f" % t.getTaxForCustomer()
     self.assertEqual(tax, "33.69")