def testGetDefaultTaxes(self):
     """
     """
     tm = ITaxManagement(self.shop)
     ids = [t.getId() for t in tm.getDefaultTaxes()]
     
     self.assertEqual(ids, ["default", "d1", "d2", "d3", "d4"])
Example #2
0
    def testGetDefaultTaxes(self):
        """
        """
        tm = ITaxManagement(self.shop)
        ids = [t.getId() for t in tm.getDefaultTaxes()]

        self.assertEqual(ids, ["default", "d1", "d2", "d3", "d4"])
 def testGetCustomerTaxes(self):
     """
     """        
     tm = ITaxManagement(self.shop)
     ids = [t.getId() for t in tm.getCustomerTaxes()]
     
     self.assertEqual(ids, ["c1", "c2", "c3", "c4"])
Example #4
0
    def testGetCustomerTaxes(self):
        """
        """
        tm = ITaxManagement(self.shop)
        ids = [t.getId() for t in tm.getCustomerTaxes()]

        self.assertEqual(ids, ["c1", "c2", "c3", "c4"])
Example #5
0
    def getCustomerTaxes(self):
        """
        """
        tm = ITaxManagement(IShopManagement(self.context).getShop())
        nc = queryUtility(INumberConverter)

        result = []
        for tax in tm.getCustomerTaxes():
            result.append({
                "id":
                tax.getId(),
                "title":
                tax.Title(),
                "rate":
                nc.floatToTaxString(tax.getRate()),
                "up_link":
                "%s/es_folder_position?position=up&id=%s" %
                (self.context.absolute_url(), tax.getId()),
                "down_link":
                "%s/es_folder_position?position=down&id=%s" %
                (self.context.absolute_url(), tax.getId()),
                "url":
                tax.absolute_url(),
                "amount_of_criteria":
                self._getAmountOfCriteria(tax.getId()),
            })

        return result
Example #6
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()
 def getTax(self, id):
     """
     """
     tm = ITaxManagement(self.shop)
     tax = tm.getTax("c2")
     
     self.assertEqual(tax.getId(), "c2")
     self.failUnless(ITax.providedBy(tax))
Example #8
0
    def getTax(self, id):
        """
        """
        tm = ITaxManagement(self.shop)
        tax = tm.getTax("c2")

        self.assertEqual(tax.getId(), "c2")
        self.failUnless(ITax.providedBy(tax))
Example #9
0
    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
Example #10
0
    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
Example #11
0
 def getCustomerTaxes(self):
     """
     """    
     tm = ITaxManagement(IShopManagement(self.context).getShop())
     nc = queryUtility(INumberConverter)
             
     result = []
     for tax in tm.getCustomerTaxes():
         result.append({
             "id"        : tax.getId(),
             "title"     : tax.Title(),
             "rate"      : nc.floatToTaxString(tax.getRate()),
             "up_link"   : "%s/es_folder_position?position=up&id=%s" % (self.context.absolute_url(), tax.getId()),
             "down_link" : "%s/es_folder_position?position=down&id=%s" % (self.context.absolute_url(), tax.getId()),
             "url"       : tax.absolute_url(),
             "amount_of_criteria" : self._getAmountOfCriteria(tax.getId()),
         })
     
     return result
Example #12
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()
Example #13
0
    def getVATRegistration(self):
        """Returns the VAT registration (if any) of the current customer.
        """
        result = []
        shop = IShopManagement(self.context).getShop()
        if shop.__dict__.has_key(
                'VATCountry') and shop.VATCountry != "None" and len(
                    ITaxManagement(self.context).getCustomerTaxes()):

            customermgmt = ICustomerManagement(self.context)
            customer = customermgmt.getAuthenticatedCustomer()
            vatreg = customer.getVATRegistration()
            if not vatreg: vatreg = ""
            vatcountries = VAT_COUNTRIES.keys()
            vatcountries.sort()

            result.append({
                "country": vatreg[:2],
                "number": vatreg[2:],
                "countries": vatcountries,
            })

        return result