示例#1
0
class AddCommandArticleView(QDialog, Ui_AddCommandArticleWidget):
    def __init__(self, articles, parent=None):
        super(AddCommandArticleView, self).__init__(parent)
        self.setupUi(self)
        self.session = Session()
        self.articles = self.session.query(Article).all()
        self.article = {}
        for _article in self.articles:
            self.comboBoxArticle.addItem(_article.designation)

    def get_form_data(self):
        return self.article

    @pyqtSlot()
    def on_pushButtonAddArticle_clicked(self):

        qte = self.spinBoxQteCommand.value()

        self.article['designation'] = self.comboBoxArticle.currentText()
        self.article['qte'] = qte

        self.close()

    def close(self):
        self.session.close()
        super().close()
示例#2
0
    def __init__(self, parent=None):
        super(MainWindowLib, self).__init__(parent)
        self.setupUi(self)

        initDB()
        self.session = Session()

        self.header = [
            'Code', 'Designation', 'Famille', 'Auteur', 'Editeur',
            'Prix d\'achat (F CFA)', 'Prix de vente (F CFA)', 'Date d\'ajout'
        ]

        self.articles = self.session.query(Article).all()

        self.article_table_model = ArticleTableModel(articles=self.articles,
                                                     header=self.header)
        # self.model = QStandardItemModel()
        # self.model.setHorizontalHeaderLabels(['Name', 'Age', 'Sex', 'Add'])
        # self.article_table_model.setHorizontalHeaderLabels(self.header)
        self.tableView.setModel(self.article_table_model)
        self.tableView.resizeColumnsToContents()
        # self.tableView.setHorizontalHeader()
        # self.toolBar.addAction(
        #     QAction(QIcon('img/interface.png'), 'Add', self))
        # self.showFullScreen()
        self.lineEditSearch.textChanged.connect(self.handleTextChanged)
        self.showMaximized()
        screen = QDesktopWidget().screenGeometry()
        width, height = screen.width(), screen.height()
示例#3
0
 def __init__(self, articles, parent=None):
     super(AddCommandArticleView, self).__init__(parent)
     self.setupUi(self)
     self.session = Session()
     self.articles = self.session.query(Article).all()
     self.article = {}
     for _article in self.articles:
         self.comboBoxArticle.addItem(_article.designation)
示例#4
0
class ArticleCommandListView(QDialog, Ui_ArticleCommandListWidget):
    def __init__(self, parent=None):
        super(ArticleCommandListView, self).__init__(parent)
        self.setupUi(self)
        self.session = Session()
        self.model = QStandardItemModel()
        self.model.setHorizontalHeaderLabels(
            ['Article', 'Quantité', 'Prix U.', 'Cout total'])
        self.tableView.setModel(self.model)
        self.cmd_articles = []
        # self.comboBoxFilter.currentTextChanged.connect(self.filterCurrentTextChanged)
        self.entries = self.session.query(CommandEntry).all()
        # print("Entries : ", self.entries)
        qtes = []
        for entry in self.entries:
            article = entry.article
            qte = entry.cmd_qte
            if article is not None:
                if article not in self.cmd_articles:
                    qtes.append(qte)
                    self.cmd_articles.append(article)
                else:
                    index = self.cmd_articles.index(article)
                    qtes[index] += qte

        i = 0
        for article in self.cmd_articles:
            selling_price = article.selling_price
            qte = qtes[i]

            item_designation = QStandardItem(article.designation)
            item_qte = QStandardItem(str(qte))
            item_price = QStandardItem(selling_price)
            item_total_price = QStandardItem(
                str(int(float(selling_price)) * int(qte)))

            self.model.setItem(i, 0, item_designation)
            self.model.setItem(i, 1, item_qte)
            self.model.setItem(i, 2, item_price)
            self.model.setItem(i, 3, item_total_price)

            i += 1

        self.labelTotalArticle.setText(str(len(self.cmd_articles)))

        self.session.close()

    def compute_total_price(self, entries):
        pass

    def filterCurrentTextChanged(self, text):
        print(text)

    def on_pushButtonQuit_clicked(self):
        self.close()
