Пример #1
0
class EditOrAddMemberDialog(QDialog, FWidget):
    def __init__(self,
                 table_p,
                 parent,
                 scoop=None,
                 member=None,
                 *args,
                 **kwargs):
        FWidget.__init__(self, parent, *args, **kwargs)

        self.table_p = table_p
        self.member = member
        self.scoop = scoop
        self.parent = parent
        full_name = ""
        self.ddn_field = FormatDate(QDate(QDate.currentDate()))

        addres = ""
        nationality = ""
        phone = ""
        if self.member:
            self.new = False
            full_name = self.member.full_name
            mddn = self.member.ddn
            if mddn:
                day, month, year = mddn.split("/")
                ddn = datetime.strptime(mddn, '%d/%m/%Y')
                self.ddn_field.setDate(QDate(ddn))
            addres = self.member.addres
            nationality = self.member.nationality
            phone = str(self.member.phone or "")

            self.title = u"Modification de {}".format(self.member)
            self.succes_msg = u"{} a été bien mise à jour".format(self.member)
        else:
            self.new = True
            self.succes_msg = u"Client a été bien enregistré"
            self.title = u"Ajout nouveau membre"
            self.member = CooperativeMember()
        self.setWindowTitle(self.title)

        vbox = QVBoxLayout()
        # vbox.addWidget(FPageTitle(u"Utilisateur: %s " % self.member.name))

        self.full_name_field = LineEdit(full_name)
        self.sex_list = CooperativeMember.SEX.items()
        # Combobox widget
        self.sex_box = QComboBox()

        for index, value in enumerate(self.sex_list):
            # form = self.sex_list[index]
            self.sex_box.addItem("{}".format(value[1].upper()), value[0])
            if self.member.sex == value[0]:
                self.sex_box.setCurrentIndex(index)
        # print("DE", ddn)
        # self.ddn_field.setDate(ddn)
        # self.ddn_field = QDateEdit(QDate(ddn))
        self.addres_field = QTextEdit(addres)
        self.nationality_field = LineEdit(nationality)
        self.phone_field = IntLineEdit(phone)
        self.phone_field.setInputMask("## ## ## ##")
        self.poste_list = get_postes()
        self.poste_box = QComboBox()
        for index, value in enumerate(self.poste_list):
            self.poste_box.addItem(
                "{}".format(self.poste_list.get(value).upper()), value)
            if self.member.poste == value:
                print(value)
                self.poste_box.setCurrentIndex(index)

        formbox = QFormLayout()
        formbox.addRow(FormLabel(u"Nom complet : *"), self.full_name_field)
        formbox.addRow(FormLabel(u"Sexe *:"), self.sex_box)
        formbox.addRow(FormLabel(u"Date de naissance *:"), self.ddn_field)
        formbox.addRow(FormLabel(u"Poste occupé *:"), self.poste_box)
        formbox.addRow(FormLabel(u"Nationalité *:"), self.nationality_field)
        formbox.addRow(FormLabel(u"Téléphone :"), self.phone_field)
        formbox.addRow(FormLabel(u"Adresse :"), self.addres_field)

        butt = Button(u"Enregistrer")
        butt.clicked.connect(self.save_edit)
        formbox.addRow("", butt)

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

    def is_valide(self):
        if check_is_empty(self.full_name_field):
            return False
        if check_is_empty(self.ddn_field):
            return False
        if check_is_empty(self.nationality_field):
            return False
        if check_is_empty(self.phone_field):
            return False
        return True

    def save_edit(self):
        ''' add operation '''
        if not self.is_valide():
            return
        print("Save")
        self.member.scoop = self.scoop
        self.member.full_name = self.full_name_field.text()
        self.member.sex = self.sex_box.itemData(self.sex_box.currentIndex())
        self.member.ddn = self.ddn_field.text()
        self.member.addres = self.addres_field.toPlainText()
        self.member.nationality = self.nationality_field.text()
        phone = self.phone_field.text()
        self.member.phone = is_int(phone)
        self.member.poste = self.poste_box.itemData(
            self.poste_box.currentIndex())
        try:
            self.member.save_()
            self.close()
            self.table_p.refresh_()
            self.parent.Notify(
                u"Le membre {} ({}) a été mise à jour".format(
                    self.member.full_name, self.member.poste), "success")
        except peewee.IntegrityError:
            field_error(self.full_name_field,
                        "Ce nom existe dans la basse de donnée.")
