def refresh_prov_clt(self): try: self.name_client, self.phone = self.name_client_field.lineEdit( ).text().split(",") clt = ProviderOrClient.get(phone=int(self.phone.replace(" ", ""))) self.table.refresh_(provid_clt_id=clt.id) except Exception as e: self.table.refresh_() print(" ", e)
def refresh_(self, provid_clt=None): """ Rafraichir la liste des provid_cltes""" self.clear() self.addItem(ProviderOrClientQListWidgetItem(ALL_CONTACTS)) qs = ProviderOrClient.select().where( ProviderOrClient.type_ == ProviderOrClient.CLT) if provid_clt: qs = qs.where(ProviderOrClient.name.contains(provid_clt)) for provid_clt in qs: self.addItem(ProviderOrClientQListWidgetItem(provid_clt))
def set_data_for(self, provid_clt_id=None, search=None): self.provid_clt_id = provid_clt_id qs = Refund.select().where( Refund.status == False).order_by(Refund.date.desc()) if isinstance(provid_clt_id, int): qs = qs.select().where( Refund.provider_client == ProviderOrClient.get(id=provid_clt_id)) self.data = [(ref.id, ref.type_, show_date(ref.date), ref.invoice.number, ref.amount, ref.remaining) for ref in qs]
def set_data_for(self, provid_clt_id=None, search=None): self.provid_clt_id = provid_clt_id qs = Refund.select().where(Refund.status == False).order_by( Refund.date.desc()) self.remaining = 0 if isinstance(provid_clt_id, int): qs = qs.select().where( Refund.provider_client == ProviderOrClient.get( id=provid_clt_id)) else: for prov in ProviderOrClient.select().where( ProviderOrClient.type_ == ProviderOrClient.CLT): self.remaining += prov.last_remaining() self.parent.remaining_box.setText( self.display_remaining(formatted_number(self.remaining))) self.data = [(ref.id, ref.type_, ref.date, ref.invoice.number, ref.amount, ref.remaining) for ref in qs.iterator()]
def __init__(self, parent=0, *args, **kwargs): super(ProvidersViewWidget, self).__init__(parent=parent, *args, **kwargs) self.parent = parent self.title = u"Movements" self.on_date = FormatDate(QDate(date.today().year, 1, 1)) self.end_date = FormatDate(QDate.currentDate()) # self.now = datetime.now().strftime("%x") self.soldeField = FormLabel("{}".format(device_amount(0))) balanceBox = QGridLayout() balanceBox.addWidget(self.soldeField, 0, 3) balanceBox.setColumnStretch(0, 1) self.string_list = [""] + [ "{},{}".format(clt.name, clt.phone) for clt in ProviderOrClient.select().where( ProviderOrClient.type_ == ProviderOrClient.CLT).order_by( ProviderOrClient.name.desc()) ] self.name_client_field = ExtendedComboBox() self.name_client_field.addItems(self.string_list) self.name_client_field.setMaximumSize( 200, self.name_client_field.maximumSize().height()) self.name_client_field.setToolTip("Nom, numero du client") self.table = RapportTableWidget(parent=self) self.button = Button(u"Ok") self.button.clicked.connect(self.refresh_prov_clt) self.btt_export = BttExportXLSX(u"Exporter") self.btt_export.clicked.connect(self.export_xls) editbox = QGridLayout() editbox.addWidget(FormLabel(u"Date debut"), 0, 1) editbox.addWidget(self.on_date, 0, 2) editbox.addWidget(FormLabel(u"Date fin"), 1, 1) editbox.addWidget(self.end_date, 1, 2) editbox.addWidget(self.name_client_field, 0, 3) editbox.addWidget(self.button, 1, 3) editbox.addWidget(self.btt_export, 1, 7) editbox.setColumnStretch(4, 2) vbox = QVBoxLayout() vbox.addWidget(FPageTitle(self.title)) vbox.addLayout(editbox) vbox.addWidget(self.table) vbox.addLayout(balanceBox) self.setLayout(vbox)
def set_data_for(self, date_, provid_clt_id=None, search=None): self.provid_clt_id = provid_clt_id qs = Invoice.select().order_by(Invoice.number.asc()) if isinstance(self.provid_clt_id, int): self.provider_clt = ProviderOrClient.get(id=self.provid_clt_id) qs = qs.select().where(Invoice.client == self.provider_clt) else: self.provider_clt = "Tous" self.data = [(vl.date, vl.number, vl.client.name, vl.amount_ivoice, "") for vl in qs if (vl.date > date_[0] and vl.date < date_[1])]
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 set_data_for(self, value): if value: value = str(value) if is_int(value): qs = ((Invoice.number == int(value))) invoices = Invoice.select().where(qs) else: invoices = [] for clt in ProviderOrClient.select().where( ProviderOrClient.name.contains(value)).iterator(): for invoice in clt.invoices().iterator(): invoices.append(invoice) else: invoices = Invoice.select()[:100] try: self.data = [(invoice.number, invoice.date, invoice.client, "") for invoice in invoices] except Exception as e: print("Exception ", e)
def popup(self, pos): row = self.selectionModel().selection().indexes()[0].row() if row < 1: return menu = QMenu() refund = menu.addAction("Reglement") editaction = menu.addAction("Modifier") action = menu.exec_(self.mapToGlobal(pos)) provid_clt = ProviderOrClient.get( ProviderOrClient.phone == self.item(row).text().split(",")[1]) if action == refund: if provid_clt.is_indebted(): self.parent.new_refund(provid_clt) else: self.parent.parent.Notify( "Le client {} n'est pas endetté".format(self.item(row).text()), "error") if action == editaction: from GCommon.ui.provider_client_edit_add import EditOrAddClientOrProviderDialog self.parent.open_dialog(EditOrAddClientOrProviderDialog, modal=True, prov_clt=provid_clt, table_p=self)
def popup(self, pos): row = self.selectionModel().selection().indexes()[0].row() if row < 1: return menu = QMenu() refund = menu.addAction("Reglement") editaction = menu.addAction("Modifier") action = menu.exec_(self.mapToGlobal(pos)) provid_clt = ProviderOrClient.get( ProviderOrClient.phone == self.item(row).text().split(",")[1]) if action == refund: if provid_clt.is_indebted(): self.parent.new_refund(provid_clt) else: self.parent.parent.Notify( "Le client {} n'est pas endetté".format( self.item(row).text()), "error") if action == editaction: from GCommon.ui.provider_client_edit_add import EditOrAddClientOrProviderDialog self.parent.open_dialog(EditOrAddClientOrProviderDialog, modal=True, prov_clt=provid_clt, table_p=self)
def __init__(self, product="", parent=0, *args, **kwargs): super(InvoiceViewWidget, self).__init__(parent=parent, *args, **kwargs) self.parentWidget().setWindowTitle( Config.APP_NAME + u" Ventes") self.parent = parent vbox = QVBoxLayout(self) # hbox = QHBoxLayout(self) editbox = QGridLayout(self) try: next_number = int( Invoice.select().order_by(Invoice.number.desc()).get().number) + 1 except: next_number = 1 self.num_invoice = IntLineEdit(str(next_number)) self.num_invoice.setToolTip(u"Le numéro") self.num_invoice.setMaximumSize( 40, self.num_invoice.maximumSize().height()) self.invoice_date = FormatDate(QDate.currentDate()) # self.name_client_field = LineEdit() self.string_list = [""] + ["{},{}".format(clt.name, clt.phone) for clt in ProviderOrClient.select().where( ProviderOrClient.type_ == ProviderOrClient.CLT).order_by(ProviderOrClient.name.desc())] # self.name_client_field_new = "" self.name_client_field = ExtendedComboBox() self.name_client_field.addItems(self.string_list) self.name_client_field.setMaximumSize( 200, self.name_client_field.maximumSize().height()) self.name_client_field.setToolTip("Nom, numero du client") self.add_clt_btt = BttSmall(u"+") self.add_clt_btt.clicked.connect(self.add_clt) self.add_clt_btt.setFixedWidth(50) # Combobox widget for add store self.liste_type_invoice = [Invoice.TYPE_FACT, Invoice.TYPE_BON] self.box_type_inv = QComboBox() for index in range(0, len(self.liste_type_invoice)): op = self.liste_type_invoice[index] sentence = u"%(name)s" % {'name': op} self.box_type_inv.addItem(sentence, op) self.search_field = LineEdit() self.search_field.setPlaceholderText("Rechercher un article") self.search_field.textChanged.connect(self.finder) # self.search_field.setFixedWidth(250) self.table_invoice = InvoiceTableWidget(parent=self) self.table_resultat = ResultatTableWidget(parent=self) self.table_info = InfoTableWidget(parent=self) self.table_resultat.refresh_("") editbox.addWidget(self.box_type_inv, 0, 2) editbox.addWidget(self.num_invoice, 0, 3) editbox.addWidget(FLabel(u"Doit :"), 1, 2) editbox.addWidget(self.name_client_field, 1, 3) # editbox.addWidget(self.add_clt_btt, 1, 4) editbox.addWidget(self.invoice_date, 0, 6) editbox.setColumnStretch(0, 1) editbox.setColumnStretch(5, 1) splitter = QSplitter(Qt.Horizontal) splitter_left = QSplitter(Qt.Vertical) splitter_left.addWidget(self.search_field) splitter_left.addWidget(self.table_resultat) # splitter_down.resize(15, 20) splitter_down = QSplitter(Qt.Vertical) splitter_down.addWidget(self.table_info) splitter_rigth = QSplitter(Qt.Vertical) # splitter_rigth.setLayout(editbox) splitter_rigth.addWidget(self.table_invoice) splitter_rigth.resize(800, 900) splitter_left.addWidget(splitter_down) splitter.addWidget(splitter_left) splitter.addWidget(splitter_rigth) vbox.addLayout(editbox) vbox.addWidget(splitter) 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 __init__(self, product="", parent=0, *args, **kwargs): super(InvoiceViewWidget, self).__init__(parent=parent, *args, **kwargs) self.parentWidget().setWindowTitle(Config.APP_NAME + u" Ventes") self.parent = parent vbox = QVBoxLayout() # hbox = QHBoxLayout(self) editbox = QGridLayout() try: next_number = int(Invoice.select().order_by( Invoice.number.desc()).get().number) + 1 except: next_number = 1 self.num_invoice = IntLineEdit(str(next_number)) self.num_invoice.setToolTip(u"Le numéro") self.num_invoice.setMaximumSize( 40, self.num_invoice.maximumSize().height()) self.invoice_date = FormatDate(QDate.currentDate()) # self.name_client_field = LineEdit() self.string_list = [""] + [ "{},{}".format(clt.name, clt.phone) for clt in ProviderOrClient.select().where( ProviderOrClient.type_ == ProviderOrClient.CLT).order_by( ProviderOrClient.name.desc()) ] # self.name_client_field_new = "" self.name_client_field = ExtendedComboBox() self.name_client_field.addItems(self.string_list) self.name_client_field.setMaximumSize( 200, self.name_client_field.maximumSize().height()) self.name_client_field.setToolTip("Nom, numero du client") self.add_clt_btt = BttSmall(u"+") self.add_clt_btt.clicked.connect(self.add_clt) self.add_clt_btt.setFixedWidth(50) # Combobox widget for add store self.liste_type_invoice = [ Invoice.TYPE_FACT, Invoice.TYPE_BON, Invoice.TYPE_PROF ] self.box_type_inv = QComboBox() for index in range(0, len(self.liste_type_invoice)): op = self.liste_type_invoice[index] sentence = u"%(name)s" % {'name': op} self.box_type_inv.addItem(sentence, op) self.search_field = LineEdit() self.search_field.setPlaceholderText("Rechercher un article") self.search_field.textChanged.connect(self.finder) # self.search_field.setFixedWidth(250) self.search_field.setMaximumHeight(40) self.table_invoice = InvoiceTableWidget(parent=self) self.table_resultat = ResultatTableWidget(parent=self) self.table_info = InfoTableWidget(parent=self) self.table_resultat.refresh_("") editbox.addWidget(self.box_type_inv, 0, 2) editbox.addWidget(self.num_invoice, 0, 3) editbox.addWidget(FLabel(u"Doit :"), 1, 2) editbox.addWidget(self.name_client_field, 1, 3) # editbox.addWidget(self.add_clt_btt, 1, 4) editbox.addWidget(self.invoice_date, 0, 6) editbox.setColumnStretch(0, 1) editbox.setColumnStretch(5, 1) splitter = QSplitter(Qt.Horizontal) splitter_left = QSplitter(Qt.Vertical) splitter_left.addWidget(self.search_field) splitter_left.addWidget(self.table_resultat) # splitter_down.resize(15, 20) splitter_down = QSplitter(Qt.Vertical) splitter_down.addWidget(self.table_info) splitter_rigth = QSplitter(Qt.Vertical) # splitter_rigth.setLayout(editbox) splitter_rigth.addWidget(self.table_invoice) splitter_rigth.resize(800, 900) splitter_left.addWidget(splitter_down) splitter.addWidget(splitter_left) splitter.addWidget(splitter_rigth) vbox.addLayout(editbox) vbox.addWidget(splitter) 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.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)