def handle(self, seller_alias): try: seller = Contact.by_alias(seller_alias) except: self.respond("Sorry, user %s was not found. Please check your spelling and try again" % seller_alias) else: response = self.get_current_stock(seller) self.respond("Stock for %s: %s" % (seller.alias, response))
def handle(self, seller_alias): try: seller = Contact.by_alias(seller_alias) except: self.respond( "Sorry, user %s was not found. Please check your spelling and try again" % seller_alias) else: response = self.get_current_stock(seller) self.respond("Stock for %s: %s" % (seller.alias, response))
def handle(self, text): stocker = self.msg.connection.contact args = text.partition(" ") if args[0] == "cancel": self.cancel_restocks(stocker) return True target_alias = args[0].lower() restock_list = self.parse_restock_string(args[2].lower()) if not restock_list: self.help() return True # confirm that alias exists try: target = Contact.objects.get(alias=target_alias) except: self.respond("Sorry, user %s was not found. Please check your spelling and try again" % target_alias) return True errors = [] stockouts = [] pending = [] response = "" notification = "" # admin must create this user, for holding pending stock transactions nobody = Contact.by_alias("nobody") for code, amount in restock_list: if amount == 0: errors.append(code) if amount == -1 or code == "": self.respond( "Missing product code or amount. Restock messages cannot contain spaces.\nExample: restock dnombo 5ew" ) return True else: current_stock = Stock.get_existing(stocker.alias, code) # make sure the initiator of the transaction has enough stock if current_stock is None or current_stock.stock_amount < amount: stockouts.append(code) else: target_product = Product.by_code(code) s = Stock(seller=nobody, product=target_product, stock_amount=amount) s.save() pending.append(s) current_stock.stock_amount -= amount current_stock.save() if pending: # create the transaction object and add stock to be moved trans = StockTransaction(initiator=stocker, recipient=target, status=2, date_initiated=datetime.now()) trans.save() # need to generate a primary key before adding products for p in pending: trans.to_transfer.add(p) response += "%s %s " % (p.stock_amount, p.product.display_name) notification += "%s %s " % (p.stock_amount, p.product.display_name) trans.save() response += "sent to %s. " % target.alias if stockouts: for out in stockouts: response += "%s " % out response += "out of stock. " if errors: for err in errors: response += "%s " % err response += "not recognized." self.respond(response) if notification: notification += "being sent by %s. Reply 'yes' to accept, 'no' to reject." % stocker.alias target.message(notification)
def handle(self, text): stocker = self.msg.connection.contact args = text.partition(' ') if args[0] == 'cancel': self.cancel_restocks(stocker) return True target_alias = args[0].lower() restock_list = self.parse_restock_string(args[2].lower()) if not restock_list: self.help() return True # confirm that alias exists try: target = Contact.objects.get(alias=target_alias) except: self.respond( "Sorry, user %s was not found. Please check your spelling and try again" % target_alias) return True errors = [] stockouts = [] pending = [] response = "" notification = "" #admin must create this user, for holding pending stock transactions nobody = Contact.by_alias("nobody") for code, amount in restock_list: if amount == 0: errors.append(code) if amount == -1 or code == '': self.respond( "Missing product code or amount. Restock messages cannot contain spaces.\nExample: restock dnombo 5ew" ) return True else: current_stock = Stock.get_existing(stocker.alias, code) #make sure the initiator of the transaction has enough stock if current_stock is None or current_stock.stock_amount < amount: stockouts.append(code) else: target_product = Product.by_code(code) s = Stock(seller=nobody, product=target_product, stock_amount=amount) s.save() pending.append(s) current_stock.stock_amount -= amount current_stock.save() if pending: #create the transaction object and add stock to be moved trans = StockTransaction(initiator=stocker, recipient=target, status=2, date_initiated=datetime.now()) trans.save( ) #need to generate a primary key before adding products for p in pending: trans.to_transfer.add(p) response += "%s %s " % (p.stock_amount, p.product.display_name) notification += "%s %s " % (p.stock_amount, p.product.display_name) trans.save() response += "sent to %s. " % target.alias if stockouts: for out in stockouts: response += "%s " % out response += "out of stock. " if errors: for err in errors: response += "%s " % err response += "not recognized." self.respond(response) if notification: notification += "being sent by %s. Reply 'yes' to accept, 'no' to reject." % stocker.alias target.message(notification)