コード例 #1
0
ファイル: invoice_view.py プロジェクト: fadiga/mstock
    def save_b(self):
        ''' add operation '''
        # entete de la facture
        if not self.table_invoice.isvalid:
            return False
        try:
            num_invoice = int(self.num_invoice.text())
            self.num_invoice_error.setText(u"")
        except:
            self.pixmap = QPixmap(u"{img_media}{img}".format(img_media=Config.img_media,
                                                      img="warning.png"))
            self.num_invoice.setStyleSheet("background-color:  rgb(255, 235, 235);")
            self.num_invoice_error.setToolTip(u"Le numero de facture est obligatoire.")
            self.num_invoice_error.setPixmap(self.pixmap)
        invoice_date = str(self.invoice_date.text())
        name_client = str(self.name_client.text())
        datetime_ = date_to_datetime(invoice_date)

        values_t = self.table_invoice.get_table_items()
        if name_client == "":
            self.name_client.setStyleSheet("background-color: rgb(255, 235, 235);")
            self.pixmap = QPixmap(u"{img_media}{img}".format(img_media=Config.img_media,
                                                      img="decline.png"))
            self.name_client_error.setToolTip(u"Nom du client est obligatoire.")
            self.name_client_error.setPixmap(self.pixmap)
            return False
        # if num_invoice > Config.credit:
        #     raise_error(("Avertisement"), u"<h2>Veuillez payer la reste de la licence</h2>")
        #     return False
        invoice = Invoice()
        try:
            invoice.owner = Owner.get(islog=True)
        except:
            if Config.DEBUG:
                invoice.owner = Owner.get(username='******')
            else:
                return False

        invoice.number = num_invoice
        invoice.date_ord = datetime_
        invoice.client = name_client.capitalize()
        invoice.location = "Bamako"
        invoice.type_ = "Facture"
        invoice.subject = ""
        invoice.tax = False
        invoice.otax_rate = 18
        try:
            invoice.save()
        except:
            raise_error("Erreur", u"Impossible d'enregistrer l'entête de la facture")
            return False

        # Save orderitems
        try:
            order = Invoice.get(number=num_invoice)
        except:
            return False
        for i in values_t:
            qty, name, price = i
            description = Product.filter(name=name).get()
            item = InvoiceItem()
            item.invoices = invoice.id
            item.quantity = int(i[0])
            item.description = description
            item.price = int(i[2])
            try:
                item.save()
                self.name_client.clear()
                self.num_invoice.clear()
            except Exception as e:
                print(e)
                invoice.delete_instance()
                raise_error("Erreur", u"Ce mouvement n'a pas pu etre "
                                      u"enregistré dans les rapports")
                return False

        self.change_main_context(ShowInvoiceViewWidget,
                                        invoice=invoice)
