def addItem_cascade(self): try: itemname = self.itemname.text itembarcode = self.barcode.text price = float(self.price.text) manufacturer = self.man.text quantity = int(self.quantity.text) quantity = int(self.quantity_update) + quantity item = models.Inventory(itemname=itemname, price=price, barcode=str(itembarcode), manufacturer=manufacturer, quantity=quantity, sold=0, id=self.id, category=self.category) saved = item.save(update=True) if saved == 1 or saved == 0: # messagebox.showinfo(title="Success", message="Item {} updated successfully".format(itemname)) popup = Popup( title='Success', content=Label( text="Item {} updated successfully".format(itemname)), size_hint=(None, None), size=(400, 400)) popup.open() self.itemname.text = "" self.barcode.text = "" self.price.text = "" self.man.text = "" self.quantity.text = "" self.available.text = "" self.label_qty.text = "Quantity" models.log(activity="Item modification", transactiontype="modify", amount=0, barcode=itembarcode, time=str(datetime.datetime.now())) else: messagebox(title="Failed", message="Nothing to update in {}".format(itemname)) except ValueError: messagebox(title="Warning", message="Price, quantity, barcode must be a Numbers") except AttributeError: messagebox( title="Oops!", message= "Seems like the item is already present in the database. \n" "Please fill in the barcode field and press \"Enter\" key to get all the details" "\nof the item and update corresponding fields")
def addItem(self, event): try: itemname = self.itemname.text itembarcode = self.barcode.text price = float(self.price.text) manufacturer = self.man.text quantity = int(self.quantity.text) item = models.Inventory(itemname=itemname, price=price, barcode=str(itembarcode), manufacturer=manufacturer, quantity=quantity, sold=0, category=self.category) saved = item.save(insert=True) if saved == 1: messagebox( title="Success", message="Item {} added successfully".format(itemname)) self.itemname.text = "" self.barcode.text = "" self.price.text = "" self.man.text = "" self.quantity.text = "" models.log(activity="Item Addition", transactiontype="additem", amount=0, barcode=itembarcode, time=str(datetime.datetime.now())) else: messagebox(title="Failed", message="Could not add {}".format(itemname)) except ValueError: messagebox(title="Warning", message="Price, quantity, barcode must be a Numbers") except pymysql.err.IntegrityError: # messagebox.showinfo(title="Error", # message="Item with same barcode cannot be added multiple times. Use update button to update the item details ") # p = Popup(title="Are you sure?", # content=Label( # text="Are you sure to overwrite the existing data for {}".format(self.itemname.text)), # size_hint=(None, None), size=(400, 200)) # p.open() # itembarcode = self.barcode.text # inventory_db = models.InventoryDB() # record = inventory_db.getInventoryRecodeByBarcode(itembarcode)[0] # self.quantity_update = str(record.quantity) # self.category_entry.text = record.category # self.category = record.category self.addItem_cascade()
def sell(self): try: # print("Sell called") barcodetext = str(self.barcode_text.text) quantity_ = int(self.quantity_.text) # print(quantity_) sellable = InventoryDB() sellable = sellable.getInventoryRecodeByBarcode(barcodetext) # print(sellable) sellable = sellable[0] if (sellable.quantity > quantity_): sellable.quantity = sellable.quantity - quantity_ saved = sellable.save(update=True) sold_price = sellable.price * quantity_ sell = Sales(barcode=barcodetext, time=str(datetime.datetime.now()), quantity=quantity_, itemname=sellable.itemname, amount=sold_price, category=sellable.category) sold = sell.save(insert=True) if saved == 1 and sold == 1: messagebox(title="Success", message="Item {} of quantity {} sold successfully".format(sellable.itemname, quantity_)) self.barcode_text.text = "" log(activity="Sales", transactiontype="sale", amount=sold_price, barcode=barcodetext, time=str(datetime.datetime.now())) else: messagebox(title="Failed", message="Could not sell {}".format(self.barcode_text.text)) elif sellable.quantity == 0: send_mail(subject="Stock Update", message="The stock for {} is finished up. Please add some stock to the inventory".format( sellable.itemname)) messagebox(title="Oops..", message="The stock is empty. A Remainder mail is sent to you") else: messagebox(title="Sorry :(", message="Stock not available. The available qunatity is {} ".format( sellable.quantity)) except IndexError: messagebox(title="Failed", message="Barcode {} does not exists".format(self.barcode_text.text)) except TypeError: messagebox(title="Failed", message="Barcode not provided")
def sellAll(self, event): try: if len(self.basket) == 0: raise EmptyBasketError for i in self.basket: # {"barcode": self.bar_str, "Item Name": record.itemname,"quantity": str(self.quantity_.text), "amount": total_price} barcodetext = str(i["barcode"]) quantity_ = int(i["quantity"]) sellable = InventoryDB() sellable = sellable.getInventoryRecodeByBarcode(barcodetext)[0] # sellable.quantity = sellable.quantity - int(quantity_) remaining = sellable.quantity - int(quantity_) if remaining <= 0: print("Quantity not available ") continue else: sellable.quantity = sellable.quantity - int(quantity_) saved = sellable.save(update=True) sold_price = sellable.price * quantity_ sell = Sales(barcode=barcodetext, time=str(datetime.datetime.now()), quantity=quantity_, itemname=sellable.itemname, amount=sold_price, category=sellable.category) sold = sell.save(insert=True) if saved == 1 and sold == 1: messagebox(title="Success", message="Item {} of quantity {} sold successfully".format(sellable.itemname, quantity_)) self.barcode_text.text = "" log(activity="Sales", transactiontype="sale", amount=sold_price, barcode=barcodetext, time=str(datetime.datetime.now())) # self.label1.text = "" # self.basket.clear() # print(self.basket) self.label1.text = "" self.basket.clear() self.quantity_.text = "1" print(self.basket) except IndexError: messagebox(title="Failed", message="Barcode {} does not exists".format(self.barcode_text.text)) self.barcode_text.text = "" except EmptyBasketError: messagebox(title="Oops!", message="Nothing to sell")
def sellAll(self, customername, paymentmode, invoice_no, tip=0): try: if len(self.basket) == 0: raise EmptyBasketError for i in self.basket: # {"barcode": self.bar_str, "Item Name": record.itemname,"quantity": str(self.quantity_.text), "amount": total_price} barcodetext = str(i["barcode"]) quantity_ = int(i["quantity"]) sellable = InventoryDB() sellable = sellable.getInventoryRecodeByBarcode(barcodetext)[0] # sellable.quantity = sellable.quantity - int(quantity_) remaining = sellable.quantity - int(quantity_) if remaining < 0 and sellable.category != "SERVICE": messagebox(title="Warning", message="Quantity not available ") continue elif sellable.category == "SERVICE": sellable.quantity = 0 else: sellable.quantity = sellable.quantity - int(quantity_) saved = sellable.save(update=True) sold_price = sellable.price * quantity_ # sold_price = float(self.selling_price.text) * quantity_ sold_price = sold_price + float(tip) sell = Sales(barcode=barcodetext, time=str(datetime.datetime.now()), quantity=quantity_, itemname=sellable.itemname, amount=sold_price, category=sellable.category, invoice_no=invoice_no, customername=customername, paymentmode=paymentmode, tip=tip, cash=self.cash_amt, card=self.card_amt, name=self.sty_name) sold = sell.save(insert=True) tip = tip - tip if saved == 1 and sold == 1: # messagebox(title="Success", # message="Item {} of quantity {} sold successfully..\nTotal amount : {}".format( # sellable.itemname, # quantity_)) self.barcode_text.text = "" log(activity="Sales", transactiontype="sale", amount=sold_price, barcode=barcodetext, time=str(datetime.datetime.now())) # self.label1.text = "" # self.basket.clear() # print(self.basket) if sellable.quantity <= config.STOCK_LIMIT: try: send_mail( subject="Stock Update", message= "The stock for {} is finished up. Current available stock is {} . Please add some stock to the inventory" .format(sellable.itemname, sellable.quantity)) except smtplib.SMTPServerDisconnected: messagebox( title="Warning", message="Mailing configuration isn't setup") messagebox(title="Success", message="Order successful") self.label1.text = "" self.basket.clear() self.quantity_.text = "1" print(self.basket) except IndexError: messagebox(title="Failed", message="Barcode {} does not exists".format( self.barcode_text.text)) self.barcode_text.text = "" except EmptyBasketError: messagebox(title="Oops!", message="Nothing to sell")