Пример #2
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))
Пример #3
0
class ImmatriculationSCoopViewWidget(FWidget):

    def __init__(self, parent, dmd=None, *args, **kwargs):
        super(ImmatriculationSCoopViewWidget, self).__init__(
            parent=parent, *args, **kwargs)

        self.parent = parent
        self.parentWidget().set_window_title("FORMULAIRE D’IMMATRICULATION")
        self.dmd = dmd
        self.scoop = self.dmd.scoop
        self.name_declarant_field = QLineEdit()
        self.name_declarant_field.setPlaceholderText("M. / Mme")
        self.name_declarant_field.setMaximumWidth(600)

        self.procuration_field = QLineEdit()
        self.procuration_field.setPlaceholderText(
            "Réf.de la Procuration le cas échéant")
        self.procuration_field.setMaximumWidth(600)
        self.quality_box = QComboBox()
        self.quality_box.setMaximumWidth(600)
        self.quality_box.currentIndexChanged.connect(self.change_select)
        self.qualities_list = get_qualities()
        for index, value in enumerate(self.qualities_list):
            self.quality_box.addItem(
                "{}".format(self.qualities_list.get(value).upper()), value)

        self.type_box = QComboBox()
        self.type_box.setMaximumWidth(600)
        self.type_lists = Immatriculation.TYPES
        for index, value in enumerate(self.type_lists):
            print(value)
            self.type_box.addItem("{}".format(value[1], index))
        self.tel_declarant_field = IntLineEdit()
        self.tel_declarant_field.setInputMask('## ## ## ##')
        self.tel_declarant_field.setMaximumWidth(600)
        self.btn = Button_save("Sauvegarder")
        self.btn.setMaximumWidth(600)
        self.btn.clicked.connect(self.save)

        declarant_formbox = QFormLayout()
        declarant_formbox.addRow(FLabel("<strong>Type de d'immatriculation *: </strong>"), self.type_box)
        declarant_formbox.addRow(FLabel("<strong>Nom et prénom du declarant *: </strong>"), self.name_declarant_field)
        declarant_formbox.addRow(FLabel("<strong>En qualité de *: </strong>"), self.quality_box)
        declarant_formbox.addRow(FLabel("<strong>Procuration *: </strong>"), self.procuration_field)
        declarant_formbox.addRow(FLabel("<strong>Numéro tel. du declarant *: </strong>"), self.tel_declarant_field)
        declarant_formbox.addRow(FLabel(""), self.btn)
        self.declarantGroupBox = QGroupBox("Info. du déclarant de la {} *".format(self.scoop.denomination))
        self.declarantGroupBox.setStyleSheet(CSS_CENTER)
        self.declarantGroupBox.setLayout(declarant_formbox)
        vbox = QVBoxLayout()
        # vbox.addWidget(self.infoGroupBox)
        vbox.addWidget(self.declarantGroupBox)
        # vbox.addLayout(editbox)
        self.setLayout(vbox)

    def change_select(self):
        self.qlt_select = self.quality_box.itemData(
            self.quality_box.currentIndex())

        self.procuration_field.setEnabled(False)
        if self.qlt_select == Immatriculation.TP:
            self.procuration_field.setEnabled(True)
            # if check_is_empty(self.procuration_field):
            #     return False

    def is_not_valide(self):
        # print(check_is_empty(self.name_declarant_field))
        if self.quality_box.itemData(self.quality_box.currentIndex()) == Immatriculation.TP:
            if check_is_empty(self.procuration_field) or check_is_empty(self.tel_declarant_field):
                return True
        return check_is_empty(self.name_declarant_field) or check_is_empty(self.tel_declarant_field)

    def save(self):
        if self.is_not_valide():
            return False

        imma = Immatriculation()
        imma.scoop = self.scoop
        imma.typ_imm = self.type_lists[self.type_box.currentIndex()][0]
        imma.name_declarant = self.name_declarant_field.text()
        imma.quality = self.quality_box.itemData(self.quality_box.currentIndex())
        imma.procuration = self.procuration_field.text()
        imma.tel_declarant = self.tel_declarant_field.text()
        imma.save_ident()
        self.dmd.status = self.dmd.ENDPROCCES
        self.dmd.save_()
        self.parent.change_context(ResgistrationManagerWidget)
