Пример #1
0
class ContactNewViewWidget(QDialog, FWidget):

    def __init__(self, parent, *args, **kwargs):
        QDialog.__init__(self, parent, *args, **kwargs)

        vbox = QVBoxLayout()
        vbox.addWidget(FBoxTitle(u"<h3>Ajout de contact </h3>"))
        self.combo_grp = QComboBox()
        groups = Group()
        groups.name = "Aucun"

        self.list_grp = Group.all()
        self.list_grp.append(groups)
        self.list_grp.reverse()

        for index in self.list_grp:
            sentence = u"%(name)s" % {'name': index.name}
            self.combo_grp.addItem(sentence)

        self.full_name = LineEdit()
        self.msg_e_or_c = FLabel("")
        self.full_name.setFont(QFont("Arial", 16))
        self.phone_number = IntLineEdit()
        self.phone_number.setInputMask("D9.99.99.99")
        self.phone_number.setAlignment(Qt.AlignCenter)
        self.phone_number.setFont(QFont("Arial", 16))

        send_butt = Button(u"Enregistrer")
        send_butt.clicked.connect(self.save_form)
        cancel_but = Button(u"Fermer")
        cancel_but.clicked.connect(self.cancel)

        formbox = QGridLayout()
        formbox.addWidget(FLabel(u"Groupes:"), 0, 0)
        formbox.addWidget(self.combo_grp, 1, 0)
        formbox.addWidget(FLabel(u"Nom complèt: "), 0, 1)
        formbox.addWidget(self.full_name, 1, 1)
        formbox.addWidget(FLabel(u"Numéro: "), 0, 2)
        formbox.addWidget(self.phone_number, 1, 2)
        formbox.addWidget(send_butt, 2, 1)
        formbox.addWidget(cancel_but, 2, 0)
        formbox.addWidget(self.msg_e_or_c, 3, 0, 3, 2)

        vbox.addLayout(formbox)
        self.setLayout(vbox)

    def cancel(self):
        self.close()

    def iscomplet(self):
        self.phone_number.setStyleSheet("")
        self.msg_e_or_c.setText("")
        self.msg_e_or_c.setStyleSheet("")

        try:
            int(self.phone_number.text().replace('.', ''))
        except:
            self.phone_number.setStyleSheet("border-bottom: 3px solid red;"
                                            "background-color:#AFAFAF;")
            self.phone_number.setToolTip(u"Ce champ est obligatoire.")
            return False
        return True

    def save_form(self):

        if not self.iscomplet():
            return
        full_name = unicode(self.full_name.text())
        phone_number = int(self.phone_number.text().replace('.', ''))
        try:
            Contact(number=phone_number, name=full_name).save()
        except:
            self.msg_e_or_c.setText(u"Ce numéro existe déjà")
            self.msg_e_or_c.setStyleSheet("color: red")
            return

        grp = unicode(self.list_grp[self.combo_grp.currentIndex()])

        if not grp == "Aucun":
            grp = Group.select().where(Group.name == grp).get()
            contact = Contact.select().where(Contact.number == phone_number).get()
            ContactGroup(group=grp.id, contact=contact).save()
        self.full_name.setText("")
        self.phone_number.setText("")
        self.msg_e_or_c.setText(u"Le numéro (<b>{}</b>) à éte bien enregistré"
                                .format(phone_number))
