예제 #1
0
 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")
예제 #2
0
    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()