Index: pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- pykota/trunk/pykota/storages/ldapstorage.py (revision 2763)
+++ pykota/trunk/pykota/storages/ldapstorage.py (revision 2765)
@@ -1462,22 +1462,22 @@
                 self.doDelete(group.ident)
                 
-    def deleteManyBillingCodesFromNames(self, billingcodes) :        
-        """Deletes many billing codes from their names."""
-        for bcode in self.getMatchingBillingCodes(",".join(billingcodes)) :
+    def deleteManyBillingCodes(self, billingcodes) :
+        """Deletes many billing codes."""
+        for bcode in billingcodes :
             bcode.delete()
         
-    def deleteManyUsersFromNames(self, usernames) :        
-        """Deletes many users from their names."""
-        for user in self.getMatchingUsers(",".join(usernames)) : 
+    def deleteManyUsers(self, users) :        
+        """Deletes many users."""
+        for user in users :
             user.delete()
             
-    def deleteManyGroupsFromNames(self, groupnames) :        
-        """Deletes many groups from their names."""
-        for group in self.getMatchingGroups(",".join(groupnames)) : 
+    def deleteManyGroups(self, groups) :        
+        """Deletes many groups."""
+        for group in groups :
             group.delete()
         
-    def deleteManyPrintersFromNames(self, printernames) :        
-        """Deletes many printers from their names."""
-        for printer in self.getMatchingPrinters(",".join(printernames)) :
+    def deleteManyPrinters(self, printers) :        
+        """Deletes many printers."""
+        for printer in printers :
             printer.delete()
         
@@ -1701,25 +1701,30 @@
         return code    
         
-    def addBillingCode(self, label) :
+    def addBillingCode(self, bcode) :
         """Adds a billing code to the quota storage, returns it."""
+        oldentry = self.getBillingCode(bcode.BillingCode)
+        if oldentry.Exists :
+            return oldentry # we return the existing entry
         uuid = self.genUUID()
         dn = "cn=%s,%s" % (uuid, self.info["billingcodebase"])
         fields = { "objectClass" : ["pykotaObject", "pykotaBilling"],
                    "cn" : uuid,
-                   "pykotaBillingCode" : self.userCharsetToDatabase(label),
-                   "pykotaPageCounter" : "0",
-                   "pykotaBalance" : "0.0",
+                   "pykotaBillingCode" : self.userCharsetToDatabase(bcode.BillingCode),
+                   "pykotaPageCounter" : str(bcode.PageCounter or 0),
+                   "pykotaBalance" : str(bcode.Balance or 0.0),
+                   "description" : self.userCharsetToDatabase(bcode.Description or ""), 
                  } 
         self.doAdd(dn, fields)
-        return self.getBillingCode(label)
-        
-    def saveBillingCode(self, code) :
+        bcode.isDirty = False
+        return None # the entry created doesn't need further modification
+        
+    def saveBillingCode(self, bcode) :
         """Sets the new description for a billing code."""
         fields = {
-                   "description" : self.userCharsetToDatabase(code.Description or ""), 
-                   "pykotaPageCounter" : str(code.PageCounter),
-                   "pykotaBalance" : str(code.Balance),
+                   "description" : self.userCharsetToDatabase(bcode.Description or ""), 
+                   "pykotaPageCounter" : str(bcode.PageCounter or 0),
+                   "pykotaBalance" : str(bcode.Balance or 0.0),
                  }
-        self.doModify(code.ident, fields)
+        self.doModify(bcode.ident, fields)
             
     def getMatchingBillingCodes(self, billingcodepattern) :
@@ -1744,5 +1749,5 @@
         return codes        
         
-    def consumeBillingCode(self, code, pagecounter, balance) :
+    def consumeBillingCode(self, bcode, pagecounter, balance) :
         """Consumes from a billing code."""
         fields = {
@@ -1750,4 +1755,4 @@
                    "pykotaPageCounter" : { "operator" : "+", "value" : pagecounter, "convert" : int },
                  }
-        return self.doModify(code.ident, fields)         
+        return self.doModify(bcode.ident, fields)         
 
