<s> from decimal import Decimal <EOL> from django import template <EOL> from livesettings import config_value <EOL> from product . utils import calc_discounted_by_percentage , find_best_auto_discount <EOL> from tax . templatetags import satchmo_tax <EOL> register = template . Library ( ) <EOL> def sale_price ( product ) : <EOL> """<STR_LIT>""" <EOL> if config_value ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return taxed_sale_price ( product ) <EOL> else : <EOL> return untaxed_sale_price ( product ) <EOL> register . filter ( '<STR_LIT>' , sale_price ) <EOL> def untaxed_sale_price ( product ) : <EOL> """<STR_LIT>""" <EOL> discount = find_best_auto_discount ( product ) <EOL> price = product . unit_price <EOL> if discount and discount . valid_for_product ( product ) : <EOL> price = calc_discounted_by_percentage ( price , discount . percentage ) <EOL> return price <EOL> register . filter ( '<STR_LIT>' , untaxed_sale_price ) <EOL> def taxed_sale_price ( product ) : <EOL> """<STR_LIT>""" <EOL> taxer = satchmo_tax . _get_taxprocessor ( ) <EOL> price = untaxed_sale_price ( product ) <EOL> price = price + taxer . by_price ( product . taxClass , price ) <EOL> return price <EOL> register . filter ( '<STR_LIT>' , taxed_sale_price ) <EOL> def discount_cart_total ( cart , discount ) : <EOL> """<STR_LIT>""" <EOL> if config_value ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return taxed_discount_cart_total ( cart , discount ) <EOL> else : <EOL> return untaxed_discount_cart_total ( cart , discount ) <EOL> register . filter ( '<STR_LIT>' , discount_cart_total ) <EOL> def untaxed_discount_cart_total ( cart , discount ) : <EOL> """<STR_LIT>""" <EOL> total = Decimal ( '<STR_LIT>' ) <EOL> for item in cart : <EOL> total += untaxed_discount_line_total ( item , discount ) <EOL> return total <EOL> register . filter ( '<STR_LIT>' , untaxed_discount_cart_total ) <EOL> def taxed_discount_cart_total ( cart , discount ) : <EOL> """<STR_LIT>""" <EOL> total = Decimal ( '<STR_LIT>' ) <EOL> for item in cart : <EOL> total += taxed_discount_line_total ( item , discount ) <EOL> return total <EOL> register . filter ( '<STR_LIT>' , taxed_discount_cart_total ) <EOL> def discount_line_total ( cartitem , discount ) : <EOL> """<STR_LIT>""" <EOL> if config_value ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return taxed_discount_line_total ( cartitem , discount ) <EOL> else : <EOL> return untaxed_discount_line_total ( cartitem , discount ) <EOL> register . filter ( '<STR_LIT>' , discount_line_total ) <EOL> def untaxed_discount_line_total ( cartitem , discount ) : <EOL> """<STR_LIT>""" <EOL> price = cartitem . line_total <EOL> if discount and discount . valid_for_product ( cartitem . product ) : <EOL> price = calc_discounted_by_percentage ( price , discount . percentage ) <EOL> return price <EOL> register . filter ( '<STR_LIT>' , untaxed_discount_line_total ) <EOL> def taxed_discount_line_total ( cartitem , discount ) : <EOL> """<STR_LIT>""" <EOL> price = untaxed_discount_line_total ( cartitem , discount ) <EOL> taxer = satchmo_tax . _get_taxprocessor ( ) <EOL> price = price + taxer . by_price ( cartitem . product . taxClass , price ) <EOL> return price <EOL> register . filter ( '<STR_LIT>' , taxed_discount_line_total ) <EOL> def discount_price ( product , discount ) : <EOL> """<STR_LIT>""" <EOL> if config_value ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return taxed_discount_price ( product , discount ) <EOL> else : <EOL> return untaxed_discount_price ( product , discount ) <EOL> register . filter ( '<STR_LIT>' , discount_price ) <EOL> def untaxed_discount_price ( product , discount ) : <EOL> """<STR_LIT>""" <EOL> up = product . unit_price <EOL> if discount and discount . valid_for_product ( product ) : <EOL> pcnt = calc_discounted_by_percentage ( up , discount . percentage ) <EOL> return pcnt <EOL> else : <EOL> return up <EOL> register . filter ( '<STR_LIT>' , untaxed_discount_price ) <EOL> def taxed_discount_price ( product , discount ) : <EOL> """<STR_LIT>""" <EOL> price = untaxed_discount_price ( product , discount ) <EOL> taxer = satchmo_tax . _get_taxprocessor ( ) <EOL> return price + taxer . by_price ( product . taxClass , price ) <EOL> register . filter ( '<STR_LIT>' , taxed_discount_price ) <EOL> def discount_ratio ( discount ) : <EOL> """<STR_LIT>""" <EOL> pcnt = discount . percentage <EOL> if pcnt > <NUM_LIT:1> : <EOL> pcnt = pcnt / <NUM_LIT:100> <EOL> return <NUM_LIT:1> - pcnt <EOL> register . filter ( '<STR_LIT>' , discount_ratio ) <EOL> def discount_saved ( product , discount ) : <EOL> """<STR_LIT>""" <EOL> if config_value ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return taxed_discount_saved ( product , discount ) <EOL> else : <EOL> return untaxed_discount_saved ( product , discount ) <EOL> register . filter ( '<STR_LIT>' , discount_saved ) <EOL> def untaxed_discount_saved ( product , discount ) : <EOL> """<STR_LIT>""" <EOL> if discount and discount . valid_for_product ( product ) : <EOL> price = product . unit_price <EOL> discounted = untaxed_discount_price ( product , discount ) <EOL> saved = price - discounted <EOL> cents = Decimal ( "<STR_LIT>" ) <EOL> return saved . quantize ( cents ) <EOL> else : <EOL> return Decimal ( '<STR_LIT>' ) <EOL> register . filter ( '<STR_LIT>' , untaxed_discount_saved ) <EOL> def taxed_discount_saved ( product , discount ) : <EOL> """<STR_LIT>""" <EOL> if discount and discount . valid_for_product ( product ) : <EOL> price = product . unit_price <EOL> discounted = taxed_discount_price ( product , discount ) <EOL> saved = price - discounted <EOL> cents = Decimal ( "<STR_LIT>" ) <EOL> return saved . quantize ( cents ) <EOL> else : <EOL> return Decimal ( '<STR_LIT>' ) <EOL> register . filter ( '<STR_LIT>' , taxed_discount_saved ) </s>
