Statistics
| Branch: | Tag: | Revision:

root / logic / credits.py @ 7b7f9205

History | View | Annotate | Download (759 Bytes)

1
#
2
# Business Logic for all Credit related activity
3
#
4
# Copyright 2010 Greek Research and Technology Network
5
#
6
from datetime import datetime
7

    
8
from db.models import Debit
9
from django.db import transaction
10

    
11
@transaction.commit_on_success
12
def debit_account(user , amount, vm, description):
13
    """Charges the user with the specified amount of credits for a vm (resource)"""
14
    date_now = datetime.datetime.now()
15
    user.credit = user.credit - amount
16
    user.save()
17

    
18
    # then write the debit entry
19
    debit = Debit()
20
    debit.user = user
21
    debit.vm = vm
22
    debit.when = date_now
23
    debit.description = description
24
    debit.save()
25

    
26

    
27
@transaction.commit_on_success
28
def credit_account(self, amount, creditor, description):
29
    """No clue :)"""
30
    return