コード例 #1
0
 def getTax(self):
     """
     """
     temp_payment_product = self._createTemporaryPaymentProduct()
     taxes = ITaxes(temp_payment_product)
     tax = taxes.getTax()
     return tax
コード例 #2
0
ファイル: taxes.py プロジェクト: viona/Easyshop
    def __init__(self, context):
        """
        """
        self.context = context

        # adapt Product to Taxes
        self.taxes = ITaxes(self.context.getProduct())
コード例 #3
0
 def getTax(self):
     """
     """
     temp_payment_product = self._createTemporaryPaymentProduct()
     taxes = ITaxes(temp_payment_product)        
     tax = taxes.getTax()
     return tax
コード例 #4
0
    def testGetTaxRateForCustomer(self):
        """
        """
        t = ITaxes(self.item1)
        self.assertEqual(t.getTaxRate(), 19.00)

        t = ITaxes(self.item2)
        self.assertEqual(t.getTaxRate(), 19.00)
コード例 #5
0
ファイル: prices.py プロジェクト: viona/Easyshop
 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()
コード例 #6
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")
コード例 #7
0
ファイル: prices.py プロジェクト: viona/Easyshop
    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()
コード例 #8
0
ファイル: taxes.py プロジェクト: Easyshop/Easyshop
    def __init__(self, context):
        """
        """
        self.context = context

        # adapt Product to Taxes
        self.taxes = ITaxes(self.context.getProduct())
コード例 #9
0
    def addOrder(self, customer=None, cart=None):
        """
        """
        cartmanager = ICartManagement(self.context)
        if customer is None:
            cm = ICustomerManagement(self.context)
            customer = cm.getAuthenticatedCustomer()

        if cart is None:
            cart = cartmanager.getCart()

        portal = getToolByName(self.context, 'portal_url').getPortalObject()

        ## The current user may not be allowed to create an order, so we
        ## temporarily change the security context to use a temporary
        ## user with manager role.
        old_sm = getSecurityManager()
        tmp_user = UnrestrictedUser(old_sm.getUser().getId(), '', ['Manager'],
                                    '')

        tmp_user = tmp_user.__of__(portal.acl_users)
        newSecurityManager(None, tmp_user)

        # Add a new order
        new_id = self._createOrderId()
        self.orders.invokeFactory("Order", id=new_id)
        new_order = getattr(self.orders, new_id)

        # Copy Customer to Order
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        cm = ICopyManagement(customer)
        cm.copyTo(new_order)

        # Add cart items to order
        IItemManagement(new_order).addItemsFromCart(cart)

        # Add total tax
        new_order.setTax(ITaxes(cart).getTaxForCustomer())

        # Add shipping values to order
        sm = IShippingPriceManagement(self.context)
        new_order.setShippingPriceNet(sm.getPriceNet())
        new_order.setShippingPriceGross(sm.getPriceForCustomer())
        new_order.setShippingTax(sm.getTaxForCustomer())
        new_order.setShippingTaxRate(sm.getTaxRateForCustomer())

        # Add payment price values to order
        pp = IPaymentPriceManagement(self.context)
        new_order.setPaymentPriceGross(pp.getPriceForCustomer())
        new_order.setPaymentPriceNet(pp.getPriceNet())
        new_order.setPaymentTax(pp.getTaxForCustomer())
        new_order.setPaymentTaxRate(pp.getTaxRateForCustomer())

        ## Reset security manager
        setSecurityManager(old_sm)

        # Index with customer again
        new_order.reindexObject()

        return new_order
コード例 #10
0
ファイル: prices.py プロジェクト: Easyshop/Easyshop
 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()
