Exemple #1
0
    def copy_inv(self, items, new_date):

        for old_item in items:
            item = Item(id=str(uuid.uuid1()))
            item.name = old_item.name
            item.anotation = old_item.anotation
            item.date = datetime.strptime(new_date, "%Y-%m-%d")
            item.quantity = old_item.quantity
            item.remaining = old_item.quantity
            item.cost = old_item.cost
            item.put()
Exemple #2
0
    def copy_inv(self, items, new_date):

        for old_item in items:
            item = Item(id=str(uuid.uuid1()))
            item.name = old_item.name
            item.anotation = old_item.anotation
            item.date = datetime.strptime(new_date, "%Y-%m-%d")
            item.quantity = old_item.quantity
            item.remaining = old_item.quantity
            item.cost = old_item.cost
            item.put()
Exemple #3
0
    def post(self):

        try:
            self.verify_admin()
            button_type = self.request.get('button')
            items_all = self.get_all_items()
            harvest_date = self.request.get('weekof')
            harvest_date = self.get_harvest_date(harvest_date)
            harvest_date_str = harvest_date.strftime("%Y-%m-%d")
    
            if button_type == "Save":
                q = self.request.get('quantity')
                n = self.request.get('item')
                a = self.request.get('anotation')
                c = self.request.get('cost')
                id = self.request.get('id')


                if n == None or n == "":
                    raise Exception("You must name the items you add")
                # do error page
                if q == None:
                # do error page
                    raise Exception("The quantity must be an integer")
                try:
                    qInt = int(q)
                except:
                    raise Exception("Inventory must be an integer")
                try:
                    cFloat = float(c)
                except:
                    raise Exception("The cost must be a floating point")

                item_query = Item.all()
                item_query.filter('id = ', id)
                g_is = item_query.fetch(1)

                if g_is == None or len(g_is) < 1:
                    item = Item(id=str(uuid.uuid1()))
                    item.quantity = q
                    item.remaining = q
                else:
                    item = g_is[0] 
                    # make sure the new quantity is ok
                    init_q = int(item.quantity)
                    remaining_q = int(item.remaining)
                    purchased_q = init_q - remaining_q
                    new_qInt = int(q)
                    new_r = new_qInt - purchased_q
                    logging.info("admin is changing the quantity of |%s| from %d to %d" % (item.name, init_q, qInt))
                    if new_r < 0:

                        # here is where i can ask who gets screwed
                        logging.error("%d %s have already been sold.  The quantity for %s must be at least %d." % (new_qInt, item.name, item.name, purchased_q))

                        raise Exception("%d %s have already been sold.  The quantity for %s must be at least %d." % (new_qInt, item.name, item.name, purchased_q))
                    item.quantity = q
                    item.remaining = str(new_r)


                item.date = harvest_date
                item.name = n
                item.cost = c
                item.anotation = a
                item.put()

            elif button_type == "New":
                template_values = {
                    'logout_url': self.url,
                    'url_linktext': self.url_linktext,
                    'harvest_date': harvest_date_str,
                  }
                path = os.path.join(os.path.dirname(__file__), 'inventoryedit.html')
                self.response.out.write(template.render(path, template_values))
                return

            elif button_type == "Remove":
                for i in items_all:
                    v = self.request.get(i.id)
                    if v == "on":
                        if int(i.quantity) != 0:
                            raise Exception("The inventory for %s was already published.  You cannot delete items once it is published.  Try changing the quantity to 0")

                        else:
                            i.delete()

            elif button_type == "Edit":
                found = False
                for i in items_all:
                    v = self.request.get(i.id)
                    if v == "on":
                        found = True
                        fi = i

                if found:
                    template_values = {
                        'item': fi,
                        'logout_url': self.url,
                        'url_linktext': self.url_linktext,
                        'harvest_date': harvest_date_str,
                      }
                    path = os.path.join(os.path.dirname(__file__), 'inventoryedit.html')
                    self.response.out.write(template.render(path, template_values))
                    return

            elif button_type == "Publish":
                if self.is_published(harvest_date):
                        
                    query = InventoryList.all()
                    query.filter('date = ', harvest_date)
                    g_us = query.fetch(1)
                    if g_us == None or len(g_us) < 1:
                        il = InventoryList()
                    else:
                        il = g_us[0]

                else:
                    il = InventoryList()
                    il.date = harvest_date

                il.item_count = len(items_all)
                il.put()

            elif button_type == "Printable":
                self.write_out(fname="inventoryprintable.html")
                return
            elif button_type == "CSV":
                self.write_out(fname="inventorycsv.html")
                return
            elif button_type == "Copy":
                cd = self.request.get('copy_date')
                if cd != None:
                    self.copy_inv(items_all, cd)

            self.write_out()

        except Exception, ex:
            self.error_write(ex)
