def export_xls(self): from Common.exports_xlsx import export_dynamic_data table = self.invent_table hheaders = table.hheaders dict_data = { 'file_name': "Inventaire", 'headers': hheaders, 'data': table.data, "extend_rows": [ (3, table.sum_totals), ], 'sheet': self.title, # 'title': self.title, 'format_money': [ "C:C", "D:D", ], 'widths': table.stretch_columns, "date": "Du {} au {}".format( date_to_datetime(self.on_date.text()).strftime(u'%d/%m/%Y'), date_to_datetime(self.end_date.text()).strftime(u'%d/%m/%Y')) } export_dynamic_data(dict_data)
def export_xls(self): from Common.exports_xlsx import export_dynamic_data dict_data = { 'file_name': "versements", 'headers': self.table.hheaders[:-1], 'data': self.table.data, "extend_rows": [ (1, self.table.label_mov_tt), (3, self.table.balance_tt), ], # "footers": [], 'sheet': self.title, # 'title': self.title, 'widths': self.table.stretch_columns, 'exclude_row': len(self.table.data) - 1, 'format_money': [ "D:D", ], 'others': [ ("A7", "B7", "Compte : {}".format(self.table.provider_clt)), ("A8", "B8", "Du {} au {} : {}".format( date_to_datetime(self.on_date.text()).strftime( Config.DATEFORMAT), date_to_datetime( self.end_date.text()).strftime(Config.DATEFORMAT), device_amount(self.table.balance_tt))), ], } export_dynamic_data(dict_data)
def save_edit(self): ''' add operation ''' if check_is_empty(self.amount_field): return amount = int(self.amount_field.text()) refund_date = unicode(self.refund_date_field.text()) # self.remaining = self.last_r.remaining if check_field( self.amount_field, "Ce montant ne peut être supperieur au dettes restante {}.".format( self.last_remaining), amount > self.last_remaining): return refund = self.refund refund.type_ = self.type_ refund.invoice = self.last_r.invoice refund.amount = amount if self.new: refund.provider_client = self.provid_clt refund.date = date_to_datetime(refund_date) try: refund.save() self.close() self.parent.Notify(u"le {type} {lib} à été enregistré avec succès".format( type=self.type_, lib=amount), "success") self.table_p.refresh_(provid_clt_id=self.provid_clt.id) except Exception as e: self.parent.Notify(e, "error")
def save_report(self): ''' add operation ''' # entete de la facture self.table_out.changed_value() if not self.table_out.isvalid: return False date_out = str(self.date_out.text()) datetime_ = date_to_datetime(date_out) self.current_store = self.liste_store[self.box_store.currentIndex()] values_t = self.table_out.get_table_items() for qty, name in values_t: rep = Reports(type_=Reports.S, store=self.current_store, date=datetime_, product=Product.get(name=name), qty_use=int(qty)) try: rep.save() except: self.parent.Notify( u"Ce mouvement n'a pas pu être enrgistré dans les raports", "error") return False self.parent.change_context(GReportViewWidget) self.parent.Notify(u"La sortie des articles avec succès", "success")
def save_edit(self): ''' add operation ''' if check_is_empty(self.amount_field): return amount = int(self.amount_field.text()) refund_date = unicode(self.refund_date_field.text()) # self.remaining = self.last_r.remaining if check_field( self.amount_field, "Ce montant ne peut être supperieur au dettes restante {}.".format( self.last_remaining), amount > self.last_remaining): return refund = self.refund refund.type_ = self.type_ refund.invoice = self.last_r.invoice refund.amount = amount if self.new: refund.provider_client = self.provid_clt refund.date = date_to_datetime(refund_date) try: refund.save() self.close() self.parent.Notify(u"le {type} {lib} à été enregistré avec succès".format( type=self.type_, lib=amount), "success") self.table_p.refresh_(self.provid_clt.id) except Exception as e: self.parent.Notify(e, "error")
def save_edit(self): ''' add operation ''' if check_is_empty(self.amount_field): return payment_date = unicode(self.payment_date_field.text()) libelle = unicode(self.libelle_field.toPlainText()) amount = int(self.amount_field.text().replace(" ", "")) payment = self.payment payment.type_ = self.type_ payment.libelle = libelle if self.new: payment.date = date_to_datetime(payment_date) if self.type_ == Payment.CREDIT: payment.credit = amount elif self.type_ == Payment.DEBIT: payment.debit = amount try: payment.save() self.close() self.parent.Notify(u"le {type} {lib} à été enregistré avec succès".format( type=self.type_, lib=libelle), "success") self.table_p.refresh_() except Exception as e: self.parent.Notify(e, "error")
def save_b(self): ''' add operation ''' # entete de la facture if not self.table_in.isvalid: return False date = str(self.date.text()) datetime_ = date_to_datetime(date) store = self.liste_store[self.box_mag.currentIndex()] values_t = self.table_in.get_table_items() for ligne in values_t: qty, name = ligne product = Product.select().where(Product.name == name).get() rep = Reports(orders=None, type_=Reports.E, store=store, date=datetime_, product=product, qty_use=int(qty)) try: rep.save() except: self.parent.Notify( u"Ce mouvement n'a pas pu être enrgistré dans les raports", "error") return False self.parent.change_context(GReportViewWidget) self.parent.Notify(u"L'entrée des articles avec succès", "success")
def export_xls(self): from Common.exports_xls import export_dynamic_data table = self.invent_table hheaders = table.hheaders dict_data = { 'file_name': "Inventaire.xls", 'headers': hheaders, 'data': table.data, "extend_rows": [(3, table.sum_totals), ], 'sheet': self.title, 'title': self.title, 'widths': table.stretch_columns, "date": "Du {} au {}".format( date_to_datetime(self.on_date.text()).strftime(u'%d/%m/%Y'), date_to_datetime(self.end_date.text()).strftime(u'%d/%m/%Y')) } export_dynamic_data(dict_data)
def refresh_(self): """ """ l_date = [ date_to_datetime(self.parent.on_date.text()), date_to_datetime(self.parent.end_date.text()) ] self._reset() self.set_data_for(l_date) self.refresh() self.hideColumn(len(self.hheaders) - 1) pw = self.parent.parent.page_width() / 5 self.setColumnWidth(0, pw) self.setColumnWidth(1, pw) self.setColumnWidth(2, pw) self.setColumnWidth(3, pw)
def refresh_(self, provid_clt_id=None, search=None): """ """ self.totals_debit = 0 self.totals_credit = 0 self.balance_tt = 0 self.d_star = date_to_datetime(self.parent.on_date.text()) self.d_end = date_to_datetime(self.parent.end_date.text()) l_date = [self.d_star, self.d_end] self._reset() self.set_data_for(l_date, provid_clt_id=provid_clt_id, search=search) self.refresh() pw = self.parent.parent.page_width() / 6 self.setColumnWidth(0, pw) self.setColumnWidth(1, pw) self.setColumnWidth(2, pw * 2) self.setColumnWidth(3, pw) self.parent.soldeField.setText( self.parent.display_remaining(device_amount(self.balance_tt)))
def export_xls(self): from Common.exports_xlsx import export_dynamic_data dict_data = { 'file_name': "versements.xlsx", 'headers': self.table.hheaders[:-1], 'data': self.table.data, "extend_rows": [ (1, self.table.label_mov_tt), (2, self.table.totals_debit), (3, self.table.totals_credit), ], "footers": [ ("C", "E", "Solde au {} = {}".format(self.now, self.table.balance_tt)), ], 'sheet': self.title, # 'title': self.title, 'format_money': [ 'C:C', 'D:D', 'E:E', ], 'widths': self.table.stretch_columns, 'exclude_row': len(self.table.data) - 1, "date": "Du {} au {}".format( date_to_datetime(self.on_date.text()).strftime(u'%d/%m/%Y'), date_to_datetime(self.end_date.text()).strftime(u'%d/%m/%Y')) } export_dynamic_data(dict_data)
def edit_report(self): type_ = self.box_type.currentIndex() product = self.liste_product[self.box_prod.currentIndex()] qty_use = str(self.nbr_carton.text()) date_ = self.date_.text() datetime_ = date_to_datetime(date_) report = self.op report.type_ = type_ report.product = product report.qty_use = qty_use report.remaining = 0 report.date = datetime_ report.save() self.cancel() self.parent.Notify(u"Votre rapport a été modifié", "success")
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)
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)
def refresh(self): self.l_date = [ date_to_datetime(self.on_date.text()), date_to_datetime(self.end_date.text()) ] self.invent_table.refresh_period(self.l_date)
def display_remaining(self, amount_text): return """ <h2>Solde du {} au {} : <b>{}</b></h2> """.format( date_to_datetime(self.on_date.text()).strftime(Config.DATEFORMAT), date_to_datetime(self.end_date.text()).strftime(Config.DATEFORMAT), amount_text)
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)
def export_xls_order(self): L = self.order_table.getTableItems() com_date = date_to_datetime(self.com_date.text()) write_order_xls("order.xls", [com_date, L])
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 refresh(self): self.l_date = [ date_to_datetime(self.on_date.text()), date_to_datetime(self.end_date.text())] self.invent_table.refresh_period(self.l_date)
def export_xls_order(self): L = self.order_table.getTableItems() com_date = date_to_datetime(self.com_date.text()) write_order_xls("order", [com_date, L])
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)