Changeset 1522

Show
Ignore:
Timestamp:
06/06/04 00:03:50 (20 years ago)
Author:
jalet
Message:

Payments history is now stored in database

Location:
pykota/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/initscripts/ldap/pykota.schema

    r1520 r1522  
    184184# pykotaPayments 
    185185attributetype ( 1.3.6.1.4.1.16868.1.1.26 NAME 'pykotaPayments' 
    186         DESC 'Stores all payments made by an user, encoded to store both date and amount' 
     186        DESC 'Stores all payments made by an user, encoded to store both date and amount, separated by a # between two spaces' 
    187187        EQUALITY caseExactIA5Match 
    188188        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) 
  • pykota/trunk/NEWS

    r1521 r1522  
    2323 
    2424 
     25    - 1.19alpha18 : 
     26     
     27        - History of payments is now stored in the database, and 
     28          updated each time an user's balance is modified with 
     29          edpykota --balance. This history represents each time 
     30          the user was given some positive or negative credit, 
     31          but doesn't reflect price paid for jobs, which appear 
     32          in the jobs history instead. 
     33           
    2534    - 1.19alpha17 : 
    2635     
  • pykota/trunk/pykota/storage.py

    r1520 r1522  
    2222# 
    2323# $Log$ 
     24# Revision 1.54  2004/06/05 22:03:49  jalet 
     25# Payments history is now stored in database 
     26# 
    2427# Revision 1.53  2004/06/03 23:14:10  jalet 
    2528# Now stores the job's size in bytes in the database. 
     
    230233        self.LifeTimePaid = None 
    231234        self.Email = None 
     235        self.Payments = [] # TODO : maybe handle this smartly for SQL, for now just don't retrieve them 
    232236         
    233237    def consumeAccountBalance(self, amount) :      
     
    238242    def setAccountBalance(self, balance, lifetimepaid) :     
    239243        """Sets the user's account balance in case he pays more money.""" 
    240         self.parent.writeUserAccountBalance(self, balance, lifetimepaid) 
    241         self.AccountBalance = balance 
    242         self.LifeTimePaid = lifetimepaid 
     244        diff = float(lifetimepaid or 0.0) - float(self.LifeTimePaid or 0.0) 
     245        self.parent.beginTransaction() 
     246        try : 
     247            self.parent.writeUserAccountBalance(self, balance, lifetimepaid) 
     248            self.parent.writeNewPayment(self, diff) 
     249        except PyKotaStorageError, msg :     
     250            self.parent.rollbackTransaction() 
     251            raise PyKotaStorageError, msg 
     252        else :     
     253            self.parent.commitTransaction() 
     254            self.AccountBalance = balance 
     255            self.LifeTimePaid = lifetimepaid 
    243256         
    244257    def setLimitBy(self, limitby) :     
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1520 r1522  
    2222# 
    2323# $Log$ 
     24# Revision 1.68  2004/06/05 22:03:50  jalet 
     25# Payments history is now stored in database 
     26# 
    2427# Revision 1.67  2004/06/03 23:14:10  jalet 
    2528# Now stores the job's size in bytes in the database. 
     
    257260import time 
    258261import md5 
     262from mx import DateTime 
    259263 
    260264from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageJob,StorageLastJob,StorageUserPQuota,StorageGroupPQuota 
     
    477481            if user.LimitBy is not None : 
    478482                user.LimitBy = user.LimitBy[0] 
    479             result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["balancerdn"], username), ["pykotaBalance", "pykotaLifeTimePaid"], base=self.info["balancebase"]) 
     483            result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["balancerdn"], username), ["pykotaBalance", "pykotaLifeTimePaid", "pykotaPayments"], base=self.info["balancebase"]) 
    480484            if result : 
    481485                fields = result[0][1] 
     
    495499                        user.LifeTimePaid = float(user.LifeTimePaid[0]) 
    496500                user.LifeTimePaid = user.LifeTimePaid or 0.0         
     501                user.Payments = [] 
     502                for payment in fields.get("pykotaPayments", []) : 
     503                    (date, amount) = payment.split(" # ") 
     504                    user.Payments.append((date, amount)) 
    497505            user.Exists = 1 
    498506        return user 
     
    944952        return self.doModify(user.idbalance, fields)          
    945953             
     954    def writeNewPayment(self, user, amount) :         
     955        """Adds a new payment to the payments history.""" 
     956        payments = [] 
     957        for payment in user.Payments : 
     958            payments.append("%s # %s" % (payment[0], str(payment[1]))) 
     959        payments.append("%s # %s" % (str(DateTime.now()), str(amount))) 
     960        fields = { 
     961                   "pykotaPayments" : payments, 
     962                 } 
     963        return self.doModify(user.idbalance, fields)          
     964         
    946965    def writeLastJobSize(self, lastjob, jobsize, jobprice) :         
    947966        """Sets the last job's size permanently.""" 
  • pykota/trunk/pykota/storages/sql.py

    r1520 r1522  
    2222# 
    2323# $Log$ 
     24# Revision 1.41  2004/06/05 22:03:50  jalet 
     25# Payments history is now stored in database 
     26# 
    2427# Revision 1.40  2004/06/03 23:14:11  jalet 
    2528# Now stores the job's size in bytes in the database. 
     
    342345            self.doModify("UPDATE users SET balance=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(user.ident))) 
    343346             
     347    def writeNewPayment(self, user, amount) :         
     348        """Adds a new payment to the payments history.""" 
     349        self.doModify("INSERT INTO payments (userid, amount) VALUES (%s, %s)" % (self.doQuote(user.ident), self.doQuote(amount))) 
     350         
    344351    def writeLastJobSize(self, lastjob, jobsize, jobprice) :         
    345352        """Sets the last job's size permanently.""" 
  • pykota/trunk/pykota/version.py

    r1517 r1522  
    2222# 
    2323 
    24 __version__ = "1.19alpha17_unofficial" 
     24__version__ = "1.19alpha18_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng.""" 
  • pykota/trunk/setup.py

    r1500 r1522  
    2424# 
    2525# $Log$ 
     26# Revision 1.44  2004/06/05 22:03:49  jalet 
     27# Payments history is now stored in database 
     28# 
    2629# Revision 1.43  2004/05/25 09:49:41  jalet 
    2730# The old pykota filter has been removed. LPRng support disabled for now. 
     
    376379     
    377380    # WARNING MESSAGE     
    378     sys.stdout.write("WARNING : IF YOU ARE UPGRADING FROM A PRE-1.19alpha7 TO 1.19alpha7 OR ABOVE\n") 
     381    sys.stdout.write("WARNING : IF YOU ARE UPGRADING FROM A PRE-1.19alpha17 TO 1.19alpha17 OR ABOVE\n") 
    379382    sys.stdout.write("AND USE THE POSTGRESQL BACKEND, THEN YOU HAVE TO MODIFY YOUR\n") 
    380383    sys.stdout.write("DATABASE SCHEMA USING initscripts/postgresql/upgrade-to-1.19.sql\n") 
    381384    sys.stdout.write("PLEASE READ DOCUMENTATION IN initscripts/postgresql/ TO LEARN HOW TO DO.\n") 
    382385    sys.stdout.write("YOU CAN DO THAT AFTER THE INSTALLATION IS FINISHED, OR PRESS CTRL+C NOW.\n") 
    383     sys.stdout.write("\n\nYOU DON'T HAVE ANYTHING SPECIAL TO DO IF THIS IS YOUR FIRST INSTALLATION\nOR IF YOU ARE ALREADY RUNNING VERSION 1.19alpha7 OR ABOVE.\n\n") 
     386    sys.stdout.write("\n\nYOU DON'T HAVE ANYTHING SPECIAL TO DO IF THIS IS YOUR FIRST INSTALLATION\nOR IF YOU ARE ALREADY RUNNING VERSION 1.19alpha17 OR ABOVE.\n\n") 
    384387    dummy = raw_input("Please press ENTER when you have read the message above. ") 
    385388