<s> from copy import deepcopy <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . contenttypes . fields import GenericForeignKey <EOL> from django . db import models <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from lfs . core . models import Country <EOL> from lfs . shipping . models import ShippingMethod <EOL> from lfs . payment . models import PaymentMethod <EOL> from lfs . addresses import settings <EOL> class Customer ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> user = models . ForeignKey ( User , blank = True , null = True ) <EOL> session = models . CharField ( blank = True , max_length = <NUM_LIT:100> ) <EOL> selected_shipping_method = models . ForeignKey ( ShippingMethod , verbose_name = _ ( u"<STR_LIT>" ) , blank = True , null = True , related_name = "<STR_LIT>" ) <EOL> selected_payment_method = models . ForeignKey ( PaymentMethod , verbose_name = _ ( u"<STR_LIT>" ) , blank = True , null = True , related_name = "<STR_LIT>" ) <EOL> selected_bank_account = models . ForeignKey ( "<STR_LIT>" , verbose_name = _ ( u"<STR_LIT>" ) , blank = True , null = True , related_name = "<STR_LIT>" ) <EOL> selected_credit_card = models . ForeignKey ( "<STR_LIT>" , verbose_name = _ ( u"<STR_LIT>" ) , blank = True , null = True , related_name = "<STR_LIT>" ) <EOL> sa_content_type = models . ForeignKey ( ContentType , related_name = "<STR_LIT>" , null = True ) <EOL> sa_object_id = models . PositiveIntegerField ( null = True ) <EOL> selected_shipping_address = GenericForeignKey ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> dsa_object_id = models . PositiveIntegerField ( null = True ) <EOL> default_shipping_address = GenericForeignKey ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ia_content_type = models . ForeignKey ( ContentType , related_name = "<STR_LIT>" , null = True ) <EOL> ia_object_id = models . PositiveIntegerField ( null = True ) <EOL> selected_invoice_address = GenericForeignKey ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> dia_object_id = models . PositiveIntegerField ( null = True ) <EOL> default_invoice_address = GenericForeignKey ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> selected_country = models . ForeignKey ( Country , verbose_name = _ ( u"<STR_LIT>" ) , blank = True , null = True ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . user , self . session ) <EOL> def get_email_address ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . user : <EOL> return self . user . email <EOL> elif self . selected_invoice_address : <EOL> return self . selected_invoice_address . email <EOL> else : <EOL> return None <EOL> def set_email_address ( self , email ) : <EOL> """<STR_LIT>""" <EOL> if self . user : <EOL> self . user . email = email <EOL> self . user . save ( ) <EOL> else : <EOL> self . selected_invoice_address . email = email <EOL> self . selected_invoice_address . save ( ) <EOL> def get_selected_shipping_address ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . selected_shipping_address or self . selected_invoice_address or None <EOL> def sync_default_to_selected_addresses ( self , force = False ) : <EOL> auto_update = settings . AUTO_UPDATE_DEFAULT_ADDRESSES <EOL> if force or not auto_update : <EOL> shipping_address = deepcopy ( self . default_shipping_address ) <EOL> if self . selected_shipping_address : <EOL> shipping_address . id = self . selected_shipping_address . id <EOL> shipping_address . pk = self . selected_shipping_address . pk <EOL> shipping_address . save ( ) <EOL> else : <EOL> shipping_address . id = None <EOL> shipping_address . pk = None <EOL> shipping_address . save ( ) <EOL> self . save ( ) <EOL> invoice_address = deepcopy ( self . default_invoice_address ) <EOL> if self . selected_invoice_address : <EOL> invoice_address . id = self . selected_invoice_address . id <EOL> invoice_address . pk = self . selected_invoice_address . pk <EOL> invoice_address . save ( ) <EOL> else : <EOL> invoice_address . id = None <EOL> invoice_address . pk = None <EOL> invoice_address . save ( ) <EOL> self . save ( ) <EOL> def sync_selected_to_default_invoice_address ( self , force = False ) : <EOL> auto_update = settings . AUTO_UPDATE_DEFAULT_ADDRESSES <EOL> if force or auto_update : <EOL> address = deepcopy ( self . selected_invoice_address ) <EOL> address . id = self . default_invoice_address . id <EOL> address . pk = self . default_invoice_address . pk <EOL> address . save ( ) <EOL> def sync_selected_to_default_shipping_address ( self , force = False ) : <EOL> auto_update = settings . AUTO_UPDATE_DEFAULT_ADDRESSES <EOL> if force or auto_update : <EOL> address = deepcopy ( self . selected_shipping_address ) <EOL> address . id = self . default_shipping_address . id <EOL> address . pk = self . default_shipping_address . pk <EOL> address . save ( ) <EOL> def sync_selected_to_default_addresses ( self , force = False ) : <EOL> self . sync_selected_to_default_invoice_address ( force ) <EOL> self . sync_selected_to_default_shipping_address ( force ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> class BankAccount ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> customer = models . ForeignKey ( Customer , verbose_name = _ ( u"<STR_LIT>" ) , blank = True , null = True , related_name = "<STR_LIT>" ) <EOL> account_number = models . CharField ( _ ( u"<STR_LIT>" ) , blank = True , max_length = <NUM_LIT:30> ) <EOL> bank_identification_code = models . CharField ( _ ( u"<STR_LIT>" ) , blank = True , max_length = <NUM_LIT:30> ) <EOL> bank_name = models . CharField ( _ ( u"<STR_LIT>" ) , blank = True , max_length = <NUM_LIT:100> ) <EOL> depositor = models . CharField ( _ ( u"<STR_LIT>" ) , blank = True , max_length = <NUM_LIT:100> ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . account_number , self . bank_name ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> class CreditCard ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> customer = models . ForeignKey ( Customer , verbose_name = _ ( u"<STR_LIT>" ) , blank = True , null = True , related_name = "<STR_LIT>" ) <EOL> type = models . CharField ( _ ( u"<STR_LIT>" ) , blank = True , max_length = <NUM_LIT:30> ) <EOL> owner = models . CharField ( _ ( u"<STR_LIT>" ) , blank = True , max_length = <NUM_LIT:100> ) <EOL> number = models . CharField ( _ ( u"<STR_LIT>" ) , blank = True , max_length = <NUM_LIT:30> ) <EOL> expiration_date_month = models . IntegerField ( _ ( u"<STR_LIT>" ) , blank = True , null = True ) <EOL> expiration_date_year = models . IntegerField ( _ ( u"<STR_LIT>" ) , blank = True , null = True ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . type , self . owner ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' </s>
