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()
def post(self): try: self.verify_admin() button_type = self.request.get('button') all = False if button_type == "Nuke": all = True if button_type == "UserChoices" or all == True: query = UserChoices.all() self.nuke_query(query) if button_type == "UserData" or all == True: query = UsersData.all() self.nuke_query(query) if button_type == "UserWaitingList" or all == True: # query = UsersWaitingList.all() # self.nuke_query(query) self.convert_wait() if button_type == "InventoryList" or all == True: query = InventoryList.all() self.nuke_query(query) if button_type == "Item" or all == True: query = Item.all() self.nuke_query(query) self.do_page() except Exception, ex: self.error_write(ex)
def get_all_items(self): harvest_date = self.request.get('weekof') harvest_date = self.get_harvest_date(harvest_date) item_query = Item.all() item_query.filter('date = ', harvest_date) item_query.order('name') items = item_query.fetch(100) return items
def get_next_inv(self): now = date.today() inv_query = InventoryList.all() inv_query.filter('date >= ', now) inv = inv_query.fetch(1) if inv == None or len(inv) < 1: msg = "The inventory for this week is not yet ready. Please try back later" return (None, None, msg) item_query = Item.all() item_query.filter('date = ', inv[0].date) items = item_query.fetch(1000) item_dict = {} for i in items: item_dict[i.name] = i return (inv[0], item_dict, None)
def get_next_inv(self): now = date.today() inv_query = InventoryList.all() inv_query.filter("date >= ", now) inv = inv_query.fetch(1) if inv == None or len(inv) < 1: msg = "The inventory for this week is not yet ready. Please try back later" return (None, None, msg) item_query = Item.all() item_query.filter("date = ", inv[0].date) items = item_query.fetch(1000) item_dict = {} for i in items: item_dict[i.name] = i return (inv[0], item_dict, None)
def do_page(self, fname="invoice.html"): harvest_date = self.request.get('weekof') harvest_date = self.get_harvest_date(harvest_date) inv_query = InventoryList.all() inv_query.filter('date = ', harvest_date) inv = inv_query.fetch(1000) locked_or_not = "unlocked" if inv != None and len(inv) > 0 and inv[0].locked == 1: locked_or_not = "locked" item_query = Item.all() item_query.filter('date = ', harvest_date) item_query.order('name') items = item_query.fetch(1000) totals = [] for i in items: totals.append(0) user_purchase_orders = [] users = self.get_all_users() for user in users: user_po = UserPO(user, harvest_date, items) if user_po.sub_total_charge > 0: user_purchase_orders.append(user_po) user_po.add_quants(totals) harvest_date_str = harvest_date.strftime("%Y-%m-%d") template_values = { 'harvest_date': harvest_date_str, 'user_pos': user_purchase_orders, 'logout_url': self.url, 'url_linktext': self.url_linktext, } path = os.path.join(os.path.dirname(__file__), fname) self.response.out.write(template.render(path, template_values))
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)
def do_page(self, fname='harvest.html'): harvest_date = self.request.get('weekof') harvest_date = self.get_harvest_date(harvest_date) inv_query = InventoryList.all() inv_query.filter('date = ', harvest_date) inv = inv_query.fetch(1000) locked_or_not = "unlocked" if inv != None and len(inv) > 0 and inv[0].locked == 1: locked_or_not = "locked" item_query = Item.all() item_query.filter('date = ', harvest_date) item_query.order('name') items = item_query.fetch(1000) totals = [] for i in items: totals.append(0) total_collect = 0.0 user_purchase_orders = [] users = self.get_all_users() for user in users: user_po = UserPO(user, harvest_date, items) if user_po.sub_total_charge > 0: user_purchase_orders.append(user_po) user_po.add_quants(totals) total_collect = total_collect + user_po.total_charge # trim out items that no one wanted # ---- find all the 0 index zero_ndxs = [] for j in range(0, len(items)): i = len(items) - j - 1 total = 0 for po in user_purchase_orders: if len(items) != len(po.quat_list): raise Exception("trouble") total = total + po.quat_list[i] if total == 0: logging.info("removing index %d" %(i)) zero_ndxs.append(i) # ---- remove all of the xero indexs for i in zero_ndxs: items.pop(i) totals.pop(i) for po in user_purchase_orders: po.quat_list.pop(i) harvest_date_str = harvest_date.strftime("%Y-%m-%d") template_values = { 'harvest_date': harvest_date_str, 'list_header': items, 'locked_or_not': locked_or_not, 'user_pos': user_purchase_orders, 'logout_url': self.url, 'totals': totals, 'total_collect':total_collect, 'url_linktext': self.url_linktext, } path = os.path.join(os.path.dirname(__file__), fname) self.response.out.write(template.render(path, template_values))
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)
def do_page(self, fname='harvest.html'): harvest_date = self.request.get('weekof') harvest_date = self.get_harvest_date(harvest_date) inv_query = InventoryList.all() inv_query.filter('date = ', harvest_date) inv = inv_query.fetch(1000) locked_or_not = "unlocked" if inv != None and len(inv) > 0 and inv[0].locked == 1: locked_or_not = "locked" item_query = Item.all() item_query.filter('date = ', harvest_date) item_query.order('name') items = item_query.fetch(1000) totals = [] for i in items: totals.append(0) total_collect = 0.0 user_purchase_orders = [] users = self.get_all_users() for user in users: user_po = UserPO(user, harvest_date, items) if user_po.sub_total_charge > 0: user_purchase_orders.append(user_po) user_po.add_quants(totals) total_collect = total_collect + user_po.total_charge # trim out items that no one wanted # ---- find all the 0 index zero_ndxs = [] for j in range(0, len(items)): i = len(items) - j - 1 total = 0 for po in user_purchase_orders: if len(items) != len(po.quat_list): raise Exception("trouble") total = total + po.quat_list[i] if total == 0: logging.info("removing index %d" % (i)) zero_ndxs.append(i) # ---- remove all of the xero indexs for i in zero_ndxs: items.pop(i) totals.pop(i) for po in user_purchase_orders: po.quat_list.pop(i) harvest_date_str = harvest_date.strftime("%Y-%m-%d") template_values = { 'harvest_date': harvest_date_str, 'list_header': items, 'locked_or_not': locked_or_not, 'user_pos': user_purchase_orders, 'logout_url': self.url, 'totals': totals, 'total_collect': total_collect, 'url_linktext': self.url_linktext, } path = os.path.join(os.path.dirname(__file__), fname) self.response.out.write(template.render(path, template_values))