Show
Ignore:
Timestamp:
11/13/06 23:24:01 (17 years ago)
Author:
jerome
Message:

The code to refund jobs is there and works (at least with PostgreSQL).
Only the pkrefund command line tool (and CGI script ?) is missing.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storage.py

    r3050 r3056  
    2323# 
    2424 
     25"""This module is the database abstraction layer for PyKota.""" 
     26 
    2527import os 
    2628import imp 
     
    3638    __str__ = __repr__ 
    3739         
     40         
    3841class StorageObject : 
    3942    """Object present in the database.""" 
     
    5760            getattr(self.parent, "save%s" % self.__class__.__name__[7:])(self) 
    5861            self.isDirty = False 
     62             
    5963         
    6064class StorageUser(StorageObject) :         
     
    124128        self.isDirty = False             
    125129         
     130    def refund(self, amount) : 
     131        """Refunds a number of credits to an user.""" 
     132        self.consumeAccountBalance(-amount) 
     133         
     134         
    126135class StorageGroup(StorageObject) :         
    127136    """User class.""" 
     
    161170        self.Exists = False 
    162171        self.isDirty = False             
     172         
    163173         
    164174class StoragePrinter(StorageObject) : 
     
    236246        self.Exists = False 
    237247        self.isDirty = False             
     248         
    238249         
    239250class StorageUserPQuota(StorageObject) : 
     
    360371        self.isDirty = False 
    361372         
     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         
    362380class StorageGroupPQuota(StorageObject) : 
    363381    """Group Print Quota class.""" 
     
    427445        self.Exists = False 
    428446        self.isDirty = False 
     447         
    429448         
    430449class StorageJob(StorageObject) : 
     
    462481        else : 
    463482            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         
    464507         
    465508class StorageLastJob(StorageJob) : 
     
    469512        self.PrinterName = printer.Name # not needed 
    470513        self.Printer = printer 
     514         
    471515         
    472516class StorageBillingCode(StorageObject) : 
     
    494538        """Consumes some pages and credits for this billing code.""" 
    495539        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         
    499548         
    500549class BaseStorage :