示例#5
0
    def __init__(self, parent=None):
        super(ArticleListView, self).__init__(parent)
        self.setupUi(self)

        self.session = Session()

        self.articles = self.session.query(Article).all()
        self.header = [
            'ID Article', 'Code', 'Designation', 'Famille', 'Auteur',
            'Editeur', 'Prix d\'achat (F CFA)', 'Prix de vente (F CFA)',
            'Date d\'ajout', 'Quantité en Stock'
        ]

        self.model = ArticleTableModel(self.header, self.articles)
        self.tableView.setModel(self.model)
        self.tableView.resizeColumnsToContents()
        self.lineEditSearchQuery.textChanged.connect(self.handleTextChanged)
示例#6
0
    def __init__(self, parent=None):
        super(CommandListView, self).__init__(parent)
        self.setupUi(self)
        self.session = Session()
        self.model = QStandardItemModel()
        self.tableView.setModel(self.model)
        self.comboBoxFilter.currentTextChanged.connect(
            self.comboBoxFilter_currentTextChanged)
        self.model.setHorizontalHeaderLabels([
            'No', 'Nb articles', 'Cout total', 'Motif', 'Fournisseur',
            'Date de Reception'
        ])

        self._filter_text = self.comboBoxFilter.currentText()
        self._filter = self.format_filter(self._filter_text)

        # self.commands = self.get_filtered_commands(self._filter)
        self.commands = self.session.query(Command).order_by(
            desc(Command.created_at)).all()
        self.populate_data_to_tableView(self.commands)