Пример #2
0
class InvoiceTableWidget(FTableWidget):

    def __init__(self, parent, *args, **kwargs):
        FTableWidget.__init__(self, parent=parent, *args, **kwargs)

        self.parent = parent
        self.pparent = parent.parent
        self.hheaders = [u"Modeles", u"Quantité", u"Prix Unitaire", u"Montant"]

        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.popup)

        self.stretch_columns = [0, 2]
        self.align_map = {3: 'r'}
        self.display_vheaders = False
        self.display_fixed = True
        self.refresh_()
        self.isvalid = False

    def refresh_(self, choix=None):
        if choix:
            self.row = [u"%s" % choix.name, "", ""]
            if not [row for row in self.data if self.row[0] in row]:
                self.set_data_for()
                self.refresh()

    def set_data_for(self):

        self._reset()
        self.data.extend([self.row])
        self.refresh()

    def popup(self, pos):
        row = self.selectionModel().selection().indexes()[0].row()
        if (len(self.data) - 1) < row:
            return False
        menu = QMenu()
        quitAction = menu.addAction("Supprimer cette ligne")
        action = menu.exec_(self.mapToGlobal(pos))
        if action == quitAction:
            try:
                self.data.pop(row)
            except IndexError:
                pass
            self.refresh()

    def extend_rows(self):
        nb_rows = self.rowCount()
        self.setRowCount(nb_rows + 3)
        self.setItem(nb_rows, 2, TotalsWidget(u"Montant"))
        monttc = TotalsWidget(formatted_number(u"%d" % 0))
        self.setItem(nb_rows, 3, monttc)
        nb_rows += 1
        bicon = QIcon.fromTheme(
            '', QIcon(u"{}save.png".format(Config.img_media)))
        self.button = QPushButton(bicon, u"Enregistrer")
        self.button.released.connect(self.parent.save_b)
        self.button.setEnabled(False)
        self.setItem(nb_rows, 2, TotalsWidget(u"Reste à payer"))
        self.paid_amount_field = IntLineEdit()
        self.setCellWidget(nb_rows, 3, self.paid_amount_field)
        self.setCellWidget(nb_rows + 1, 3, self.button)
        self.setSpan(nb_rows - 1, 0, 3, 2)

        pw = self.parent.parent.page_width() / 7
        self.setColumnWidth(0, pw * 2)
        self.setColumnWidth(1, pw)
        self.setColumnWidth(2, pw)

    def _update_data(self, row_num, new_data):
        self.data[row_num] = (self.data[row_num][0], new_data[0], new_data[1],
                              new_data[2])

    def _item_for_data(self, row, column, data, context=None):
        if column == 1 or column == 2:
            self.line_edit = IntLineEdit(u"%s" % data)
            self.line_edit.textChanged.connect(self.changed_value)
            self.line_edit.setAlignment(Qt.AlignRight)
            return self.line_edit
        return super(InvoiceTableWidget, self)._item_for_data(row, column,
                                                              data, context)

    def get_table_items(self):
        """ Recupère les elements du tableau """

        list_invoice = []
        for i in range(self.rowCount() - 3):
            liste_item = []
            row_data = self.data[i]
            try:
                liste_item.append(unicode(row_data[0]))
                liste_item.append(int(row_data[1]))
                liste_item.append(int(row_data[2]))
                list_invoice.append(liste_item)
            except AttributeError:
                raise
                liste_item.append("")

        return list_invoice

    def changed_value(self, refresh=False):
        """ Calcule les Resultat """
        self.mtt_ht = 0
        # self.button.setEnabled(False)
        for row_num in xrange(0, self.data.__len__()):
            product = Product.get(
                Product.name == unicode(self.item(row_num, 0).text()))
            last_report = product.last_report
            last_price = product.last_price()
            qtremaining = last_report.remaining
            selling_price = last_price
            invoice_date = unicode(self.parent.invoice_date.text())

            qtsaisi = is_int(self.cellWidget(row_num, 1).text())
            pusaisi = is_int(self.cellWidget(row_num, 2).text())

            if check_is_empty(self.parent.num_invoice):
                return
            if check_is_empty(self.parent.name_client_field.lineEdit()):
                return
            # if check_field(self.parent.invoice_date,
            #                "Le {} est Inférieure à la date de la dernière rapport (<b>{}</b>)".format(date_to_datetime(invoice_date), last_report.date), (last_report.date > date_to_datetime(invoice_date))):
            #     return
            if (pusaisi and check_is_empty(self.cellWidget(row_num, 1))):
                return
            if (pusaisi and check_is_empty(self.cellWidget(row_num, 2))):
                return
            if check_field(self.cellWidget(row_num, 1),
                           u"<b>{}</b> est supérieur à la quantité restante (<b>{}</b>)".format(
                    qtsaisi, qtremaining), qtremaining < qtsaisi):
                return
            if check_field(self.cellWidget(row_num, 2),
                           u"<b>{}</b> est inférieure au prix minimum de vente<b> {} CFA</b>".format(
                    pusaisi, selling_price), pusaisi < selling_price):
                print("E")
                # return

            montant = (qtsaisi * pusaisi)
            self.mtt_ht += montant
            self.setItem(row_num, 3, TotalsWidget(formatted_number(montant)))
            self._update_data(row_num, [qtsaisi, pusaisi, self.mtt_ht])
        self.setItem(
            row_num + 1, 3, TotalsWidget(formatted_number(self.mtt_ht)))
        typ = self.parent.liste_type_invoice[
            self.parent.box_type_inv.currentIndex()]
        self.paid_amount_field.setText(
            str(self.mtt_ht) if typ == Invoice.TYPE_BON else "0")
        self.button.setEnabled(True)
