def testGetCustomerTaxes(self): """ """ tm = ITaxManagement(self.shop) ids = [t.getId() for t in tm.getCustomerTaxes()] self.assertEqual(ids, ["c1", "c2", "c3", "c4"])
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
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 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
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()