Show
Ignore:
Timestamp:
01/12/04 23:43:40 (20 years ago)
Author:
jalet
Message:

New formula to compute a job's price

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storage.py

    r1274 r1285  
    2222# 
    2323# $Log$ 
     24# Revision 1.38  2004/01/12 22:43:40  jalet 
     25# New formula to compute a job's price 
     26# 
    2427# Revision 1.37  2004/01/12 14:35:01  jalet 
    2528# Printing history added to CGI script. 
     
    300303        self.PageCounter = 0 
    301304         
    302     def increasePagesUsage(self, nbpages) : 
     305    def computeJobPrice(self, jobsize) :     
     306        """Computes the job price as the sum of all parent printers' prices + current printer's ones.""" 
     307        totalprice = 0.0     
     308        if jobsize : 
     309            for upq in [ self ] + self.ParentPrintersUserPQuota : 
     310                price = (float(upq.Printer.PricePerPage or 0.0) * jobsize) + float(upq.Printer.PricePerJob or 0.0) 
     311                totalprice += price 
     312        return totalprice     
     313             
     314    def increasePagesUsage(self, jobsize) : 
    303315        """Increase the value of used pages and money.""" 
    304         jobprice = (float(self.Printer.PricePerPage or 0.0) * nbpages) + float(self.Printer.PricePerJob or 0.0) 
    305         self.parent.beginTransaction() 
    306         try : 
    307             if nbpages : 
     316        jobprice = self.computeJobPrice(jobsize) 
     317        if jobsize : 
     318            self.parent.beginTransaction() 
     319            try : 
    308320                self.User.consumeAccountBalance(jobprice) 
    309321                for upq in [ self ] + self.ParentPrintersUserPQuota : 
    310                     self.parent.increaseUserPQuotaPagesCounters(upq, nbpages) 
    311                     upq.PageCounter = int(upq.PageCounter or 0) + nbpages 
    312                     upq.LifePageCounter = int(upq.LifePageCounter or 0) + nbpages 
    313         except PyKotaStorageError, msg :     
    314             self.parent.rollbackTransaction() 
    315             raise PyKotaStorageError, msg 
    316         else :     
    317             self.parent.commitTransaction() 
     322                    self.parent.increaseUserPQuotaPagesCounters(upq, jobsize) 
     323                    upq.PageCounter = int(upq.PageCounter or 0) + jobsize 
     324                    upq.LifePageCounter = int(upq.LifePageCounter or 0) + jobsize 
     325            except PyKotaStorageError, msg :     
     326                self.parent.rollbackTransaction() 
     327                raise PyKotaStorageError, msg 
     328            else :     
     329                self.parent.commitTransaction() 
     330        return jobprice 
    318331         
    319332class StorageGroupPQuota(StorageObject) : 
     
    366379    def setSize(self, jobsize) : 
    367380        """Sets the last job's size.""" 
    368         jobprice = (float(self.Printer.PricePerPage or 0.0) * jobsize) + float(self.Printer.PricePerJob or 0.0) 
     381        jobprice = self.parent.getUserPQuota(self.User, self.Printer).computeJobPrice(jobsize) 
    369382        self.parent.writeLastJobSize(self, jobsize, jobprice) 
    370383        self.JobSize = jobsize