Example #1
0
 def save_b(self):
     ''' add operation '''
     # entete de la facture
     if not self.table_buy.isvalid:
         return False
     owner = Owner.get(Owner.islog == True)
     date = str(self.date.text())
     values_t = self.table_buy.get_table_items()
     buy = Buy()
     # buy.date = datetime_
     buy.provd_or_clt = \
         ProviderOrClient.get_or_create(
             "Fournisseur", 000000, ProviderOrClient.FSEUR)
     buy.owner = owner
     try:
         buy.save()
         err = False
     except:
         raise
         raise_error("Erreur",
                     u"Impossible d'enregistrer l'entête de la facture")
         return False
     for name, qty, cost_buying, selling_price in values_t:
         rep = Report()
         rep.buy = buy
         rep.type_ = Report.E
         rep.store = 1
         rep.date = date_to_datetime(date)
         rep.product = Product.get(name=name)
         rep.qty = int(qty)
         rep.cost_buying = int(cost_buying)
         rep.selling_price = int(selling_price)
         try:
             rep.save()
         except Exception as e:
             print(e)
             err = True
     if err:
         buy.delete_instance()
         raise_error(
             "Erreur", u"Ce mouvement n'a pas pu etre "
             u"enregistré dans les rapports")
         return False
     else:
         self.parent.Notify(u"L'entrée des articles avec succès", "success")
     self.change_main_context(BuyShowViewWidget, buy=buy)
Example #2
0
File: buy.py Project: Ciwara/GCiss
 def save_b(self):
     ''' add operation '''
     # entete de la facture
     if not self.table_buy.isvalid:
         return False
     owner = Owner.get(Owner.islog == True)
     date = str(self.date.text())
     values_t = self.table_buy.get_table_items()
     buy = Buy()
     # buy.date = datetime_
     buy.provd_or_clt = \
         ProviderOrClient.get_or_create(
             "Fournisseur", 000000, ProviderOrClient.FSEUR)
     buy.owner = owner
     try:
         buy.save()
         err = False
     except:
         raise
         raise_error(
             "Erreur", u"Impossible d'enregistrer l'entête de la facture")
         return False
     for name, qty, cost_buying, selling_price in values_t:
         rep = Report()
         rep.buy = buy
         rep.type_ = Report.E
         rep.store = 1
         rep.date = date_to_datetime(date)
         rep.product = Product.get(name=name)
         rep.qty = int(qty)
         rep.cost_buying = int(cost_buying)
         rep.selling_price = int(selling_price)
         try:
             rep.save()
         except Exception as e:
             print(e)
             err = True
     if err:
         buy.delete_instance()
         raise_error("Erreur", u"Ce mouvement n'a pas pu etre "
                     u"enregistré dans les rapports")
         return False
     else:
         self.parent.Notify(u"L'entrée des articles avec succès", "success")
     self.change_main_context(BuyShowViewWidget, buy=buy)
Example #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.change_main_context(ShowInvoiceViewWidget,
                                     invoice_num=invoice.number)
Example #4
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)