コード例 #1
0
    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")
コード例 #2
0
    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")
コード例 #3
0
    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")