def click_item(self, row, column, *args): last_column = self.hheaders.__len__() - 1 if column != last_column: return try: self.parent.change_main_context(ShowInvoiceViewWidget, invoice=Invoice.get(number=(self.data[row][1]))) except IndexError: pass
def __init__(self, table_p, invoice_num, parent=0, *args, **kwargs): # super(ShowInvoiceViewWidget, self).__init__( # parent=parent, *args, **kwargs) QDialog.__init__(self, parent, *args, **kwargs) self.invoice = Invoice.get(number=invoice_num) self.parentWidget().setWindowTitle( "{} {}".format(Config.APP_NAME, "CONSULTATION DE FACTURE")) self.parent = parent self.table_p = table_p vbox = QVBoxLayout() self.title = self.invoice.type_ self.table_show = ShowOrderTableWidget(parent=self) editbox = QGridLayout() xls_bicon = QIcon.fromTheme( 'document-del', QIcon(u"{}xls.png".format(Config.img_cmedia))) pdf_icon = QIcon.fromTheme( 'document-del', QIcon(u"{}pdf.png".format(Config.img_cmedia))) self.button_pdf = QPushButton(pdf_icon, u"") self.button_pdf.setFixedWidth(30) self.button_pdf.setFixedHeight(30) self.button_xls = QPushButton(xls_bicon, u"") self.button_xls.setFixedWidth(30) self.button_xls.setFixedHeight(30) self.button_pdf.released.connect(self.printer_pdf) self.button_xls.released.connect(self.export_xls) self.button_dl = DeletedBtt(u"Annuler la facture") self.button_dl.released.connect(self.cancellation) editbox.addWidget(FLabel(u"{typ} N°: {num}".format( num=self.invoice.number, typ=self.invoice.type_)), 0, 0) editbox.addWidget(FLabel(u"%s le %s" % ( self.invoice.location, show_date(self.invoice.date))), 1, 4) editbox.addWidget(FLabel(u"Doit: %s " % self.invoice.client), 1, 0) editbox.addWidget(self.button_pdf, 1, 5) editbox.addWidget(self.button_dl, 0, 4) editbox.addWidget(self.button_xls, 1, 6) vbox.addLayout(editbox) vbox.addWidget(self.table_show) self.setLayout(vbox)
def __init__(self, invoice_num, parent=0, *args, **kwargs): super(ShowInvoiceViewWidget, self).__init__( parent=parent, *args, **kwargs) self.invoice = Invoice.get(number=invoice_num) self.parentWidget().setWindowTitle(Config.NAME_ORGA + u" CONSULTATION DE FACTURE") self.parent = parent vbox = QVBoxLayout() self.title = self.invoice.type_ self.table_show = ShowOrderTableWidget(parent=self) editbox = QGridLayout() xls_bicon = QIcon.fromTheme( 'document-del', QIcon(u"{}xls.png".format(Config.img_cmedia))) pdf_icon = QIcon.fromTheme( 'document-del', QIcon(u"{}pdf.png".format(Config.img_cmedia))) self.button_pdf = QPushButton(pdf_icon, u"") self.button_pdf.setFixedWidth(30) self.button_pdf.setFixedHeight(30) self.button_xls = QPushButton(xls_bicon, u"") self.button_xls.setFixedWidth(30) self.button_xls.setFixedHeight(30) self.button_pdf.released.connect(self.printer_pdf) self.button_xls.released.connect(self.export_xls) self.button_dl = Deleted_btt(u"Annuler la facture") self.button_dl.released.connect(self.cancellation) editbox.addWidget(FLabel(u"{typ} N°: {num}".format( num=self.invoice.number, typ=self.invoice.type_)), 0, 0) editbox.addWidget(FLabel(u"%s le %s" % (self.invoice.location, show_date(self.invoice.date))), 1, 4) editbox.addWidget(FLabel(u"Doit: %s " % self.invoice.client), 1, 0) # editbox.addWidget(self.button_pdf, 1, 5) editbox.addWidget(self.button_dl, 0, 4) editbox.addWidget(self.button_xls, 1, 6) vbox.addLayout(editbox) vbox.addWidget(self.table_show) self.setLayout(vbox)
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)
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)
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)