コード例 #1
0
ファイル: server.py プロジェクト: truonghn/infoshopkeeper
    def titlelist(self, **args):
        self.common()
        self._titlelisttemplate.titles = []
        try:
            if type(args['titles']) == type("string"):
                self._titlelisttemplate.titles.append(Title.get(
                    args['titles']))
            else:
                for id in args['titles']:
                    self._titlelisttemplate.titles.append(Title.get(id))
        except KeyError:
            pass

        try:
            if (args['delete']):
                #delete the titles
                for title in self._titlelisttemplate.titles:
                    #                    for author in title.author:
                    #                        Author.delete(author.id)
                    for book in title.books:
                        Book.delete(book.id)
                    for category in title.categorys:
                        Category.delete(category.id)

                    Title.delete(title.id)

            #and back to the search
                from cherrypy.lib import httptools
                httptools.redirect(cherrypy.session['lastsearch'])
        except:
            return self._titlelisttemplate.respond()
コード例 #2
0
ファイル: server.py プロジェクト: aliceriot/infoshopkeeper
    def titlelist(self,**args):
        self.common()
        self._titlelisttemplate.titles=[]
        try:
            if type(args['titles']) == type("string"):
                self._titlelisttemplate.titles.append(Title.get(args['titles']))
            else:
                for id in args['titles']:
                    self._titlelisttemplate.titles.append(Title.get(id))
        except KeyError:
            pass

        try: 
            if (args['delete']):
            #delete the titles
                for title in self._titlelisttemplate.titles:
#                    for author in title.author:
#                        Author.delete(author.id)
                    for book in title.books:
                        Book.delete(book.id)
                    for category in title.categorys:
                        Category.delete(category.id)
                    
                    Title.delete(title.id)

            #and back to the search
                from cherrypy.lib import httptools
                httptools.redirect(cherrypy.session['lastsearch'])	
        except:
            return self._titlelisttemplate.respond()
コード例 #3
0
ファイル: server.py プロジェクト: truonghn/infoshopkeeper
    def checkout(self, **args):
        self.common()
        self._checkouttemplate.status_from = args.get("status_from", "STOCK")
        self._checkouttemplate.status_to = args.get("status_to", "RETURNED")
        self._checkouttemplate.schedules = [("list price", 1)
                                            ] + cfg.get("multiple_prices")

        if "change" in args:
            return self.addtocart(**args)
        if "finalize" in args:
            schedule_name = args["schedule"]
            schedule = [
                x for x in cfg.get("multiple_prices") + [("list price", 1)]
                if x[0] == schedule_name
            ]
            schedule_price = schedule[0][1]
            receipt = ""
            for q in cherrypy.session.get('quantities', []):

                original = q[0]
                howmany = q[1]

                for copy in list(
                        Book.select(
                            AND(Book.q.titleID == original.titleID,
                                Book.q.status == "STOCK", Book.q.listprice ==
                                original.listprice)))[0:howmany]:
                    cursor = self.conn.cursor()
                    cursor.execute(
                        """
                        INSERT INTO transactionLog SET
                        action = "SALE",
                        amount = %s,
                        cashier = %s,
                        date = NOW(),
                        info = %s,
                        schedule = %s,
                        owner = %s
                        """,
                        (copy.listprice * schedule_price, args["cashier"],
                         "[%s] %s" % (copy.distributor, copy.title.booktitle),
                         schedule_name, copy.owner))
                    copy.sellme()
                    cursor.close()
                line_pt_1 = "%s  X  %s  @ $%.2f * %i%%" % (
                    original.title.booktitle[:25], howmany, original.listprice,
                    schedule_price * 100)
                receipt = receipt + string.ljust(line_pt_1, 50) + string.rjust(
                    "$%.2f" %
                    (howmany * schedule_price * original.listprice), 10)
            return receipt

        if "restatus" in args and "status_to" in args and "status_from" in args:
            for q in cherrypy.session.get('quantities', []):
                original = q[0]
                howmany = q[1]
                for copy in list(
                        Book.select(
                            AND(Book.q.titleID == original.titleID,
                                Book.q.status == args["status_from"],
                                Book.q.listprice ==
                                original.listprice)))[0:howmany]:

                    copy.status = args["status_to"]

            cherrypy.session['quantities'] = []

        if "delete" in args:
            for q in cherrypy.session.get('quantities', []):
                original = q[0]
                original_price = original.listprice
                original_status = original.status
                original_title_id = original.titleID
                howmany = q[1]
                for copy in list(
                        Book.select(
                            AND(Book.q.titleID == original_title_id,
                                Book.q.status == original_status,
                                Book.q.listprice ==
                                original_price)))[0:howmany]:

                    Book.delete(copy.id)

            cherrypy.session['quantities'] = []

        self._checkouttemplate.quantities = cherrypy.session.get(
            'quantities', [])
        return self._checkouttemplate.respond()
コード例 #4
0
ファイル: server.py プロジェクト: aliceriot/infoshopkeeper
    def checkout(self,**args):
        self.common()
        self._checkouttemplate.status_from=args.get("status_from","STOCK")
        self._checkouttemplate.status_to=args.get("status_to","RETURNED")
        self._checkouttemplate.schedules = [("list price",1)]+cfg.get("multiple_prices")
        
        if "change" in args:
            return self.addtocart(**args)
        if "finalize" in args:
            schedule_name=args["schedule"]
            schedule=[x for x in cfg.get("multiple_prices")+[("list price",1)] if x[0]==schedule_name] 
            schedule_price=schedule[0][1]
            receipt=""
            for q in cherrypy.session.get('quantities',[]):

                original=q[0]
                howmany=q[1]
                
                for copy in list(Book.select(AND(Book.q.titleID==original.titleID,Book.q.status=="STOCK",Book.q.listprice==original.listprice)))[0:howmany]:
                    cursor=self.conn.cursor()
                    cursor.execute("""
                        INSERT INTO transactionLog SET
                        action = "SALE",
                        amount = %s,
                        cashier = %s,
                        date = NOW(),
                        info = %s,
                        schedule = %s,
                        owner = %s
                        """,(copy.listprice * schedule_price,args["cashier"],"[%s] %s" % (copy.distributor,copy.title.booktitle),schedule_name,copy.owner))
                    copy.sellme()
                    cursor.close()
                line_pt_1 =  "%s  X  %s  @ $%.2f * %i%%" % (original.title.booktitle[:25],howmany,original.listprice,schedule_price * 100)
                receipt=receipt+string.ljust(line_pt_1,50)+string.rjust("$%.2f" % (howmany*schedule_price*original.listprice),10)
            return receipt
        
        if "restatus" in args and "status_to" in args and "status_from" in args:
            for q in cherrypy.session.get('quantities',[]):
                original=q[0]
                howmany=q[1]
                for copy in list(Book.select(AND(Book.q.titleID==original.titleID,Book.q.status==args["status_from"],Book.q.listprice==original.listprice)))[0:howmany]:
                    
                    copy.status=args["status_to"]
                    
            cherrypy.session['quantities']=[]

        if "delete" in args:
            for q in cherrypy.session.get('quantities',[]):
                original=q[0]
                original_price=original.listprice
                original_status=original.status
                original_title_id=original.titleID
                howmany=q[1]
                for copy in list(Book.select(AND(Book.q.titleID==original_title_id,Book.q.status==original_status,Book.q.listprice==original_price)))[0:howmany]:
                    
                    Book.delete(copy.id)
                    
            cherrypy.session['quantities']=[]

            
        
        self._checkouttemplate.quantities=cherrypy.session.get('quantities',[])
        return self._checkouttemplate.respond()