@@ -1285,15 +1285,24 @@ def _sibling_discount_get(self):
1285
1285
return self ._sibling_discount
1286
1286
1287
1287
def _sibling_discount_set (self , value ):
1288
+ from esp .accounting .models import LineItemType
1288
1289
if value is not None :
1289
1290
self ._sibling_discount = Decimal (value )
1290
1291
Tag .setTag ('sibling_discount' , target = self , value = self ._sibling_discount )
1292
+ LineItemType .objects .get_or_create (text = 'Sibling discount' , program = self , amount_dec = self ._sibling_discount )
1291
1293
else :
1292
1294
self ._sibling_discount = Decimal ('0.00' )
1293
1295
Tag .objects .filter (key = 'sibling_discount' , object_id = self .id ).delete ()
1296
+ LineItemType .objects .filter (text = 'Sibling discount' , program = self ).delete ()
1294
1297
1295
1298
sibling_discount = property (_sibling_discount_get , _sibling_discount_set )
1296
1299
1300
+ def base_cost (self ):
1301
+ from esp .accounting .controllers import ProgramAccountingController
1302
+ pac = ProgramAccountingController (self )
1303
+ return pac .default_admission_lineitemtype ().amount_dec
1304
+ base_cost = property (base_cost )
1305
+
1297
1306
@property
1298
1307
def splashinfo_objects (self ):
1299
1308
"""
@@ -1317,8 +1326,8 @@ class SplashInfo(models.Model):
1317
1326
student = AjaxForeignKey (ESPUser )
1318
1327
# Program field may be empty for backwards compatibility with Stanford data
1319
1328
program = AjaxForeignKey (Program , null = True )
1320
- lunchsat = models .CharField (max_length = 32 , blank = True , null = True )
1321
- lunchsun = models .CharField (max_length = 32 , blank = True , null = True )
1329
+ lunchsat = models .CharField (max_length = 32 , blank = True , null = True ) # No longer used, kept for backwards compatibility
1330
+ lunchsun = models .CharField (max_length = 32 , blank = True , null = True ) # No longer used, kept for backwards compatibility
1322
1331
siblingdiscount = models .NullBooleanField (default = False , blank = True )
1323
1332
siblingname = models .CharField (max_length = 64 , blank = True , null = True )
1324
1333
submitted = models .NullBooleanField (default = False , blank = True )
@@ -1351,62 +1360,22 @@ def getForUser(user, program=None):
1351
1360
n .save ()
1352
1361
return n
1353
1362
1354
- def pretty_version (self , attr_name ):
1355
- # Look up choices
1356
- tag_data = Tag .getProgramTag ('splashinfo_choices' , self .program )
1357
-
1358
- # Check for matching item in list of choices
1359
- if tag_data :
1360
- tag_struct = json .loads (tag_data )
1361
- for item in tag_struct [attr_name ]:
1362
- if item [0 ] == getattr (self , attr_name ):
1363
- return item [1 ].decode ('utf-8' )
1364
-
1365
- return u'N/A'
1366
-
1367
- def pretty_satlunch (self ):
1368
- return self .pretty_version ('lunchsat' )
1369
-
1370
- def pretty_sunlunch (self ):
1371
- return self .pretty_version ('lunchsun' )
1372
-
1373
1363
def execute_sibling_discount (self ):
1364
+ from esp .accounting .controllers import IndividualAccountingController
1365
+ from esp .accounting .models import Transfer
1366
+ iac = IndividualAccountingController (self .program , self .student )
1367
+ line_item_type = iac .default_siblingdiscount_lineitemtype ()
1368
+ source_account = iac .default_finaid_account ()
1369
+ dest_account = iac .default_source_account ()
1374
1370
if self .siblingdiscount :
1375
- from esp .accounting .controllers import IndividualAccountingController
1376
- from esp .accounting .models import Transfer
1377
- iac = IndividualAccountingController (self .program , self .student )
1378
- source_account = iac .default_finaid_account ()
1379
- dest_account = iac .default_source_account ()
1380
- line_item_type = iac .default_siblingdiscount_lineitemtype ()
1381
- transfer , created = Transfer .objects .get_or_create (source = source_account , destination = dest_account , user = self .student , line_item = line_item_type , amount_dec = Decimal ('20.00' ))
1371
+ transfer , created = Transfer .objects .get_or_create (source = source_account , destination = dest_account , user = self .student , line_item = line_item_type , amount_dec = self .program .sibling_discount )
1382
1372
return transfer
1373
+ else :
1374
+ Transfer .objects .filter (source = source_account , destination = dest_account , user = self .student , line_item = line_item_type ).delete ()
1383
1375
1384
1376
def save (self ):
1385
- from esp .accounting .controllers import IndividualAccountingController
1386
-
1387
- # We have two things to put in: "Saturday Lunch" and "Sunday Lunch".
1388
- # If they are not there, they will be created. These names are hard coded.
1389
- from esp .accounting .models import LineItemType
1390
- LineItemType .objects .get_or_create (program = self .program , text = 'Saturday Lunch' )
1391
- LineItemType .objects .get_or_create (program = self .program , text = 'Sunday Lunch' )
1392
-
1393
- # Figure out how much everything costs
1394
- cost_info = json .loads (Tag .getProgramTag ('splashinfo_costs' , self .program ))
1395
-
1396
- # Save accounting information
1397
- iac = IndividualAccountingController (self .program , self .student )
1398
-
1399
- if not self .lunchsat or self .lunchsat == 'no' :
1400
- iac .set_preference ('Saturday Lunch' , 0 )
1401
- elif 'lunchsat' in cost_info :
1402
- iac .set_preference ('Saturday Lunch' , 1 , cost_info ['lunchsat' ][self .lunchsat ])
1403
-
1404
- if not self .lunchsun or self .lunchsun == 'no' :
1405
- iac .set_preference ('Sunday Lunch' , 0 )
1406
- elif 'lunchsun' in cost_info :
1407
- iac .set_preference ('Sunday Lunch' , 1 , cost_info ['lunchsun' ][self .lunchsun ])
1408
-
1409
1377
super (SplashInfo , self ).save ()
1378
+ self .execute_sibling_discount ()
1410
1379
1411
1380
1412
1381
class RegistrationProfile (models .Model ):
0 commit comments