Exemple #4
0
    def post(self):

        try:
            self.verify_admin()
            button_type = self.request.get('button')
            items_all = self.get_all_items()
            harvest_date = self.request.get('weekof')
            harvest_date = self.get_harvest_date(harvest_date)
            harvest_date_str = harvest_date.strftime("%Y-%m-%d")

            if button_type == "Save":
                q = self.request.get('quantity')
                n = self.request.get('item')
                a = self.request.get('anotation')
                c = self.request.get('cost')
                id = self.request.get('id')

                if n == None or n == "":
                    raise Exception("You must name the items you add")
                # do error page
                if q == None:
                    # do error page
                    raise Exception("The quantity must be an integer")
                try:
                    qInt = int(q)
                except:
                    raise Exception("Inventory must be an integer")
                try:
                    cFloat = float(c)
                except:
                    raise Exception("The cost must be a floating point")

                item_query = Item.all()
                item_query.filter('id = ', id)
                g_is = item_query.fetch(1)

                if g_is == None or len(g_is) < 1:
                    item = Item(id=str(uuid.uuid1()))
                    item.quantity = q
                    item.remaining = q
                else:
                    item = g_is[0]
                    # make sure the new quantity is ok
                    init_q = int(item.quantity)
                    remaining_q = int(item.remaining)
                    purchased_q = init_q - remaining_q
                    new_qInt = int(q)
                    new_r = new_qInt - purchased_q
                    logging.info(
                        "admin is changing the quantity of |%s| from %d to %d"
                        % (item.name, init_q, qInt))
                    if new_r < 0:

                        # here is where i can ask who gets screwed
                        logging.error(
                            "%d %s have already been sold.  The quantity for %s must be at least %d."
                            % (new_qInt, item.name, item.name, purchased_q))

                        raise Exception(
                            "%d %s have already been sold.  The quantity for %s must be at least %d."
                            % (new_qInt, item.name, item.name, purchased_q))
                    item.quantity = q
                    item.remaining = str(new_r)

                item.date = harvest_date
                item.name = n
                item.cost = c
                item.anotation = a
                item.put()

            elif button_type == "New":
                template_values = {
                    'logout_url': self.url,
                    'url_linktext': self.url_linktext,
                    'harvest_date': harvest_date_str,
                }
                path = os.path.join(os.path.dirname(__file__),
                                    'inventoryedit.html')
                self.response.out.write(template.render(path, template_values))
                return

            elif button_type == "Remove":
                for i in items_all:
                    v = self.request.get(i.id)
                    if v == "on":
                        if int(i.quantity) != 0:
                            raise Exception(
                                "The inventory for %s was already published.  You cannot delete items once it is published.  Try changing the quantity to 0"
                            )

                        else:
                            i.delete()

            elif button_type == "Edit":
                found = False
                for i in items_all:
                    v = self.request.get(i.id)
                    if v == "on":
                        found = True
                        fi = i

                if found:
                    template_values = {
                        'item': fi,
                        'logout_url': self.url,
                        'url_linktext': self.url_linktext,
                        'harvest_date': harvest_date_str,
                    }
                    path = os.path.join(os.path.dirname(__file__),
                                        'inventoryedit.html')
                    self.response.out.write(
                        template.render(path, template_values))
                    return

            elif button_type == "Publish":
                if self.is_published(harvest_date):

                    query = InventoryList.all()
                    query.filter('date = ', harvest_date)
                    g_us = query.fetch(1)
                    if g_us == None or len(g_us) < 1:
                        il = InventoryList()
                    else:
                        il = g_us[0]

                else:
                    il = InventoryList()
                    il.date = harvest_date

                il.item_count = len(items_all)
                il.put()

            elif button_type == "Printable":
                self.write_out(fname="inventoryprintable.html")
                return
            elif button_type == "CSV":
                self.write_out(fname="inventorycsv.html")
                return
            elif button_type == "Copy":
                cd = self.request.get('copy_date')
                if cd != None:
                    self.copy_inv(items_all, cd)

            self.write_out()

        except Exception, ex:
            self.error_write(ex)