<s> """<STR_LIT>""" <EOL> from decimal import Decimal , ROUND_CEILING <EOL> from django . contrib . sites . models import Site <EOL> from django . conf import settings <EOL> from django . core import urlresolvers <EOL> from django . db import models <EOL> from django . utils . encoding import force_unicode <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils . translation import ugettext , ugettext_lazy as _ <EOL> from l10n . models import Country <EOL> from l10n . utils import moneyfmt <EOL> from livesettings import ConfigurationSettings , config_value <EOL> from payment . fields import PaymentChoiceCharField <EOL> from product . models import Discount , Product , Price , get_product_quantity_adjustments <EOL> from product . prices import PriceAdjustmentCalc , PriceAdjustment <EOL> from satchmo_store . contact . models import Contact <EOL> from satchmo_utils . fields import CurrencyField <EOL> from satchmo_utils . numbers import trunc_decimal <EOL> from shipping . fields import ShippingChoiceCharField <EOL> from tax . utils import get_tax_processor <EOL> import datetime <EOL> import keyedcache <EOL> import logging <EOL> import operator <EOL> import signals <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> class NullConfig ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . store_name = self . store_description = _ ( "<STR_LIT>" ) <EOL> self . store_email = self . street1 = self . street2 = self . city = self . state = self . postal_code = self . phone = "<STR_LIT>" <EOL> self . site = self . country = None <EOL> self . in_country_only = True <EOL> self . sales_country = None <EOL> def _options ( self ) : <EOL> return ConfigurationSettings ( ) <EOL> options = property ( fget = _options ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" <EOL> class ConfigManager ( models . Manager ) : <EOL> def get_current ( self , site = None ) : <EOL> """<STR_LIT>""" <EOL> if not site : <EOL> site = Site . objects . get_current ( ) <EOL> site = site . id <EOL> try : <EOL> shop_config = keyedcache . cache_get ( "<STR_LIT>" , site ) <EOL> except keyedcache . NotCachedError , nce : <EOL> try : <EOL> shop_config = self . get ( site__id__exact = site ) <EOL> keyedcache . cache_set ( nce . key , value = shop_config ) <EOL> except Config . DoesNotExist : <EOL> log . warning ( "<STR_LIT>" , site ) <EOL> shop_config = NullConfig ( ) <EOL> return shop_config <EOL> class Config ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> site = models . OneToOneField ( Site , verbose_name = _ ( "<STR_LIT>" ) , primary_key = True ) <EOL> store_name = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:100> , unique = True ) <EOL> store_description = models . TextField ( _ ( "<STR_LIT>" ) , blank = True , null = True ) <EOL> store_email = models . EmailField ( _ ( "<STR_LIT>" ) , blank = True , null = True , max_length = <NUM_LIT> ) <EOL> street1 = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:50> , blank = True , null = True ) <EOL> street2 = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:50> , blank = True , null = True ) <EOL> city = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:50> , blank = True , null = True ) <EOL> state = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:30> , blank = True , null = True ) <EOL> postal_code = models . CharField ( _ ( "<STR_LIT>" ) , blank = True , null = True , max_length = <NUM_LIT:9> ) <EOL> country = models . ForeignKey ( Country , blank = False , null = False , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> phone = models . CharField ( _ ( "<STR_LIT>" ) , blank = True , null = True , max_length = <NUM_LIT:30> ) <EOL> in_country_only = models . BooleanField ( <EOL> _ ( "<STR_LIT>" ) , <EOL> default = True ) <EOL> sales_country = models . ForeignKey ( <EOL> Country , blank = True , null = True , <EOL> related_name = '<STR_LIT>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) ) <EOL> shipping_countries = models . ManyToManyField ( <EOL> Country , <EOL> blank = True , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> related_name = "<STR_LIT>" ) <EOL> objects = ConfigManager ( ) <EOL> def _options ( self ) : <EOL> return ConfigurationSettings ( ) <EOL> options = property ( fget = _options ) <EOL> def areas ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . in_country_only : <EOL> return self . sales_country . adminarea_set . filter ( active = True ) <EOL> else : <EOL> return None <EOL> def countries ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . in_country_only : <EOL> return Country . objects . filter ( pk = self . sales_country . pk ) <EOL> else : <EOL> return self . shipping_countries . filter ( active = True ) <EOL> def _base_url ( self , secure = False ) : <EOL> prefix = "<STR_LIT:http>" <EOL> if secure : <EOL> prefix += "<STR_LIT:s>" <EOL> return prefix + "<STR_LIT>" + self . site . domain <EOL> base_url = property ( fget = _base_url ) <EOL> def save ( self , ** kwargs ) : <EOL> keyedcache . cache_delete ( "<STR_LIT>" , self . site . id ) <EOL> mycountry = self . country <EOL> if mycountry : <EOL> if not self . sales_country : <EOL> log . debug ( "<STR_LIT>" , self , mycountry ) <EOL> self . sales_country = mycountry <EOL> else : <EOL> log . warn ( "<STR_LIT>" , self ) <EOL> super ( Config , self ) . save ( ** kwargs ) <EOL> keyedcache . cache_set ( "<STR_LIT>" , self . site . id , value = self ) <EOL> def __unicode__ ( self ) : <EOL> return self . store_name <EOL> class Meta : <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> class NullCart ( object ) : <EOL> """<STR_LIT>""" <EOL> desc = None <EOL> date_time_created = None <EOL> customer = None <EOL> total = Decimal ( "<STR_LIT:0>" ) <EOL> numItems = <NUM_LIT:0> <EOL> def add_item ( self , * args , ** kwargs ) : <EOL> pass <EOL> def remove_item ( self , * args , ** kwargs ) : <EOL> pass <EOL> def empty ( self ) : <EOL> pass <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def __iter__ ( self ) : <EOL> return iter ( [ ] ) <EOL> def __len__ ( self ) : <EOL> return <NUM_LIT:0> <EOL> class OrderCart ( NullCart ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , order ) : <EOL> self . _order = order <EOL> def _numItems ( self ) : <EOL> return self . _order . orderitem_set . count ( ) <EOL> numItems = property ( _numItems ) <EOL> def _cartitem_set ( self ) : <EOL> return self . _order . orderitem_set <EOL> cartitem_set = property ( _cartitem_set ) <EOL> def _total ( self ) : <EOL> return self . _order . balance <EOL> total = property ( _total ) <EOL> is_shippable = False <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . _order . id , len ( self ) ) <EOL> def __len__ ( self ) : <EOL> return self . numItems <EOL> class CartManager ( models . Manager ) : <EOL> def from_request ( self , request , create = False , return_nullcart = True ) : <EOL> """<STR_LIT>""" <EOL> cart = None <EOL> try : <EOL> contact = Contact . objects . from_request ( request , create = False ) <EOL> except Contact . DoesNotExist : <EOL> contact = None <EOL> if '<STR_LIT>' in request . session : <EOL> cartid = request . session [ '<STR_LIT>' ] <EOL> if cartid == "<STR_LIT>" : <EOL> log . debug ( "<STR_LIT>" ) <EOL> try : <EOL> order = Order . objects . from_request ( request ) <EOL> cart = OrderCart ( order ) <EOL> except Order . DoesNotExist : <EOL> pass <EOL> else : <EOL> try : <EOL> cart = Cart . objects . get ( id = cartid ) <EOL> except Cart . DoesNotExist : <EOL> log . debug ( '<STR_LIT>' ) <EOL> del request . session [ '<STR_LIT>' ] <EOL> if isinstance ( cart , NullCart ) and not isinstance ( cart , OrderCart ) and contact is not None : <EOL> carts = Cart . objects . filter ( customer = contact ) <EOL> if carts . count ( ) > <NUM_LIT:0> : <EOL> cart = carts [ <NUM_LIT:0> ] <EOL> request . session [ '<STR_LIT>' ] = cart . id <EOL> if not cart : <EOL> if create : <EOL> site = Site . objects . get_current ( ) <EOL> if contact is None : <EOL> cart = Cart ( site = site ) <EOL> else : <EOL> cart = Cart ( site = site , customer = contact ) <EOL> cart . save ( ) <EOL> request . session [ '<STR_LIT>' ] = cart . id <EOL> elif return_nullcart : <EOL> cart = NullCart ( ) <EOL> else : <EOL> raise Cart . DoesNotExist ( ) <EOL> return cart <EOL> class Cart ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> site = models . ForeignKey ( Site , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> desc = models . CharField ( _ ( "<STR_LIT>" ) , blank = True , null = True , max_length = <NUM_LIT:10> ) <EOL> date_time_created = models . DateTimeField ( _ ( "<STR_LIT>" ) ) <EOL> customer = models . ForeignKey ( Contact , blank = True , null = True , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> objects = CartManager ( ) <EOL> def _get_count ( self ) : <EOL> itemCount = <NUM_LIT:0> <EOL> for item in self . cartitem_set . all ( ) : <EOL> itemCount += item . quantity <EOL> return ( itemCount ) <EOL> numItems = property ( _get_count ) <EOL> def _get_discount ( self ) : <EOL> return self . undiscounted_total - self . total <EOL> discount = property ( _get_discount ) <EOL> def _get_total ( self , include_discount = True ) : <EOL> total = Decimal ( "<STR_LIT:0>" ) <EOL> for item in self . cartitem_set . all ( ) : <EOL> if include_discount : <EOL> total += item . line_total <EOL> else : <EOL> total += item . undiscounted_line_total <EOL> return ( total ) <EOL> total = property ( _get_total ) <EOL> def _get_undiscounted_total ( self ) : <EOL> return self . _get_total ( False ) <EOL> undiscounted_total = property ( _get_undiscounted_total ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . cartitem_set . all ( ) ) <EOL> def __len__ ( self ) : <EOL> return self . cartitem_set . count ( ) <EOL> def __nonzero__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def _is_empty ( self ) : <EOL> return self . cartitem_set . count ( ) == <NUM_LIT:0> <EOL> is_empty = property ( _is_empty ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % self . date_time_created <EOL> def add_item ( self , chosen_item , number_added , details = [ ] ) : <EOL> alreadyInCart = False <EOL> if '<STR_LIT>' in chosen_item . get_subtypes ( ) : <EOL> item_to_modify = CartItem ( cart = self , product = chosen_item , quantity = Decimal ( '<STR_LIT:0>' ) ) <EOL> else : <EOL> item_to_modify = CartItem ( cart = self , product = chosen_item , quantity = Decimal ( '<STR_LIT:0>' ) ) <EOL> for similarItem in self . cartitem_set . filter ( product__id = chosen_item . id ) : <EOL> looksTheSame = len ( details ) == similarItem . details . count ( ) <EOL> if looksTheSame : <EOL> for detail in details : <EOL> try : <EOL> similarItem . details . get ( <EOL> name = detail [ '<STR_LIT:name>' ] , <EOL> value = str ( detail [ '<STR_LIT:value>' ] ) , <EOL> price_change = detail [ '<STR_LIT>' ] <EOL> ) <EOL> except CartItemDetails . DoesNotExist : <EOL> looksTheSame = False <EOL> if looksTheSame : <EOL> item_to_modify = similarItem <EOL> alreadyInCart = True <EOL> break <EOL> signals . satchmo_cart_add_verify . send ( <EOL> self , <EOL> cart = self , <EOL> cartitem = item_to_modify , <EOL> added_quantity = number_added , <EOL> details = details ) <EOL> if not alreadyInCart : <EOL> self . cartitem_set . add ( item_to_modify ) <EOL> item_to_modify . quantity += number_added <EOL> item_to_modify . save ( ) <EOL> if not alreadyInCart : <EOL> for data in details : <EOL> item_to_modify . add_detail ( data ) <EOL> return item_to_modify <EOL> def remove_item ( self , chosen_item_id , number_removed ) : <EOL> item_to_modify = self . cartitem_set . get ( id = chosen_item_id ) <EOL> item_to_modify . quantity -= number_removed <EOL> if item_to_modify . quantity <= <NUM_LIT:0> : <EOL> item_to_modify . delete ( ) <EOL> self . save ( ) <EOL> def merge_carts ( self , src_cart ) : <EOL> """<STR_LIT>""" <EOL> for item in src_cart . cartitem_set . all ( ) : <EOL> self . add_item ( item . product , item . quantity , item . details . all ( ) ) <EOL> item . delete ( ) <EOL> self . save ( ) <EOL> def empty ( self ) : <EOL> for item in self . cartitem_set . all ( ) : <EOL> item . delete ( ) <EOL> self . save ( ) <EOL> def save ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not self . pk : <EOL> self . date_time_created = datetime . datetime . now ( ) <EOL> try : <EOL> site = self . site <EOL> except Site . DoesNotExist : <EOL> self . site = Site . objects . get_current ( ) <EOL> super ( Cart , self ) . save ( ** kwargs ) <EOL> def _get_shippable ( self ) : <EOL> """<STR_LIT>""" <EOL> for cartitem in self . cartitem_set . all ( ) : <EOL> if cartitem . is_shippable : <EOL> return True <EOL> return False <EOL> is_shippable = property ( _get_shippable ) <EOL> def get_shipment_list ( self ) : <EOL> """<STR_LIT>""" <EOL> items = [ ] <EOL> for cartitem in self . cartitem_set . all ( ) : <EOL> if cartitem . is_shippable : <EOL> p = cartitem . product <EOL> q = int ( cartitem . quantity . quantize ( Decimal ( '<STR_LIT:0>' ) , ROUND_CEILING ) ) <EOL> for single in range ( <NUM_LIT:0> , q ) : <EOL> items . append ( p ) <EOL> return items <EOL> class Meta : <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> class NullCartItem ( object ) : <EOL> def __init__ ( self , itemid ) : <EOL> self . id = itemid <EOL> self . quantity = Decimal ( '<STR_LIT:0>' ) <EOL> self . line_total = <NUM_LIT:0> <EOL> class CartItem ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> cart = models . ForeignKey ( Cart , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> product = models . ForeignKey ( Product , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> quantity = models . DecimalField ( _ ( "<STR_LIT>" ) , max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:6> ) <EOL> def _get_line_unitprice ( self , include_discount = True ) : <EOL> if config_value ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> qty = self . cart . numItems <EOL> else : <EOL> qty = self . quantity <EOL> self . qty_price = self . get_qty_price ( qty , include_discount = include_discount ) <EOL> self . detail_price = self . get_detail_price ( ) <EOL> if include_discount : <EOL> signals . satchmo_cartitem_price_query . send ( self , cartitem = self ) <EOL> price = self . qty_price + self . detail_price <EOL> del self . qty_price <EOL> del self . detail_price <EOL> return price <EOL> unit_price = property ( _get_line_unitprice ) <EOL> def _get_undiscounted_unitprice ( self ) : <EOL> return self . _get_line_unitprice ( include_discount = False ) <EOL> undiscounted_unit_price = property ( _get_undiscounted_unitprice ) <EOL> def get_detail_price ( self ) : <EOL> """<STR_LIT>""" <EOL> delta = Decimal ( "<STR_LIT:0>" ) <EOL> if self . has_details : <EOL> for detail in self . details . all ( ) : <EOL> if detail . price_change and detail . value : <EOL> delta += detail . price_change <EOL> return delta <EOL> def get_qty_price ( self , qty , include_discount = True ) : <EOL> """<STR_LIT>""" <EOL> return self . product . get_qty_price ( qty , include_discount = include_discount ) <EOL> def _get_line_total ( self ) : <EOL> return self . unit_price * self . quantity <EOL> line_total = property ( _get_line_total ) <EOL> def _get_undiscounted_line_total ( self ) : <EOL> return self . undiscounted_unit_price * self . quantity <EOL> undiscounted_line_total = property ( _get_undiscounted_line_total ) <EOL> def _get_description ( self ) : <EOL> return self . product . translated_name ( ) <EOL> description = property ( _get_description ) <EOL> def _is_shippable ( self ) : <EOL> return self . product . is_shippable <EOL> is_shippable = property ( fget = _is_shippable ) <EOL> def add_detail ( self , data ) : <EOL> detl = CartItemDetails ( <EOL> cartitem = self , <EOL> name = data [ '<STR_LIT:name>' ] , <EOL> value = data [ '<STR_LIT:value>' ] , <EOL> sort_order = data [ '<STR_LIT>' ] , <EOL> price_change = data [ '<STR_LIT>' ] ) <EOL> detl . save ( ) <EOL> def _has_details ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( self . details . count ( ) > <NUM_LIT:0> ) <EOL> has_details = property ( _has_details ) <EOL> def __unicode__ ( self ) : <EOL> money_format = force_unicode ( moneyfmt ( self . line_total ) ) <EOL> return u'<STR_LIT>' % ( self . quantity , self . product . name , <EOL> money_format ) <EOL> class Meta : <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> ordering = ( '<STR_LIT:id>' , ) <EOL> class CartItemDetails ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> cartitem = models . ForeignKey ( CartItem , related_name = '<STR_LIT>' , ) <EOL> value = models . TextField ( _ ( '<STR_LIT>' ) ) <EOL> name = models . CharField ( _ ( '<STR_LIT:name>' ) , max_length = <NUM_LIT:100> ) <EOL> price_change = CurrencyField ( _ ( "<STR_LIT>" ) , max_digits = <NUM_LIT:6> , <EOL> decimal_places = <NUM_LIT:2> , blank = True , null = True ) <EOL> sort_order = models . IntegerField ( _ ( "<STR_LIT>" ) , <EOL> help_text = _ ( "<STR_LIT>" ) ) <EOL> class Meta : <EOL> ordering = ( '<STR_LIT>' , ) <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> ORDER_CHOICES = ( <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ) <EOL> ORDER_STATUS = ( <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ) <EOL> class OrderManager ( models . Manager ) : <EOL> def from_request ( self , request ) : <EOL> """<STR_LIT>""" <EOL> order = None <EOL> if '<STR_LIT>' in request . session : <EOL> try : <EOL> order = Order . objects . get ( id = request . session [ '<STR_LIT>' ] ) <EOL> except Order . DoesNotExist : <EOL> pass <EOL> if not order : <EOL> del request . session [ '<STR_LIT>' ] <EOL> if not order : <EOL> raise Order . DoesNotExist ( ) <EOL> return order <EOL> def remove_partial_order ( self , request ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> order = Order . objects . from_request ( request ) <EOL> if not order . status : <EOL> del request . session [ '<STR_LIT>' ] <EOL> log . info ( "<STR_LIT>" , order . id ) <EOL> order . delete ( ) <EOL> return True <EOL> except Order . DoesNotExist : <EOL> pass <EOL> return False <EOL> class Order ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> site = models . ForeignKey ( Site , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> contact = models . ForeignKey ( Contact , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> ship_addressee = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT> , blank = True ) <EOL> ship_street1 = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT> , blank = True ) <EOL> ship_street2 = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT> , blank = True ) <EOL> ship_city = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:50> , blank = True ) <EOL> ship_state = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:50> , blank = True ) <EOL> ship_postal_code = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:30> , blank = True ) <EOL> ship_country = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:2> , blank = True ) <EOL> bill_addressee = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT> , blank = True ) <EOL> bill_street1 = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT> , blank = True ) <EOL> bill_street2 = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT> , blank = True ) <EOL> bill_city = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:50> , blank = True ) <EOL> bill_state = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:50> , blank = True ) <EOL> bill_postal_code = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:30> , blank = True ) <EOL> bill_country = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:2> , blank = True ) <EOL> notes = models . TextField ( _ ( "<STR_LIT>" ) , blank = True , null = True ) <EOL> sub_total = CurrencyField ( _ ( "<STR_LIT>" ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> , blank = True , null = True , display_decimal = <NUM_LIT:4> ) <EOL> total = CurrencyField ( _ ( "<STR_LIT>" ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> , blank = True , null = True , display_decimal = <NUM_LIT:4> ) <EOL> discount_code = models . CharField ( <EOL> _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:20> , blank = True , null = True , <EOL> help_text = _ ( "<STR_LIT>" ) ) <EOL> discount = CurrencyField ( _ ( "<STR_LIT>" ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> , blank = True , null = True ) <EOL> method = models . CharField ( _ ( "<STR_LIT>" ) , <EOL> choices = ORDER_CHOICES , max_length = <NUM_LIT:50> , blank = True ) <EOL> shipping_description = models . CharField ( _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT:50> , blank = True , null = True ) <EOL> shipping_method = models . CharField ( _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT:50> , blank = True , null = True ) <EOL> shipping_model = ShippingChoiceCharField ( _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT:30> , blank = True , null = True ) <EOL> shipping_cost = CurrencyField ( _ ( "<STR_LIT>" ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> , blank = True , null = True ) <EOL> shipping_discount = CurrencyField ( _ ( "<STR_LIT>" ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> , blank = True , null = True ) <EOL> tax = CurrencyField ( _ ( "<STR_LIT>" ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> , blank = True , null = True ) <EOL> time_stamp = models . DateTimeField ( _ ( "<STR_LIT>" ) , blank = True , null = True ) <EOL> status = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:20> , choices = ORDER_STATUS , <EOL> blank = True , help_text = _ ( "<STR_LIT>" ) ) <EOL> objects = OrderManager ( ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . id , self . contact . full_name ) <EOL> def add_status ( self , status = None , notes = "<STR_LIT>" ) : <EOL> orderstatus = OrderStatus ( ) <EOL> if not status : <EOL> try : <EOL> curr_status = self . orderstatus_set . latest ( ) <EOL> status = curr_status . status <EOL> except OrderStatus . DoesNotExist : <EOL> status = '<STR_LIT>' <EOL> orderstatus . status = status <EOL> orderstatus . notes = notes <EOL> orderstatus . order = self <EOL> orderstatus . save ( ) <EOL> def add_variable ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> v = self . variables . get ( key__exact = key ) <EOL> v . value = value <EOL> except OrderVariable . DoesNotExist : <EOL> v = OrderVariable ( order = self , key = key , value = value ) <EOL> v . save ( ) <EOL> def _authorized_remaining ( self ) : <EOL> auths = [ p . amount for p in self . authorizations . filter ( complete = False ) ] <EOL> if auths : <EOL> amount = reduce ( operator . add , auths ) <EOL> else : <EOL> amount = Decimal ( '<STR_LIT>' ) <EOL> return amount <EOL> authorized_remaining = property ( fget = _authorized_remaining ) <EOL> def _get_count ( self ) : <EOL> itemCount = <NUM_LIT:0> <EOL> for item in self . orderitem_set . all ( ) : <EOL> itemCount += item . quantity <EOL> return ( itemCount ) <EOL> numItems = property ( _get_count ) <EOL> def get_variable ( self , key , default = None ) : <EOL> qry = self . variables . filter ( key__exact = key ) <EOL> ct = qry . count ( ) <EOL> if ct == <NUM_LIT:0> : <EOL> return default <EOL> else : <EOL> return qry [ <NUM_LIT:0> ] <EOL> def copy_addresses ( self ) : <EOL> """<STR_LIT>""" <EOL> shipaddress = self . contact . shipping_address <EOL> billaddress = self . contact . billing_address <EOL> self . ship_addressee = shipaddress . addressee <EOL> self . ship_street1 = shipaddress . street1 <EOL> self . ship_street2 = shipaddress . street2 <EOL> self . ship_city = shipaddress . city <EOL> self . ship_state = shipaddress . state <EOL> self . ship_postal_code = shipaddress . postal_code <EOL> self . ship_country = shipaddress . country . iso2_code <EOL> self . bill_addressee = billaddress . addressee <EOL> self . bill_street1 = billaddress . street1 <EOL> self . bill_street2 = billaddress . street2 <EOL> self . bill_city = billaddress . city <EOL> self . bill_state = billaddress . state <EOL> self . bill_postal_code = billaddress . postal_code <EOL> self . bill_country = billaddress . country . iso2_code <EOL> def remove_all_items ( self ) : <EOL> """<STR_LIT>""" <EOL> for item in self . orderitem_set . all ( ) : <EOL> item . delete ( ) <EOL> self . save ( ) <EOL> def _balance ( self ) : <EOL> if self . total is None : <EOL> self . force_recalculate_total ( save = True ) <EOL> return trunc_decimal ( self . total - self . balance_paid , <NUM_LIT:2> ) <EOL> balance = property ( fget = _balance ) <EOL> def balance_forward ( self ) : <EOL> return moneyfmt ( self . balance ) <EOL> balance_forward = property ( fget = balance_forward ) <EOL> def _balance_paid ( self ) : <EOL> payments = [ p . amount for p in self . payments . all ( ) ] <EOL> if payments : <EOL> paid = reduce ( operator . add , payments ) <EOL> else : <EOL> paid = Decimal ( "<STR_LIT>" ) <EOL> return paid + self . authorized_remaining <EOL> balance_paid = property ( _balance_paid ) <EOL> def _credit_card ( self ) : <EOL> """<STR_LIT>""" <EOL> from payment . models import CreditCardDetail <EOL> for payment in self . payments . order_by ( '<STR_LIT>' ) : <EOL> try : <EOL> if payment . creditcards . count ( ) > <NUM_LIT:0> : <EOL> return payment . creditcards . get ( ) <EOL> except CreditCardDetail . DoesNotExist : <EOL> pass <EOL> return None <EOL> credit_card = property ( _credit_card ) <EOL> def _full_bill_street ( self , delim = "<STR_LIT:\n>" ) : <EOL> """<STR_LIT>""" <EOL> if self . bill_street2 : <EOL> address = self . bill_street1 + delim + self . bill_street2 <EOL> else : <EOL> address = self . bill_street1 <EOL> return mark_safe ( address ) <EOL> full_bill_street = property ( _full_bill_street ) <EOL> def _full_ship_street ( self , delim = "<STR_LIT:\n>" ) : <EOL> """<STR_LIT>""" <EOL> if self . ship_street2 : <EOL> address = self . ship_street1 + delim + self . ship_street2 <EOL> else : <EOL> address = self . ship_street1 <EOL> return mark_safe ( address ) <EOL> full_ship_street = property ( _full_ship_street ) <EOL> def _ship_country_name ( self ) : <EOL> return Country . objects . get ( iso2_code = self . ship_country ) . name <EOL> ship_country_name = property ( _ship_country_name ) <EOL> def _bill_country_name ( self ) : <EOL> return Country . objects . get ( iso2_code = self . bill_country ) . name <EOL> bill_country_name = property ( _bill_country_name ) <EOL> def _ship_first_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:U+0020>' . join ( self . ship_addressee . split ( ) [ <NUM_LIT:0> : - <NUM_LIT:1> ] ) or '<STR_LIT>' <EOL> ship_first_name = property ( _ship_first_name ) <EOL> def _ship_last_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:U+0020>' . join ( self . ship_addressee . split ( ) [ - <NUM_LIT:1> : ] ) or '<STR_LIT>' <EOL> ship_last_name = property ( _ship_last_name ) <EOL> def _discounted_sub_total ( self ) : <EOL> return self . sub_total - self . item_discount <EOL> discounted_sub_total = property ( _discounted_sub_total ) <EOL> def _get_balance_remaining_url ( self ) : <EOL> return ( '<STR_LIT>' , None , { '<STR_LIT>' : self . id } ) <EOL> get_balance_remaining_url = models . permalink ( _get_balance_remaining_url ) <EOL> def _partially_paid ( self ) : <EOL> return self . balance_paid > Decimal ( "<STR_LIT>" ) <EOL> partially_paid = property ( _partially_paid ) <EOL> def _is_partially_paid ( self ) : <EOL> if self . total : <EOL> return ( <EOL> float ( self . balance ) > <NUM_LIT:0.0> <EOL> and float ( self . balance_paid ) > <NUM_LIT:0.0> <EOL> and self . balance != self . balance_paid <EOL> ) <EOL> else : <EOL> return False <EOL> is_partially_paid = property ( fget = _is_partially_paid ) <EOL> def payments_completed ( self ) : <EOL> q = self . payments . exclude ( transaction_id__isnull = False , transaction_id = "<STR_LIT>" ) <EOL> result = [ p for p in q if p . amount ] <EOL> return result <EOL> def save ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not self . pk : <EOL> self . time_stamp = datetime . datetime . now ( ) <EOL> self . copy_addresses ( ) <EOL> super ( Order , self ) . save ( ** kwargs ) <EOL> def invoice ( self ) : <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , None , None , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:id>' : self . id } ) <EOL> return mark_safe ( u'<STR_LIT>' % ( url , ugettext ( '<STR_LIT>' ) ) ) <EOL> invoice . allow_tags = True <EOL> def _item_discount ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . discount - self . shipping_discount <EOL> item_discount = property ( _item_discount ) <EOL> def packingslip ( self ) : <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , None , None , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:id>' : self . id } ) <EOL> return mark_safe ( u'<STR_LIT>' % ( url , ugettext ( '<STR_LIT>' ) ) ) <EOL> packingslip . allow_tags = True <EOL> def recalculate_total ( self , save = True ) : <EOL> """<STR_LIT>""" <EOL> if self . is_partially_paid : <EOL> log . debug ( "<STR_LIT>" , self . id ) <EOL> else : <EOL> self . force_recalculate_total ( save = save ) <EOL> def force_recalculate_total ( self , save = True ) : <EOL> """<STR_LIT>""" <EOL> zero = Decimal ( "<STR_LIT>" ) <EOL> total_discount = Decimal ( "<STR_LIT>" ) <EOL> discount = Discount . objects . by_code ( self . discount_code ) <EOL> discount . calc ( self ) <EOL> discounts = discount . item_discounts <EOL> itemprices = [ ] <EOL> fullprices = [ ] <EOL> qty_override = config_value ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if qty_override : <EOL> itemct = self . numItems <EOL> for lineitem in self . orderitem_set . all ( ) : <EOL> lid = lineitem . id <EOL> if lid in discounts : <EOL> lineitem . discount = discounts [ lid ] <EOL> total_discount += lineitem . discount <EOL> else : <EOL> lineitem . discount = zero <EOL> if qty_override : <EOL> qty = itemct <EOL> else : <EOL> qty = lineitem . quantity <EOL> adjustment = get_product_quantity_adjustments ( lineitem . product , qty = qty ) <EOL> if adjustment and adjustment . price : <EOL> baseprice = adjustment . price . price <EOL> finalprice = adjustment . final_price ( ) <EOL> baseprice += lineitem . get_detail_price ( ) <EOL> finalprice += lineitem . get_detail_price ( ) <EOL> if baseprice > finalprice or baseprice != lineitem . unit_price : <EOL> unitdiscount = ( lineitem . discount / lineitem . quantity ) + baseprice - finalprice <EOL> unitdiscount = trunc_decimal ( unitdiscount , <NUM_LIT:2> ) <EOL> linediscount = unitdiscount * lineitem . quantity <EOL> total_discount += linediscount <EOL> fullydiscounted = ( baseprice - unitdiscount ) * lineitem . quantity <EOL> lineitem . unit_price = baseprice <EOL> lineitem . discount = linediscount <EOL> lineitem . line_item_price = baseprice * lineitem . quantity <EOL> log . debug ( '<STR_LIT>' , <EOL> lineitem . product . slug , baseprice , unitdiscount , lineitem . quantity , fullydiscounted ) <EOL> if save : <EOL> lineitem . save ( ) <EOL> itemprices . append ( lineitem . sub_total ) <EOL> fullprices . append ( lineitem . line_item_price ) <EOL> shipprice = Price ( ) <EOL> shipprice . price = self . shipping_cost <EOL> shipadjust = PriceAdjustmentCalc ( shipprice ) <EOL> if '<STR_LIT>' in discounts : <EOL> shipadjust += PriceAdjustment ( '<STR_LIT>' , _ ( '<STR_LIT>' ) , discounts [ '<STR_LIT>' ] ) <EOL> signals . satchmo_shipping_price_query . send ( self , adjustment = shipadjust ) <EOL> shipdiscount = shipadjust . total_adjustment ( ) <EOL> self . shipping_discount = shipdiscount <EOL> total_discount += shipdiscount <EOL> self . discount = total_discount <EOL> if itemprices : <EOL> item_sub_total = reduce ( operator . add , itemprices ) <EOL> else : <EOL> item_sub_total = zero <EOL> if fullprices : <EOL> full_sub_total = reduce ( operator . add , fullprices ) <EOL> else : <EOL> full_sub_total = zero <EOL> self . sub_total = full_sub_total <EOL> taxProcessor = get_tax_processor ( self ) <EOL> totaltax , taxrates = taxProcessor . process ( ) <EOL> self . tax = totaltax <EOL> for taxdetl in self . taxes . all ( ) : <EOL> taxdetl . delete ( ) <EOL> for taxdesc , taxamt in taxrates . items ( ) : <EOL> taxdetl = OrderTaxDetail ( order = self , tax = taxamt , description = taxdesc , method = taxProcessor . method ) <EOL> taxdetl . save ( ) <EOL> log . debug ( "<STR_LIT>" , <EOL> self . id , <EOL> moneyfmt ( item_sub_total ) , <EOL> moneyfmt ( self . shipping_sub_total ) , <EOL> moneyfmt ( self . discount ) , <EOL> moneyfmt ( self . tax ) ) <EOL> self . total = Decimal ( item_sub_total + self . shipping_sub_total + self . tax ) <EOL> if save : <EOL> self . save ( ) <EOL> def shippinglabel ( self ) : <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , None , None , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:id>' : self . id } ) <EOL> return mark_safe ( u'<STR_LIT>' % ( url , ugettext ( '<STR_LIT>' ) ) ) <EOL> shippinglabel . allow_tags = True <EOL> def _order_total ( self ) : <EOL> return moneyfmt ( self . total ) <EOL> order_total = property ( _order_total ) <EOL> def order_success ( self ) : <EOL> """<STR_LIT>""" <EOL> log . info ( "<STR_LIT>" , self ) <EOL> for orderitem in self . orderitem_set . all ( ) : <EOL> subtype = orderitem . product . get_subtype_with_attr ( '<STR_LIT>' ) <EOL> if subtype : <EOL> subtype . order_success ( self , orderitem ) <EOL> signals . order_success . send ( self , order = self ) <EOL> def order_cancel ( self ) : <EOL> """<STR_LIT>""" <EOL> self . is_cancellable = self . status not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> signals . order_cancel_query . send ( self , order = self ) <EOL> if self . is_cancellable : <EOL> self . add_status ( '<STR_LIT>' ) <EOL> signals . order_cancelled . send ( self , order = self ) <EOL> return self . is_cancellable <EOL> def _paid_in_full ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . balance == Decimal ( '<STR_LIT>' ) <EOL> paid_in_full = property ( fget = _paid_in_full ) <EOL> def _has_downloads ( self ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in settings . INSTALLED_APPS and self . downloadlink_set . count ( ) > <NUM_LIT:0> : <EOL> return True <EOL> return False <EOL> has_downloads = property ( _has_downloads ) <EOL> def _is_downloadable ( self ) : <EOL> """<STR_LIT>""" <EOL> for orderitem in self . orderitem_set . all ( ) : <EOL> if not orderitem . product . is_downloadable : <EOL> return False <EOL> return True <EOL> is_downloadable = property ( _is_downloadable ) <EOL> def _is_shippable ( self ) : <EOL> """<STR_LIT>""" <EOL> for orderitem in self . orderitem_set . all ( ) : <EOL> if orderitem . is_shippable : <EOL> return True <EOL> return False <EOL> is_shippable = property ( _is_shippable ) <EOL> def _shipping_sub_total ( self ) : <EOL> if self . shipping_cost is None : <EOL> self . shipping_cost = Decimal ( '<STR_LIT>' ) <EOL> if self . shipping_discount is None : <EOL> self . shipping_discount = Decimal ( '<STR_LIT>' ) <EOL> return self . shipping_cost - self . shipping_discount <EOL> shipping_sub_total = property ( _shipping_sub_total ) <EOL> def _shipping_tax ( self ) : <EOL> rates = self . taxes . filter ( description__iexact = '<STR_LIT>' ) <EOL> if rates . count ( ) > <NUM_LIT:0> : <EOL> tax = reduce ( operator . add , [ t . tax for t in rates ] ) <EOL> else : <EOL> tax = Decimal ( "<STR_LIT>" ) <EOL> return tax <EOL> shipping_tax = property ( _shipping_tax ) <EOL> def _shipping_with_tax ( self ) : <EOL> return self . shipping_sub_total + self . shipping_tax <EOL> shipping_with_tax = property ( _shipping_with_tax ) <EOL> def sub_total_with_tax ( self ) : <EOL> return reduce ( operator . add , [ o . total_with_tax for o in self . orderitem_set . all ( ) ] ) <EOL> def update_status ( self , status ) : <EOL> """<STR_LIT>""" <EOL> oldstatus = self . status <EOL> self . status = status <EOL> self . save ( ) <EOL> if ( oldstatus != self . status ) : <EOL> signals . satchmo_order_status_changed . send ( self , oldstatus = oldstatus , newstatus = status , order = self ) <EOL> def validate ( self , request ) : <EOL> """<STR_LIT>""" <EOL> valid = True <EOL> for orderitem in self . orderitem_set . all ( ) : <EOL> for subtype_name in orderitem . product . get_subtypes ( ) : <EOL> subtype = getattr ( orderitem . product , subtype_name . lower ( ) ) <EOL> validate_method = getattr ( subtype , '<STR_LIT>' , None ) <EOL> if validate_method : <EOL> valid = valid and validate_method ( request , self , orderitem ) <EOL> return valid <EOL> class Meta : <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> class OrderItem ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> order = models . ForeignKey ( Order , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> product = models . ForeignKey ( Product , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> quantity = models . DecimalField ( _ ( "<STR_LIT>" ) , max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:6> ) <EOL> unit_price = CurrencyField ( _ ( "<STR_LIT>" ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> ) <EOL> unit_tax = CurrencyField ( _ ( "<STR_LIT>" ) , default = Decimal ( '<STR_LIT>' ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> ) <EOL> line_item_price = CurrencyField ( _ ( "<STR_LIT>" ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> ) <EOL> tax = CurrencyField ( _ ( "<STR_LIT>" ) , default = Decimal ( '<STR_LIT>' ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> ) <EOL> expire_date = models . DateField ( _ ( "<STR_LIT>" ) , help_text = _ ( "<STR_LIT>" ) , blank = True , null = True ) <EOL> completed = models . BooleanField ( _ ( "<STR_LIT>" ) , default = False ) <EOL> discount = CurrencyField ( _ ( "<STR_LIT>" ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> , blank = True , null = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . product . translated_name ( ) <EOL> def _get_category ( self ) : <EOL> return ( self . product . get_category . translated_name ( ) ) <EOL> category = property ( _get_category ) <EOL> def _is_shippable ( self ) : <EOL> return self . product . is_shippable <EOL> is_shippable = property ( fget = _is_shippable ) <EOL> def _has_details ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( self . orderitemdetail_set . count ( ) > <NUM_LIT:0> ) <EOL> has_details = property ( _has_details ) <EOL> def get_detail_price ( self ) : <EOL> """<STR_LIT>""" <EOL> delta = Decimal ( "<STR_LIT>" ) <EOL> if self . has_details : <EOL> for detail in self . orderitemdetail_set . all ( ) : <EOL> if detail . price_change and detail . value : <EOL> delta += detail . price_change <EOL> return delta <EOL> def _sub_total ( self ) : <EOL> if self . discount : <EOL> return self . line_item_price - self . discount <EOL> else : <EOL> return self . line_item_price <EOL> sub_total = property ( _sub_total ) <EOL> def _total_with_tax ( self ) : <EOL> return self . sub_total + self . tax <EOL> total_with_tax = property ( _total_with_tax ) <EOL> def _unit_price_with_tax ( self ) : <EOL> return self . unit_price + self . unit_tax <EOL> unit_price_with_tax = property ( _unit_price_with_tax ) <EOL> def _get_description ( self ) : <EOL> return self . product . translated_name ( ) <EOL> description = property ( _get_description ) <EOL> def _get_line_total ( self ) : <EOL> return self . unit_price * self . quantity <EOL> line_total = property ( _get_line_total ) <EOL> def save ( self , ** kwargs ) : <EOL> self . update_tax ( ) <EOL> super ( OrderItem , self ) . save ( ** kwargs ) <EOL> def update_tax ( self ) : <EOL> taxclass = self . product . taxClass <EOL> processor = get_tax_processor ( order = self . order ) <EOL> if self . product . taxable : <EOL> self . unit_tax = processor . by_price ( taxclass , self . unit_price ) <EOL> self . tax = processor . by_orderitem ( self ) <EOL> class Meta : <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> ordering = ( '<STR_LIT:id>' , ) <EOL> class OrderItemDetail ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> item = models . ForeignKey ( OrderItem , verbose_name = _ ( "<STR_LIT>" ) , ) <EOL> name = models . CharField ( _ ( '<STR_LIT:Name>' ) , max_length = <NUM_LIT:100> ) <EOL> value = models . CharField ( _ ( '<STR_LIT>' ) , max_length = <NUM_LIT:255> ) <EOL> price_change = CurrencyField ( _ ( "<STR_LIT>" ) , max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> , blank = True , null = True ) <EOL> sort_order = models . IntegerField ( _ ( "<STR_LIT>" ) , <EOL> help_text = _ ( "<STR_LIT>" ) ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . item , self . name , self . value ) <EOL> class Meta : <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> ordering = ( '<STR_LIT>' , ) <EOL> class OrderStatus ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> order = models . ForeignKey ( Order , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> status = models . CharField ( _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT:20> , choices = ORDER_STATUS , blank = True ) <EOL> notes = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:100> , blank = True ) <EOL> time_stamp = models . DateTimeField ( _ ( "<STR_LIT>" ) ) <EOL> def __unicode__ ( self ) : <EOL> return self . status <EOL> def save ( self , ** kwargs ) : <EOL> if not self . pk and not self . time_stamp : <EOL> self . time_stamp = datetime . datetime . now ( ) <EOL> super ( OrderStatus , self ) . save ( ** kwargs ) <EOL> self . order . update_status ( self . status ) <EOL> class Meta : <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> ordering = ( '<STR_LIT>' , ) <EOL> get_latest_by = '<STR_LIT>' <EOL> class OrderPaymentBase ( models . Model ) : <EOL> payment = PaymentChoiceCharField ( _ ( "<STR_LIT>" ) , <EOL> max_length = <NUM_LIT> , blank = True ) <EOL> amount = CurrencyField ( _ ( "<STR_LIT>" ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> , blank = True , null = True ) <EOL> time_stamp = models . DateTimeField ( _ ( "<STR_LIT>" ) , blank = True , null = True ) <EOL> transaction_id = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT> , blank = True , null = True ) <EOL> details = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:255> , blank = True , null = True ) <EOL> reason_code = models . CharField ( _ ( '<STR_LIT>' ) , max_length = <NUM_LIT:255> , blank = True , null = True ) <EOL> def _credit_card ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . creditcards . get ( ) <EOL> except self . creditcards . model . DoesNotExist : <EOL> return None <EOL> credit_card = property ( _credit_card ) <EOL> def _amount_total ( self ) : <EOL> return moneyfmt ( self . amount ) <EOL> amount_total = property ( fget = _amount_total ) <EOL> def save ( self , ** kwargs ) : <EOL> if not self . pk : <EOL> self . time_stamp = datetime . datetime . now ( ) <EOL> super ( OrderPaymentBase , self ) . save ( ** kwargs ) <EOL> class Meta : <EOL> abstract = True <EOL> class OrderAuthorization ( OrderPaymentBase ) : <EOL> order = models . ForeignKey ( Order , related_name = "<STR_LIT>" ) <EOL> capture = models . ForeignKey ( '<STR_LIT>' , related_name = "<STR_LIT>" ) <EOL> complete = models . BooleanField ( _ ( '<STR_LIT>' ) , default = False ) <EOL> def __unicode__ ( self ) : <EOL> if self . id is not None : <EOL> return u"<STR_LIT>" % self . id <EOL> else : <EOL> return u"<STR_LIT>" <EOL> def remaining ( self ) : <EOL> payments = [ p . amount for p in self . order . payments . all ( ) ] <EOL> if payments : <EOL> amount = reduce ( operator . add , payments ) <EOL> else : <EOL> amount = Decimal ( '<STR_LIT>' ) <EOL> remaining = self . order . total - amount <EOL> if remaining > self . amount : <EOL> remaining = self . amount <EOL> return trunc_decimal ( remaining , <NUM_LIT:2> ) <EOL> def save ( self , ** kwargs ) : <EOL> try : <EOL> capture = self . capture <EOL> except OrderPayment . DoesNotExist : <EOL> log . debug ( '<STR_LIT>' ) <EOL> log . debug ( '<STR_LIT>' , self . order ) <EOL> self . capture = OrderPayment . objects . create_linked ( self ) <EOL> super ( OrderPaymentBase , self ) . save ( ** kwargs ) <EOL> class Meta : <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> class OrderPaymentManager ( models . Manager ) : <EOL> def create_linked ( self , other , ** kwargs ) : <EOL> linked = OrderPayment ( <EOL> order = other . order , <EOL> payment = other . payment , <EOL> amount = Decimal ( '<STR_LIT>' ) , <EOL> transaction_id = "<STR_LIT>" , <EOL> details = other . details , <EOL> reason_code = "<STR_LIT>" ) <EOL> linked . save ( ** kwargs ) <EOL> return linked <EOL> class OrderPayment ( OrderPaymentBase ) : <EOL> order = models . ForeignKey ( Order , related_name = "<STR_LIT>" ) <EOL> objects = OrderPaymentManager ( ) <EOL> def __unicode__ ( self ) : <EOL> if self . id is not None : <EOL> return u"<STR_LIT>" % self . id <EOL> else : <EOL> return u"<STR_LIT>" <EOL> class Meta : <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> class OrderPendingPayment ( OrderPaymentBase ) : <EOL> order = models . ForeignKey ( Order , related_name = "<STR_LIT>" ) <EOL> capture = models . ForeignKey ( '<STR_LIT>' , related_name = "<STR_LIT>" ) <EOL> def __unicode__ ( self ) : <EOL> if self . id is not None : <EOL> return u"<STR_LIT>" % self . id <EOL> else : <EOL> return u"<STR_LIT>" <EOL> def save ( self , ** kwargs ) : <EOL> try : <EOL> capture = self . capture <EOL> except OrderPayment . DoesNotExist : <EOL> log . debug ( '<STR_LIT>' ) <EOL> self . capture = OrderPayment . objects . create_linked ( self , ** kwargs ) <EOL> super ( OrderPaymentBase , self ) . save ( ** kwargs ) <EOL> class Meta : <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> class OrderPaymentFailure ( OrderPaymentBase ) : <EOL> order = models . ForeignKey ( Order , null = True , blank = True , related_name = '<STR_LIT>' ) <EOL> class OrderVariable ( models . Model ) : <EOL> order = models . ForeignKey ( Order , related_name = "<STR_LIT>" ) <EOL> key = models . SlugField ( _ ( '<STR_LIT:key>' ) , ) <EOL> value = models . CharField ( _ ( '<STR_LIT:value>' ) , max_length = <NUM_LIT:100> ) <EOL> class Meta : <EOL> ordering = ( '<STR_LIT:key>' , ) <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> verbose_name_plural = _ ( "<STR_LIT>" ) <EOL> def __unicode__ ( self ) : <EOL> if len ( self . value ) > <NUM_LIT:10> : <EOL> v = self . value [ : <NUM_LIT:10> ] + '<STR_LIT>' <EOL> else : <EOL> v = self . value <EOL> return u"<STR_LIT>" % ( self . key , v ) <EOL> class OrderTaxDetail ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> order = models . ForeignKey ( Order , related_name = "<STR_LIT>" ) <EOL> method = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:50> , ) <EOL> description = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:50> , blank = True ) <EOL> tax = CurrencyField ( _ ( "<STR_LIT>" ) , <EOL> max_digits = <NUM_LIT> , decimal_places = <NUM_LIT:10> , blank = True , null = True ) <EOL> def __unicode__ ( self ) : <EOL> if self . description : <EOL> return u"<STR_LIT>" % ( self . description , self . tax ) <EOL> else : <EOL> return u"<STR_LIT>" % self . tax <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> ordering = ( '<STR_LIT:id>' , ) <EOL> import config <EOL> import listeners <EOL> listeners . start_default_listening ( ) </s>
