Index: /pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- /pykota/trunk/pykota/storages/ldapstorage.py (revision 1601)
+++ /pykota/trunk/pykota/storages/ldapstorage.py (revision 1692)
@@ -22,4 +22,8 @@
 #
 # $Log$
+# Revision 1.74  2004/09/02 10:09:30  jalet
+# Fixed bug in LDAP user deletion code which didn't correctly delete the user's
+# pykotaLastJob entries.
+#
 # Revision 1.73  2004/07/17 20:37:27  jalet
 # Missing file... Am I really stupid ?
@@ -633,5 +637,9 @@
             lastjob.lastjobident = result[0][0]
             lastjobident = result[0][1]["pykotaLastJobIdent"][0]
-            result = self.doSearch("objectClass=pykotaJob", ["pykotaJobSizeBytes", "pykotaHostName", "pykotaUserName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaJobSize", "pykotaAction", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "createTimestamp"], base="cn=%s,%s" % (lastjobident, self.info["jobbase"]), scope=ldap.SCOPE_BASE)
+            result = None
+            try :
+                result = self.doSearch("objectClass=pykotaJob", ["pykotaJobSizeBytes", "pykotaHostName", "pykotaUserName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaJobSize", "pykotaAction", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "createTimestamp"], base="cn=%s,%s" % (lastjobident, self.info["jobbase"]), scope=ldap.SCOPE_BASE)
+            except PyKotaStorageError :    
+                pass # Last job entry exists, but job probably doesn't exist anymore. 
             if result :
                 fields = result[0][1]
@@ -1145,16 +1153,24 @@
     def deleteUser(self, user) :    
         """Completely deletes an user from the Quota Storage."""
-        # TODO : What should we do if we delete the last person who used a given printer ?
-        # TODO : we can't reassign the last job to the previous one, because next user would be
-        # TODO : incorrectly charged (overcharged).
-        result = self.doSearch("(&(objectClass=pykotaLastJob)(pykotaUserName=%s))" % user.Name, base=self.info["lastjobbase"])
-        for (ident, fields) in result :
-            self.doDelete(ident)
+        todelete = []    
         result = self.doSearch("(&(objectClass=pykotaJob)(pykotaUserName=%s))" % user.Name, base=self.info["jobbase"])
         for (ident, fields) in result :
+            todelete.append(ident)
+            
+        result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s))" % user.Name, ["pykotaPrinterName", "pykotaUserName"], base=self.info["userquotabase"])
+        for (ident, fields) in result :
+            # ensure the user print quota entry will be deleted
+            todelete.append(ident)
+            
+            # if last job of current printer was printed by the user
+            # to delete, we also need to delete the printer's last job entry.
+            printername = fields["pykotaPrinterName"][0]
+            printer = self.getPrinter(printername)
+            if printer.LastJob.UserName == user.Name :
+                todelete.append(printer.LastJob.lastjobident)
+            
+        for ident in todelete :    
             self.doDelete(ident)
-        result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s))" % user.Name, ["pykotaUserName"], base=self.info["userquotabase"])
-        for (ident, fields) in result :
-            self.doDelete(ident)
+            
         result = self.doSearch("objectClass=pykotaAccount", None, base=user.ident, scope=ldap.SCOPE_BASE)    
         if result :
Index: /pykota/trunk/pykota/reporter.py
===================================================================
--- /pykota/trunk/pykota/reporter.py (revision 1582)
+++ /pykota/trunk/pykota/reporter.py (revision 1692)
@@ -22,4 +22,8 @@
 #
 # $Log$
+# Revision 1.10  2004/09/02 10:09:30  jalet
+# Fixed bug in LDAP user deletion code which didn't correctly delete the user's
+# pykotaLastJob entries.
+#
 # Revision 1.9  2004/07/01 17:45:49  jalet
 # Added code to handle the description field for printers
@@ -88,8 +92,10 @@
             
     def getPrinterRealPageCounter(self, printer) :        
-        try :
-            msg = "%9i" % printer.LastJob.PrinterPageCounter
-        except TypeError :     
-            msg = _("unknown")
+        msg = _("unknown")
+        if printer.LastJob.Exists :
+            try :
+                msg = "%9i" % printer.LastJob.PrinterPageCounter
+            except TypeError :     
+                pass
         return _("Real : %s") % msg
                 
Index: /pykota/trunk/pykota/storage.py
===================================================================
--- /pykota/trunk/pykota/storage.py (revision 1624)
+++ /pykota/trunk/pykota/storage.py (revision 1692)
@@ -22,4 +22,8 @@
 #
 # $Log$
+# Revision 1.58  2004/09/02 10:09:30  jalet
+# Fixed bug in LDAP user deletion code which didn't correctly delete the user's
+# pykotaLastJob entries.
+#
 # Revision 1.57  2004/07/22 22:41:48  jalet
 # Hardware accounting for LPRng should be OK now. UNTESTED.
@@ -480,5 +484,5 @@
         
 class StorageJob(StorageObject) :
-    """Printer's Last Job class."""
+    """Printer's Job class."""
     def __init__(self, parent) :
         StorageObject.__init__(self, parent)
Index: /pykota/trunk/pykota/version.py
===================================================================
--- /pykota/trunk/pykota/version.py (revision 1687)
+++ /pykota/trunk/pykota/version.py (revision 1692)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.20alpha5_unofficial"
+__version__ = "1.20alpha6_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 1687)
+++ /pykota/trunk/NEWS (revision 1692)
@@ -22,4 +22,8 @@
 PyKota NEWS :
 
+    - 1.20alpha6 :
+      
+        - Fixed a bug in LDAP user deletion code.
+        
     - 1.20alpha5 :
       
