<s> from decimal import Decimal <EOL> from django . conf import settings <EOL> from django . db import models <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from l10n . utils import lookup_translation <EOL> from product . models import Product , OptionGroup , get_product_quantity_price , get_product_quantity_adjustments <EOL> from product . modules . configurable . models import get_all_options <EOL> from satchmo_utils . fields import CurrencyField <EOL> from satchmo_utils . unique_id import slugify <EOL> SATCHMO_PRODUCT = True <EOL> def get_product_types ( ) : <EOL> return ( '<STR_LIT>' , ) <EOL> class CustomProduct ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> product = models . OneToOneField ( Product , verbose_name = _ ( '<STR_LIT>' ) , primary_key = True ) <EOL> downpayment = models . IntegerField ( _ ( "<STR_LIT>" ) , default = <NUM_LIT:20> ) <EOL> deferred_shipping = models . BooleanField ( _ ( '<STR_LIT>' ) , <EOL> help_text = _ ( '<STR_LIT>' ) , <EOL> default = False ) <EOL> option_group = models . ManyToManyField ( <EOL> OptionGroup , <EOL> verbose_name = _ ( '<STR_LIT>' ) , <EOL> blank = True ) <EOL> def _is_shippable ( self ) : <EOL> return not self . deferred_shipping <EOL> is_shippable = property ( fget = _is_shippable ) <EOL> def _get_fullPrice ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get_qty_price ( Decimal ( '<STR_LIT:1>' ) ) <EOL> unit_price = property ( _get_fullPrice ) <EOL> def add_template_context ( self , context , selected_options , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> from product . utils import serialize_options <EOL> options = serialize_options ( self , selected_options ) <EOL> if not '<STR_LIT>' in context : <EOL> context [ '<STR_LIT>' ] = options <EOL> else : <EOL> curr = list ( context [ '<STR_LIT>' ] ) <EOL> curr . extend ( list ( options ) ) <EOL> context [ '<STR_LIT>' ] = curr <EOL> return context <EOL> def get_qty_price ( self , qty , include_discount = True ) : <EOL> """<STR_LIT>""" <EOL> if include_discount : <EOL> price = get_product_quantity_price ( self . product , qty ) <EOL> else : <EOL> adjustment = get_product_quantity_adjustments ( self , qty ) <EOL> if adjustment . price is not None : <EOL> price = adjustment . price . price <EOL> else : <EOL> price = None <EOL> if not price and qty == Decimal ( '<STR_LIT:1>' ) : <EOL> price = Decimal ( "<STR_LIT>" ) <EOL> elif not price : <EOL> price = self . product . _get_fullPrice ( ) <EOL> return price * self . downpayment / <NUM_LIT:100> <EOL> def get_full_price ( self , qty = Decimal ( '<STR_LIT:1>' ) ) : <EOL> """<STR_LIT>""" <EOL> price = get_product_quantity_price ( self . product , qty ) <EOL> if not price : <EOL> price = self . product . unit_price <EOL> return price <EOL> full_price = property ( fget = get_full_price ) <EOL> def _get_subtype ( self ) : <EOL> return '<STR_LIT>' <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % self . product . name <EOL> def get_valid_options ( self ) : <EOL> """<STR_LIT>""" <EOL> return get_all_options ( self , ids_only = True ) <EOL> def save ( self , ** kwargs ) : <EOL> if hasattr ( self . product , '<STR_LIT>' ) : <EOL> del self . product . _sub_types <EOL> super ( CustomProduct , self ) . save ( ** kwargs ) <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> class CustomTextField ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( _ ( '<STR_LIT>' ) , max_length = <NUM_LIT> , ) <EOL> slug = models . SlugField ( _ ( "<STR_LIT>" ) , help_text = _ ( "<STR_LIT>" ) , <EOL> blank = True ) <EOL> products = models . ForeignKey ( CustomProduct , verbose_name = _ ( '<STR_LIT>' ) , <EOL> related_name = '<STR_LIT>' ) <EOL> sort_order = models . IntegerField ( _ ( "<STR_LIT>" ) , <EOL> help_text = _ ( "<STR_LIT>" ) , default = <NUM_LIT:0> ) <EOL> price_change = CurrencyField ( _ ( "<STR_LIT>" ) , max_digits = <NUM_LIT> , <EOL> decimal_places = <NUM_LIT:6> , blank = True , null = True ) <EOL> def save ( self , ** kwargs ) : <EOL> if not self . slug : <EOL> self . slug = slugify ( self . name , instance = self ) <EOL> super ( CustomTextField , self ) . save ( ** kwargs ) <EOL> def translated_name ( self , language_code = None ) : <EOL> return lookup_translation ( self , '<STR_LIT:name>' , language_code ) <EOL> class Meta : <EOL> ordering = ( '<STR_LIT>' , ) <EOL> unique_together = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class CustomTextFieldTranslation ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> customtextfield = models . ForeignKey ( CustomTextField , related_name = "<STR_LIT>" ) <EOL> languagecode = models . CharField ( _ ( '<STR_LIT>' ) , max_length = <NUM_LIT:10> , choices = settings . LANGUAGES ) <EOL> name = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:255> , ) <EOL> version = models . IntegerField ( _ ( '<STR_LIT:version>' ) , default = <NUM_LIT:1> ) <EOL> active = models . BooleanField ( _ ( '<STR_LIT>' ) , default = True ) <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> ordering = ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> unique_together = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:version>' ) <EOL> def __unicode__ ( self ) : <EOL> return u"<STR_LIT>" % ( self . languagecode , self . version , self . customtextfield , self . name ) </s>
