Changeset 1285

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

New formula to compute a job's price

Location:
pykota/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r1280 r1285  
    2424# 
    2525# $Log$ 
     26# Revision 1.22  2004/01/12 22:43:40  jalet 
     27# New formula to compute a job's price 
     28# 
    2629# Revision 1.21  2004/01/12 18:17:36  jalet 
    2730# Denied jobs weren't stored into the history anymore, this is now fixed. 
     
    192195             
    193196            # update the quota for the current user on this printer  
    194             jobprice = (float(printer.PricePerPage or 0.0) * jobsize) + float(printer.PricePerJob or 0.0) 
    195             if jobsize : 
    196                 self.logdebug("Updating user %s's quota on printer %s" % (user.Name, printer.Name)) 
    197                 userpquota.increasePagesUsage(jobsize) 
     197            self.logdebug("Updating user %s's quota on printer %s" % (user.Name, printer.Name)) 
     198            jobprice = userpquota.increasePagesUsage(jobsize) 
    198199             
    199200            # adds the current job to history     
  • pykota/trunk/bin/pykotme

    r1257 r1285  
    2424# 
    2525# $Log$ 
     26# Revision 1.7  2004/01/12 22:43:40  jalet 
     27# New formula to compute a job's price 
     28# 
    2629# Revision 1.6  2004/01/08 14:10:32  jalet 
    2730# Copyright year changed. 
     
    157160        print _("Job size : %i pages") % nbpages     
    158161        for printer in printers : 
    159             cost = (nbpages * float(printer.PricePerPage or 0)) + float(printer.PricePerJob or 0) 
     162            userpquota = self.storage.getUserPQuota(user, printer) 
     163            cost = userpquota.computeJobPrice(nbpages) 
    160164            print _("Cost on printer %s : %.2f") % (printer.Name, cost) 
    161165             
  • pykota/trunk/NEWS

    r1284 r1285  
    2222PyKota NEWS : 
    2323 
     24    - 1.16alpha26 : 
     25     
     26        - Job price is now computed like this : 
     27         
     28          SUM((NbPages * PricePerPage) + PricePerJob) 
     29           
     30          For current printer and all the printers groups it is  
     31          a member of. 
     32           
     33          This may be difficult to grasp, but offers unprecedented 
     34          flexibility. 
     35           
    2436    - 1.16alpha25 : 
    2537     
  • pykota/trunk/pykota/accounter.py

    r1272 r1285  
    2222# 
    2323# $Log$ 
     24# Revision 1.13  2004/01/12 22:43:40  jalet 
     25# New formula to compute a job's price 
     26# 
    2427# Revision 1.12  2004/01/11 23:43:31  jalet 
    2528# Bug wrt number of copies with CUPS should be fixed. 
     
    131134         
    132135        # adds the current job to history     
    133         jobprice = (float(userpquota.Printer.PricePerPage or 0.0) * jobsize) + float(userpquota.Printer.PricePerJob or 0.0) 
     136        jobprice = userpquota.computeJobPrice(jobsize) 
    134137        userpquota.Printer.addJobToHistory(self.filter.jobid, userpquota.User, self.getLastPageCounter(), action, jobsize, jobprice, self.filter.preserveinputfile, self.filter.title, self.filter.copies, self.filter.options) 
    135138        self.endJob(userpquota) 
  • 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 
  • pykota/trunk/pykota/version.py

    r1284 r1285  
    2222# 
    2323 
    24 __version__ = "1.16alpha25_unofficial" 
     24__version__ = "1.16alpha26_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""