Example #1
0
    def statustag(self,book_id,status):
	book=Book.get(book_id)
        if status == "CONFIRM":
            book.status="STOCK"
            book.set_tag(category="inventory",key="confirmation11",value="stock")
        else:
            if status=="SOLD":
                book.sold_when=now()
                book.status="SOLD"
                book.set_tag(category="inventory",key="confirmation11",value="sold_at_some_point")
            else:
                book.status=status
                book.set_tag(category="inventory",key="confirmation11",value="removed")
	return book.status
    def onSelectItem(self,event):
        currentItem = event.m_itemIndex
        m_item=inventoried_merchandise("book")
        m_item.setBook(Book.get(int(self.getColumnText(currentItem, 9))))
        m_item.setPrice(self.getColumnText(currentItem, 2))
        m_item.setDescription(self.list.GetItemText(currentItem))
        m_item.source=self.getColumnText(currentItem,10)
        
        win = InventoriedMerchandisePopup(self.parent,m_item,self.parent)

        # Show the popup right below or above the button
        # depending on available screen space...
        btn = event.GetEventObject()
        pos = btn.ClientToScreen( (0,0) )
        sz =  btn.GetSize()
        #win.Position(pos, (0, sz.height))
        win.CenterOnScreen()
        win.ShowModal()
        win.Destroy()
Example #3
0
    def onSelectItem(self, event):
        currentItem = event.m_itemIndex
        m_item = inventoried_merchandise("book")
        m_item.setBook(Book.get(int(self.getColumnText(currentItem, 8))))
        m_item.setPrice(self.getColumnText(currentItem, 2))
        m_item.setDescription(self.list.GetItemText(currentItem))
        m_item.source = self.getColumnText(currentItem, 9)

        win = InventoriedMerchandisePopup(self.parent, m_item, self.parent)

        # Show the popup right below or above the button
        # depending on available screen space...
        btn = event.GetEventObject()
        pos = btn.ClientToScreen((0, 0))
        sz = btn.GetSize()
        #win.Position(pos, (0, sz.height))
        win.CenterOnScreen()
        win.ShowModal()
        win.Destroy()
Example #4
0
 def statustag(self, book_id, status):
     book = Book.get(book_id)
     if status == "CONFIRM":
         book.status = "STOCK"
         book.set_tag(category="inventory",
                      key="confirmation11",
                      value="stock")
     else:
         if status == "SOLD":
             book.sold_when = now()
             book.status = "SOLD"
             book.set_tag(category="inventory",
                          key="confirmation11",
                          value="sold_at_some_point")
         else:
             book.status = status
             book.set_tag(category="inventory",
                          key="confirmation11",
                          value="removed")
     return book.status
Example #5
0
    def addtocart(self, **args):
        self.common()

        if args.get('reset_quantities') == "true":
            cherrypy.session['quantities'] = []

        #these are multiple copies of the same book
        for a in args.keys():
            match = re.compile("^select_x_like_(\d+)").match(a)
            if match:
                try:
                    number_of_copies_to_sell = int(args[a])
                    id = match.group(1)
                    original = Book.get(id)
                    try:
                        quantities = cherrypy.session.get('quantities', [])
                        quantities.append((original, number_of_copies_to_sell))
                        cherrypy.session['quantities'] = quantities
                    except:
                        pass

                except Exception, e:
                    print str(e)
Example #6
0
    def addtocart(self,**args):
        self.common() 
        
        if args.get('reset_quantities')=="true":
            cherrypy.session['quantities']=[]

        #these are multiple copies of the same book
        for a in args.keys():
            match=re.compile("^select_x_like_(\d+)").match(a)
            if match:
                try:
                    number_of_copies_to_sell=int(args[a])
                    id=match.group(1)
                    original=Book.get(id)
                    try:
                        quantities=cherrypy.session.get('quantities',[])
                        quantities.append((original,number_of_copies_to_sell))
                        cherrypy.session['quantities']=quantities
                    except:
                        pass

                except Exception,e:
                    print str(e)
