def post(self): user = getUser(self, '/addpurchase') title = unicode(self.request.get('title')) description = unicode(self.request.get('description')) priority = unicode(self.request.get('priority')) logging.info('Post request') logging.info('Message from form title:' + title) logging.info('Message from form description:' + description) logging.info('Message from form priority:' + priority) purchase = Purchase(user=user,title=title,description=description, priority = int(priority)) purchase.put() self.redirect('/addpurchase')
def _get_purchase_variants(books_list, current_purchase_sequence=None, purchase_sequences_top=None): books_list = books_list[:] # copy # if not purchase_sequences_top: # purchase_sequences_top = [] if not current_purchase_sequence: current_purchase_sequence = [] current_purchase_sequence = copy.deepcopy(current_purchase_sequence) if len(books_list) <= BOUGHT_BOOKS_IN_ONE_PURCHASE: # leftovers - buy all of them as is current_purchase_sequence.append(Purchase(bought_books=books_list[:])) return current_purchase_sequence else: books_combinations = itertools.combinations(books_list, BOUGHT_BOOKS_IN_ONE_PURCHASE) for books_combination in books_combinations: # check all books groups to buy combinations purchase = Purchase(bought_books=books_combination) min_cost = purchase.get_minimum_cost() leftovers_books = _substract_lists(books_list, books_combination) from_purchases_list = _get_books_from_purchases_list(current_purchase_sequence) leftovers_books = _substract_lists(leftovers_books, from_purchases_list) free_getting_books = list(get_books_cost_less_equals(leftovers_books, min_cost)) for free_book in free_getting_books: # check all free books possible variants purchase.free_book = free_book other_books = leftovers_books[:] other_books.remove(free_book) mod_purchase_sequence = current_purchase_sequence[:] mod_purchase_sequence.append(purchase) # TODO problem is here sequence = _get_purchase_variants(books_list=other_books, current_purchase_sequence=mod_purchase_sequence[:], purchase_sequences_top=purchase_sequences_top) if sequence: purchase_sequences_top.append(PurchaseSequence(sequence)) return None
def get(self): logging.info('ShowPurchases::get()') user = getUser(self,self.request.uri) q = Purchase.all() q.filter('user', user) q.order('-priority') purchases = q.fetch(100) param = {'user' : user, 'purchases' : purchases} path = os.path.join(os.path.dirname(__file__), 'view/show_purchases.html') self.response.out.write(template.render(path, param))
def tally(self, split_text, chat, telegram_id, name, make_new_user=True): nsp = NumericStringParser() # We only drink an integer amount of real beer amount = int(nsp.eval(split_text[0]).real) if abs(amount) > 99: self.send_message( "Tally between -100 and 100, " + str(amount) + " given", chat) return if abs(amount) < 0.5: self.send_message("That's a bunch of nothing you have there", chat) return user = self.db.get_user_by_telegram_id(telegram_id) if (not make_new_user) & (user == False): self.send_message("Unknown user: "******"Unknown product: " + split_text[1], chat) return purchase = Purchase(user, product, amount, self.db.get_chat(chat)) # Get old score and new score all_tallies = self.db.get_all_tallies(chat, user) if product.name in all_tallies.keys(): new_score = copy.copy(all_tallies[product.name]) old_score = new_score - amount else: old_score = 0 new_score = amount # Tallied and balance message: message = "Tallied {1!s} {3!s} for {0!s} (current balance is {2!s} {3!s}).".format( user.name, amount, new_score, product.name) # Attach some additional message if called for If user remains on the wrong end with a positive tally, # add a simple notification & sometimes a personal message: if (old_score >= 0) and (new_score > 0) and (amount > 0): message += "\n{0!s} has run out of {3!s} and is consuming another person's {3!s}!".format( user.name, amount, new_score, product.name) # Every fourth product or tally of at least 4 products, remind the user personally if new_score % 4 == 0: self.snark(user, new_score, product) elif amount >= 4: self.snark(user, new_score, product) # If a user remains on the wrong end with a negative tally, a more encouraging message: elif (old_score >= 0) and (new_score > 0) and (amount < 0): message += "\n{0!s}, thank you for adding some {3!s} to your stock. You did not add enough to return to " \ "Tally's good graces, though!".format( user.name, amount, new_score, product.name) # Notify those who add exactly enough: elif (old_score >= 0) and (new_score == 0) and (amount < 0): message += "\n{0!s}, thank you for adding some {3!s} to your stock. Tally likes those who do their " \ "bookkeeping to the letter!".format( user.name, amount, new_score, product.name) # Warn a user if their last item is tallied: elif (old_score < 0) and (new_score >= 0): message += "\nBetter enjoy that {3!s}, {0!s}! You've depleted your stock!".format( user.name, amount, new_score, product.name) self.send_message( "{0!s}, your last {3!s} was just tallied!".format( user.name, amount, new_score, product.name), telegram_id) # Send message & commit purchase to database self.send_message(message, chat) self.db.add_purchase(purchase) return
import pandas as pd from json import dumps from Purchase import Purchase from Sale import Sale from pathlib import Path pur = Purchase("./pur_inv.xlsx") sale = Sale("./sale_inv.xlsx") # Populating pur_sale table by going through each sale against purchase for each_sale_inv in sale.inv: for item in each_sale_inv["_item"]: # if PUR_INV_ID was specified explicitly on sale_inv_xlsx pur_inv_id = str(item["PUR_INV_ID"]).strip() if pur_inv_id == "nan" or pur_inv_id == "": pur_inv_id = None pur.purchase(item["SIZE"], item["PCS"], each_sale_inv["_id"], item["_id"], pur_inv_id=pur_inv_id) from Report import Report from view_ship_wise_sale import Ship_Wise from view_inv_wise_sale import Inv_Wise view_list = [ Report(pur.inv, sale.inv), Ship_Wise(pur.inv, sale.inv),
def purchase_event(): jsonData = simplejson.loads(request.body.read()) if request.body else {} purchaseOrder = False if jsonData: from Purchase import Purchase purchaseObj = Purchase(db) purchaseOrder = purchaseObj.create_purchase_order(jsonData) if purchaseOrder: if purchaseOrder.get("successCode") == 1: from datetime import datetime PurchaseDateTime = datetime.now().strftime( "%A, %b %d %Y at %I:%M:%S %p") + "(GMT)" thisMessage = "On " + PurchaseDateTime + ":\n" + jsonData.get( "fName") + " " + jsonData.get("lName") + "\n" if jsonData.get("memberID"): thisMessage = thisMessage + "Member ID - " + jsonData.get( "memberID") + "\n" if jsonData.get("fName1") and jsonData.get("lName1"): thisMessage = thisMessage + "attending with" + jsonData.get( "fName1") + " " + jsonData.get("lName1") + "\n" thisMessage = thisMessage + "Purchased: " + jsonData.get( "label") + "\n" if purchaseOrder.get("eventName"): thisMessage = thisMessage + "for " + purchaseOrder.get( "eventName") + "\n" thisMessage = thisMessage + "Cost: $" + str( jsonData.get("price", 0)) + "\n" thisMessage = thisMessage + "___________________________________________\nThe transaction was approved.\n" thisMessage = thisMessage + "NMI transaction ID: " + purchaseOrder.get( "txnID") + "\n" thisMessage = thisMessage + "Players Confirmation Code: " + purchaseOrder.get( "confirmation") + "\n" x = mail.send(to=['*****@*****.**'], subject="Event Purchase Online", message=thisMessage) if x == True and jsonData.get("email"): cardMap = { "card": "Credit", "amex": "American Express", "visa": "Visa", "mastercard": "Mastercard", "discover": "Discover" } otherMessage = "On " + PurchaseDateTime + ":\n" otherMessage = otherMessage + jsonData.get( "billingData")["firstname"] + " " + jsonData.get( "billingData")["lastname"] + "'s\n" otherMessage = otherMessage + cardMap[jsonData.get( "cardData", {"thisCard": "card" })["thisCard"]] + " card ending in \"" otherMessage = otherMessage + jsonData.get( "cardData")["cleanCCnumber"][-4:] + "\" was charged\n" otherMessage = otherMessage + "$" + str( jsonData.get("price", 0)) + "\n" otherMessage = otherMessage + "Purchased: " + jsonData.get( "label") + "\n" if purchaseOrder.get("eventName"): otherMessage = otherMessage + "for " + purchaseOrder.get( "eventName") + "\n" otherMessage = otherMessage + "___________________________________________\nThe purchase was approved\n" otherMessage = otherMessage + "for " + jsonData.get( "fName") + " " + jsonData.get("lName") + ", " if jsonData.get("memberID"): otherMessage = otherMessage + "Member ID - " + jsonData.get( "memberID") if jsonData.get("fName1") and jsonData.get("lName1"): otherMessage = otherMessage + ",\n" + "who will be attending with " + jsonData.get( "fName1") + " " + jsonData.get("lName1") + "\n" otherMessage = otherMessage + "Players Confirmation Code: " + purchaseOrder.get( "confirmation") + "\n" mail.send(to=[jsonData.get("email")], subject="Purchase confirmation", message=otherMessage) return api_response(thisPurchase=purchaseOrder)
conn = None try: conn = sqlite3.connect(db_file) except sqlite3.Error as e: print(e) return conn db = DBHelper() con = create_connection('radix.sqlite') purchases = con.execute("SELECT * FROM purchase").fetchall() group = db.get_chat(-1001487022745) for tup in purchases: u = db.get_user(tup[1]) pr = db.get_product(tup[2]) amount = tup[3] p = Purchase(u, pr, amount, group, date=tup[5]) db.add_purchase(p)
def removeElement(key): logging.info('transaction started') purchase = Purchase.get(key) if purchase: purchase.delete() logging.info('transaction finished')
def OnPurchase(self, event): window = Purchase(self.plMain, 'Purchases', PurchaseLogic(self.session, self.peripherals)) window.AddToAuiNotebook(self.plMain)