Пример #4
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))
Пример #5
0
class NewOrEditOfficeViewWidget(QDialog, FWidget):
    def __init__(self, pp=None, owner=None, parent=None, *args, **kwargs):
        QDialog.__init__(self, parent, *args, **kwargs)

        self.setWindowTitle(u"Nouvel Organisation")
        self.parent = parent

        vbox = QVBoxLayout()

        self.office_group_box()
        vbox.addWidget(self.organGroupBoxBtt)
        self.setLayout(vbox)

    def office_group_box(self):
        self.organGroupBoxBtt = QGroupBox(
            self.tr("Configuration des localités"))

        self.office_box = QComboBox()
        self.office_box.currentIndexChanged.connect(self.change_select_office)

        self.office_list = get_offices()
        self.region_box = QComboBox()
        self.region_label = FLabel()
        self.cercle_label = FLabel()
        self.phone_field = IntLineEdit()
        self.phone_field.setInputMask('## ## ## ##')
        self.bp = LineEdit()
        self.adress_org = QTextEdit()
        self.email_org = LineEdit()

        for index, value in enumerate(self.office_list):
            self.office_box.addItem("{}".format(office_name(value)), value)

        formbox = QFormLayout()
        formbox.addRow(FormLabel(u"Nom service :"), self.office_box)
        formbox.addRow(FormLabel(u"Région"), self.region_label)
        formbox.addRow(FormLabel(u"Cercle"), self.cercle_label)
        formbox.addRow(FormLabel(u"Tel :"), self.phone_field)
        formbox.addRow(FormLabel(u"B.P :"), self.bp)
        formbox.addRow(FormLabel(u"E-mail :"), self.email_org)
        formbox.addRow(FormLabel(u"Adresse complete :"), self.adress_org)
        butt = Button_save(u"Enregistrer")
        butt.clicked.connect(self.save_edit)
        formbox.addRow("", butt)

        self.organGroupBoxBtt.setLayout(formbox)

    def change_select_office(self):
        select_o = self.office_box.itemData(self.office_box.currentIndex())
        self.r_select = office_region(select_o)
        self.c_select = office_cercle(select_o)
        self.region_label.setText(get_entity_name(self.r_select))
        self.cercle_label.setText(get_entity_name(self.c_select))

    def is_valide(self):
        if check_is_empty(self.phone_field):
            return False
        return True

    def save_edit(self):
        ''' add operation '''

        if not self.is_valide():
            return

        office = Office()
        office.slug = self.office_box.itemData(self.office_box.currentIndex())
        office.slug_region = self.r_select
        office.slug_cercle = self.c_select
        office.phone = is_int(self.phone_field.text())
        office.email_org = str(self.email_org.text())
        office.bp = str(self.bp.text())
        office.adress_org = str(self.adress_org.toPlainText())
        office.save_()
        self.accept()
