Пример #1
0
    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)
Пример #2
0
class InvoiceViewWidget(FWidget):

    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 add_clt(self):
        from GCommon.ui.provider_client_edit_add import EditOrAddClientOrProviderDialog

        self.open_dialog(EditOrAddClientOrProviderDialog, modal=True,
                         prov_clt=None, table_p=self)

    def finder(self):
        search_term = self.search_field.text()
        value = unicode(search_term)
        self.table_resultat.refresh_(value)

    def is_valide(self):
        print("is_valide")
        try:
            self.name_client, self.phone = self.name_client_field.lineEdit().text().split(
                ",")
        except Exception as e:
            # print(e)
            field_error(
                self.name_client_field, "Nom, numéro de téléphone du client")
            return False
        return True

    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)