<s> from lfs . criteria . utils import get_first_valid <EOL> from lfs . customer_tax . models import CustomerTax <EOL> def get_customer_tax_rate ( request , product ) : <EOL> """<STR_LIT>""" <EOL> cache_key = '<STR_LIT>' % product . pk <EOL> if request and hasattr ( request , cache_key ) : <EOL> return getattr ( request , cache_key ) <EOL> customer_tax = get_first_valid ( request , CustomerTax . objects . all ( ) , product ) <EOL> if customer_tax : <EOL> taxrate = customer_tax . rate <EOL> else : <EOL> taxrate = _calc_product_tax_rate ( request , product ) <EOL> if request : <EOL> setattr ( request , cache_key , taxrate ) <EOL> return taxrate <EOL> def _calc_product_tax_rate ( request , product ) : <EOL> try : <EOL> return product . get_product_tax_rate ( request ) <EOL> except AttributeError : <EOL> return <NUM_LIT:0.0> </s>
