<s> import datetime <EOL> import os <EOL> import socket <EOL> from django . db import models <EOL> from core . models import PlCoreBase , Site , Slice , Instance , Deployment <EOL> from core . models . plcorebase import StrippedCharField <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . contenttypes import generic <EOL> from django . db . models import Sum <EOL> from django . utils import timezone <EOL> class Account ( PlCoreBase ) : <EOL> site = models . ForeignKey ( Site , related_name = "<STR_LIT>" , help_text = "<STR_LIT>" ) <EOL> @ property <EOL> def total_invoices ( self ) : <EOL> x = self . charges . filter ( invoice__isnull = False ) . aggregate ( Sum ( '<STR_LIT>' ) ) [ "<STR_LIT>" ] <EOL> if ( x == None ) : <EOL> return <NUM_LIT:0.0> <EOL> return x <EOL> @ property <EOL> def total_payments ( self ) : <EOL> x = self . payments . all ( ) . aggregate ( Sum ( '<STR_LIT>' ) ) [ "<STR_LIT>" ] <EOL> if ( x == None ) : <EOL> return <NUM_LIT:0.0> <EOL> return x <EOL> @ property <EOL> def balance_due ( self ) : <EOL> return self . total_invoices - self . total_payments <EOL> def __unicode__ ( self ) : return u'<STR_LIT:%s>' % ( self . site . name ) <EOL> class Invoice ( PlCoreBase ) : <EOL> date = models . DateTimeField ( ) <EOL> account = models . ForeignKey ( Account , related_name = "<STR_LIT>" ) <EOL> @ property <EOL> def amount ( self ) : <EOL> return str ( self . charges . all ( ) . aggregate ( Sum ( '<STR_LIT>' ) ) [ "<STR_LIT>" ] ) <EOL> def __unicode__ ( self ) : return u'<STR_LIT>' % ( self . account . site . name , str ( self . date ) ) <EOL> class UsableObject ( PlCoreBase ) : <EOL> name = StrippedCharField ( max_length = <NUM_LIT> ) <EOL> def __unicode__ ( self ) : return u'<STR_LIT:%s>' % ( self . name ) <EOL> class Payment ( PlCoreBase ) : <EOL> account = models . ForeignKey ( Account , related_name = "<STR_LIT>" ) <EOL> amount = models . FloatField ( default = <NUM_LIT:0.0> ) <EOL> date = models . DateTimeField ( default = timezone . now ) <EOL> def __unicode__ ( self ) : return u'<STR_LIT>' % ( self . account . site . name , self . amount , str ( self . date ) ) <EOL> class Charge ( PlCoreBase ) : <EOL> KIND_CHOICES = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> STATE_CHOICES = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> account = models . ForeignKey ( Account , related_name = "<STR_LIT>" ) <EOL> slice = models . ForeignKey ( Slice , related_name = "<STR_LIT>" , null = True , blank = True ) <EOL> kind = StrippedCharField ( max_length = <NUM_LIT:30> , choices = KIND_CHOICES , default = "<STR_LIT>" ) <EOL> state = StrippedCharField ( max_length = <NUM_LIT:30> , choices = STATE_CHOICES , default = "<STR_LIT>" ) <EOL> date = models . DateTimeField ( ) <EOL> object = models . ForeignKey ( UsableObject ) <EOL> amount = models . FloatField ( default = <NUM_LIT:0.0> ) <EOL> coreHours = models . FloatField ( default = <NUM_LIT:0.0> ) <EOL> invoice = models . ForeignKey ( Invoice , blank = True , null = True , related_name = "<STR_LIT>" ) <EOL> def __unicode__ ( self ) : return u'<STR_LIT>' % ( self . account . site . name , self . amount , str ( self . date ) ) </s>