示例#7
0
class MainWindowLib(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindowLib, self).__init__(parent)
        self.setupUi(self)

        initDB()
        self.session = Session()

        self.header = [
            'Code', 'Designation', 'Famille', 'Auteur', 'Editeur',
            'Prix d\'achat (F CFA)', 'Prix de vente (F CFA)', 'Date d\'ajout'
        ]

        self.articles = self.session.query(Article).all()

        self.article_table_model = ArticleTableModel(articles=self.articles,
                                                     header=self.header)
        # self.model = QStandardItemModel()
        # self.model.setHorizontalHeaderLabels(['Name', 'Age', 'Sex', 'Add'])
        # self.article_table_model.setHorizontalHeaderLabels(self.header)
        self.tableView.setModel(self.article_table_model)
        self.tableView.resizeColumnsToContents()
        # self.tableView.setHorizontalHeader()
        # self.toolBar.addAction(
        #     QAction(QIcon('img/interface.png'), 'Add', self))
        # self.showFullScreen()
        self.lineEditSearch.textChanged.connect(self.handleTextChanged)
        self.showMaximized()
        screen = QDesktopWidget().screenGeometry()
        width, height = screen.width(), screen.height()
        # print(width, height)

    def handleTextChanged(self, value):
        if not value:
            self.article_table_model.set_articles(self.articles)
            self.emit_tableView_layout_change_event()

    @pyqtSlot()
    def on_add_article_clicked(self):
        article_form_win = ArticleFormWindow(session=self.session)
        article_form_win.exec_()
        form_data_obj = article_form_win.get_form_data()
        if form_data_obj:
            self.article_table_model.add_articles(form_data_obj)
            self.emit_tableView_layout_change_event()
            self.articles = self.session.query(Article).all()

    def emit_tableView_layout_change_event(self):
        self.tableView.model().layoutChanged.emit()

    @pyqtSlot()
    def on_pushButtonImport_clicked(self):
        file_name = QFileDialog.getOpenFileName(self, 'Ouvrir le fichier', '',
                                                'Text files (*.xlsx)')[0]

        wb = xlrd.open_workbook(file_name)
        # sheet = wb.active
        # for row in sheet.iter_rows():
        #     for cell in row:
        #         print(cell.value, end=' ')
        #     print()

        # print(str(sheet.max_row))
        # print(str(sheet.max_column))

        sheet = wb.sheet_by_index(0)

        # # print(sheet.cell_value(0, 0))
        article_list = []
        for i in range(2, sheet.nrows):
            # for j in range(0, sheet.ncols):
            article = Article(
                code=sheet.cell_value(i, 0),
                designation=sheet.cell_value(i, 1),
                family=sheet.cell_value(i, 2),
                author=sheet.cell_value(i, 3),
                editor=sheet.cell_value(i, 4),
                selling_price=sheet.cell_value(i, 5),
            )
            article_list.append({
                'code': sheet.cell_value(i, 0),
                'designation': sheet.cell_value(i, 1),
                'familly': sheet.cell_value(i, 2),
                'author': sheet.cell_value(i, 3),
                'editor': sheet.cell_value(i, 4),
                'selling_price': sheet.cell_value(i, 5)
            })
            self.session.add(article)

        self.session.commit()

        self.articles = self.session.query(Article).all()
        self.article_table_model.add_articles(article_list)
        self.emit_tableView_layout_change_event()

    @pyqtSlot()
    def on_pushButtonArticleStock_clicked(self):
        article_list_win = ArticleListView()
        article_list_win.exec_()

    @pyqtSlot()
    def on_add_selling_clicked(self):
        selling_form_win = SellingFormView(session=self.session,
                                           articles=self.articles)
        selling_form_win.exec_()
        self.emit_tableView_layout_change_event()

    @pyqtSlot()
    def on_pushButtonSearch_clicked(self):
        query = self.lineEditSearch.text()

        if not query:
            self.lineEditSearch.setFocus()
            return

        search_results = [
            obj for obj in self.articles
            if query.lower() in (obj.designation + obj.author + obj.code +
                                 obj.editor + obj.family).lower()
        ]
        print(search_results)
        if not search_results:
            QMessageBox.information(
                self, 'Recherche',
                'Aucune donnée trouvée pour le mot clef: {}'.format(query),
                QMessageBox.Yes)
            return
        self.article_table_model.set_articles(search_results)
        self.emit_tableView_layout_change_event()

    @pyqtSlot()
    def on_add_command_clicked(self):
        add_command = CommandFormView(session=self.session,
                                      articles=self.articles)
        add_command.exec_()

    @pyqtSlot()
    def on_show_command_clicked(self):
        show_command = CommandListView()
        show_command.exec_()

    @pyqtSlot()
    def on_show_command_article_clicked(self):
        show_command_article = ArticleCommandListView()
        show_command_article.exec_()

    @pyqtSlot()
    def on_selling_history_clicked(self):
        selling_history = SellingHistoryView()
        selling_history.exec_()

    @pyqtSlot()
    def on_pushButtonCmdRapport_clicked(self):
        sell_rapport_win = SellingRapportView()
        sell_rapport_win.exec_()
        periods = sell_rapport_win.get_periods()
        if periods is not None:
            commands = self.session.query(Command).all()

            if not periods.get('all_periods', False):
                commands = self.session.query(Command).filter(
                    and_(Command.date_reception >= periods.get('start'),
                         Command.date_reception <= periods.get('end'))).all()

            if commands:
                header = [
                    'Article',
                    'Quantité',
                    'Fournisseur',
                    'Date de vente',
                ]
                gen_pdf_win = GenPDFView(collection=commands,
                                         periods=periods,
                                         header=header)
                gen_pdf_win.exec_()
                QMessageBox.information(
                    self, 'Info', 'Votre fichier a été genéré avec succès',
                    QMessageBox.Yes)
                return

            QMessageBox.information(
                self, 'Info',
                'Aucune vente trouvée pour la génération du rapport',
                QMessageBox.Yes)

    @pyqtSlot()
    def on_selling_rapport_clicked(self):
        sell_rapport_win = SellingRapportView()
        sell_rapport_win.exec_()
        periods = sell_rapport_win.get_periods()
        if periods is not None:
            sellings = self.session.query(Selling).all()

            if not periods.get('all_periods', False):
                sellings = self.session.query(Selling).filter(
                    and_(Selling.selling_date >= periods.get('start'),
                         Selling.selling_date <= periods.get('end'))).all()

            if sellings:
                gen_pdf_win = GenPDFView(collection=sellings, periods=periods)
                gen_pdf_win.exec_()
                QMessageBox.information(
                    self, 'Info', 'Votre fichier a été genéré avec succès',
                    QMessageBox.Yes)
                return

            QMessageBox.information(
                self, 'Info',
                'Aucune vente trouvée pour la génération du rapport',
                QMessageBox.Yes)

    def close(self):
        self.session.close()
        super(MainWindowLib, self).close()