Пример #3
0
class ContactNewViewWidget(QDialog, FWidget):
    def __init__(self, parent, *args, **kwargs):
        QDialog.__init__(self, parent, *args, **kwargs)

        vbox = QVBoxLayout()
        vbox.addWidget(FBoxTitle(u"<h3>Ajout de contact </h3>"))
        self.combo_grp = QComboBox()
        groups = Group()
        groups.name = "Aucun"

        self.list_grp = Group.all()
        self.list_grp.append(groups)
        self.list_grp.reverse()

        for index in self.list_grp:
            sentence = u"%(name)s" % {'name': index.name}
            self.combo_grp.addItem(sentence)

        self.full_name = LineEdit()
        self.msg_e_or_c = FLabel("")
        self.full_name.setFont(QFont("Arial", 16))
        self.phone_number = IntLineEdit()
        self.phone_number.setInputMask("D9.99.99.99")
        self.phone_number.setAlignment(Qt.AlignCenter)
        self.phone_number.setFont(QFont("Arial", 16))

        send_butt = Button(u"Enregistrer")
        send_butt.clicked.connect(self.save_form)
        cancel_but = Button(u"Fermer")
        cancel_but.clicked.connect(self.cancel)

        formbox = QGridLayout()
        formbox.addWidget(FLabel(u"Groupes:"), 0, 0)
        formbox.addWidget(self.combo_grp, 1, 0)
        formbox.addWidget(FLabel(u"Nom complèt: "), 0, 1)
        formbox.addWidget(self.full_name, 1, 1)
        formbox.addWidget(FLabel(u"Numéro: "), 0, 2)
        formbox.addWidget(self.phone_number, 1, 2)
        formbox.addWidget(send_butt, 2, 1)
        formbox.addWidget(cancel_but, 2, 0)
        formbox.addWidget(self.msg_e_or_c, 3, 0, 3, 2)

        vbox.addLayout(formbox)
        self.setLayout(vbox)

    def cancel(self):
        self.close()

    def iscomplet(self):
        self.phone_number.setStyleSheet("")
        self.msg_e_or_c.setText("")
        self.msg_e_or_c.setStyleSheet("")

        try:
            int(self.phone_number.text().replace('.', ''))
        except:
            self.phone_number.setStyleSheet("border-bottom: 3px solid red;"
                                            "background-color:#AFAFAF;")
            self.phone_number.setToolTip(u"Ce champ est obligatoire.")
            return False
        return True

    def save_form(self):

        if not self.iscomplet():
            return
        full_name = unicode(self.full_name.text())
        phone_number = int(self.phone_number.text().replace('.', ''))
        try:
            Contact(number=phone_number, name=full_name).save()
        except:
            self.msg_e_or_c.setText(u"Ce numéro existe déjà")
            self.msg_e_or_c.setStyleSheet("color: red")
            return

        grp = unicode(self.list_grp[self.combo_grp.currentIndex()])

        if not grp == "Aucun":
            grp = Group.select().where(Group.name == grp).get()
            contact = Contact.select().where(
                Contact.number == phone_number).get()
            ContactGroup(group=grp.id, contact=contact).save()
        self.full_name.setText("")
        self.phone_number.setText("")
        self.msg_e_or_c.setText(
            u"Le numéro (<b>{}</b>) à éte bien enregistré".format(
                phone_number))