Example #7
0
class InventoryServer:
    def __init__(self):
        self.reportlist = [
            getattr(__import__('reports.' + x, globals(), {}, [1]), x)
            for x in cfg.get("reports")
        ]

        self._indextemplate = IndexTemplate()
        self._carttemplate = CartTemplate()
        self._checkouttemplate = CheckoutTemplate()
        self._searchtemplate = SearchTemplate()
        self._bookedittemplate = BookEditTemplate()
        self._authoredittemplate = AuthorEditTemplate()
        self._categoryedittemplate = CategoryEditTemplate()
        self._kindedittemplate = KindEditTemplate()
        self._kindlisttemplate = KindListTemplate()
        self._titleedittemplate = TitleEditTemplate()
        self._titlelisttemplate = TitleListTemplate()
        self._reportlisttemplate = ReportListTemplate()
        self._reporttemplate = ReportTemplate()
        self._transactionstemplate = TransactionsTemplate()

        self.conn = db.connect()

    def common(self):
        for x in [getattr(self, x) for x in dir(self) if 'template' in x]:
            x.lastsearch = cherrypy.session.get('lastsearch', False)

    def index(self, **args):
        self.common()
        cherrypy.session['c'] = cherrypy.session.get('c', 0) + 1
        print cherrypy.session['c']
        return self._indextemplate.respond()

    def bookedit(self, **args):
        self.common()
        self._bookedittemplate.book = Book.form_to_object(Book, args)
        return self._bookedittemplate.respond()

    def authoredit(self, **args):
        self.common()
        self._authoredittemplate.author = Author.form_to_object(Author, args)
        return self._authoredittemplate.respond()

    def categoryedit(self, **args):
        self.common()
        self._categoryedittemplate.category = Category.form_to_object(
            Category, args)
        return self._categoryedittemplate.respond()

    def kindedit(self, **args):
        self.common()
        if ('kindName' in args.keys()):
            self._kindedittemplate.kind = Kind.form_to_object(Kind, args)
            return self.kindlist()
        else:
            self._kindedittemplate.kind = Kind.form_to_object(Kind, args)
            return self._kindedittemplate.respond()

    def kindlist(self, **args):
        self.common()
        self._kindlisttemplate.kinds = list(Kind.select())
        return self._kindlisttemplate.respond()

    def titleedit(self, **args):
        self.common()
        self._titleedittemplate.title = Title.form_to_object(Title, args)
        return self._titleedittemplate.respond()

    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()

    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()

    def addtocart(self, **args):
        self.common()

        if args.get('reset_quantities') == "true":
            cherrypy.session['quantities'] = []

        #these are multiple copies of the same book
        for a in args.keys():
            match = re.compile("^select_x_like_(\d+)").match(a)
            if match:
                try:
                    number_of_copies_to_sell = int(args[a])
                    id = match.group(1)
                    original = Book.get(id)
                    try:
                        quantities = cherrypy.session.get('quantities', [])
                        quantities.append((original, number_of_copies_to_sell))
                        cherrypy.session['quantities'] = quantities
                    except:
                        pass

                except Exception, e:
                    print str(e)

        #these are checked individual copies
        copy_ids = []
        try:
            if type(args['copy_id']) == type([0, 1]):
                for copy_id in args['copy_id']:
                    copy_ids.append(copy_id)
            else:
                copy_ids.append(args['copy_id'])
        except:
            pass

        for copy_id in copy_ids:
            quantities = cherrypy.session.get('quantities', [])
            quantities.append((Book.get(copy_id), 1))
            cherrypy.session['quantities'] = quantities

        if "checkout" in args:
            return self.checkout(**args)
        else:
            self._carttemplate.quantities = cherrypy.session.get(
                'quantities', [])
            return self._carttemplate.respond()
Example #8
0
 def confirm(self,title,book,**kw):
     book=Book.get(book)
     title=Title.get(title)
     book.set_tag(category="inventory",key="confirmation11",value="stock")
     return self.title(title.id)
Example #9
0
 def confirm(self, title, book, **kw):
     book = Book.get(book)
     title = Title.get(title)
     book.set_tag(category="inventory", key="confirmation11", value="stock")
     return self.title(title.id)