示例#8
0
class ArticleListView(QDialog, Ui_ArticleListWidget):
    def __init__(self, parent=None):
        super(ArticleListView, self).__init__(parent)
        self.setupUi(self)

        self.session = Session()

        self.articles = self.session.query(Article).all()
        self.header = [
            'ID Article', 'Code', 'Designation', 'Famille', 'Auteur',
            'Editeur', 'Prix d\'achat (F CFA)', 'Prix de vente (F CFA)',
            'Date d\'ajout', 'Quantité en Stock'
        ]

        self.model = ArticleTableModel(self.header, self.articles)
        self.tableView.setModel(self.model)
        self.tableView.resizeColumnsToContents()
        self.lineEditSearchQuery.textChanged.connect(self.handleTextChanged)

    def emit_tableView_layout_change_event(self):
        self.tableView.model().layoutChanged.emit()

    def handleTextChanged(self, value):
        if not value:
            self.model.set_articles(self.articles)
            self.emit_tableView_layout_change_event()

    @pyqtSlot()
    def on_pushButtonSearch_clicked(self):
        query = self.lineEditSearchQuery.text()

        if not query:
            self.lineEditSearchQuery.setFocus()
            return

        search_results = [
            obj for obj in self.articles
            if query.lower() in (obj.designation + obj.author + obj.code +
                                 obj.editor + obj.family).lower()
        ]

        if not search_results:
            QMessageBox.information(
                self, 'Recherche',
                'Aucune donnée trouvée pour le mot clef: {}'.format(query),
                QMessageBox.Yes)
            return
        self.model.set_articles(search_results)
        self.emit_tableView_layout_change_event()

    @pyqtSlot()
    def on_pushButtonUpdate_clicked(self):
        row, index = get_index_table(self, self.tableView)

        if not index and not row:
            return

        article_id = index.data()
        article = get_data_by_model_pk(self.articles, int(article_id))
        # article = [ _article for _article in self.articles if _article.id == int(article_id) ][0]
        article_form_win = ArticleFormWindow(session=self.session,
                                             data=article)
        article_form_win.exec_()
        form_data = article_form_win.get_form_data()
        if form_data:
            # print(form_data)
            article = [
                obj for obj in self.articles
                if obj.id == form_data[0].get('id')
            ][0]
            index = self.articles.index(article)
            self.articles[index] = article

            self.model.set_articles(self.articles)
            self.emit_tableView_layout_change_event()
            self.articles = self.session.query(Article).all()

    def close(self):
        self.session.close()
        super().close()

    @pyqtSlot()
    def on_pushButtonDelete_clicked(self):
        mBox = QMessageBox.critical(
            self, 'Avertissement',
            'Vous êtes sur le point de supprimer un article, continuer ?',
            QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
        if mBox == QMessageBox.Yes:
            print('Le Message Va être supprimer')

    @pyqtSlot()
    def on_pushButtonQuit_clicked(self):
        self.close()

    @pyqtSlot()
    def on_pushButtonInventaire_clicked(self):
        inventaire_win = InventaireView(self.articles)
        inventaire_win.exec_()
        data = inventaire_win.get_return_data()

        if data:
            if data.get('all_article', False):
                collection = self.articles
            else:
                collection = [
                    article for article in self.articles
                    if article.designation == data.get('article')
                ]
                # print(collection[0].selling_entry)
            gen = GenPDFView(collection, is_inventaire=True)
            exit_code = gen.exec_()
            QMessageBox.information(
                self, 'Info', 'Votre fichier a été géneré avec succès !',
                QMessageBox.Yes)
示例#9
0
class CommandListView(QDialog, Ui_CommandListWidget):
    def __init__(self, parent=None):
        super(CommandListView, self).__init__(parent)
        self.setupUi(self)
        self.session = Session()
        self.model = QStandardItemModel()
        self.tableView.setModel(self.model)
        self.comboBoxFilter.currentTextChanged.connect(
            self.comboBoxFilter_currentTextChanged)
        self.model.setHorizontalHeaderLabels([
            'No', 'Nb articles', 'Cout total', 'Motif', 'Fournisseur',
            'Date de Reception'
        ])

        self._filter_text = self.comboBoxFilter.currentText()
        self._filter = self.format_filter(self._filter_text)

        # self.commands = self.get_filtered_commands(self._filter)
        self.commands = self.session.query(Command).order_by(
            desc(Command.created_at)).all()
        self.populate_data_to_tableView(self.commands)

    def comboBoxFilter_currentTextChanged(self, text):
        _filter = self.format_filter(text)
        _data = self.get_filtered_commands(_filter)
        self.model.removeRows(0, self.model.rowCount())
        self.populate_data_to_tableView(_data)

    def get_filtered_commands(self, _filter):
        if _filter is not None:
            return self.session.query(Command).filter(
                Command.receptionned == _filter).all()
        else:
            return self.session.query(Command).all()

    def format_filter(self, filter_text):
        if filter_text == 'Réceptionnées':
            return True
        elif filter_text == 'Non réceptionnées':
            return False
        else:
            return None

    def format_status(self, status):
        return 'Receptionnée' if status == True else 'Non receptionnée'

    def populate_data_to_tableView(self, data):
        # prices = []
        for index, command in enumerate(data):
            entries = command.command_entries
            price = self.compute_command_price(entries)
            # prices.append(price)
            item_provider = QStandardItem(command.provider.full_name)
            item_articles = QStandardItem(str(len(entries)))
            item_cost = QStandardItem(str(price))
            item_motif = QStandardItem(command.motif)
            # item_emission_date = QStandardItem(str(command.emission_date))
            # item_reception_date = QStandardItem(str(command.reception_date))
            item_id = QStandardItem(str(command.id))
            item_date_recep = QStandardItem(str(command.date_reception))

            self.model.setItem(index, 0, item_id)
            self.model.setItem(index, 1, item_articles)
            self.model.setItem(index, 2, item_cost)
            self.model.setItem(index, 3, item_motif)
            # self.model.setItem(index, 4, item_emission_date)
            # self.model.setItem(index, 5, item_reception_date)
            self.model.setItem(index, 4, item_provider)
            self.model.setItem(index, 5, item_date_recep)

        # self.labelTotalCost.setText(str(sum(prices)) + ' F CFA')

    def compute_command_price(self, entries):
        return sum([
            int(float(obj.article.selling_price)) * obj.cmd_qte
            for obj in entries
        ])

    @pyqtSlot()
    def on_pushButtonQuit_clicked(self):
        self.close()

    @pyqtSlot()
    def on_pushButtonUpdate_clicked(self):
        row, index = get_index_table(self, self.tableView)

        if not index and not row:
            return

        command = [
            cmd for cmd in self.commands if cmd.id == int(index.data())
        ][0]

        articles = self.session.query(Article).all()
        cmd_form_win = CommandFormView(articles=articles,
                                       session=self.session,
                                       command=command)
        cmd_form_win.exec_()

        # item_status = QStandardItem(
        #     self.format_status(command.receptionned))
        # self.model.setItem(row, 3, item_status)

        # QMessageBox.information(
        #     self, 'Info', 'Commande receptionnée avec succès !', QMessageBox.Yes)

        # self.close()
        # print(command.receptionned)

    @pyqtSlot()
    def on_pushButtonDelete_clicked(self):
        indexes = self.tableView.selectedIndexes()

        if not indexes and self.cmd_entries:
            QMessageBox.information(
                self, 'Info',
                "Veuillez selectionner au préalable un article !",
                QMessageBox.Yes)
            return

        if not indexes:
            return

        if len(indexes) >= 2:
            QMessageBox.information(
                self, 'Info', 'Impossible de faire une selection groupée !',
                QMessageBox.Yes)
            return

        mBox = QMessageBox.critical(
            self, 'Alerte', 'Voulez vous vraiment supprimer cette commande ?',
            QMessageBox.No | QMessageBox.Yes, QMessageBox.No)

        if mBox == QMessageBox.No:
            return

        row = self.tableView.currentIndex().row()
        index = self.tableView.model().index(row, 0)

        for _row in indexes:
            command = get_data_by_model_pk(self.commands, int(index.data()))

            for entry in command.command_entries:
                article = entry.article
                article.quantity -= entry.cmd_qte
                self.session.add(article)

            self.session.delete(command)

            index_ = self.commands.index(command)
            self.commands.pop(index_)
            # self.model.removeRow(index)

            self.session.commit()
            i = _row.row()
            self.model.removeRow(i)

    def close(self):
        self.session.close()
        super().close()