Index: /pykota/trunk/pykota/accounter.py
===================================================================
--- /pykota/trunk/pykota/accounter.py (revision 1272)
+++ /pykota/trunk/pykota/accounter.py (revision 1285)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.13  2004/01/12 22:43:40  jalet
+# New formula to compute a job's price
+#
 # Revision 1.12  2004/01/11 23:43:31  jalet
 # Bug wrt number of copies with CUPS should be fixed.
@@ -131,5 +134,5 @@
         
         # adds the current job to history    
-        jobprice = (float(userpquota.Printer.PricePerPage or 0.0) * jobsize) + float(userpquota.Printer.PricePerJob or 0.0)
+        jobprice = userpquota.computeJobPrice(jobsize)
         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)
         self.endJob(userpquota)
Index: /pykota/trunk/pykota/storage.py
===================================================================
--- /pykota/trunk/pykota/storage.py (revision 1274)
+++ /pykota/trunk/pykota/storage.py (revision 1285)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.38  2004/01/12 22:43:40  jalet
+# New formula to compute a job's price
+#
 # Revision 1.37  2004/01/12 14:35:01  jalet
 # Printing history added to CGI script.
@@ -300,20 +303,30 @@
         self.PageCounter = 0
         
-    def increasePagesUsage(self, nbpages) :
+    def computeJobPrice(self, jobsize) :    
+        """Computes the job price as the sum of all parent printers' prices + current printer's ones."""
+        totalprice = 0.0    
+        if jobsize :
+            for upq in [ self ] + self.ParentPrintersUserPQuota :
+                price = (float(upq.Printer.PricePerPage or 0.0) * jobsize) + float(upq.Printer.PricePerJob or 0.0)
+                totalprice += price
+        return totalprice    
+            
+    def increasePagesUsage(self, jobsize) :
         """Increase the value of used pages and money."""
-        jobprice = (float(self.Printer.PricePerPage or 0.0) * nbpages) + float(self.Printer.PricePerJob or 0.0)
-        self.parent.beginTransaction()
-        try :
-            if nbpages :
+        jobprice = self.computeJobPrice(jobsize)
+        if jobsize :
+            self.parent.beginTransaction()
+            try :
                 self.User.consumeAccountBalance(jobprice)
                 for upq in [ self ] + self.ParentPrintersUserPQuota :
-                    self.parent.increaseUserPQuotaPagesCounters(upq, nbpages)
-                    upq.PageCounter = int(upq.PageCounter or 0) + nbpages
-                    upq.LifePageCounter = int(upq.LifePageCounter or 0) + nbpages
-        except PyKotaStorageError, msg :    
-            self.parent.rollbackTransaction()
-            raise PyKotaStorageError, msg
-        else :    
-            self.parent.commitTransaction()
+                    self.parent.increaseUserPQuotaPagesCounters(upq, jobsize)
+                    upq.PageCounter = int(upq.PageCounter or 0) + jobsize
+                    upq.LifePageCounter = int(upq.LifePageCounter or 0) + jobsize
+            except PyKotaStorageError, msg :    
+                self.parent.rollbackTransaction()
+                raise PyKotaStorageError, msg
+            else :    
+                self.parent.commitTransaction()
+        return jobprice
         
 class StorageGroupPQuota(StorageObject) :
@@ -366,5 +379,5 @@
     def setSize(self, jobsize) :
         """Sets the last job's size."""
-        jobprice = (float(self.Printer.PricePerPage or 0.0) * jobsize) + float(self.Printer.PricePerJob or 0.0)
+        jobprice = self.parent.getUserPQuota(self.User, self.Printer).computeJobPrice(jobsize)
         self.parent.writeLastJobSize(self, jobsize, jobprice)
         self.JobSize = jobsize
Index: /pykota/trunk/pykota/version.py
===================================================================
--- /pykota/trunk/pykota/version.py (revision 1284)
+++ /pykota/trunk/pykota/version.py (revision 1285)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.16alpha25_unofficial"
+__version__ = "1.16alpha26_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: /pykota/trunk/bin/cupspykota
===================================================================
--- /pykota/trunk/bin/cupspykota (revision 1280)
+++ /pykota/trunk/bin/cupspykota (revision 1285)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.22  2004/01/12 22:43:40  jalet
+# New formula to compute a job's price
+#
 # Revision 1.21  2004/01/12 18:17:36  jalet
 # Denied jobs weren't stored into the history anymore, this is now fixed.
@@ -192,8 +195,6 @@
             
             # update the quota for the current user on this printer 
-            jobprice = (float(printer.PricePerPage or 0.0) * jobsize) + float(printer.PricePerJob or 0.0)
-            if jobsize :
-                self.logdebug("Updating user %s's quota on printer %s" % (user.Name, printer.Name))
-                userpquota.increasePagesUsage(jobsize)
+            self.logdebug("Updating user %s's quota on printer %s" % (user.Name, printer.Name))
+            jobprice = userpquota.increasePagesUsage(jobsize)
             
             # adds the current job to history    
Index: /pykota/trunk/bin/pykotme
===================================================================
--- /pykota/trunk/bin/pykotme (revision 1257)
+++ /pykota/trunk/bin/pykotme (revision 1285)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.7  2004/01/12 22:43:40  jalet
+# New formula to compute a job's price
+#
 # Revision 1.6  2004/01/08 14:10:32  jalet
 # Copyright year changed.
@@ -157,5 +160,6 @@
         print _("Job size : %i pages") % nbpages    
         for printer in printers :
-            cost = (nbpages * float(printer.PricePerPage or 0)) + float(printer.PricePerJob or 0)
+            userpquota = self.storage.getUserPQuota(user, printer)
+            cost = userpquota.computeJobPrice(nbpages)
             print _("Cost on printer %s : %.2f") % (printer.Name, cost)
             
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 1284)
+++ /pykota/trunk/NEWS (revision 1285)
@@ -22,4 +22,16 @@
 PyKota NEWS :
 
+    - 1.16alpha26 :
+    
+        - Job price is now computed like this :
+        
+          SUM((NbPages * PricePerPage) + PricePerJob)
+          
+          For current printer and all the printers groups it is 
+          a member of.
+          
+          This may be difficult to grasp, but offers unprecedented
+          flexibility.
+          
     - 1.16alpha25 :
     