Пример #4
0
class InvoiceTableWidget(FTableWidget):
    def __init__(self, parent, *args, **kwargs):
        FTableWidget.__init__(self, parent=parent, *args, **kwargs)

        self.parent = parent
        self.pparent = parent.parent
        self.hheaders = [u"Modeles", u"Quantité", u"Prix Unitaire", u"Montant"]

        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.popup)

        self.stretch_columns = [0, 2]
        self.align_map = {3: 'r'}
        self.display_vheaders = False
        self.display_fixed = True
        self.refresh_()
        self.isvalid = False

    def refresh_(self, choix=None):
        if choix:
            self.row = [u"%s" % choix.name, "", ""]
            if not [row for row in self.data if self.row[0] in row]:
                self.set_data_for()
                self.refresh()

    def set_data_for(self):

        self._reset()
        self.data.extend([self.row])
        self.refresh()

    def popup(self, pos):
        row = self.selectionModel().selection().indexes()[0].row()
        if (len(self.data) - 1) < row:
            return False
        menu = QMenu()
        quitAction = menu.addAction("Supprimer cette ligne")
        action = menu.exec_(self.mapToGlobal(pos))
        if action == quitAction:
            try:
                self.data.pop(row)
            except IndexError:
                pass
            self.refresh()

    def extend_rows(self):
        nb_rows = self.rowCount()
        self.setRowCount(nb_rows + 3)
        self.setItem(nb_rows, 2, TotalsWidget(u"Montant"))
        monttc = TotalsWidget(formatted_number(u"%d" % 0))
        self.setItem(nb_rows, 3, monttc)
        nb_rows += 1
        bicon = QIcon.fromTheme('',
                                QIcon(u"{}save.png".format(Config.img_media)))
        self.button = QPushButton(bicon, u"Enregistrer")
        self.button.released.connect(self.parent.save_b)
        self.button.setEnabled(False)
        self.setItem(nb_rows, 2, TotalsWidget(u"Reste à payer"))
        self.paid_amount_field = IntLineEdit()
        self.setCellWidget(nb_rows, 3, self.paid_amount_field)
        self.setCellWidget(nb_rows + 1, 3, self.button)
        self.setSpan(nb_rows - 1, 0, 3, 2)

        pw = self.parent.parent.page_width() / 7
        self.setColumnWidth(0, pw * 2)
        self.setColumnWidth(1, pw)
        self.setColumnWidth(2, pw)

    def _update_data(self, row_num, new_data):
        self.data[row_num] = (self.data[row_num][0], new_data[0], new_data[1],
                              new_data[2])

    def _item_for_data(self, row, column, data, context=None):
        if column == 1 or column == 2:
            self.line_edit = IntLineEdit(u"%s" % data)
            self.line_edit.textChanged.connect(self.changed_value)
            self.line_edit.setAlignment(Qt.AlignRight)
            return self.line_edit
        return super(InvoiceTableWidget,
                     self)._item_for_data(row, column, data, context)

    def get_table_items(self):
        """ Recupère les elements du tableau """

        list_invoice = []
        for i in range(self.rowCount() - 3):
            liste_item = []
            row_data = self.data[i]
            try:
                liste_item.append(unicode(row_data[0]))
                liste_item.append(int(row_data[1]))
                liste_item.append(int(row_data[2]))
                list_invoice.append(liste_item)
            except AttributeError:
                raise
                liste_item.append("")

        return list_invoice

    def changed_value(self, refresh=False):
        """ Calcule les Resultat """
        self.mtt_ht = 0
        # self.button.setEnabled(False)
        for row_num in xrange(0, self.data.__len__()):
            product = Product.get(
                Product.name == unicode(self.item(row_num, 0).text()))
            last_report = product.last_report
            last_price = product.last_price()
            qtremaining = last_report.remaining
            selling_price = last_price
            invoice_date = unicode(self.parent.invoice_date.text())

            qtsaisi = is_int(self.cellWidget(row_num, 1).text())
            pusaisi = is_int(self.cellWidget(row_num, 2).text())

            if check_is_empty(self.parent.num_invoice):
                return
            if check_is_empty(self.parent.name_client_field.lineEdit()):
                return
            # if check_field(self.parent.invoice_date,
            #                "Le {} est Inférieure à la date de la dernière rapport (<b>{}</b>)".format(date_to_datetime(invoice_date), last_report.date), (last_report.date > date_to_datetime(invoice_date))):
            #     return
            if (pusaisi and check_is_empty(self.cellWidget(row_num, 1))):
                return
            if (pusaisi and check_is_empty(self.cellWidget(row_num, 2))):
                return
            if check_field(
                    self.cellWidget(row_num, 1),
                    u"<b>{}</b> est supérieur à la quantité restante (<b>{}</b>)"
                    .format(qtsaisi, qtremaining), qtremaining < qtsaisi):
                return
            if check_field(
                    self.cellWidget(row_num, 2),
                    u"<b>{}</b> est inférieure au prix minimum de vente<b> {} CFA</b>"
                    .format(pusaisi, selling_price), pusaisi < selling_price):
                print("E")
                # return

            montant = (qtsaisi * pusaisi)
            self.mtt_ht += montant
            self.setItem(row_num, 3, TotalsWidget(formatted_number(montant)))
            self._update_data(row_num, [qtsaisi, pusaisi, self.mtt_ht])
        self.setItem(row_num + 1, 3,
                     TotalsWidget(formatted_number(self.mtt_ht)))
        typ = self.parent.liste_type_invoice[
            self.parent.box_type_inv.currentIndex()]
        self.paid_amount_field.setText(
            str(self.mtt_ht) if typ == Invoice.TYPE_BON else "0")
        self.button.setEnabled(True)