def testGetPriceNet(self):
     """
     """
     pp = IPaymentPriceManagement(self.shop)
     price_net = pp.getPriceNet()
     
     self.assertEqual("%.2f" % price_net, "84.03")
Esempio n. 2
0
    def getPaymentPrices(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        pp = IPaymentPriceManagement(shop)
        cm = ICurrencyManagement(shop)

        result = []
        for payment_price in pp.getPaymentPrices():

            price = cm.priceToString(payment_price.getPrice())

            result.append(
                {
                    "id": payment_price.getId(),
                    "title": payment_price.Title(),
                    "price": price,
                    "url": payment_price.absolute_url(),
                    "up_url": "%s/es_folder_position?position=up&id=%s"
                    % (self.context.absolute_url(), payment_price.getId()),
                    "down_url": "%s/es_folder_position?position=down&id=%s"
                    % (self.context.absolute_url(), payment_price.getId()),
                    "amount_of_criteria": self._getAmountOfCriteria(payment_price.getId()),
                }
            )

        return result
    def testGetTaxForCustomer(self):
        """
        """
        pp = IPaymentPriceManagement(self.shop)
        tax = pp.getTaxForCustomer()

        self.assertEqual("%.2f" % tax, "15.97")
 def testGetPriceForCustomer(self):
     """
     """
     pp = IPaymentPriceManagement(self.shop)
     price_gross = pp.getPriceGross()
     
     self.assertEqual(price_gross, 100.0)
    def testGetPriceNet(self):
        """
        """
        pp = IPaymentPriceManagement(self.shop)
        price_net = pp.getPriceNet()

        self.assertEqual("%.2f" % price_net, "84.03")
    def testGetTaxRateForCustomer(self):
        """
        """
        pp = IPaymentPriceManagement(self.shop)
        tax = pp.getTaxRateForCustomer()

        self.assertEqual(tax, 19.0)
    def testGetPriceForCustomer(self):
        """
        """
        pp = IPaymentPriceManagement(self.shop)
        price_gross = pp.getPriceGross()

        self.assertEqual(price_gross, 100.0)
    def testGetTaxForCustomer(self):
        """
        """
        pp = IPaymentPriceManagement(self.shop)
        tax = pp.getTaxForCustomer()

        self.assertEqual("%.2f" % tax, "15.97")
    def testGetTaxRateForCustomer(self):
        """
        """
        pp = IPaymentPriceManagement(self.shop)
        tax = pp.getTaxRateForCustomer()

        self.assertEqual(tax, 19.0)
Esempio n. 10
0
    def getPaymentPrices(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        pp = IPaymentPriceManagement(shop)
        cm = ICurrencyManagement(shop)

        result = []
        for payment_price in pp.getPaymentPrices():

            price = cm.priceToString(payment_price.getPrice())

            result.append({
                "id":
                payment_price.getId(),
                "title":
                payment_price.Title(),
                "price":
                price,
                "url":
                payment_price.absolute_url(),
                "up_url":
                "%s/es_folder_position?position=up&id=%s" %
                (self.context.absolute_url(), payment_price.getId()),
                "down_url":
                "%s/es_folder_position?position=down&id=%s" %
                (self.context.absolute_url(), payment_price.getId()),
                "amount_of_criteria":
                self._getAmountOfCriteria(payment_price.getId())
            })

        return result
Esempio n. 11
0
    def getPriceNet(self,
                    with_shipping=True,
                    with_payment=True,
                    with_discount=True):
        """Returns the net price of the cart. This is just a sum over net
        prices of all items of the cart plus shipping and payment.
        """
        im = IItemManagement(self.context)
        if im.hasItems() == False:
            return 0.0

        price = 0.0
        for cart_item in im.getItems():
            # NOTE: with_discount is passed here
            price += IPrices(cart_item).getPriceNet(
                with_discount=with_discount)

        if with_shipping == True:
            sm = IShippingPriceManagement(self.shop)
            shipping_price = sm.getPriceNet()
            price += shipping_price

        if with_payment == True:
            sm = IPaymentPriceManagement(self.shop)
            payment_price = sm.getPriceNet()
            price += payment_price

        return price
Esempio n. 12
0
    def getPaymentInfo(self):
        """
        """
        pp = IPaymentPriceManagement(self.context)
        price = pp.getPriceForCustomer()

        cm = ICurrencyManagement(self.context)
        price = cm.priceToString(price, suffix=None)

        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        pim = IPaymentInformationManagement(customer)
        selected_payment_method = pim.getSelectedPaymentMethod()

        if selected_payment_method is None:
            return {"display": False}
        else:
            return {
                "price": price,
                "title": selected_payment_method.Title(),
                "display": len(self.getCartItems()) > 0,
            }
Esempio n. 13
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
Esempio n. 14
0
    def getPaymentMethodInfo(self):
        """
        """
        # method
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        selected_payment_method = customer.selected_payment_method

        pm = IPaymentMethodManagement(self.context)
        method = pm.getPaymentMethod(selected_payment_method)

        # price
        pp = IPaymentPriceManagement(self.context)
        payment_price = pp.getPriceGross()
        cm = ICurrencyManagement(self.context)
        price = cm.priceToString(payment_price)

        return {
            "type": method.portal_type,
            "title": method.Title(),
            "price": price,
            "display": payment_price != 0,
        }
Esempio n. 15
0
 def getPaymentMethodInfo(self):
     """
     """
     # method
     customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
     selected_payment_method = customer.selected_payment_method
     
     pm = IPaymentMethodManagement(self.context)
     method = pm.getPaymentMethod(selected_payment_method)
     
     # price
     pp = IPaymentPriceManagement(self.context)
     payment_price = pp.getPriceGross()
     cm = ICurrencyManagement(self.context)
     price = cm.priceToString(payment_price)
     
     return {
         "type"    : method.portal_type,
         "title"   : method.Title(),
         "price"   : price,
         "display" : payment_price != 0,
     }
Esempio n. 16
0
    def getPaymentInfo(self):
        """
        """
        pp = IPaymentPriceManagement(self.context)
        price = pp.getPriceForCustomer()

        cm = ICurrencyManagement(self.context)
        price =  cm.priceToString(price, suffix=None)

        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        pim = IPaymentInformationManagement(customer)
        selected_payment_method = pim.getSelectedPaymentMethod()
        
        if selected_payment_method is None: 
            return {
                "display" : False
            }
        else:    
            return {
                "price"   : price,
                "title"   : selected_payment_method.Title(),
                "display" : len(self.getCartItems()) > 0,
            }
Esempio n. 17
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
 def testGetPaymentPrices(self):
     """
     """            
     pp = IPaymentPriceManagement(self.shop)
     ids = [pp.getId() for pp in pp.getPaymentPrices()]
     self.assertEqual(ids, ["default"])
Esempio n. 19
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
 def testGetPaymentPrices(self):
     """
     """
     pp = IPaymentPriceManagement(self.shop)
     ids = [pp.getId() for pp in pp.getPaymentPrices()]
     self.assertEqual(ids, ["default"])