Revision 7b7f9205 db/models.py

b/db/models.py
2 2

  
3 3
from django.conf import settings
4 4
from django.db import models
5
from django.db import transaction
5

  
6
from logic.credits import debit_account
6 7

  
7 8
import datetime
8 9

  
......
51 52
        
52 53
    min_credits = property(_get_min_credits)
53 54

  
54
    @transaction.commit_on_success
55
    def debit_account(self, amount, vm, description):
56
        """Charges the user with the specified amount of credits for a vm (resource)"""
57
        date_now = datetime.datetime.now()
58
        self.credit = self.credit - amount
59
        self.save()
60

  
61
        # then write the debit entry
62
        debit = Debit()
63

  
64
        debit.user = self
65
        debit.vm = vm
66
        debit.when = date_now
67
        debit.description = description
68

  
69
        debit.save()
70

  
71
    def credit_account(self, amount, creditor, description):
72
        """No clue :)"""
73
        return
74

  
75 55

  
76 56
class Image(models.Model):
77 57
    # This is WIP, FIXME
......
506 486

  
507 487
            # add the debit entry
508 488
            description = "Server = %s, charge = %d for state: %s" % (self.name, total_cost, self._operstate)
509
            self.owner.debit_account(total_cost, self, description)
489
            debit_account(self.owner, total_cost, self, description)
510 490
        
511 491
        self.save()
512 492

  

Also available in: Unified diff