Пример #6
0
class RegistrationViewWidget(FWidget):
    """ Shows the home page  """
    def __init__(self, parent=0, *args, **kwargs):
        super(RegistrationViewWidget, self).__init__(parent=parent,
                                                     *args,
                                                     **kwargs)
        self.parent = parent

        self.parentWidget().set_window_title("FORMULAIRE D’IMMATRICULATION")
        self.title = FLabel("<h3>FORMULAIRE D’IMMATRICULATION</h3>")
        self.office = Office.select().where(Office.id == 1).get()
        self.created_date_field = FormatDate(QDate.currentDate())
        self.created_date_field.setMaximumWidth(130)
        # self.created_date_field.setInputMask('##/##/####')
        self.rue_field = IntLineEdit()
        self.porte_field = IntLineEdit()
        self.tel_field = IntLineEdit()
        self.tel_field.setInputMask('## ## ## ##')
        self.tel2_field = IntLineEdit()
        self.tel2_field.setInputMask('## ## ## ##')
        self.bp_field = IntLineEdit()
        self.email_field = LineEdit()
        self.denomination_field = LineEdit()
        self.commercial_name_field = LineEdit()
        self.declaration_date_field = FormatDate(QDate.currentDate())
        self.declaration_date_field.setMaximumWidth(130)
        self.amount_capital_social_initial = FLabel()
        self.amount_part_social_field = IntLineEdit()
        self.apports_numeraire_field = IntLineEdit()
        self.apports_numeraire_field.textChanged.connect(self.cal_total)
        self.apports_nature_field = IntLineEdit()
        self.apports_nature_field.textChanged.connect(self.cal_total)
        self.apports_industrie_field = IntLineEdit()
        self.apports_industrie_field.textChanged.connect(self.cal_total)

        self.duree_statutaire_field = IntLineEdit()
        self.duree_statutaire_field.setMaximumWidth(80)
        self.spinneret_box = QComboBox()
        self.spinneret_box.setMaximumWidth(800)

        self.activites_box = QComboBox()
        self.activites_box.setMaximumWidth(800)
        self.activites_box.currentIndexChanged.connect(self.sp_change_select)
        self.activities_list = get_activities()
        for index, value in enumerate(self.activities_list):
            self.activites_box.addItem(
                "{}".format(self.activities_list.get(value).upper()), value)
            # if self.store and self.store.name == op.name:
            #     self.box_store.setCurrentIndex(index)

        self.formes_box = QComboBox()
        self.formes_box.setMaximumWidth(800)
        self.formes_list = get_formes()
        for index, value in enumerate(self.formes_list):
            self.formes_box.addItem(
                "{}".format(self.formes_list.get(value).upper()), value)

        self.commune_list = entity_children(self.office.slug_cercle).items()
        self.commune_box = ExtendedComboBox()
        for index, value in enumerate(self.commune_list):
            self.commune_box.addItem("{}".format(value[1].upper()), value[0])
        # self.commune_box.addItems(self.commune_list)
        self.commune_box.setToolTip("commune")
        self.commune_box.currentIndexChanged.connect(self.c_change_select)

        # self.vfq_list = self.get_vfq_list()
        self.vfq_box = ExtendedComboBox()
        self.vfq_list = self.get_vfq_list()
        for index, value in enumerate(self.vfq_list):
            self.vfq_box.addItem("{}".format(self.vfq_list.get(value).upper()),
                                 value)
        self.vfq_box.setToolTip("vfq")

        formbox = QFormLayout()
        formbox.addRow(FLabel(DATE_DEMANTE), self.declaration_date_field)
        formbox.addRow(FLabel("1. " + DENOMINATION_S_SC),
                       self.denomination_field)
        formbox.addRow(FLabel("2. " + NOM_COMMERCIAL),
                       self.commercial_name_field)
        formbox.addRow(FLabel("3. " + DATE_CREATION_SC),
                       self.created_date_field)
        formbox.addRow(FLabel("4. " + ACTIVITES_E), self.activites_box)
        formbox.addRow(FLabel("5. " + FILIERE), self.spinneret_box)
        formbox.addRow(FLabel("6. " + FORME_SC), self.formes_box)
        # Capital Social Initial
        capital_formbox = QFormLayout()
        capital_formbox.addRow(FLabel("7.1. " + MONTANT_PART_S),
                               self.amount_part_social_field)
        capital_formbox.addRow(FLabel("7.2. " + MONTANT_APPORTS_NUM),
                               self.apports_numeraire_field)
        capital_formbox.addRow(FLabel("7.3. " + MONTANT_APPORTS_NAT),
                               self.apports_nature_field)
        capital_formbox.addRow(FLabel("7.4. " + MONTANT_APPORTS_INDU),
                               self.apports_industrie_field)
        self.capitalSGroupBox = QGroupBox("7. " + MONTANT_CAPITAL_SI)
        self.capitalSGroupBox.setLayout(capital_formbox)
        self.capitalSGroupBox.setStyleSheet(CSS)
        # self.capitalSGroupBox.setMaximumWidth(1300)
        # Adresse du siège social

        self.vline = QFrame()
        self.vline.setFrameShape(QFrame.VLine)
        self.vline.setFrameShadow(QFrame.Sunken)

        self.addresGroupBox = QGroupBox("8. " + ADRESSE_SS)
        self.addresGroupBox.setStyleSheet(CSS)
        addres_gribox = QGridLayout()
        addres_gribox.addWidget(FRLabel(CERCLE), 0, 0)
        addres_gribox.addWidget(FLabel(self.office.cercle_name()), 0, 1)
        addres_gribox.addWidget(FRLabel(COMMUNE), 1, 0)
        addres_gribox.addWidget(self.commune_box, 1, 1)
        # addres_gribox.addWidget(self.vline, 0, 3, 2, 5)
        addres_gribox.addWidget(FRLabel(VFQ), 2, 0)
        addres_gribox.addWidget(self.vfq_box, 2, 1)
        addres_gribox.addWidget(FRLabel(RUE), 0, 2)
        addres_gribox.addWidget(self.rue_field, 0, 3)
        addres_gribox.addWidget(FRLabel(PORTE), 1, 2)
        addres_gribox.addWidget(self.porte_field, 1, 3)
        addres_gribox.addWidget(FRLabel(BP), 0, 4)
        addres_gribox.addWidget(self.bp_field, 0, 5)
        addres_gribox.addWidget(FRLabel(EMAIL), 1, 4)
        addres_gribox.addWidget(self.email_field, 1, 5)
        addres_gribox.addWidget(FRLabel(TEL), 2, 2)
        addres_gribox.addWidget(self.tel_field, 2, 3)
        addres_gribox.addWidget(FRLabel(TEL2), 2, 4)
        addres_gribox.addWidget(self.tel2_field, 2, 5)
        # addres_gribox.setColumnStretch(6, 5)
        self.addresGroupBox.setLayout(addres_gribox)
        # self.addresGroupBox.setMaximumWidth(1300)
        # Durée statutaire de la société coopérative
        duree_fbox = QFormLayout()
        duree_fbox.addRow(FLabel("9. " + DUREE_STATUTAIRE_SC),
                          self.duree_statutaire_field)
        butt = Button_save(SAVE)
        butt.clicked.connect(self.save_and_goto_manager)
        butt_and_continous = Button_save(SAVE_AND_CONTINNUES)
        butt_and_continous.clicked.connect(self.save_and_goto_add_member)

        butt_and_continous.setMaximumWidth(300)
        duree_fbox.addRow(FLabel(""), FLabel(""))
        duree_fbox.addRow(butt, butt_and_continous)

        vbox = QVBoxLayout()
        vbox.addLayout(formbox)
        vbox.addWidget(self.capitalSGroupBox)
        vbox.addWidget(self.addresGroupBox)
        vbox.addLayout(duree_fbox)
        self.setLayout(vbox)

    def get_vfq_list(self):
        # c_dic = {}
        co_select = self.commune_box.itemData(self.commune_box.currentIndex())
        return entity_children(co_select)

    def c_change_select(self):
        self.vfq_box.clear()
        self.vfq_list = self.get_vfq_list()
        for index, value in enumerate(self.vfq_list):
            self.vfq_box.addItem("{}".format(self.vfq_list.get(value).upper()),
                                 value)

    def get_spinneret_list(self):
        # c_dic = {}
        r_select = self.activites_box.itemData(
            self.activites_box.currentIndex())
        return get_spinneret_activites(r_select)

    def sp_change_select(self):
        self.spinneret_box.clear()
        self.spinneret_list = self.get_spinneret_list()

        for index, value in enumerate(self.spinneret_list):
            self.spinneret_box.addItem(
                "{}".format(self.spinneret_list.get(value).upper()), value)

    def is_valide(self):
        if check_is_empty(self.denomination_field):
            return False

        if CooperativeCompanie.select().where(
                CooperativeCompanie.denomination ==
                self.denomination_field.text()).exists():
            field_error(
                self.denomination_field,
                "Cette dénomination existe déjà dans la base de données !")
            return False
        if check_is_empty(self.commercial_name_field):
            return False
        if check_is_empty(self.created_date_field):
            return False
        if check_is_empty(self.denomination_field):
            return False
        if check_is_empty(self.apports_numeraire_field):
            return False
        if check_is_empty(self.apports_nature_field):
            return False
        if check_is_empty(self.apports_industrie_field):
            return False
        # if check_is_empty(self.rue_field):
        #     return False
        # if check_is_empty(self.porte_field):
        #     return False
        # print(len(self.tel_field.text()))
        if len(self.tel_field.text()) != 11:
            field_error(self.tel_field, "Numéro requis")
            return False
        # if check_is_empty(self.bp_field):
        #     return False
        # if check_is_empty(self.email_field):
        #     return False
        if check_is_empty(self.duree_statutaire_field):
            return False
        # print(int(self.duree_statutaire_field.text()))
        if int(self.duree_statutaire_field.text()) > 99:
            field_error(
                self.duree_statutaire_field,
                "La durée statutaire ne peut être supérieure à 99 ans")
            return False
        return True

    def save(self):
        if not self.is_valide():
            return
        self.scoop = CooperativeCompanie()
        self.scoop.office = self.office
        self.scoop.created_date = str(self.created_date_field.text())
        self.scoop.denomination = str(self.denomination_field.text())
        self.scoop.commercial_name = str(self.commercial_name_field.text())
        self.scoop.activity = self.activites_box.itemData(
            self.activites_box.currentIndex())
        self.scoop.spinneret = self.spinneret_box.itemData(
            self.spinneret_box.currentIndex())
        self.scoop.forme = self.formes_box.itemData(
            self.formes_box.currentIndex())
        self.scoop.amount_part_social = is_int(
            self.amount_part_social_field.text())
        self.scoop.apports_numeraire = is_int(
            self.apports_numeraire_field.text())
        self.scoop.apports_nature = is_int(self.apports_nature_field.text())
        self.scoop.apports_industrie = is_int(
            self.apports_industrie_field.text())
        self.scoop.region = self.office.slug_region
        self.scoop.cercle = self.office.slug_cercle
        self.scoop.commune = self.commune_box.itemData(
            self.commune_box.currentIndex())
        self.scoop.vfq = self.vfq_box.itemData(self.vfq_box.currentIndex())
        self.scoop.rue = is_int(self.rue_field.text())
        self.scoop.porte = is_int(self.porte_field.text())
        self.scoop.tel = is_int(self.tel_field.text())
        self.scoop.tel2 = is_int(self.tel2_field.text())
        self.scoop.bp = is_int(self.bp_field.text())
        self.scoop.email = self.email_field.text()
        self.scoop.duree_statutaire = is_int(
            self.duree_statutaire_field.text())
        self.scoop.save_()
        check_list = CheckList()
        check_list.save_()
        self.dmd = Demande()
        self.dmd.check_list = check_list
        self.dmd.declaration_date = str(self.declaration_date_field.text())
        self.dmd.scoop = self.scoop
        self.dmd.status = self.dmd.ADDMEMBER
        self.dmd.save_()
        return True

    def save_and_goto_add_member(self):
        if self.save():
            from ui.member_manager import MemberManagerWidget
            self.parent.change_context(MemberManagerWidget, dmd=self.dmd)

    def save_and_goto_manager(self):
        if self.save():
            self.parent.change_context(ResgistrationManagerWidget)

    def cal_total(self):
        total = is_int(self.apports_numeraire_field.text() or 0) + is_int(
            self.apports_nature_field.text() or 0) + is_int(
                self.apports_industrie_field.text() or 0)
        self.capitalSGroupBox.setTitle("7. {} :  {}".format(
            MONTANT_CAPITAL_SI, device_amount(total)))