コード例 #11
0
    def getTotalTax(self):
        """
        """
        cart = self._getCart()
        total = ITaxes(cart).getTaxForCustomer()

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(total)
コード例 #12
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
コード例 #13
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        
コード例 #14
0
ファイル: cart.py プロジェクト: viona/Easyshop
    def getTaxForCustomer(self):
        """
        """
        cm = ICurrencyManagement(self.context)
        cart = self._getCart()

        if cart is None:
            tax = 0.0
        else:
            tax = ITaxes(cart).getTaxForCustomer()

        return cm.priceToString(tax, suffix=None)
コード例 #15
0
ファイル: property_management.py プロジェクト: viona/Easyshop
    def getPriceForCustomer(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.
        tax_rate_for_customer = ITaxes(self.context).getTaxRateForCustomer()

        price_net = self.getPriceNet(property_id, option_id)
        price_for_customer = price_net * ((tax_rate_for_customer + 100) / 100)

        return price_for_customer
コード例 #16
0
ファイル: taxes.py プロジェクト: Easyshop/Easyshop
    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
コード例 #17
0
ファイル: taxes.py プロジェクト: viona/Easyshop
    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
コード例 #18
0
    def testGetTaxRateForCustomer(self):
        """
        """
        t = ITaxes(self.item1)
        self.assertEqual(t.getTaxRate(), 19.00)

        t = ITaxes(self.item2)
        self.assertEqual(t.getTaxRate(), 19.00)
コード例 #19
0
ファイル: prices.py プロジェクト: Easyshop/Easyshop
    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()
コード例 #20
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")
コード例 #21
0
ファイル: property_management.py プロジェクト: viona/Easyshop
    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)
コード例 #22
0
    def getTaxForCustomer(self):
        """
        """
        # If there a no items the shipping tax is 0
        cart_manager = ICartManagement(self.context)
        cart = cart_manager.getCart()

        if cart is None:
            return 0

        cart_item_manager = IItemManagement(cart)
        if cart_item_manager.hasItems() == False:
            return 0

        temp_shipping_product = self._createTemporaryShippingProduct()
        return ITaxes(temp_shipping_product).getTaxForCustomer()
コード例 #23
0
ファイル: property_management.py プロジェクト: viona/Easyshop
    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
コード例 #24
0
 def testGetTaxRateForCustomer(self):
     """
     """
     t = ITaxes(self.shop.products.product_1)
     self.assertEqual(t.getTaxRateForCustomer(), 10.0)
コード例 #25
0
 def testGetTax(self):
     """
     """
     t = ITaxes(self.shop.products.product_1)
     self.assertEqual("%.2f" % t.getTax(), "3.51")
コード例 #26
0
 def testGetTaxRateForCustomer(self):
     """
     """
     t = ITaxes(self.cart)
     self.assertRaises(ValueError, t.getTaxRateForCustomer)
コード例 #27
0
 def testGetTaxRate(self):
     """
     """
     t = ITaxes(self.shop.products.product_1)
     self.assertEqual(t.getTaxRate(), 19.0)
コード例 #28
0
 def testGetTaxForCustomer(self):
     """
     """
     t = ITaxes(self.cart)
     tax = "%.2f" % t.getTaxForCustomer()
     self.assertEqual(tax, "33.69")
コード例 #29
0
ファイル: item_management.py プロジェクト: viona/Easyshop
    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)
コード例 #30
0
 def getTax(self):
     """
     """
     temp_shipping_product = self._createTemporaryShippingProduct()
     return ITaxes(temp_shipping_product).getTax()
コード例 #31
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()
コード例 #32
0
ファイル: prices.py プロジェクト: Easyshop/Easyshop
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)
コード例 #33
0
 def testGetTaxForCustomer(self):
     """
     """
     t = ITaxes(self.shop.products.product_1)
     self.assertEqual("%.2f" % t.getTaxForCustomer(), "1.85")
コード例 #34
0
ファイル: prices.py プロジェクト: viona/Easyshop
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)
コード例 #35
0
ファイル: item_management.py プロジェクト: Easyshop/Easyshop
    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)
コード例 #36
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()