コード例 #2
0
ファイル: invoice.py プロジェクト: Ciwara/GCiss
    def save_b(self):
        ''' add operation '''
        # entete de la facture
        print("save")
        if not self.is_valide():
            return
        invoice_date = unicode(self.invoice_date.text())
        num_invoice = int(self.num_invoice.text())
        invoice_type = self.liste_type_invoice[
            self.box_type_inv.currentIndex()]
        lis_error = []
        invoice = Invoice()
        try:
            self.owner = Owner.get(Owner.islog == True)
        except:
            lis_error.append("Aucun utilisateur est connecté <br/>")
        paid_amount = int(self.table_invoice.paid_amount_field.text())
        try:
            clt = ProviderOrClient.get_or_create(
                self.name_client, int(self.phone.replace(" ", "")), ProviderOrClient.CLT)
        except ValueError:
            field_error(
                self.name_client_field, "Nom, numéro de téléphone du client")
        invoice.number = num_invoice
        invoice.owner = self.owner
        invoice.client = clt
        invoice.location = "Bamako"
        invoice.type_ = invoice_type
        invoice.subject = ""
        invoice.paid_amount = paid_amount
        invoice.tax = False
        try:
            invoice.save()
            if int(paid_amount) != 0 or invoice_type == Invoice.TYPE_BON:
                Refund(type_=Refund.DT, owner=self.owner, amount=paid_amount,
                       date=date_to_datetime(invoice_date), provider_client=clt,
                       invoice=Invoice.get(number=num_invoice)).save()
        except Exception as e:
            invoice.deletes_data()
            lis_error.append(
                "Erreur sur l'enregistrement d'entête de facture<br/>")
            return False
        # Save invoiceitems
        invoice = Invoice.get(Invoice.number == num_invoice)
        for name, qty, price in self.table_invoice.get_table_items():
            rep = Report()
            product = Product.get(Product.name == name)
            rep.store = 1
            rep.product = product
            rep.invoice = invoice
            rep.type_ = Report.S
            rep.cost_buying = int(product.last_report.cost_buying)
            rep.date = date_to_datetime(invoice_date)
            rep.qty = int(qty)
            rep.selling_price = int(price)
            try:
                rep.save()
            except Exception as e:
                lis_error.append(e)
        if lis_error != []:
            invoice.delete_instance()
            self.parent.Notify(lis_error, "error")
            return False
        else:
            self.parent.Notify("Facture Enregistrée avec succès", "success")

            self.change_main_context(ShowInvoiceViewWidget,
                                     invoice_num=invoice.number)
コード例 #3
0
 def save_b(self):
     ''' add operation '''
     # entete de la facture
     print("save")
     if not self.is_valide():
         return
     invoice_date = unicode(self.invoice_date.text())
     num_invoice = int(self.num_invoice.text())
     invoice_type = self.liste_type_invoice[
         self.box_type_inv.currentIndex()]
     lis_error = []
     invoice = Invoice()
     try:
         self.owner = Owner.get(Owner.islog == True)
     except:
         lis_error.append("Aucun utilisateur est connecté <br/>")
     paid_amount = int(self.table_invoice.paid_amount_field.text())
     try:
         clt = ProviderOrClient.get_or_create(
             self.name_client, int(self.phone.replace(" ", "")),
             ProviderOrClient.CLT)
     except ValueError:
         field_error(self.name_client_field,
                     "Nom, numéro de téléphone du client")
     invoice.number = num_invoice
     invoice.owner = self.owner
     invoice.client = clt
     invoice.location = "Bamako"
     invoice.type_ = invoice_type
     invoice.subject = ""
     invoice.paid_amount = paid_amount
     invoice.tax = False
     try:
         invoice.save()
         if int(paid_amount) != 0 or invoice_type == Invoice.TYPE_BON:
             Refund(type_=Refund.DT,
                    owner=self.owner,
                    amount=paid_amount,
                    date=date_to_datetime(invoice_date),
                    provider_client=clt,
                    invoice=Invoice.get(number=num_invoice)).save()
     except Exception as e:
         invoice.deletes_data()
         lis_error.append(
             "Erreur sur l'enregistrement d'entête de facture<br/>")
         return False
     # Save invoiceitems
     invoice = Invoice.get(Invoice.number == num_invoice)
     for name, qty, price in self.table_invoice.get_table_items():
         rep = Report()
         product = Product.get(Product.name == name)
         rep.store = 1
         rep.product = product
         rep.invoice = invoice
         rep.type_ = Report.S
         rep.cost_buying = int(product.last_report.cost_buying)
         rep.date = date_to_datetime(invoice_date)
         rep.qty = int(qty)
         rep.selling_price = int(price)
         try:
             rep.save()
         except Exception as e:
             lis_error.append(e)
     if lis_error != []:
         invoice.delete_instance()
         self.parent.Notify(lis_error, "error")
         return False
     else:
         self.parent.Notify("Facture Enregistrée avec succès", "success")
         self.table_invoice._reset()
         try:
             self.parent.open_dialog(ShowInvoiceViewWidget,
                                     modal=True,
                                     opacity=100,
                                     table_p=self,
                                     invoice_num=invoice.number)
         except Exception as e:
             print(e)