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