Changeset 3056 for pykota/trunk/pykota/storage.py
- Timestamp:
- 11/13/06 23:24:01 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storage.py
r3050 r3056 23 23 # 24 24 25 """This module is the database abstraction layer for PyKota.""" 26 25 27 import os 26 28 import imp … … 36 38 __str__ = __repr__ 37 39 40 38 41 class StorageObject : 39 42 """Object present in the database.""" … … 57 60 getattr(self.parent, "save%s" % self.__class__.__name__[7:])(self) 58 61 self.isDirty = False 62 59 63 60 64 class StorageUser(StorageObject) : … … 124 128 self.isDirty = False 125 129 130 def refund(self, amount) : 131 """Refunds a number of credits to an user.""" 132 self.consumeAccountBalance(-amount) 133 134 126 135 class StorageGroup(StorageObject) : 127 136 """User class.""" … … 161 170 self.Exists = False 162 171 self.isDirty = False 172 163 173 164 174 class StoragePrinter(StorageObject) : … … 236 246 self.Exists = False 237 247 self.isDirty = False 248 238 249 239 250 class StorageUserPQuota(StorageObject) : … … 360 371 self.isDirty = False 361 372 373 def refund(self, nbpages) : 374 """Refunds a number of pages to an user on a particular printer.""" 375 self.parent.increaseUserPQuotaPagesCounters(self, -nbpages) 376 self.PageCounter = int(self.PageCounter or 0) - nbpages 377 self.LifePageCounter = int(self.LifePageCounter or 0) - nbpages 378 379 362 380 class StorageGroupPQuota(StorageObject) : 363 381 """Group Print Quota class.""" … … 427 445 self.Exists = False 428 446 self.isDirty = False 447 429 448 430 449 class StorageJob(StorageObject) : … … 462 481 else : 463 482 raise AttributeError, name 483 484 def refund(self) : 485 """Refund a particular print job.""" 486 if (not self.JobSize) or (self.JobAction in ("DENY", "REFUND")) : 487 return 488 self.parent.beginTransaction() 489 try : 490 if self.JobBillingCode : 491 bcode = self.parent.getBillingCode(self.JobBillingCode) 492 bcode.refund(self.JobSize, self.JobPrice) 493 494 if self.User.Exists : 495 self.User.refund(self.JobPrice) 496 if self.Printer.Exists : 497 upq = self.parent.getUserPQuota(self.User, self.Printer) 498 if upq.Exists : 499 upq.refund(self.JobSize) 500 self.parent.refundJob(self.ident) 501 except : 502 self.parent.rollbackTransaction() 503 raise 504 else : 505 self.parent.commitTransaction() 506 464 507 465 508 class StorageLastJob(StorageJob) : … … 469 512 self.PrinterName = printer.Name # not needed 470 513 self.Printer = printer 514 471 515 472 516 class StorageBillingCode(StorageObject) : … … 494 538 """Consumes some pages and credits for this billing code.""" 495 539 if pages : 496 self.parent.consumeBillingCode(self, pages, price) 497 self.PageCounter += pages 498 self.Balance -= price 540 self.parent.consumeBillingCode(self, pages, price) 541 self.PageCounter += pages 542 self.Balance -= price 543 544 def refund(self, pages, price) : 545 """Refunds a particular billing code.""" 546 self.consume(-pages, -price) 547 499 548 500 549 class BaseStorage :