Пример #1
0
class DialogAjoutFournisseur(wx.Dialog):
    def __init__(self, adherent):
        wx.Dialog.__init__(self,
                           None,
                           -1,
                           title=u"Ajouter un fournisseur",
                           pos=wx.DefaultPosition,
                           size=wx.DefaultSize,
                           style=wx.DEFAULT_DIALOG_STYLE)

        self.adherent = adherent

        self.liste_fournisseurs = ObjectListView(
            self, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)

        self.liste_fournisseurs.SetColumns(
            [ColumnDefn("Fournisseur", "left", -1, "nom", minimumWidth=100)])

        self.liste_fournisseurs.Bind(wx.EVT_LIST_ITEM_ACTIVATED,
                                     self.OnClickFournisseur)

        self.__set_properties()
        self.__remplissage_liste()
        self.__do_layout()

    def __set_properties(self):
        self.SetMinSize((200, 300))
        self.liste_fournisseurs.SortBy(0)

    def __remplissage_liste(self):
        try:
            requete = Fournisseur.select().where(
                ~(Fournisseur.id << self.adherent.fournisseurs))
            self.liste_fournisseurs.SetObjects([f for f in requete])

            #On dimentionne le dialog selon la largeur des colonnes
            largeur = 0
            for num_colonne in range(1):
                largeur += self.liste_fournisseurs.GetColumnWidth(num_colonne)

            self.liste_fournisseurs.SetMinSize((largeur + 20, 300))

        except BaseException as ex:
            print ex

    def __do_layout(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.liste_fournisseurs, 1, wx.ALL | wx.EXPAND, 10)
        self.SetSizer(sizer)
        sizer.Fit(self)
        self.Layout()

    def GetFournisseur(self):
        return self.liste_fournisseurs.GetSelectedObject()

    def OnClickFournisseur(self, event):
        self.EndModal(wx.ID_OK)
Пример #2
0
class FicheAchat(wx.Dialog):
    """Permet d'éditer un achat. Dialog modal"""
    def __init__(self, parent, achat=None, adherent=None):
        wx.Dialog.__init__(self, parent, style=wx.DEFAULT_DIALOG_STYLE)

        if achat == None:
            if adherent == None:
                #TODO : à modifier quand le système d'identification sera en place
                adherent = Adherent.select().where(Adherent.id == 1).get()

            achat = Achat.create(adherent=adherent)

        self.achat = achat

        self.sizer_infos_staticbox = wx.StaticBox(self, -1, "Informations")

        self.label_credit_restant = wx.StaticText(self, -1, u"Crédit restant")
        self.label_cotisation = wx.StaticText(self, -1, u"Cotisation du mois")
        self.label_cotisation_payee = wx.StaticText(self, -1,
                                                    u"- Payée le xx-xx-xx")
        self.label_total_achats = wx.StaticText(self, -1, "Total des achats")
        self.label_solde = wx.StaticText(self, -1, u"Solde après achat")
        self.label_credit_restant_valeur = wx.StaticText(self, -1, u"0.00 ¤")
        self.label_cotisation_valeur = wx.StaticText(self, -1, u"0.00 ¤")
        self.label_total_achats_valeur = wx.StaticText(self,
                                                       -1,
                                                       u"0.00 ¤",
                                                       style=wx.ALIGN_RIGHT)
        self.label_cout_supplementaire = wx.StaticText(
            self, -1, u"Coût supplémentaire")
        self.text_cout_supplementaire = wx.TextCtrl(
            self,
            -1,
            validator=GenericTextValidator(VALIDATE_FLOAT, obligatoire=False))
        self.text_cout_supplementaire_commentaire = TextCtrlDescriptive(
            self, -1, style=wx.TE_MULTILINE)
        self.label_solde_valeur = wx.StaticText(self, -1, u"0.00 ¤")

        self.sizer_liste_produits_staticbox = wx.StaticBox(
            self, -1, "Liste des produits")
        self.label_titre_achat = wx.StaticText(self, -1, "Achat pour ")
        self.search_nom = wx.SearchCtrl(self, -1, "")
        self.liste_produits = ObjectListView(self,
                                             -1,
                                             style=wx.LC_REPORT
                                             | wx.SUNKEN_BORDER)

        self.liste_produits.SetColumns([
            ColumnDefn("Ref GASE", "left", -1, "ref_GASE", minimumWidth=70),
            ColumnDefn("Nom", "left", -1, "nom", minimumWidth=100),
            ColumnDefn("Prix",
                       "right",
                       -1,
                       "prix_vente_format",
                       minimumWidth=100,
                       isSpaceFilling=True)
        ])
        self.liste_produits.SetEmptyListMsg("Aucun produits")
        self.liste_produits.AutoSizeColumns()

        self.sizer_achat_staticbox = wx.StaticBox(self, -1, "Achat")
        self.liste_lignes_achat = ObjectListView(self,
                                                 -1,
                                                 style=wx.LC_REPORT
                                                 | wx.SUNKEN_BORDER)

        self.liste_lignes_achat.SetColumns([
            ColumnDefn("Ref GASE",
                       "left",
                       -1,
                       "produit.ref_GASE",
                       minimumWidth=70),
            ColumnDefn("Nom", "left", -1, "produit.nom", minimumWidth=100),
            ColumnDefn("Prix",
                       "left",
                       -1,
                       "produit.prix_vente_format",
                       minimumWidth=100),
            ColumnDefn(u"Quantité",
                       "left",
                       -1,
                       "quantite_format",
                       minimumWidth=70),
            ColumnDefn("Total TTC",
                       "right",
                       -1,
                       "prix_total",
                       stringConverter=u"%.2f ¤",
                       minimumWidth=70,
                       isSpaceFilling=True)
        ])
        self.liste_lignes_achat.AutoSizeColumns()

        self.liste_lignes_achat.SetEmptyListMsg(u"Produits achetés")

        self.bouton_sauvegarder = wx.Button(self, wx.ID_SAVE)
        self.bouton_annuler = wx.Button(self, wx.ID_CANCEL)

        self.__set_properties()
        self.__set_tooltips()
        self.__set_values()
        self.__do_layout()

        self.bouton_sauvegarder.Bind(wx.EVT_BUTTON, self.OnSauvegarder)
        self.bouton_annuler.Bind(wx.EVT_BUTTON, self.OnClose)
        self.text_cout_supplementaire.Bind(wx.EVT_TEXT, self.OnChangeCoutSupp)
        self.search_nom.Bind(wx.EVT_TEXT, self.OnFilter)
        self.liste_produits.Bind(wx.EVT_LIST_ITEM_ACTIVATED,
                                 self.OnAjoutProduit)
        self.liste_lignes_achat.Bind(wx.EVT_LIST_ITEM_ACTIVATED,
                                     self.OnModifProduit)
        self.Bind(wx.EVT_CLOSE, self.OnClose)

    def __set_properties(self):
        self.label_titre_achat.SetFont(
            wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.sizer_infos_staticbox.SetFont(
            wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.sizer_liste_produits_staticbox.SetFont(
            wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.sizer_achat_staticbox.SetFont(
            wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))

        font_italic = self.label_cotisation.GetFont()
        font_italic.SetStyle(wx.ITALIC)

        self.label_cotisation_payee.SetFont(font_italic)
        """self.label_credit_restant.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_cotisation.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_total_achats.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_solde.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_credit_restant_valeur.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_cotisation_valeur.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_total_achats_valeur.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_solde_valeur.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))"""

        self.text_cout_supplementaire.SetMinSize((60, -1))
        self.text_cout_supplementaire_commentaire.SetMinSize((-1, 50))
        self.label_credit_restant.SetMinSize((130, -1))
        self.search_nom.SetMinSize((200, -1))
        self.search_nom.SetDescriptiveText("Recherche sur le nom")

    def __set_tooltips(self):
        self.text_cout_supplementaire_commentaire.SetToolTip(
            wx.ToolTip(u"Description des coûts supplémentaires"))

    def __set_values(self):
        try:
            produits = Produit.select().where((Produit.retrait == False) | (
                Produit.retrait == True and Produit.stock > 0))
            self.liste_produits.SetObjects([p for p in produits])
            self.liste_produits.AutoSizeColumns()

            self.liste_lignes_achat.SetObjects(
                [la for la in self.achat.lignes_achat])

            credit_restant = self.achat.adherent.solde - self.achat.total

            self.label_credit_restant_valeur.SetLabel(u"%.2f ¤" %
                                                      credit_restant)

            if credit_restant >= 0:
                self.label_credit_restant_valeur.SetForegroundColour("#00AA00")
            else:
                self.label_credit_restant_valeur.SetForegroundColour("#DD0000")

            cotisation_du_mois = self.achat.adherent.cotisation_du_mois

            if cotisation_du_mois:
                self.label_cotisation_valeur.SetLabel("\\")
                self.label_cotisation_payee.SetLabel(
                    u"- %.2f ¤, payée le %s" %
                    (cotisation_du_mois.montant,
                     cotisation_du_mois.date.strftime("%d-%m-%Y")))
            else:
                self.label_cotisation_valeur.SetLabel(
                    u"%.2f ¤" % self.achat.adherent.cotisation_type.prix)
                self.label_cotisation_payee.Hide()

            print self.achat.cout_supplementaire
            self.text_cout_supplementaire.SetValue(
                "%.2f" % float(self.achat.cout_supplementaire))
            self.text_cout_supplementaire_commentaire.SetValue(
                self.achat.cout_supplementaire_commentaire)

            self.__update_total()

        except BaseException as ex:
            print ex

    def __do_layout(self):
        grid_sizer_infos = rcs.RowColSizer()

        grid_sizer_infos.Add(self.label_credit_restant, row=0, col=0)
        grid_sizer_infos.Add(self.label_credit_restant_valeur,
                             flag=wx.ALIGN_RIGHT,
                             row=0,
                             col=1)
        grid_sizer_infos.Add(self.label_cotisation, row=1, col=0)
        grid_sizer_infos.Add(self.label_cotisation_valeur,
                             flag=wx.ALIGN_RIGHT,
                             row=1,
                             col=1)
        grid_sizer_infos.Add(self.label_cotisation_payee,
                             row=2,
                             col=0,
                             colspan=2)
        grid_sizer_infos.Add(self.label_total_achats, row=3, col=0)
        grid_sizer_infos.Add(self.label_total_achats_valeur,
                             flag=wx.ALIGN_RIGHT,
                             row=3,
                             col=1)
        grid_sizer_infos.Add(self.label_cout_supplementaire,
                             flag=wx.ALIGN_CENTER_VERTICAL,
                             row=4,
                             col=0)
        grid_sizer_infos.Add(self.text_cout_supplementaire,
                             flag=wx.ALIGN_RIGHT,
                             row=4,
                             col=1)
        grid_sizer_infos.Add(self.text_cout_supplementaire_commentaire,
                             flag=wx.EXPAND,
                             row=5,
                             col=0,
                             colspan=2)
        grid_sizer_infos.Add(wx.StaticLine(self, style=wx.LI_HORIZONTAL),
                             flag=wx.EXPAND,
                             row=6,
                             col=0,
                             colspan=2)
        grid_sizer_infos.Add(self.label_solde, row=7, col=0)
        grid_sizer_infos.Add(self.label_solde_valeur,
                             flag=wx.ALIGN_RIGHT,
                             row=7,
                             col=1)

        sizer_infos = wx.StaticBoxSizer(self.sizer_infos_staticbox,
                                        wx.VERTICAL)
        sizer_infos.Add(grid_sizer_infos, 1, wx.ALL | wx.EXPAND, 5)

        sizer_liste_produits = wx.StaticBoxSizer(
            self.sizer_liste_produits_staticbox, wx.VERTICAL)
        sizer_liste_produits.Add(self.search_nom, 0, wx.BOTTOM, 6)
        sizer_liste_produits.Add(self.liste_produits, 1, wx.EXPAND, 0)

        sizer_infos_produits = wx.BoxSizer(wx.HORIZONTAL)
        sizer_infos_produits.Add(sizer_infos, 0, wx.EXPAND | wx.RIGHT, 5)
        sizer_infos_produits.Add(sizer_liste_produits, 1, wx.EXPAND, 0)

        sizer_achat = wx.StaticBoxSizer(self.sizer_achat_staticbox,
                                        wx.VERTICAL)
        sizer_achat.Add(self.liste_lignes_achat, 1, wx.EXPAND, 0)

        sizer_boutons = wx.BoxSizer(wx.HORIZONTAL)
        sizer_boutons.Add(self.bouton_sauvegarder, 1)
        sizer_boutons.Add((10, 10), 1, wx.EXPAND)
        sizer_boutons.Add(self.bouton_annuler, 1)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.label_titre_achat, 0, wx.BOTTOM | wx.EXPAND, 10)
        sizer.Add(sizer_infos_produits, 1, wx.TOP | wx.BOTTOM | wx.EXPAND, 5)
        sizer.Add(sizer_achat, 1, wx.EXPAND, 0)
        sizer.Add(sizer_boutons, 0, wx.TOP | wx.ALIGN_CENTER_HORIZONTAL, 6)

        sizer_dialog = wx.BoxSizer(wx.VERTICAL)
        sizer_dialog.Add(sizer, 1, wx.ALL | wx.EXPAND, 10)

        self.SetSizer(sizer_dialog)
        sizer_dialog.Fit(self)

    def __update_total(self):
        solde = self.achat.adherent.solde

        self.label_total_achats_valeur.SetLabel(u"%.2f ¤" % self.achat.total)
        self.label_solde_valeur.SetLabel(u"%.2f ¤" % solde)

        if solde >= 0:
            self.label_solde_valeur.SetForegroundColour("#00AA00")
        else:
            self.label_solde_valeur.SetForegroundColour("#DD0000")

        self.Layout()

    def GetAchat(self):
        return self.achat

    def OnChangeCoutSupp(self, event):
        try:
            #PAS FINI !!
            if self.text_cout_supplementaire.GetValue() != "":
                self.achat.cout_supplementaire = float(
                    self.text_cout_supplementaire.GetValue())
                self.text_cout_supplementaire.SetBackgroundColour(
                    wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
                self.__update_total()
        except ValueError:
            self.text_cout_supplementaire.SetBackgroundColour('#ffcccc')

    def OnFilter(self, event):
        filtre_texte = Filter.TextSearch(self.liste_produits,
                                         text=self.search_nom.GetValue())
        self.liste_produits.SetFilter(filtre_texte)
        self.liste_produits.RepopulateList()

    def OnAjoutProduit(self, event):
        deja_ajoute = False
        produit_selectionne = self.liste_produits.GetSelectedObject()

        for la_liste in self.liste_lignes_achat.GetObjects():
            if la_liste.produit.get_id() == produit_selectionne.get_id():
                deja_ajoute = True
                break

        if deja_ajoute == False:
            la = LigneAchat(achat=self.achat, produit=produit_selectionne)

            dlg = DialogChoixQuantite(la)

            if dlg.ShowModal() == wx.ID_OK:
                if dlg.GetQuantite() != 0:
                    la.quantite = dlg.GetQuantite()
                    la.save()
                    self.liste_lignes_achat.AddObject(la)
                    self.liste_lignes_achat.AutoSizeColumns()

                    #Mise à jour du total de l'achat
                    self.__update_total()

            dlg.Destroy()

    def OnModifProduit(self, event):
        la_selectionnee = self.liste_lignes_achat.GetSelectedObject()

        dlg = DialogChoixQuantite(la_selectionnee)

        id_resultat = dlg.ShowModal()

        if id_resultat == wx.ID_OK and dlg.GetQuantite() != 0:
            la_selectionnee.quantite = dlg.GetQuantite()
            la_selectionnee.save()
            self.liste_lignes_achat.RefreshObject(la_selectionnee)
            self.liste_lignes_achat.AutoSizeColumns()
        elif id_resultat == wx.ID_DELETE or dlg.GetQuantite() == 0:
            self.liste_lignes_achat.RemoveObject(la_selectionnee)
            self.liste_lignes_achat.RefreshObject(la_selectionnee)
            la_selectionnee.delete_instance()
            self.liste_lignes_achat.AutoSizeColumns()

        #Mise à jour du total de la achat
        self.__update_total()

        dlg.Destroy()

    def OnSauvegarder(self, event):
        if self.Validate():
            cotisation = self.achat.adherent.paye_cotisation_du_mois()
            cotisation.save()

            self.achat.date = datetime.today()
            if self.text_cout_supplementaire.GetValue():
                self.achat.cout_supplementaire = float(
                    self.text_cout_supplementaire.GetValue())
            else:
                self.achat.cout_supplementaire = 0
            self.achat.cout_supplementaire_commentaire = self.text_cout_supplementaire_commentaire.GetValue(
            )
            self.achat.save()
            DATABASE.commit()
            wx.MessageBox(u"L'achat a été enregistré", "Notification")
            self.EndModal(wx.ID_SAVE)

    def OnClose(self, event):
        dlg = wx.MessageDialog(parent=None,
                               message=u"Voulez vous sauvegarder cet achat ?",
                               caption=u"Sauvegarde de l'achat",
                               style=wx.YES_NO | wx.ICON_QUESTION)

        if dlg.ShowModal() == wx.ID_YES:
            self.OnSauvegarder(event)
        else:
            DATABASE.rollback()
            self.EndModal(wx.ID_CANCEL)
Пример #3
0
class GestionCommandes(wx.Panel):
    def __init__(self, *args, **kwds):
        # begin wxGlade: SuiviCommandes.__init__
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)

        #self.sizer_navigation_staticbox = wx.StaticBox(self, -1, u"Suivi des commandes")

        self.commande = None

        self.sizer_navigation_staticbox = wx.StaticBox(self, -1, "Gestion des commandes")
        #self.sizer_liste_commandes_staticbox = wx.StaticBox(self, -1, "Liste des commandes")
        self.sizer_commande_staticbox = wx.StaticBox(self, -1, u"Détails de la Commande")
        self.button_Modifier = wx.Button(self, -1, "Modifier")
        self.button_nouvelle_commande = wx.Button(self, -1, "Faire une nouvelle commande")
        self.button_Supprimer = wx.Button(self, -1, "Supprimer")
        self.button_Imprimer = wx.Button(self, -1, "Imprimer le bon de commande")
        self.button_PDF = wx.Button(self, -1, u"Générer le bon de commande")
        self.button_Email = wx.Button(self, -1, u"Envoyer le bon de commande")
        self.button_Commandee = wx.Button(self, -1, u"Commandée")
        self.button_Livree = wx.Button(self, -1, u"Livrée")
        self.button_Verifiee = wx.Button(self, -1, u"Vérifiée")
        self.label_nom_fournisseur = wx.StaticText(self, -1, "Fournisseur :")
        self.label_montant_commande = wx.StaticText(self, -1, "Montant :")
        self.label_nom_fournisseur_valeur = wx.StaticText(self, -1, "")
        self.label_montant_commande_valeur = wx.StaticText(self, -1, "")
        self.label_date_commande = wx.StaticText(self, -1, "Date de commande :")
        self.label_date_livraison = wx.StaticText(self, -1, u"Date de réception :")
        self.label_date_commande_valeur = wx.StaticText(self, -1, "")
        self.label_date_livraison_valeur = wx.StaticText(self, -1, "")

        #self.label_suivi_commandes = wx.StaticText(self, -1, u"Suivi des commandes")

        #self.label_suivi_commandes_description = wx.StaticText(self, -1, u"C'est là qu'on gère les commandes")

        self.liste_commandes = ObjectListView(self, -1, style=wx.LC_REPORT|
                                              wx.SUNKEN_BORDER|wx.LC_SINGLE_SEL)

        self.liste_commandes.SetColumns([
            ColumnDefn("Fournisseur", "left", -1, "fournisseur.nom", minimumWidth=100),
            ColumnDefn("Date commande", "left", -1, "date_commande", stringConverter=u"%d/%m/%y", minimumWidth=130),
            ColumnDefn("Total TTC", "left", -1, "total_TTC", stringConverter=u"%.2f ¤", minimumWidth=100),
            ColumnDefn("statut", "left", -1, "statut_nom", isSpaceFilling=True, minimumWidth=100)
        ])

        def rowFormatterLC(listItem, commande):
            if commande.statut == 0:
                #C5CBFF
                listItem.SetBackgroundColour("#D8DDFF")
            elif commande.statut == 1:
                #FFA3A2
                listItem.SetBackgroundColour("#FFD3D3")
            elif commande.statut == 2:
                #E8E9A0
                listItem.SetBackgroundColour("#FBFCC8")
            elif commande.statut == 3:
                #B7D69E
                listItem.SetBackgroundColour("#E3FFCB")

        self.liste_commandes.rowFormatter = rowFormatterLC
        self.liste_commandes.AutoSizeColumns()
        self.liste_commandes.SortBy(1, False)

        self.liste_commandes.SetEmptyListMsg("Il n'y a aucune commande")

        self.liste_lignes_commande = ObjectListView(self, -1,
                                                    style=wx.LC_REPORT|wx.SUNKEN_BORDER|
                                                    wx.LC_SINGLE_SEL)

        self.__set_lignes_commandes_colonnes()

        self.liste_lignes_commande.SetEmptyListMsg("La commande ne contient aucun produit")

        self.__set_properties()
        self.__do_layout()
        self.__remplissage_liste()
        self.__affichage_boutons(-1, 0)

        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectionCommande, self.liste_commandes)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnVerifLigne, self.liste_lignes_commande)
        self.Bind(wx.EVT_BUTTON, self.OnNouvelleCommande, self.button_nouvelle_commande)
        self.Bind(wx.EVT_BUTTON, self.OnModifier, self.button_Modifier)
        self.Bind(wx.EVT_BUTTON, self.OnSupprimer, self.button_Supprimer)
        self.Bind(wx.EVT_BUTTON, self.OnImprimer, self.button_Imprimer)
        self.Bind(wx.EVT_BUTTON, self.OnPDF, self.button_PDF)
        self.Bind(wx.EVT_BUTTON, self.OnEmail, self.button_Email)
        self.Bind(wx.EVT_BUTTON, self.OnCommandee, self.button_Commandee)
        self.Bind(wx.EVT_BUTTON, self.OnLivree, self.button_Livree)
        self.Bind(wx.EVT_BUTTON, self.OnVerifiee, self.button_Verifiee)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: SuiviCommandes.__set_properties
        self.sizer_navigation_staticbox.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_nom_fournisseur.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        #self.label_suivi_commandes.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_montant_commande.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_date_commande.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_date_livraison.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_nom_fournisseur_valeur.SetMinSize((200, -1))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: SuiviCommandes.__do_layout
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer_titre = wx.StaticBoxSizer(self.sizer_navigation_staticbox, wx.VERTICAL)

        sizer_haut = wx.BoxSizer(wx.HORIZONTAL)
        sizer_boutons = wx.BoxSizer(wx.VERTICAL)
        #wx.StaticBoxSizer(self.sizer_liste_commandes_staticbox,wx.VERTICAL)

        sizer_bas = wx.StaticBoxSizer(self.sizer_commande_staticbox, wx.VERTICAL)

        sizer_infos_commande = wx.BoxSizer(wx.HORIZONTAL)

        sizer_col4 = wx.BoxSizer(wx.VERTICAL)
        sizer_col3 = wx.BoxSizer(wx.VERTICAL)
        sizer_col2 = wx.BoxSizer(wx.VERTICAL)
        sizer_col1 = wx.BoxSizer(wx.VERTICAL)

        #sizer.Add(self.label_suivi_commandes, 0, wx.EXPAND, 0)
        #sizer_titre.Add(self.label_suivi_commandes_description, 1, wx.TOP|wx.BOTTOM|wx.EXPAND, 5)
        sizer_titre.Add(self.button_nouvelle_commande, 0, wx.TOP|wx.BOTTOM, 5)
        sizer.Add(sizer_titre, 0, wx.EXPAND, 0)

        #sizer haut
        sizer_boutons.Add(self.button_Modifier, 0, wx.BOTTOM|wx.EXPAND, 5)
        sizer_boutons.Add(self.button_Supprimer, 0, wx.BOTTOM|wx.EXPAND, 5)
        sizer_boutons.Add(self.button_Imprimer, 0, wx.BOTTOM|wx.EXPAND, 5)
        sizer_boutons.Add(self.button_PDF, 0, wx.BOTTOM|wx.EXPAND, 5)
        sizer_boutons.Add(self.button_Email, 0, wx.BOTTOM|wx.EXPAND, 5)
        sizer_boutons.Add(self.button_Commandee, 0, wx.BOTTOM|wx.EXPAND, 5)
        sizer_boutons.Add(self.button_Livree, 0, wx.BOTTOM|wx.EXPAND, 5)
        sizer_boutons.Add(self.button_Verifiee, 0, wx.EXPAND, 0)
        sizer_boutons.Add(sizer_boutons.GetMinSize(), 0, wx.EXPAND, 0)

        sizer_haut.Add(sizer_boutons, 0, wx.RIGHT|wx.EXPAND, 10)

        sizer_haut.Add(self.liste_commandes, 1, wx.TOP|wx.EXPAND, 0)

        sizer.Add(sizer_haut, 1, wx.TOP|wx.EXPAND, 5)

        #sizer infos
        sizer_col1.Add(self.label_nom_fournisseur, 0, 0, 0)
        sizer_col1.Add((20, 10), 0, 0, 0)
        sizer_col1.Add(self.label_montant_commande, 0, 0, 0)
        sizer_infos_commande.Add(sizer_col1, 0, wx.RIGHT|wx.EXPAND, 10)
        sizer_col2.Add(self.label_nom_fournisseur_valeur, 0, 0, 0)
        sizer_col2.Add((20, 10), 0, 0, 0)
        sizer_col2.Add(self.label_montant_commande_valeur, 0, 0, 0)
        sizer_infos_commande.Add(sizer_col2, 0, wx.RIGHT|wx.EXPAND, 20)
        sizer_col3.Add(self.label_date_commande, 0, 0, 0)
        sizer_col3.Add((20, 10), 0, 0, 0)
        sizer_col3.Add(self.label_date_livraison, 0, 0, 0)
        sizer_infos_commande.Add(sizer_col3, 0, wx.RIGHT|wx.EXPAND, 10)
        sizer_col4.Add(self.label_date_commande_valeur, 0, 0, 0)
        sizer_col4.Add((20, 10), 0, 0, 0)
        sizer_col4.Add(self.label_date_livraison_valeur, 0, 0, 0)
        sizer_infos_commande.Add(sizer_col4, 0, wx.EXPAND, 0)

        sizer_bas.Add(sizer_infos_commande, 0, wx.TOP|wx.EXPAND, 5)

        sizer.Add(sizer_bas, 0, wx.TOP|wx.EXPAND, 5)

        sizer.Add(self.liste_lignes_commande, 1, wx.TOP|wx.EXPAND, 5)

        self.SetSizer(sizer)
        sizer.Fit(self)
        # end wxGlade

    def __remplissage_liste(self):
        try:
            commandes = Commande.select()

            self.liste_commandes.SetObjects([c for c in commandes])
            self.liste_commandes.AutoSizeColumns()

        except BaseException as ex:
            print ex

    def __affichage_boutons(self, statut, n_lignes):
        if statut == 0:
            self.button_Modifier.Enable()
            self.button_Supprimer.Enable()
            if n_lignes>0:
                self.button_Imprimer.Enable()
                self.button_PDF.Enable()
                self.button_Email.Enable()
                self.button_Commandee.Show()
            else:
                self.button_Imprimer.Disable()
                self.button_PDF.Disable()
                self.button_Email.Disable()
                self.button_Commandee.Hide()

            self.button_Livree.Hide()
            self.button_Verifiee.Hide()
        elif statut == 1:
            self.button_Modifier.Enable()
            self.button_Supprimer.Disable()
            self.button_Imprimer.Enable()
            self.button_PDF.Enable()
            self.button_Email.Enable()
            self.button_Commandee.Hide()
            self.button_Livree.Show()
            self.button_Verifiee.Hide()
        elif statut == 2:
            self.button_Modifier.Disable()
            self.button_Supprimer.Disable()
            self.button_Imprimer.Enable()
            self.button_PDF.Enable()
            self.button_Email.Disable()
            self.button_Commandee.Hide()
            self.button_Livree.Hide()
            self.button_Verifiee.Show()
        elif statut == 3:
            self.button_Modifier.Disable()
            self.button_Supprimer.Disable()
            self.button_Imprimer.Enable()
            self.button_PDF.Enable()
            self.button_Email.Disable()
            self.button_Commandee.Hide()
            self.button_Livree.Hide()
            self.button_Verifiee.Hide()
        else:
            self.button_Modifier.Disable()
            self.button_Supprimer.Disable()
            self.button_Imprimer.Disable()
            self.button_PDF.Disable()
            self.button_Email.Disable()
            self.button_Commandee.Hide()
            self.button_Livree.Hide()
            self.button_Verifiee.Hide()

        self.Layout()

    def __set_lignes_commandes_colonnes(self):
        if self.commande:
            if self.commande.statut >= 2:

                def rowFormatter(listItem, lc):
                    if lc.is_verifiee:
                        if lc.quantite_livree != lc.quantite_commandee:
                            listItem.SetBackgroundColour("#FFD3D3")
                        else:
                            listItem.SetBackgroundColour("#E3FFCB")

                self.liste_lignes_commande.rowFormatter = rowFormatter

                self.liste_lignes_commande.SetColumns([
                    ColumnDefn("Ref Fournisseur", "left", -1, "produit.ref_fournisseur", minimumWidth=120),
                    ColumnDefn("Nom", "left", -1, "produit.nom", minimumWidth=200),
                    ColumnDefn(u"Quantité commandée", "left", -1, "quantite_commandee_conditionnement", minimumWidth=200),
                    ColumnDefn(u"Quantité livrée", "left", -1, "quantite_livree_conditionnement", minimumWidth=200, isSpaceFilling=True),
                    ])
                self.liste_lignes_commande.AutoSizeColumns()
            else:
                self.liste_lignes_commande.SetColumns([
                    ColumnDefn("Ref Fournisseur", "left", -1, "produit.ref_fournisseur", minimumWidth=120),
                    ColumnDefn("Nom", "left", -1, "produit.nom", minimumWidth=200),
                    ColumnDefn(u"Quantité commandée", "left", -1, "quantite_commandee_conditionnement", minimumWidth=150),
                    ColumnDefn("Total TTC", "right", -1, "prix_total_commande_ttc", stringConverter=u"%s ¤", isSpaceFilling=True, minimumWidth=100)
                    ])
                self.liste_lignes_commande.AutoSizeColumns()

    def OnSelectionCommande(self, event):
        self.commande = self.liste_commandes.GetSelectedObject()

        if self.commande:
            self.liste_lignes_commande.SetObjects([lc for lc in self.commande.lignes_commande])
            self.__set_lignes_commandes_colonnes()
            self.label_nom_fournisseur_valeur.SetLabel(self.commande.fournisseur.nom)

            if self.commande.statut > 1:
                self.label_montant_commande_valeur.SetLabel(u"%.2f ¤" % self.commande.total_livraison_TTC())
            else:
                self.label_montant_commande_valeur.SetLabel(u"%.2f ¤" % self.commande.total_commande_TTC())

            self.label_date_commande_valeur.SetLabel(self.commande.date_commande_format())
            self.label_date_livraison_valeur.SetLabel(self.commande.date_livraison_format())
            self.__affichage_boutons(self.commande.statut, self.commande.lignes_commande.count())

            if self.commande.fournisseur.email == "":
                self.button_Email.Disable()

        else:
            self.liste_lignes_commande.SetObjects(None)
            self.label_nom_fournisseur_valeur.SetLabel("")
            self.label_montant_commande_valeur.SetLabel("")
            self.label_date_commande_valeur.SetLabel("")
            self.label_date_livraison_valeur.SetLabel("")
            self.__affichage_boutons(-1, 0)

    def OnVerifLigne(self, event):
        if self.commande.statut == 2:
            lc_selectionne = self.liste_lignes_commande.GetSelectedObject()

            if lc_selectionne.produit.vrac:
                label_u = lc_selectionne.produit.conditionnement_format(majuscule=False)
                quantite = lc_selectionne.quantite_livree / lc_selectionne.produit.poids_volume
            else:
                label_u = u"unité(s)"
                quantite = lc_selectionne.quantite_livree

            dlg = ChoixQuantite("", label_u, quantite=quantite, validator=GenericTextValidator(flag=VALIDATE_INT))

            id_resultat = dlg.ShowModal()

            if id_resultat == wx.ID_OK:
                lc_selectionne.is_verifiee = True
                lc_selectionne.quantite_livree = dlg.GetValue()
                self.liste_lignes_commande.RefreshObject(lc_selectionne)

            elif id_resultat == wx.ID_DELETE:
                lc_selectionne.is_verifiee = True
                lc_selectionne.quantite_livree = 0
                self.liste_lignes_commande.RefreshObject(lc_selectionne)

            dlg.Destroy()

    def OnNouvelleCommande(self, event):
        nouvelle_commande = NouvelleCommande(self.GetTopLevelParent())
        nouvelle_commande.ShowModal()

    def OnModifier(self, event):
        if self.commande:
            if self.commande.statut < 2:
                ecranprincipal = self.GetTopLevelParent()
                ecranprincipal.SetPanelPrincipal(FicheCommande, session_close=False, commande=self.commande)

    def OnSupprimer(self, event):
        if self.commande:
            if self.commande.statut == 0:
                dlg = wx.MessageDialog(parent=None, message=u"Voulez vous vraiment supprimer la commande ?",
                                       caption=u"Suppression de la commande", style=wx.OK|wx.CANCEL|wx.ICON_QUESTION)

                if dlg.ShowModal() == wx.ID_OK:
                    self.liste_commandes.RemoveObject(self.commande)
                    self.liste_lignes_commande.SetObjects(None)

                    self.commande.delete_instance(recursive=True)

                    self.commande = None

                    self.OnSelectionCommande(None)

                    DATABASE.commit()

    def OnPDF(self, event):
        if self.commande:

            if not self.commande.date_commande:
                nom_fichier = self.commande.fournisseur.nom + " - Bon de commande du " + datetime.today().strftime("%d-%m-%Y") + ".pdf"
            else:
                nom_fichier = self.commande.fournisseur.nom + " - Bon de commande du " + self.commande.date_commande_format() + ".pdf"

            dlg = wx.FileDialog(
                self, message="Sauvegarde du bon de commande ...",
                defaultDir="",
                defaultFile=nom_fichier, wildcard="PDF (*.pdf)|*.pdf", style=wx.SAVE
                )

            if dlg.ShowModal() == wx.ID_OK:
                chemin = dlg.GetPath()
                self.commande.genere_PDF(chemin)

            dlg.Destroy()

    def OnEmail(self, event):
        if self.commande:
            if self.commande.statut < 2:
                envoi_email = EnvoiEmailCommande(self, self.commande)
                envoi_email.ShowModal()
                envoi_email.Destroy()

                if envoi_email.ShowModal() == wx.ID_OK:
                    self.commande.statut(1)
                    self.commande.save()
                    self.liste_commandes.RefreshObject(self.commande)
                    self.OnSelectionCommande(None)

                    DATABASE.commit()

    def OnImprimer(self, event):
        if self.commande:
            self.commande.genere_PDF(os.getcwd() + "/dernier_bon_imprime.pdf")

            '''if sys.platform.startswith('linux'):
			    subprocess.call(["xdg-open", os.getcwd() + "/dernier_bon_imprime.pdf"])
            else:
                os.startfile(file)'''

            desktop.open(os.getcwd() + "/dernier_bon_imprime.pdf")

            '''preview_pdf = PreviewPDF(os.getcwd() + "/dernier_bon_imprime.pdf")
            preview_pdf.ShowModal()
            preview_pdf.Destroy()'''

    def OnCommandee(self, event):
        if self.commande:
            dlg = wx.MessageDialog(parent=None, message=u"La commande a bien été commandée ?",
                                   caption=u"Commande de la commande", style=wx.YES_NO|wx.ICON_QUESTION)

            if dlg.ShowModal() == wx.ID_YES:
                self.commande.statut = 1
                self.commande.save()
                self.liste_commandes.RefreshObject(self.commande)
                self.OnSelectionCommande(None)
                DATABASE.commit()

            dlg.Destroy()

    def OnLivree(self, event):
        #TODO : ajouter la possibilité de choisir la date de livraison
        #Ajouter également une vérification sur les prix
        if self.commande:
            dlg = wx.MessageDialog(parent=None, message=u"La commande a bien été livrée ?",
                                   caption=u"Livraison de la commande", style=wx.YES_NO|wx.ICON_QUESTION)

            if dlg.ShowModal() == wx.ID_YES:
                self.commande.statut = 2
                self.commande.save()
                self.liste_commandes.RefreshObject(self.commande)
                self.OnSelectionCommande(None)
                DATABASE.commit()

            dlg.Destroy()

    def OnVerifiee(self, event):
        if self.commande:
            commande_verifiee = True

            for lc in self.liste_lignes_commande.GetObjects():
                if not lc.is_verifiee:
                    commande_verifiee = False

            if commande_verifiee:
                dlg = wx.MessageDialog(parent=None, message=u"La livraison a bien été vérifiée ?",
                                      caption=u"Vérification de la livraison", style=wx.YES_NO|wx.ICON_QUESTION)

                if dlg.ShowModal() == wx.ID_YES:
                    for lc in self.liste_lignes_commande.GetObjects():
                        lc.save()
                        
                    self.commande.statut = 3
                    self.commande.save()

                    self.liste_commandes.RefreshObject(self.commande)
                    self.OnSelectionCommande(None)

                    with DATABASE.transaction():
                        DATABASE.commit()

                dlg.Destroy()
            else:
                wx.MessageBox(u"La livraison n'a pas encoré été entièrement vérifiée", "Erreur", style=wx.ICON_ERROR)
Пример #4
0
class GestionFournisseurs(wx.Panel):
    def __init__(self, *args, **kwds):
        # begin wxGlade: GestionFournisseurs.__init__
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)
        self.sizer_navigation_staticbox = wx.StaticBox(
            self, -1, "Gestion des fournisseurs")
        self.button_ajout_fournisseur = wx.Button(
            self, -1, "Ajouter un nouveau fournisseur")
        self.button_tableau_fournisseur = wx.Button(
            self, -1, u"Générer la liste des fournisseurs")
        self.liste_fournisseurs = ObjectListView(
            self, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)

        self.liste_fournisseurs.SetColumns([
            ColumnDefn("Nom",
                       "left",
                       -1,
                       "nom",
                       imageGetter=self.IconeCouleurDef),
            ColumnDefn("Code postal",
                       "center",
                       -1,
                       "code_postal",
                       fixedWidth=90),
            ColumnDefn("Ville", "left", -1, "ville"),
            ColumnDefn(u"Tel fixe",
                       "left",
                       -1,
                       "telephone_fixe",
                       minimumWidth=100),
            ColumnDefn(u"Tel portable",
                       "left",
                       -1,
                       "telephone_portable",
                       minimumWidth=100),
            ColumnDefn(u"Nb référents",
                       "right",
                       100,
                       "referents.count",
                       isSpaceFilling=True,
                       minimumWidth=100)
        ])

        self.__set_properties()
        self.__do_layout()
        self.__remplissage_liste()

        self.Bind(wx.EVT_BUTTON, self.OnAjoutFournisseur,
                  self.button_ajout_fournisseur)
        self.Bind(wx.EVT_BUTTON, self.OnGenereTableauFournisseur,
                  self.button_tableau_fournisseur)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnModifFournisseur,
                  self.liste_fournisseurs)
        # end wxGlade

    def __set_properties(self):
        self.sizer_navigation_staticbox.SetFont(
            wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))

    def __do_layout(self):
        sizer_entete = wx.StaticBoxSizer(self.sizer_navigation_staticbox,
                                         wx.HORIZONTAL)
        sizer_entete.Add(self.button_tableau_fournisseur, 0,
                         wx.BOTTOM | wx.TOP | wx.ALIGN_LEFT, 5)
        sizer_entete.Add((1, 1), 1)
        sizer_entete.Add(self.button_ajout_fournisseur, 0,
                         wx.BOTTOM | wx.TOP | wx.ALIGN_RIGHT, 5)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(sizer_entete, 0, wx.BOTTOM | wx.EXPAND, 10)
        sizer.Add(self.liste_fournisseurs, 1, wx.EXPAND, 0)
        self.SetSizer(sizer)
        sizer.Fit(self)

    def __remplissage_liste(self):
        try:
            self.liste_fournisseurs.SetObjects(
                [f for f in Fournisseur.select()])
        except BaseException as ex:
            print ex

    def IconeCouleurDef(self, fournisseur):
        return self.liste_fournisseurs.AddImages(
            self.IconeCouleur16(fournisseur.couleur),
            self.IconeCouleur32(fournisseur.couleur))

    def IconeCouleur16(self, couleurHex):
        couleur_data = wx.Colour()
        couleur_data.SetFromString(couleurHex)
        return wx.EmptyBitmapRGBA(16, 16, couleur_data.Red(),
                                  couleur_data.Green(), couleur_data.Blue(),
                                  couleur_data.Alpha())

    def IconeCouleur32(self, couleurHex):
        couleur_data = wx.Colour()
        couleur_data.SetFromString(couleurHex)
        return wx.EmptyBitmapRGBA(32, 32, couleur_data.Red(),
                                  couleur_data.Green(), couleur_data.Blue(),
                                  couleur_data.Alpha())

    def OnAjoutFournisseur(self, event):
        dialog_fournisseur = wx.Dialog(self, title=u"Nouveau fournisseur")
        fiche_fournisseur = FicheFournisseur(dialog_fournisseur)
        dialog_fournisseur.Fit()
        dialog_fournisseur.ShowModal()
        dialog_fournisseur.Destroy()

        if dialog_fournisseur.GetReturnCode() == wx.ID_OK:
            self.liste_fournisseurs.AddObject(fiche_fournisseur.fournisseur)
            self.liste_fournisseurs.AutoSizeColumns()

    def OnModifFournisseur(self, event):
        fournisseur = self.liste_fournisseurs.GetSelectedObject()

        dialog_fournisseur = wx.Dialog(self,
                                       title=u"Fournisseur : " +
                                       fournisseur.nom)
        FicheFournisseur(dialog_fournisseur, fournisseur)
        dialog_fournisseur.Fit()
        dialog_fournisseur.ShowModal()
        dialog_fournisseur.Destroy()

        if dialog_fournisseur.GetReturnCode() == wx.ID_OK:
            self.liste_fournisseurs.RefreshObject(
                self.liste_fournisseurs.GetSelectedObject())
            self.liste_fournisseurs.AutoSizeColumns()

    def OnGenereTableauFournisseur(self, event):
        lst = []
        tableau = []
        tableau_style = []
        hauteurs_lignes = []

        tableau_style.append(('FONTSIZE', (0, 0), (-1, -1), 16))
        tableau_style.append(('FONTNAME', (0, 0), (-1, -1), 'Helvetica-Bold'))
        tableau_style.append(('VALIGN', (0, 0), (-1, -1), 'MIDDLE'))
        tableau_style.append(('TOPPADDING', (0, 0), (-1, -1), 0))
        tableau_style.append(('BOTTOMPADDING', (0, 0), (-1, -1), 0))
        tableau_style.append(('LEADING', (0, 0), (-1, -1), 20))

        for fournisseur in self.liste_fournisseurs.GetObjects():
            tableau.append([fournisseur.nom])
            i = len(tableau) - 1
            tableau_style.append(
                ('BACKGROUND', (0, i), (1, i), fournisseur.couleur))
            tableau_style.append(('BOX', (0, i), (1, i), 1, colors.black))
            tableau_style.append(
                ('INNERGRID', (0, i), (1, i), 1, colors.black))
            hauteurs_lignes.append(1 * cm)

            #Ajout du blanc
            tableau.append([""])
            i = len(tableau) - 1
            tableau_style.append(('BACKGROUND', (0, i), (1, i), colors.white))
            hauteurs_lignes.append(0.5 * cm)

        tableau_fournisseurs = Table(tableau, rowHeights=hauteurs_lignes)
        tableau_fournisseurs.setStyle(TableStyle(tableau_style))

        titre_style = ParagraphStyle('Titre',
                                     alignment=TA_CENTER,
                                     leading=40,
                                     fontName='Helvetica-Bold',
                                     fontSize=20)

        lst.append(Paragraph(u"Liste des fournisseurs", titre_style))
        lst.append(tableau_fournisseurs)

        rep = os.path.dirname(os.getcwd() + "/Fournisseurs/")

        if not os.path.exists(rep):
            os.makedirs(rep)

        chemin_fichier = os.path.join(rep, "Liste des fournisseurs.pdf")

        doc = SimpleDocTemplate(chemin_fichier,
                                title="Liste des fournisseurs",
                                pagesize=A4,
                                topMargin=2 * cm,
                                bottomMargin=2 * cm,
                                leftMargin=1.5 * cm,
                                rightMargin=1.5 * cm)

        doc.build(lst)
        '''pdfviewer = PreviewPDF(os.path.join(dir, "Liste des fournisseurs.pdf"))
        pdfviewer.ShowModal()
        pdfviewer.Destroy()   '''

        desktop.open(chemin_fichier)
Пример #5
0
class GestionProduits(wx.Panel):
    def __init__(self, *args, **kwds):
        # begin wxGlade: GestionProduits.__init__
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)
        self.sizer_navigation_staticbox = wx.StaticBox(self, -1, "Gestion des produits")
        self.label_Fournisseur = wx.StaticText(self, -1, "Fournisseur :")
        self.combo_box_Fournisseur = wx.ComboBox(self, -1,
                                                 choices=[], style=wx.CB_DROPDOWN|wx.CB_READONLY)
        self.label_RechercheNom = wx.StaticText(self, -1, "Recherche sur le nom :")
        self.text_ctrl_RechercheNom = wx.TextCtrl(self, -1, "")
        self.button_AjoutProduit = wx.Button(self, -1, "Ajouter un nouveau produit")
        self.button_ImpressionEtiquettes = wx.Button(self, -1,
                                                     u"Imprimer les étiquettes des produits cochés")
        self.liste_produits = ObjectListView(self, -1,
                                             style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_SINGLE_SEL)



        self.liste_produits.SetColumns([
            ColumnDefn("Ref GASE", "left", -1, "ref_GASE",
                       checkStateGetter="a_etiquetter", fixedWidth=90),
            ColumnDefn("Nom", "left", -1, "nom"),
            ColumnDefn("Fournisseur", "left", -1, "fournisseur.nom", minimumWidth=100),
            ColumnDefn("Prix de vente", "left", -1, "prix_vente_format", minimumWidth=120),
            ColumnDefn("Stock", "left", 100,
                       "stock_format",
                       stringConverter="%s",
                       isSpaceFilling=True, minimumWidth=100)
        ])

        def RFListeProduits(listItem, produit):
            if produit.retrait:
                listItem.SetTextColour("#AAAAAA")
            else:
                listItem.SetTextColour("#000000")

        self.liste_produits.rowFormatter = RFListeProduits

        self.__set_properties()
        self.__do_layout()
        self.__remplissage_liste()
        self.liste_produits.SetSortColumn(0, True)

        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnEditionProduit, self.liste_produits)
        self.Bind(wx.EVT_COMBOBOX, self.OnFilter, self.combo_box_Fournisseur)
        self.Bind(wx.EVT_TEXT, self.OnFilter, self.text_ctrl_RechercheNom)
        self.Bind(wx.EVT_BUTTON, self.OnAjoutProduit, self.button_AjoutProduit)
        self.Bind(wx.EVT_BUTTON, self.OnImpressionEtiquettes, self.button_ImpressionEtiquettes)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: GestionProduits.__set_properties
        self.sizer_navigation_staticbox.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_Fournisseur.SetMinSize((200, -1))
        self.label_Fournisseur.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.combo_box_Fournisseur.SetMinSize((200, -1))
        self.label_RechercheNom.SetMinSize((200, -1))
        self.label_RechercheNom.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.text_ctrl_RechercheNom.SetMinSize((200, -1))
        # end wxGlade

    def __do_layout(self):
        grid_sizer = wx.FlexGridSizer(2, 2, 4, 0)
        grid_sizer.Add(self.label_Fournisseur, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer.Add(self.combo_box_Fournisseur, 0, 0, 0)
        grid_sizer.Add(self.label_RechercheNom, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        grid_sizer.Add(self.text_ctrl_RechercheNom, 0, 0, 0)

        sizer_boutons = wx.BoxSizer(wx.VERTICAL)
        sizer_boutons.Add(self.button_AjoutProduit, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT|wx.EXPAND, 5)
        sizer_boutons.Add(self.button_ImpressionEtiquettes, 0, wx.TOP|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 5)

        sizer_header = wx.StaticBoxSizer(self.sizer_navigation_staticbox, wx.HORIZONTAL)
        sizer_header.Add(grid_sizer, 0, wx.TOP, 5)
        sizer_header.Add((20, 20), 1, wx.TOP|wx.EXPAND, 5)
        sizer_header.Add(sizer_boutons, 0, wx.TOP|wx.ALIGN_CENTER_VERTICAL, 5)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(sizer_header, 0, wx.EXPAND, 0)
        sizer.Add(self.liste_produits, 1, wx.TOP|wx.EXPAND, 10)
        self.SetSizer(sizer)
        sizer.Fit(self)
        # end wxGlade

    def __remplissage_liste(self):
        try:
            self.liste_produits.SetObjects([p for p in Produit.select()])
            self.combo_box_Fournisseur.Append("Tous", 0)

            fournisseurs = [f for f in Fournisseur.select().order_by(Fournisseur.nom.asc())]

            for fournisseur in fournisseurs:
                self.combo_box_Fournisseur.Append(fournisseur.nom, fournisseur.get_id())

            self.combo_box_Fournisseur.Select(0)

        except BaseException as ex:
            print ex

    def OnAjoutProduit(self, event):
        dialog_produit = wx.Dialog(self, title=u"Nouveau produit")
        fiche_produit = FicheProduit(dialog_produit)
        dialog_produit.Fit()
        dialog_produit.ShowModal()
        dialog_produit.Destroy()

        if dialog_produit.GetReturnCode() == wx.ID_OK:
            self.liste_produits.AddObject(fiche_produit.produit)
            self.liste_produits.AutoSizeColumns()

    def OnEditionProduit(self, event):
        produit = self.liste_produits.GetSelectedObject()

        dialog_produit = wx.Dialog(self, title=u"Produit : " + produit.nom)
        FicheProduit(dialog_produit, produit)
        dialog_produit.Fit()
        dialog_produit.ShowModal()
        dialog_produit.Destroy()

        if dialog_produit.GetReturnCode() == wx.ID_OK:
            self.liste_produits.RefreshObject(self.liste_produits.GetSelectedObject())
            self.liste_produits.AutoSizeColumns()

    def OnImpressionEtiquettes(self, event):
        lst = []
        ligne_etiquettes = []
        tableau_etiquettes = []
        tableau_style = []
        hauteurs_lignes = []

        tableau_style.append(('VALIGN', (0, 0), (-1, -1), 'MIDDLE'))
        tableau_style.append(('TOPPADDING', (0, 0), (-1, -1), 0))
        tableau_style.append(('BOTTOMPADDING', (0, 0), (-1, -1), 0))
        tableau_style.append(('LEFTPADDING', (0, 0), (-1, -1), 2))
        tableau_style.append(('RIGHTPADDING', (0, 0), (-1, -1), 2))
        tableau_style.append(('BOX', (0, 0), (-1, -1), 2, colors.black))
        tableau_style.append(('INNERGRID', (0, 0), (-1, -1), 2, colors.black))

        n_produit = 0

        ref_style = ParagraphStyle('RefProduit', alignment=TA_CENTER, leading=16, fontName='Helvetica-Bold', fontSize=14)
        nom_style = ParagraphStyle('NomProduit', alignment=TA_CENTER, leading=16, fontName='Helvetica-Bold', fontSize=12)
        prix_style = ParagraphStyle('PrixProduit', alignment=TA_CENTER, leading=16, fontName='Helvetica-Bold', fontSize=14)

        liste_produits_etiquettes = []

        for produit in self.liste_produits.GetObjects():
            if produit.a_etiquetter:
                n_produit += 1

                if n_produit%2 == 0:
                    x = 3
                else:
                    x = 0

                y = (n_produit-1)/2

                ligne_etiquettes.append(Paragraph(produit.ref_GASE, ref_style))
                ligne_etiquettes.append(Paragraph(produit.nom, nom_style))

                ligne_etiquettes.append(Paragraph(produit.prix_vente_format, prix_style))

                tableau_style.append(('BACKGROUND',
                                      (x, y), (x+2, y),
                                      produit.fournisseur.couleur))

                if n_produit%2 == 0:
                    tableau_etiquettes.append(ligne_etiquettes)
                    hauteurs_lignes.append(2*cm)
                    ligne_etiquettes = []

                produit.a_etiquetter = False
                liste_produits_etiquettes.append(produit)

        #Si aucun produit n'est selectionnee on ne continue pas
        if n_produit > 0:
            if n_produit%2 != 0:
                ligne_etiquettes.append("")
                ligne_etiquettes.append("")
                ligne_etiquettes.append("")
                tableau_etiquettes.append(ligne_etiquettes)
                hauteurs_lignes.append(2*cm)

            table_etiquettes = Table(tableau_etiquettes,
                                     colWidths=[2*cm, 5.5*cm, 2*cm, 2*cm, 5.5*cm, 2*cm],
                                     rowHeights=hauteurs_lignes)
            table_etiquettes.setStyle(TableStyle(tableau_style))

            lst.append(table_etiquettes)

            #Création des répertoires si ils n'existent pas
            rep = os.path.dirname(os.getcwd() + "/Etiquettes/")

            if not os.path.exists(rep):
                os.makedirs(rep)

            date_jour = datetime.now()

            chemin_fichier = os.path.join(rep, "Etiquettes - " + date_jour.strftime("%d-%m-%Y %H-%M-%S") + ".pdf")

            doc = SimpleDocTemplate(chemin_fichier, title="Etiquettes - " + date_jour.strftime("%d-%m-%Y %H-%M-%S"), pagesize=A4, topMargin=2*cm, bottomMargin=2*cm, leftMargin=1.5*cm, rightMargin=1.5*cm)

            doc.build(lst)

            #session.commit()
            self.liste_produits.RefreshObjects(self.liste_produits.GetObjects())

            '''preview_pdf = PreviewPDF(chemin_fichier)
            preview_pdf.ShowModal()
            preview_pdf.Destroy()'''

            desktop.open(chemin_fichier)

            try:
                for p in liste_produits_etiquettes:
                    p.save()

                DATABASE.commit()
            except:
                DATABASE.rollback()

    def OnFilter(self, event):
        filtre_texte = Filter.TextSearch(self.liste_produits, text=self.text_ctrl_RechercheNom.GetValue())

        pk_fournisseur = self.combo_box_Fournisseur.GetClientData(self.combo_box_Fournisseur.GetSelection())

        if pk_fournisseur != 0:
            filtre_fournisseur = Filter.Predicate(lambda x: x.fournisseur.get_id() == pk_fournisseur)
            self.liste_produits.SetFilter(Filter.Chain(filtre_texte, filtre_fournisseur))
        else:
            self.liste_produits.SetFilter(filtre_texte)

        self.liste_produits.RepopulateList()
        event.Skip()
Пример #6
0
class GestionExercices(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          pos=wx.DefaultPosition,
                          style=wx.TAB_TRAVERSAL)

        description = u"Les exercices correspondent aux exercices comptables de l'association.\nIls permettent d'avoir un aperçu, sur une période définie, des mouvements de trésorerie."

        self.sizer_details_exercice_staticbox = wx.StaticBox(
            self, -1, u"Détails de l'exercice sélectionné")
        self.sizer_navigation_staticbox = wx.StaticBox(
            self, -1, "Gestion des exercices")
        self.label_description = wx.StaticText(self, -1, description)
        self.static_line_1 = wx.StaticLine(self, -1)
        self.bouton_ajout_exercice = wx.Button(self, -1,
                                               "Ajouter un nouvel exercice")
        self.liste_exercices = ObjectListView(
            self, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)
        self.details_exercice = DetailsExercice(self, -1)

        self.liste_exercices.SetColumns([
            ColumnDefn("Nom", "left", -1, "nom", minimumWidth=100),
            ColumnDefn(u"Date début",
                       "left",
                       -1,
                       "date_debut",
                       stringConverter="%d-%m-%Y",
                       minimumWidth=100),
            ColumnDefn(u"Date fin",
                       "left",
                       100,
                       "date_fin",
                       stringConverter="%d-%m-%Y",
                       isSpaceFilling=True)
        ])

        def rowFormatterLE(listItem, exercice):
            if exercice.date_debut < date.today(
            ) and exercice.date_fin > date.today():
                listItem.SetTextColour(wx.BLACK)
            else:
                listItem.SetTextColour("#616161")

        self.liste_exercices.rowFormatter = rowFormatterLE
        self.liste_exercices.SortBy(1, False)
        self.liste_exercices.SetEmptyListMsg(
            u"Il n'y a aucun exercice pour l'instant")

        self.__set_properties()
        self.__remplissage_liste()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.OnAjoutExercice,
                  self.bouton_ajout_exercice)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnEditionExercice,
                  self.liste_exercices)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnExerciceSelectionne,
                  self.liste_exercices)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: GestionExercices.__set_properties
        self.sizer_navigation_staticbox.SetFont(
            wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: GestionExercices.__do_layout
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer_bas = wx.BoxSizer(wx.HORIZONTAL)
        sizer_details_exercice = wx.StaticBoxSizer(
            self.sizer_details_exercice_staticbox, wx.HORIZONTAL)
        sizer_header = wx.StaticBoxSizer(self.sizer_navigation_staticbox,
                                         wx.VERTICAL)
        sizer_header.Add(self.label_description, 0, wx.ALL, 5)
        sizer_header.Add(self.static_line_1, 0, wx.EXPAND, 0)
        sizer_header.Add(self.bouton_ajout_exercice, 0, wx.ALL, 5)
        sizer.Add(sizer_header, 0, wx.EXPAND, 0)
        sizer_bas.Add(self.liste_exercices, 1, wx.EXPAND, 0)
        sizer_details_exercice.Add(self.details_exercice, 1, wx.EXPAND, 0)
        sizer_bas.Add(sizer_details_exercice, 1, wx.LEFT, 10)
        sizer.Add(sizer_bas, 1, wx.EXPAND, 0)
        self.SetSizer(sizer)
        sizer.Fit(self)
        # end wxGlade

    def __remplissage_liste(self):
        try:
            self.liste_exercices.SetObjects([e for e in Exercice.select()])
        except BaseException as ex:
            print ex

    def OnExerciceSelectionne(self, event):
        self.details_exercice.SetExercice(
            self.liste_exercices.GetSelectedObject())

    def OnAjoutExercice(self, event):
        dialog_exercice = wx.Dialog(self, title=u"Nouvel exercice")
        fiche_exercice = FicheExercice(dialog_exercice)
        dialog_exercice.Fit()
        dialog_exercice.ShowModal()
        dialog_exercice.Destroy()

        if dialog_exercice.GetReturnCode() == wx.ID_OK:
            self.liste_exercices.AddObject(fiche_exercice.GetExercice())
            self.liste_exercices.AutoSizeColumns()

    def OnEditionExercice(self, event):
        exercice = self.liste_exercices.GetSelectedObject()

        dialog_exercice = wx.Dialog(self, title=u"Exercice : " + exercice.nom)
        FicheExercice(dialog_exercice, exercice)
        dialog_exercice.Fit()
        dialog_exercice.ShowModal()
        dialog_exercice.Destroy()

        if dialog_exercice.GetReturnCode() == wx.ID_OK:
            self.liste_exercices.RefreshObject(
                self.liste_exercices.GetSelectedObject())
            self.liste_exercices.AutoSizeColumns()
Пример #7
0
class DialogAjoutProduit(wx.Dialog):
    def __init__(self, inventaire):
        wx.Dialog.__init__(self, None, -1, title=u"Ajouter un produit", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE)

        self.inventaire = inventaire

        self.search_nom = wx.SearchCtrl(self, -1, "")
        self.liste_produits = ObjectListView(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_SINGLE_SEL)

        self.liste_produits.SetColumns([
            ColumnDefn("Ref GASE", "left", -1, "ref_GASE", fixedWidth=90),
            ColumnDefn("Nom", "left", -1, "nom"),
            ColumnDefn("Fournisseur", "left", -1, "fournisseur.nom", minimumWidth=100)
        ])

        self.search_nom.Bind(wx.EVT_TEXT, self.OnFilter)
        self.liste_produits.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnClickProduit)

        self.__set_properties()
        self.__remplissage_liste()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        self.SetMinSize((400,300))
        self.search_nom.SetDescriptiveText("Recherche sur le nom")
    
    def __remplissage_liste(self):
        try:
            requete = Produit.select().where(~(Produit.pk << self.inventaire.produits))
            self.liste_produits.SetObjects([p for p in requete])
            
            #On dimentionne le dialog selon la largeur des colonnes
            largeur = 0
            for num_colonne in range(3) :
                largeur += self.liste_produits.GetColumnWidth(num_colonne)
             
            self.liste_produits.SetMinSize((largeur+20,300))
            
        except BaseException as ex:
            print ex

    def __do_layout(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.search_nom, 0, wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND, 10)
        sizer.Add(self.liste_produits, 1, wx.ALL|wx.EXPAND, 10)
        self.SetSizer(sizer)
        sizer.Fit(self)
        self.Layout()

    def GetProduit(self):
        return self.liste_produits.GetSelectedObject()

    def OnClickProduit(self, event):
        self.EndModal(wx.ID_OK)
        
    def OnFilter(self, event):
        filtre_texte = Filter.TextSearch(self.liste_produits, text=self.search_nom.GetValue())
        self.liste_produits.SetFilter(filtre_texte)
        self.liste_produits.RepopulateList()
        event.Skip()
Пример #8
0
class GestionAdhesions(wx.Panel):
    def __init__(self, parent, adherent):
        wx.Panel.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          pos=wx.DefaultPosition,
                          style=wx.TAB_TRAVERSAL)

        self.adherent = adherent

        self.label_description = wx.StaticText(
            self, -1, u"Liste des cotisations réglées par l'adhérent.")
        self.staticline = wx.StaticLine(self, wx.ID_ANY, wx.DefaultPosition,
                                        wx.DefaultSize, wx.LI_HORIZONTAL)
        self.bouton_ajout_adhesion = wx.BitmapButton(
            self, -1, wx.Bitmap("../icons/16x16/ajouter.ico"))
        self.bouton_supprime_adhesion = wx.BitmapButton(
            self, -1, wx.Bitmap("../icons/16x16/enlever.ico"))
        self.liste_adhesions = ObjectListView(
            self, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)

        self.liste_adhesions.SetColumns([
            ColumnDefn(u"Adhésion",
                       "left",
                       -1,
                       "adhesion_type.nom",
                       minimumWidth=100),
            ColumnDefn("Date",
                       "left",
                       -1,
                       "date",
                       stringConverter="%d-%m-%Y",
                       minimumWidth=100),
            ColumnDefn("Montant",
                       "left",
                       100,
                       "montant",
                       stringConverter=u"%.2f ¤",
                       isSpaceFilling=True)
        ])

        self.__set_properties()
        self.__do_layout()
        self.__remplissage_liste()

        self.Bind(wx.EVT_BUTTON, self.OnAjoutAdhesion,
                  self.bouton_ajout_adhesion)
        self.Bind(wx.EVT_BUTTON, self.OnSupprimeAdhesion,
                  self.bouton_supprime_adhesion)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnEditionAdhesion,
                  self.liste_adhesions)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectionAdhesion,
                  self.liste_adhesions)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnSelectionAdhesion,
                  self.liste_adhesions)
        # end wxGlade

    def __set_properties(self):
        self.bouton_ajout_adhesion.SetToolTip(
            wx.ToolTip(u"Ajouter une nouvelle adhésion"))
        self.bouton_supprime_adhesion.SetToolTip(
            wx.ToolTip(u"Supprimer l'adhésion sélectionnée"))
        self.bouton_supprime_adhesion.Disable()

        self.liste_adhesions.SetEmptyListMsg(u"Aucune adhésion")
        self.liste_adhesions.SortBy(1, False)

    def __do_layout(self):
        sizer_boutons = wx.BoxSizer(wx.HORIZONTAL)
        sizer_boutons.Add(self.bouton_ajout_adhesion, 0,
                          wx.BOTTOM | wx.TOP | wx.ALIGN_RIGHT, 5)
        sizer_boutons.Add((10, 10))
        sizer_boutons.Add(self.bouton_supprime_adhesion, 0,
                          wx.BOTTOM | wx.TOP | wx.ALIGN_RIGHT, 5)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.label_description, 0, wx.TOP | wx.EXPAND, 10)
        sizer.Add(self.staticline, 0, wx.BOTTOM | wx.TOP | wx.EXPAND, 10)
        sizer.Add(sizer_boutons, 0, wx.BOTTOM | wx.ALIGN_RIGHT | wx.EXPAND, 5)
        sizer.Add(self.liste_adhesions, 1, wx.EXPAND)
        self.SetSizer(sizer)
        sizer.Fit(self)

    def __remplissage_liste(self):
        try:
            self.liste_adhesions.SetObjects(
                [a for a in self.adherent.adhesions])
        except BaseException as ex:
            print ex

    def OnSelectionAdhesion(self, event):
        if self.liste_adhesions.GetSelectedObject():
            self.bouton_supprime_adhesion.Enable()
        else:
            self.bouton_supprime_adhesion.Disable()

    def OnAjoutAdhesion(self, event):
        if self.adherent:
            dialog_adhesion = wx.Dialog(self, title=u"Nouvelle adhésion")
            fiche_adhesion = FicheAdhesion(dialog_adhesion,
                                           adherent=self.adherent)

            dialog_adhesion.Fit()
            dialog_adhesion.ShowModal()
            dialog_adhesion.Destroy()

            if dialog_adhesion.GetReturnCode() == wx.ID_OK:
                self.liste_adhesions.AddObject(fiche_adhesion.adhesion)
                self.liste_adhesions.AutoSizeColumns()

    def OnSupprimeAdhesion(self, event):
        adhesion = self.liste_adhesions.GetSelectedObject()

        msgbox = wx.MessageBox(
            u"Supprimer l'adhésion du %s ?" %
            adhesion.date.strftime("%d/%m/%y"), "Suppression",
            wx.YES_NO | wx.ICON_QUESTION)

        if msgbox == wx.YES:
            with DATABASE.transaction():
                adhesion.delete_instance()

            self.liste_adhesions.RemoveObject(adhesion)

    def OnEditionAdhesion(self, event):
        adhesion = self.liste_adhesions.GetSelectedObject()

        dialog_adhesion = wx.Dialog(self, title=u"Edition de l'adhésion")
        FicheAdhesion(dialog_adhesion, adhesion=adhesion)
        dialog_adhesion.Fit()
        dialog_adhesion.ShowModal()
        dialog_adhesion.Destroy()

        if dialog_adhesion.GetReturnCode() == wx.ID_OK:
            self.liste_adhesions.RefreshObject(
                self.liste_adhesions.GetSelectedObject())
            self.liste_adhesions.AutoSizeColumns()
Пример #9
0
class GestionInventaires(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          pos=wx.DefaultPosition,
                          style=wx.TAB_TRAVERSAL)

        self.sizer_navigation_staticbox = wx.StaticBox(
            self, -1, "Gestion des inventaires")
        self.bouton_ajout_inventaire = wx.BitmapButton(
            self, -1, wx.Bitmap("../icons/16x16/ajouter.ico"))
        self.bouton_suppression_inventaire = wx.BitmapButton(
            self, -1, wx.Bitmap("../icons/16x16/enlever.ico"))
        self.liste_inventaires = ObjectListView(
            self, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)

        def is_valide(value):
            if value:
                return u"Validé"
            else:
                return "En cours de validation"

        self.liste_inventaires.SetColumns([
            ColumnDefn("Date",
                       "left",
                       200,
                       "date",
                       stringConverter="Inventaire du %d-%m-%Y",
                       minimumWidth=200),
            ColumnDefn("Statut",
                       "left",
                       -1,
                       "is_valide",
                       stringConverter=is_valide),
            ColumnDefn(u"Valeur du stock théorique",
                       "left",
                       100,
                       "valeur_stock_theorique",
                       stringConverter=u"%.2f ¤"),
            ColumnDefn(u"Valeur du stock réel",
                       "left",
                       100,
                       "valeur_stock_reel",
                       stringConverter=u"%.2f ¤",
                       isSpaceFilling=True)
        ])

        def rowFormatterLI(listItem, commande):
            if commande.is_valide == 0:
                #C5CBFF
                listItem.SetBackgroundColour("#FBFCC8")
            elif commande.is_valide == 1:
                #FFA3A2
                listItem.SetBackgroundColour("#E3FFCB")

        self.liste_inventaires.rowFormatter = rowFormatterLI

        self.__set_properties()
        self.__do_layout()
        self.__remplissage_liste()

        self.Bind(wx.EVT_BUTTON, self.OnAjoutInventaire,
                  self.bouton_ajout_inventaire)
        self.Bind(wx.EVT_BUTTON, self.OnSuppressionInventaire,
                  self.bouton_suppression_inventaire)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnEditionInventaire,
                  self.liste_inventaires)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectionInventaire,
                  self.liste_inventaires)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnSelectionInventaire,
                  self.liste_inventaires)
        # end wxGlade

    def __set_properties(self):
        self.sizer_navigation_staticbox.SetFont(
            wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.bouton_ajout_inventaire.SetToolTip(
            wx.ToolTip(u"Faire un nouvel inventaire"))
        self.bouton_suppression_inventaire.SetToolTip(
            wx.ToolTip(u"Supprimer l'inventaire sélectionné"))
        self.bouton_suppression_inventaire.Disable()

    def __do_layout(self):
        sizer_entete = wx.StaticBoxSizer(self.sizer_navigation_staticbox,
                                         wx.HORIZONTAL)
        sizer_entete.Add(self.bouton_ajout_inventaire, 0,
                         wx.BOTTOM | wx.TOP | wx.ALIGN_RIGHT, 5)
        sizer_entete.Add((10, 10))
        sizer_entete.Add(self.bouton_suppression_inventaire, 0,
                         wx.BOTTOM | wx.TOP | wx.ALIGN_RIGHT, 5)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(sizer_entete, 0, wx.BOTTOM | wx.ALIGN_RIGHT | wx.EXPAND, 10)
        sizer.Add(self.liste_inventaires, 1, wx.EXPAND)

        self.SetSizer(sizer)
        sizer.Fit(self)

    def __remplissage_liste(self):
        try:
            self.liste_inventaires.SetObjects([i for i in Inventaire.select()])
        except BaseException as ex:
            print ex

    def OnSelectionInventaire(self, event):
        if self.liste_inventaires.GetSelectedObject():
            self.bouton_suppression_inventaire.Enable()
        else:
            self.bouton_suppression_inventaire.Disable()

    def OnAjoutInventaire(self, event):
        self.Hide()

        fiche_inventaire = FicheInventaire(self.GetParent())

        sizer = self.GetParent().GetSizer()
        sizer.Add(fiche_inventaire, 1, wx.EXPAND)
        self.GetParent().SetSizer(sizer)
        self.GetParent().Layout()

    def OnSuppressionInventaire(self, event):
        inventaire = self.liste_inventaires.GetSelectedObject()

        msgbox = wx.MessageBox(
            u"Supprimer l'inventaire du %s ?" %
            inventaire.date.strftime("%d/%m/%y"), "Suppression",
            wx.YES_NO | wx.ICON_QUESTION)

        if msgbox == wx.YES:
            with DATABASE.transaction():
                inventaire.delete_instance(recursive=True)

            self.liste_inventaires.RemoveObject(inventaire)

    def OnEditionInventaire(self, event):
        inventaire = self.liste_inventaires.GetSelectedObject()

        self.Hide()

        fiche_inventaire = FicheInventaire(self.GetParent(),
                                           inventaire=inventaire)

        sizer = self.GetParent().GetSizer()
        sizer.Add(fiche_inventaire, 1, wx.EXPAND)
        self.GetParent().SetSizer(sizer)
        self.GetParent().Layout()
        '''if dialog_inventaire.GetReturnCode() == wx.ID_OK:
Пример #10
0
class GestionAdherents(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, style=wx.TAB_TRAVERSAL)

        self.sizer_communication_staticbox = wx.StaticBox(self, -1, "Communication")
        self.sizer_autre_staticbox = wx.StaticBox(self, -1, "Autre")
        self.sizer_critere_utilisateur_staticbox = wx.StaticBox(self, -1, "Utilisateurs")
        self.checkbox_gase = wx.CheckBox(self, -1, "GASE")
        self.checkbox_paniers = wx.CheckBox(self, -1, "Paniers")
        self.radio_box_etat_adhesion = wx.RadioBox(self, -1, u"Etat de l'adhésion", choices=["Tous", u"Adhésion à jour", u"Adhésion à renouveler"], majorDimension=1, style=wx.RA_SPECIFY_COLS)
        self.checkbox_sans_email = wx.CheckBox(self, -1, "Sans email")
        self.checkbox_sans_telephone = wx.CheckBox(self, -1, u"Sans téléphone")
        self.checkbox_ancien_adherents = wx.CheckBox(self, -1, u"Anciens adhérents")
        self.bouton_ajout_adhesion = wx.BitmapButton(self, -1, wx.Bitmap("../icons/32x32/nouvelle_adhesion.ico", wx.BITMAP_TYPE_ANY))
        self.bouton_ajout_credit = wx.BitmapButton(self, -1, wx.Bitmap("../icons/32x32/ajout_credit.png", wx.BITMAP_TYPE_ANY))
        self.static_line_1 = wx.StaticLine(self, -1, style=wx.LI_VERTICAL)
        self.label_recherche = wx.StaticText(self, -1, "Recherche sur le nom")
        self.text_ctrl_recherche = wx.TextCtrl(self, -1, "")
        self.static_line_2 = wx.StaticLine(self, -1, style=wx.LI_VERTICAL)
        self.bouton_ajout_adherent = wx.BitmapButton(self, -1, wx.Bitmap("../icons/32x32/nouvel_adherent.ico", wx.BITMAP_TYPE_ANY))
        self.liste_adherents = ObjectListView(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_SINGLE_SEL)

        def AJour(value):
            if value:
                return "A jour"
            else:
                return u"Pas à jour"

        self.liste_adherents.SetColumns([
            ColumnDefn("Nom", "left", -1, "nom",  minimumWidth=100, useInitialLetterForGroupKey=True),
            ColumnDefn(u"Prénom", "left", -1, "prenom", minimumWidth=100),
            ColumnDefn("Ville", "left", -1, "ville", minimumWidth=100),
            ColumnDefn(u"Téléphone", "left", -1, "telephone", minimumWidth=100),
            ColumnDefn(u"Cotisation", "left", -1, "cotisation_type.nom", minimumWidth=100),
            ColumnDefn(u"Adhésion", "left", 100, "is_adhesion_a_jour", stringConverter=AJour, isSpaceFilling=True, minimumWidth=100)
        ])

        def RFListeAdherents(listItem, adherent):
            if adherent.is_adhesion_a_jour:
                listItem.SetBackgroundColour("#E3FFCB")
            else:
                listItem.SetBackgroundColour("#FFD3D3")

        self.liste_adherents.rowFormatter = RFListeAdherents

        self.__set_properties()
        self.__do_layout()
        self.__remplissage_liste()
        self.liste_adherents.SetSortColumn(0, True)

        self.filtres = {}

        self.Bind(wx.EVT_BUTTON, self.OnAjoutAdhesion, self.bouton_ajout_adhesion)
        self.Bind(wx.EVT_BUTTON, self.OnAjoutCredit, self.bouton_ajout_credit)
        self.Bind(wx.EVT_BUTTON, self.OnAjoutAdherent, self.bouton_ajout_adherent)
        self.Bind(wx.EVT_RADIOBOX, self.OnFilterAdhesion, self.radio_box_etat_adhesion)
        self.Bind(wx.EVT_CHECKBOX, self.OnFilterSansEmail, self.checkbox_sans_email)
        self.Bind(wx.EVT_CHECKBOX, self.OnFilterSansTelephone, self.checkbox_sans_telephone)
        self.Bind(wx.EVT_CHECKBOX, self.OnFilterUtilisateursPaniers, self.checkbox_paniers)
        self.Bind(wx.EVT_CHECKBOX, self.OnFilterAnciensAdherents, self.checkbox_ancien_adherents)
        self.Bind(wx.EVT_TEXT, self.OnFilterNom, self.text_ctrl_recherche)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnEditionAdherent, self.liste_adherents)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectionAdherent, self.liste_adherents)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnDeselectionAdherent, self.liste_adherents)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnClickDroitListe, self.liste_adherents)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: GestionAdherents.__set_properties
        self.checkbox_gase.SetToolTipString("Afficher les utilisateurs du GASE")
        self.checkbox_paniers.SetToolTipString("Afficher les utilisateurs des paniers")
        self.radio_box_etat_adhesion.SetSelection(0)
        self.checkbox_sans_email.SetToolTipString(u"Afficher les adhérents n'ayant pas d'email")
        self.checkbox_sans_telephone.SetToolTipString(u"Afficher les adhérents n'ayant pas de téléphone")
        self.checkbox_ancien_adherents.SetToolTipString(u"Afficher les anciens adhérents")
        self.bouton_ajout_adhesion.SetToolTipString(u"Ajouter un adhésion")
        self.bouton_ajout_adhesion.Enable(False)
        self.bouton_ajout_adhesion.SetSize(self.bouton_ajout_adhesion.GetBestSize())
        self.bouton_ajout_credit.SetToolTipString(u"Ajouter un crédit")
        self.bouton_ajout_credit.Enable(False)
        self.bouton_ajout_credit.SetSize(self.bouton_ajout_credit.GetBestSize())
        self.text_ctrl_recherche.SetMinSize((200, -1))
        self.bouton_ajout_adherent.SetToolTipString(u"Ajouter un nouvel adhérent")
        self.bouton_ajout_adherent.SetSize(self.bouton_ajout_adherent.GetBestSize())
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: GestionAdherents.__do_layout
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer_toolbar = wx.BoxSizer(wx.HORIZONTAL)
        sizer_criteres = wx.BoxSizer(wx.HORIZONTAL)
        sizer_autre = wx.StaticBoxSizer(self.sizer_autre_staticbox, wx.VERTICAL)
        sizer_communication = wx.StaticBoxSizer(self.sizer_communication_staticbox, wx.VERTICAL)

        sizer_critere_utilisateur = wx.StaticBoxSizer(self.sizer_critere_utilisateur_staticbox, wx.VERTICAL)
        sizer_critere_utilisateur.Add(self.checkbox_gase, 0, 0, 0)
        sizer_critere_utilisateur.Add(self.checkbox_paniers, 0, 0, 0)
        sizer_criteres.Add(sizer_critere_utilisateur, 1, wx.EXPAND, 0)

        sizer_criteres.Add(self.radio_box_etat_adhesion, 1, 0, 20)

        sizer_communication.Add(self.checkbox_sans_email, 0, 0, 0)
        sizer_communication.Add(self.checkbox_sans_telephone, 0, 0, 0)
        sizer_criteres.Add(sizer_communication, 1, wx.EXPAND, 0)

        sizer_autre.Add(self.checkbox_ancien_adherents, 0, 0, 0)
        sizer_criteres.Add(sizer_autre, 1, wx.EXPAND, 0)

        sizer.Add(sizer_criteres, 0, wx.EXPAND, 0)

        sizer_toolbar.Add(self.bouton_ajout_adhesion, 0, wx.RIGHT, 5)
        sizer_toolbar.Add(self.bouton_ajout_credit, 0, 0, 0)
        sizer_toolbar.Add(self.static_line_1, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, 5)
        sizer_toolbar.Add(self.label_recherche, 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 10)
        sizer_toolbar.Add(self.text_ctrl_recherche, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        sizer_toolbar.Add(self.static_line_2, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, 10)
        sizer_toolbar.Add(self.bouton_ajout_adherent, 0, 0, 0)
        sizer.Add(sizer_toolbar, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 20)

        sizer.Add(self.liste_adherents, 1, wx.EXPAND, 0)
        self.SetSizer(sizer)
        sizer.Fit(self)
        # end wxGlade

    def __remplissage_liste(self):
        try:
            self.liste_adherents.SetObjects([a for a in Adherent.select()])
            self.liste_adherents.AutoSizeColumns()
        except BaseException as ex:
            print ex

    def OnAjoutAdhesion(self, event):
        dialog_adhesion = wx.Dialog(self, title=u"Nouvelle adhésion")
        FicheAdhesion(dialog_adhesion, adherent=self.liste_adherents.GetSelectedObject())
        dialog_adhesion.Fit()
        dialog_adhesion.ShowModal()
        dialog_adhesion.Destroy()

        if dialog_adhesion.GetReturnCode() == wx.ID_OK:
            self.liste_adherents.RefreshObject(self.liste_adherents.GetSelectedObject())
            self.liste_adherents.AutoSizeColumns()

    def OnAjoutCredit(self, event):
        print "Event handler `OnAjoutCredit' not implemented"
        event.Skip()

    def OnAjoutAdherent(self, event):
        try:
            CotisationType.select().get()

            dialog_adherent = wx.Dialog(self, title=u"Nouvel adhérent")
            fiche_adherent = FicheAdherent(dialog_adherent)
            dialog_adherent.Fit()
            dialog_adherent.ShowModal()
            dialog_adherent.Destroy()
            
            if dialog_adherent.GetReturnCode() == wx.ID_OK:
                adherent = fiche_adherent.GetAdherent()

                dialog_adhesion = wx.Dialog(self, title=u"Nouvelle adhésion")
                FicheAdhesion(dialog_adhesion, adherent=adherent)
                dialog_adhesion.Fit()
                dialog_adhesion.ShowModal()
                dialog_adhesion.Destroy()

                self.liste_adherents.AddObject(adherent)
                self.liste_adherents.AutoSizeColumns()

        except DoesNotExist:
            wx.MessageBox(u"Vous devez d'abord créer des cotisations", "Notification")

    def OnEditionAdherent(self, event):
        adherent = self.liste_adherents.GetSelectedObject()

        dialog_adherent = wx.Dialog(self, title=adherent.nom_prenom)
        FicheAdherent(dialog_adherent, adherent)
        dialog_adherent.Fit()
        dialog_adherent.ShowModal()
        dialog_adherent.Destroy()

        self.liste_adherents.RefreshObject(self.liste_adherents.GetSelectedObject())
        self.liste_adherents.AutoSizeColumns()

    def OnSelectionAdherent(self, event):
        self.bouton_ajout_adhesion.Enable()
        self.bouton_ajout_credit.Enable()

    def OnDeselectionAdherent(self, event):
        self.bouton_ajout_adhesion.Disable()
        self.bouton_ajout_credit.Disable()

    def OnClickDroitListe(self, event):
        menu = wx.Menu()

        menu.Append(1, u"Ajouter une adhésion")
        wx.EVT_MENU(menu, 1, self.OnAjoutAdhesion)

        menu.Append(2, u"Ajouter un crédit")
        wx.EVT_MENU(menu, 2, self.OnAjoutCredit)

        self.liste_adherents.PopupMenu(menu, event.GetPoint())
        menu.Destroy()

    #filtres de recherche

    def OnFilter(self, event):
        self.liste_adherents.SetFilter(Filter.Chain(*self.filtres.values()))
        self.liste_adherents.RepopulateList()
        event.Skip()

    def OnFilterNom(self, event):
        self.filtres["nom"] = Filter.TextSearch(self.liste_adherents,
                                            [self.liste_adherents.columns[0], self.liste_adherents.columns[1]],
                                            text=self.text_ctrl_recherche.GetValue())
        self.OnFilter(event)
        event.Skip()

    def OnFilterAdhesion(self, event):
        if self.radio_box_etat_adhesion.GetSelection() == 1:
            self.filtres["adhesion"] = Filter.Predicate(lambda x: x.is_adhesion_a_jour)
        elif self.radio_box_etat_adhesion.GetSelection() == 2:
            self.filtres["adhesion"] = Filter.Predicate(lambda x: not x.is_adhesion_a_jour)
        else:
            self.filtres.pop("adhesion")

        self.OnFilter(event)
        event.Skip()

    def OnFilterSansEmail(self, event):
        if self.checkbox_sans_email.IsChecked():
            self.filtres["sans_email"] = Filter.Predicate(lambda x: x.email=="")
        else:
            self.filtres.pop("sans_email")

        self.OnFilter(event)
        event.Skip()

    def OnFilterSansTelephone(self, event):
        if self.checkbox_sans_telephone.IsChecked():
            self.filtres["sans_telephone"] = Filter.Predicate(lambda x: x.telephone=="")
        else:
            self.filtres.pop("sans_telephone")

        self.OnFilter(event)
        event.Skip()

    def OnFilterUtilisateursPaniers(self, event):
        if self.checkbox_paniers.IsChecked():
            self.filtres["utilisateurs_paniers"] = Filter.Predicate(lambda x: x.utilisateur_paniers)
        else:
            self.filtres.pop("utilisateurs_paniers")

        self.OnFilter(event)
        event.Skip()

    def OnFilterAnciensAdherents(self, event):
        if self.checkbox_ancien_adherents.IsChecked():
            self.filtres["anciens_adherents"] = Filter.Predicate(lambda x: x.ancien_adherent)
        else:
            self.filtres.pop("anciens_adherents")

        self.OnFilter(event)
        event.Skip()
Пример #11
0
class GestionTVAs(wx.Panel):
    def __init__(self, *args, **kwds):
        # begin wxGlade: GestionTvas.__init__
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)
        self.sizer_navigation_staticbox = wx.StaticBox(self, -1,
                                                       u"Gestion des taux de TVA")
        self.button_ajout_tva = wx.Button(self, -1,
                                                u"Ajouter un nouveau taux de TVA")
        self.liste_tvas = ObjectListView(self, -1,
                                               style=wx.LC_REPORT |
                                                     wx.SUNKEN_BORDER |
                                                     wx.LC_SINGLE_SEL)

        self.liste_tvas.SetColumns([
            ColumnDefn("Taux", "center", -1, "taux", stringConverter="%s %%", fixedWidth=70),
            ColumnDefn("Nombre de produits avec ce taux", "left", 100,
                       "nombre_produits",
                       stringConverter="%s produit(s)",
                       isSpaceFilling=True)
        ])

        self.__set_properties()
        self.__do_layout()
        self.__remplissage_liste()

        self.Bind(wx.EVT_BUTTON, self.OnAjoutTVA,
                  self.button_ajout_tva)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnModifTVA,
                  self.liste_tvas)
        # end wxGlade

    def __set_properties(self):
        self.sizer_navigation_staticbox.SetFont(wx.Font(14,
                                                        wx.DEFAULT,
                                                        wx.NORMAL,
                                                        wx.BOLD,
                                                        0, ""))

    def __do_layout(self):
        # begin wxGlade: GestionTvas.__do_layout
        sizer_entete = wx.StaticBoxSizer(self.sizer_navigation_staticbox,
                                         wx.HORIZONTAL)
        sizer_entete.Add((1, 1), 1)
        sizer_entete.Add(self.button_ajout_tva, 0,
                         wx.BOTTOM |
                         wx.TOP |
                         wx.ALIGN_RIGHT, 5)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(sizer_entete, 0,
                  wx.BOTTOM |
                  wx.ALIGN_RIGHT |
                  wx.EXPAND, 10)
        sizer.Add(self.liste_tvas, 1, wx.EXPAND)
        self.SetSizer(sizer)
        sizer.Fit(self)
        # end wxGlade

    def __remplissage_liste(self):
        try:
            self.liste_tvas.SetObjects([t for t in Tva.select()])
        except BaseException as ex:
            print ex

    def OnAjoutTVA(self, event):
        dialog_tva = wx.Dialog(self, title=u"Nouveau taux de TVA")
        fiche_tva = FicheTVA(dialog_tva)
        dialog_tva.Fit()
        dialog_tva.ShowModal()
        dialog_tva.Destroy()

        if dialog_tva.GetReturnCode() == wx.ID_OK:
            self.liste_tvas.AddObject(fiche_tva.tva)
            self.liste_tvas.AutoSizeColumns()

    def OnModifTVA(self, event):
        tva = self.liste_tvas.GetSelectedObject()

        dialog_tva = wx.Dialog(self,
                                     title=u"TVA à " + str(tva.taux) + u" %")
        FicheTVA(dialog_tva, tva)
        dialog_tva.Fit()
        dialog_tva.ShowModal()
        dialog_tva.Destroy()

        if dialog_tva.GetReturnCode() == wx.ID_OK:
            self.liste_tvas.RefreshObject(
                                  self.liste_tvas.GetSelectedObject())
            self.liste_tvas.AutoSizeColumns()
Пример #12
0
class GestionCategories(wx.Panel):
    def __init__(self, *args, **kwds):
        # begin wxGlade: GestionCategories.__init__
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)
        self.sizer_navigation_staticbox = wx.StaticBox(
            self, -1, u"Gestion des catégories")
        self.button_ajout_categorie = wx.Button(
            self, -1, u"Ajouter une nouvelle catégorie")
        self.liste_categories = ObjectListView(
            self, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)

        self.liste_categories.SetColumns([
            ColumnDefn("ID", "right", valueGetter="get_id", fixedWidth=70),
            ColumnDefn("Nom", "left", -1, "nom"),
            ColumnDefn("Nombre de produits",
                       "left",
                       100,
                       "nombre_produits",
                       stringConverter="%s produit(s)",
                       isSpaceFilling=True)
        ])

        self.__set_properties()
        self.__do_layout()
        self.__remplissage_liste()

        self.Bind(wx.EVT_BUTTON, self.OnAjoutCategorie,
                  self.button_ajout_categorie)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnModifCategorie,
                  self.liste_categories)
        # end wxGlade

    def __set_properties(self):
        self.sizer_navigation_staticbox.SetFont(
            wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))

    def __do_layout(self):
        # begin wxGlade: GestionCategories.__do_layout
        sizer_entete = wx.StaticBoxSizer(self.sizer_navigation_staticbox,
                                         wx.HORIZONTAL)
        sizer_entete.Add((1, 1), 1)
        sizer_entete.Add(self.button_ajout_categorie, 0,
                         wx.BOTTOM | wx.TOP | wx.ALIGN_RIGHT, 5)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(sizer_entete, 0, wx.BOTTOM | wx.ALIGN_RIGHT | wx.EXPAND, 10)
        sizer.Add(self.liste_categories, 1, wx.EXPAND)
        self.SetSizer(sizer)
        sizer.Fit(self)
        # end wxGlade

    def __remplissage_liste(self):
        try:
            self.liste_categories.SetObjects([c for c in Categorie.select()])
        except BaseException as ex:
            print ex

    def OnAjoutCategorie(self, event):
        dialog_categorie = wx.Dialog(self, title=u"Nouvelle catégorie")
        fiche_categorie = FicheCategorie(dialog_categorie)
        dialog_categorie.Fit()
        dialog_categorie.ShowModal()
        dialog_categorie.Destroy()

        if dialog_categorie.GetReturnCode() == wx.ID_OK:
            self.liste_categories.AddObject(fiche_categorie.categorie)
            self.liste_categories.AutoSizeColumns()

    def OnModifCategorie(self, event):
        categorie = self.liste_categories.GetSelectedObject()

        dialog_categorie = wx.Dialog(self,
                                     title=u"Catégorie : " + categorie.nom)
        FicheCategorie(dialog_categorie, categorie)
        dialog_categorie.Fit()
        dialog_categorie.ShowModal()
        dialog_categorie.Destroy()

        if dialog_categorie.GetReturnCode() == wx.ID_OK:
            self.liste_categories.RefreshObject(
                self.liste_categories.GetSelectedObject())
            self.liste_categories.AutoSizeColumns()
Пример #13
0
class DialogAjoutReferent(wx.Dialog):
    def __init__(self, fournisseur):
        wx.Dialog.__init__(self,
                           None,
                           -1,
                           title=u"Ajouter un référent",
                           pos=wx.DefaultPosition,
                           size=wx.DefaultSize,
                           style=wx.DEFAULT_DIALOG_STYLE)

        self.fournisseur = fournisseur
        """ Attention, ici le référent est un objet Adherent"""

        self.liste_referents = ObjectListView(
            self, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)

        self.liste_referents.SetColumns([
            ColumnDefn("Nom", "left", -1, "nom", minimumWidth=100),
            ColumnDefn(u"Prénom",
                       "left",
                       -1,
                       "prenom",
                       minimumWidth=100,
                       isSpaceFilling=True)
        ])

        self.liste_referents.Bind(wx.EVT_LIST_ITEM_ACTIVATED,
                                  self.OnClickReferent)

        self.__set_properties()
        self.__remplissage_liste()
        self.__do_layout()

    def __set_properties(self):
        self.SetMinSize((200, 300))
        self.liste_referents.SortBy(0)

    def __remplissage_liste(self):
        try:
            requete = Adherent.select().where(
                ~(Adherent.id << self.fournisseur.referents))
            self.liste_referents.SetObjects([a for a in requete])

            #On dimentionne le dialog selon la largeur des colonnes
            largeur = 0
            for num_colonne in range(2):
                largeur += self.liste_referents.GetColumnWidth(num_colonne)

            self.liste_referents.SetMinSize((largeur + 20, 300))

        except BaseException as ex:
            print ex

    def __do_layout(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.liste_referents, 1, wx.ALL | wx.EXPAND, 10)
        self.SetSizer(sizer)
        sizer.Fit(self)
        self.Layout()

    def GetReferent(self):
        return self.liste_referents.GetSelectedObject()

    def OnClickReferent(self, event):
        self.EndModal(wx.ID_OK)
Пример #14
0
class GestionReferents(wx.Panel):
    def __init__(self, parent, fournisseur):
        wx.Panel.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          pos=wx.DefaultPosition,
                          style=wx.TAB_TRAVERSAL)

        self.fournisseur = fournisseur
        """ Attention, ici le référent est un objet Adherent"""

        self.label_description = wx.StaticText(
            self, -1, u"Liste des référents du fournisseur.")
        self.staticline = wx.StaticLine(self, wx.ID_ANY, wx.DefaultPosition,
                                        wx.DefaultSize, wx.LI_HORIZONTAL)
        self.bouton_ajout_referent = wx.BitmapButton(
            self, -1, wx.Bitmap("../icons/16x16/ajouter.ico"))
        self.bouton_supprime_referent = wx.BitmapButton(
            self, -1, wx.Bitmap("../icons/16x16/enlever.ico"))
        self.liste_referents = ObjectListView(
            self, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)

        self.liste_referents.SetColumns([
            ColumnDefn("Nom", "left", -1, "nom", minimumWidth=100),
            ColumnDefn(u"Prénom",
                       "left",
                       -1,
                       "prenom",
                       minimumWidth=100,
                       isSpaceFilling=True)
        ])

        self.__set_properties()
        self.__do_layout()
        self.__remplissage_liste()

        self.Bind(wx.EVT_BUTTON, self.OnAjoutReferent,
                  self.bouton_ajout_referent)
        self.Bind(wx.EVT_BUTTON, self.OnSupprimeReferent,
                  self.bouton_supprime_referent)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectionReferent,
                  self.liste_referents)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnSelectionReferent,
                  self.liste_referents)
        # end wxGlade

    def __set_properties(self):
        self.bouton_ajout_referent.SetToolTip(
            wx.ToolTip(u"Ajouter un nouveau référent"))
        self.bouton_supprime_referent.SetToolTip(
            wx.ToolTip(u"Supprimer le référent sélectionné"))
        self.bouton_supprime_referent.Disable()

        self.liste_referents.SetEmptyListMsg(u"Aucun référent")
        self.liste_referents.SortBy(0)

    def __do_layout(self):
        sizer_boutons = wx.BoxSizer(wx.HORIZONTAL)
        sizer_boutons.Add(self.bouton_ajout_referent, 0,
                          wx.BOTTOM | wx.TOP | wx.ALIGN_RIGHT, 5)
        sizer_boutons.Add((10, 10))
        sizer_boutons.Add(self.bouton_supprime_referent, 0,
                          wx.BOTTOM | wx.TOP | wx.ALIGN_RIGHT, 5)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.label_description, 0, wx.TOP | wx.EXPAND, 10)
        sizer.Add(self.staticline, 0, wx.BOTTOM | wx.TOP | wx.EXPAND, 10)
        sizer.Add(sizer_boutons, 0, wx.BOTTOM | wx.ALIGN_RIGHT | wx.EXPAND, 5)
        sizer.Add(self.liste_referents, 1, wx.EXPAND)
        self.SetSizer(sizer)
        sizer.Fit(self)

    def __remplissage_liste(self):
        try:
            self.liste_referents.SetObjects(
                [a for a in self.fournisseur.referents])
        except BaseException as ex:
            print ex

    def OnSelectionReferent(self, event):
        if self.liste_referents.GetSelectedObject():
            self.bouton_supprime_referent.Enable()
        else:
            self.bouton_supprime_referent.Disable()

    def OnAjoutReferent(self, event):
        if self.fournisseur:
            dlg = DialogAjoutReferent(self.fournisseur)

            dlg.ShowModal()

            if dlg.GetReturnCode() == wx.ID_OK:
                Referent.create(fournisseur=self.fournisseur,
                                adherent=dlg.GetReferent())
                self.liste_referents.AddObject(dlg.GetReferent())
                self.liste_referents.AutoSizeColumns()

            dlg.Destroy()

    def OnSupprimeReferent(self, event):
        adherent = self.liste_referents.GetSelectedObject()

        msgbox = wx.MessageBox(
            u"Enlever %s de la liste des référent pour %s ?" %
            (adherent.prenom_nom, self.fournisseur.nom), "Suppression",
            wx.YES_NO | wx.ICON_QUESTION)

        if msgbox == wx.YES:
            referent = Referent.select().where(
                (Referent.fournisseur == self.fournisseur)
                & (Referent.adherent == adherent)).get()
            referent.delete_instance()

            self.liste_referents.RemoveObject(adherent)
Пример #15
0
class GestionCotisationTypes(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, style=wx.TAB_TRAVERSAL)

        self.bouton_ajout_cotisation_type = wx.BitmapButton(self, -1, wx.Bitmap("../icons/16x16/ajouter.ico"))
        self.bouton_supprime_cotisation_type = wx.BitmapButton(self, -1, wx.Bitmap("../icons/16x16/enlever.ico"))

        self.liste_cotisation_types = ObjectListView(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_SINGLE_SEL)

        self.liste_cotisation_types.SetColumns([
            ColumnDefn("Nom", "left", -1, "nom", minimumWidth=100),
            ColumnDefn(u"Prix", "left", 50, "prix", stringConverter=u"%s ¤", isSpaceFilling=True)
        ])

        self.liste_cotisation_types.SetEmptyListMsg(u"Il n'y a aucun type de cotisation pour l'instant")

        self.__set_properties()
        self.__remplissage_liste()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.OnAjoutTypeCotisation, self.bouton_ajout_cotisation_type)
        self.Bind(wx.EVT_BUTTON, self.OnSupprimeTypeCotisation, self.bouton_supprime_cotisation_type)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnEditionTypeCotisation, self.liste_cotisation_types)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectionTypeCotisation, self.liste_cotisation_types)
        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnDeselectionTypeCotisation, self.liste_cotisation_types)
        # end wxGlade

    def __set_properties(self):
        self.bouton_ajout_cotisation_type.SetToolTip(wx.ToolTip(u"Ajouter un nouveau type de cotisation"))
        self.bouton_supprime_cotisation_type.SetToolTip(wx.ToolTip(u"Supprimer le type de cotisation sélectionné"))
        self.bouton_supprime_cotisation_type.Disable()

    def __remplissage_liste(self):
        try:
            self.liste_cotisation_types.SetObjects([c for c in CotisationType.select()])
        except BaseException as ex:
            print ex

    def __do_layout(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer_haut = wx.BoxSizer(wx.HORIZONTAL)
        sizer_haut.Add(self.bouton_ajout_cotisation_type, 0, 0, 0)
        sizer_haut.Add(self.bouton_supprime_cotisation_type, 0, 0, 0)
        sizer.Add(sizer_haut, 0, wx.BOTTOM|wx.EXPAND, 10)
        sizer.Add((300, -1))
        sizer.Add(self.liste_cotisation_types, 1, wx.EXPAND, 0)
        self.SetSizer(sizer)
        sizer.Fit(self)
        # end wxGlade

    def OnSelectionTypeCotisation(self, event):
        cotisation_type = self.liste_cotisation_types.GetSelectedObject()

        if cotisation_type.adherents.count() == 0:
            self.bouton_supprime_cotisation_type.Enable()
        else:
            self.bouton_supprime_cotisation_type.Disable()

    def OnDeselectionTypeCotisation(self, event):
        self.bouton_supprime_cotisation_type.Disable()

    def OnAjoutTypeCotisation(self, event):
        dialog_cotisation_type = wx.Dialog(self, title=u"Nouveau type de cotisation")
        fiche_cotisation_type = FicheCotisationType(dialog_cotisation_type)
        dialog_cotisation_type.Fit()
        dialog_cotisation_type.ShowModal()
        dialog_cotisation_type.Destroy()

        if dialog_cotisation_type.GetReturnCode() == wx.ID_OK:
            self.liste_cotisation_types.AddObject(fiche_cotisation_type.GetTypeCotisation())
            self.liste_cotisation_types.AutoSizeColumns()

    def OnSupprimeTypeCotisation(self, event):
        cotisation_type = self.liste_cotisation_types.GetSelectedObject()

        if cotisation_type.adherents.count() == 0:
            msgbox = wx.MessageBox(u"Supprimer le type de cotisation '%s'?" % cotisation_type.nom, "Suppression", wx.YES_NO | wx.ICON_QUESTION)

            if msgbox == wx.YES:
                with DATABASE.transaction():
                    cotisation_type.delete_instance()

                self.liste_cotisation_types.RemoveObject(cotisation_type)

    def OnEditionTypeCotisation(self, event):
        cotisation_type = self.liste_cotisation_types.GetSelectedObject()

        dialog_cotisation_type = wx.Dialog(self, title=cotisation_type.nom)
        FicheCotisationType(dialog_cotisation_type, cotisation_type)
        dialog_cotisation_type.Fit()
        dialog_cotisation_type.ShowModal()
        dialog_cotisation_type.Destroy()

        if dialog_cotisation_type.GetReturnCode() == wx.ID_OK:
            self.liste_cotisation_types.RefreshObject(self.liste_cotisation_types.GetSelectedObject())
            self.liste_cotisation_types.AutoSizeColumns()
Пример #16
0
class FicheInventaire(wx.Panel):
    def __init__(self, parent, inventaire=None):
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
        
        if inventaire:
            self.inventaire = inventaire
        else:
            inventaire = Inventaire.create()
            inventaire.initialisation()
            
        self.inventaire = inventaire

        self.sizer_inventaire_staticbox = wx.StaticBox(self, -1, "Liste des produits")
        self.label_titre_inventaire = wx.StaticText(self, -1, "Inventaire du ")
        self.label_fournisseur = wx.StaticText(self, -1, "Fournisseur :")
        self.combo_box_fournisseur = wx.ComboBox(self, -1,
                                                 choices=[], style=wx.CB_DROPDOWN|wx.CB_READONLY)
        self.search_nom = wx.SearchCtrl(self, -1, "")
        self.label_commentaire = wx.StaticText(self, -1, "Commentaires :")
        self.text_commentaire = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE)
        #self.bouton_ajout_produit = buttons.GenBitmapTextButton(self, -1, wx.Bitmap("../icons/16x16/ajouter.ico"), u" Ajouter un produit non listé", style=wx.BORDER_NONE)
        self.bouton_ajout_produit = wx.Button(self, -1, u"Ajouter un produit non listé")
        self.liste_lignes_inventaire = ObjectListView(self, -1,
                                                      style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)

        def update_stock_reel(li, valeur):
            if valeur<0:
                valeur = 0

            if li.produit.vrac:
                li.stock_reel = valeur *  1000
            else:
                li.stock_reel = valeur
                
            li.save()

            if self.inventaire.pret_a_valider():
                self.bouton_valider.Enable()
            
                
        def editor_stock_reel(olv, rowIndex, subItemIndex):
            if olv.GetObjectAt(rowIndex).produit.vrac:
                return StockFloatEditor(olv, subItemIndex, validator=CellEditor.NumericValidator("0123456789.,"))
            else:
                return StockIntEditor(olv, subItemIndex, validator=CellEditor.NumericValidator("0123456789"))
            
        
        self.liste_lignes_inventaire.SetColumns([
            ColumnDefn("Ref GASE", "left", -1, "produit.ref_GASE", fixedWidth=90),
            ColumnDefn("Nom", "left", -1, "produit.nom",  minimumWidth=100),
            ColumnDefn("Fournisseur", "left", -1, "produit.fournisseur.nom", minimumWidth=100),
            ColumnDefn(u"Stock théorique", "left", -1,
                       "stock_theorique_format",
                       stringConverter="%s", minimumWidth=80),
            ColumnDefn(u"Stock réel", "left", -1,
                       "stock_reel_format", isEditable=True,
                       cellEditorCreator = editor_stock_reel,
                       valueSetter=update_stock_reel, minimumWidth=80),
            ColumnDefn(u"Différence", "u_", -1,
                       "stock_difference", minimumWidth=80)
        ])

        def RFLignesInventaire(listItem, ligne_inventaire):
            if ligne_inventaire.stock_reel:
                listItem.SetBackgroundColour("#E3FFCB")
            else:
                listItem.SetBackgroundColour("#FFD3D3")
                
        #self.liste_lignes_inventaire.rowFormatter = RFLignesInventaire

        self.bouton_enregistrer = wx.Button(self, wx.ID_SAVE, "Enregistrer")
        self.bouton_valider = wx.Button(self, wx.ID_OK, u"Valider l'inventaire")

        self.__set_properties()
        self.__set_valeurs()
        self.__remplissage_liste()
        self.__do_layout()

        self.combo_box_fournisseur.Bind(wx.EVT_COMBOBOX, self.OnFilter)
        self.search_nom.Bind(wx.EVT_TEXT, self.OnFilter)
        self.bouton_ajout_produit.Bind(wx.EVT_BUTTON, self.OnAjoutProduit)
        self.liste_lignes_inventaire.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnModifStock)
        self.bouton_enregistrer.Bind(wx.EVT_BUTTON, self.OnEnregistrer)
        self.bouton_valider.Bind(wx.EVT_BUTTON, self.OnValider)

        self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)

    def __set_properties(self):
        self.label_titre_inventaire.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.text_commentaire.SetMinSize((-1, 200))
        self.combo_box_fournisseur.SetMinSize((200, -1))
        self.search_nom.SetMinSize((200, -1))
        self.search_nom.SetDescriptiveText("Recherche sur le nom")
        self.sizer_inventaire_staticbox.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        
        if self.inventaire.is_valide:
            self.text_commentaire.Disable()
            self.bouton_ajout_produit.Hide()
            self.bouton_enregistrer.Hide()
            self.bouton_valider.Hide()

    def __set_valeurs(self):
        self.label_titre_inventaire.SetLabel("Inventaire du %s" % self.inventaire.date.strftime("%d/%m/%y"))
        self.text_commentaire.SetValue(self.inventaire.commentaire)
        if not self.inventaire.pret_a_valider():
            self.bouton_valider.Disable()
        
    def __remplissage_liste(self):
        try:
            self.liste_lignes_inventaire.SetObjects([li for li in self.inventaire.lignes_inventaire])
            
            self.combo_box_fournisseur.Append("Tous", 0)

            fournisseurs = [f for f in Fournisseur.select().order_by(Fournisseur.nom.asc())]

            for fournisseur in fournisseurs:
                self.combo_box_fournisseur.Append(fournisseur.nom, fournisseur.get_id())

            self.combo_box_fournisseur.Select(0)
        except BaseException as ex:
            print ex
            
    def __do_layout(self):
        sizer_recherche = wx.BoxSizer(wx.HORIZONTAL)
        sizer_recherche.Add(self.search_nom, 0, wx.ALIGN_CENTER_VERTICAL, 0)
        sizer_recherche.Add(self.label_fournisseur, 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 10)
        sizer_recherche.Add(self.combo_box_fournisseur, 0, wx.ALIGN_CENTER_VERTICAL, 0)

        sizer_inventaire = wx.StaticBoxSizer(self.sizer_inventaire_staticbox, wx.VERTICAL)
        sizer_inventaire.Add(self.liste_lignes_inventaire, 1, wx.ALL|wx.EXPAND, 0)
        sizer_inventaire.Add(self.bouton_ajout_produit, 0, wx.TOP, 10)

        sizer_bouton = wx.BoxSizer(wx.HORIZONTAL)
        sizer_bouton.Add((20, 20), 1, 0, 0)
        sizer_bouton.Add(self.bouton_enregistrer, 0, 0, 0)
        sizer_bouton.Add((20, 20), 1, 0, 0)
        sizer_bouton.Add(self.bouton_valider, 0, 0, 0)
        sizer_bouton.Add((20, 20), 1, 0, 0)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.label_titre_inventaire, 0, wx.ALL|wx.EXPAND, 10)
        sizer.Add(self.label_commentaire, 0, wx.ALL|wx.EXPAND, 10)
        sizer.Add(self.text_commentaire, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, 10)
        sizer.Add(sizer_recherche, 0, wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND, 10)
        sizer.Add(sizer_inventaire, 1, wx.ALL|wx.EXPAND, 10)
        sizer.Add(sizer_bouton, 0, wx.TOP|wx.BOTTOM|wx.EXPAND, 10)

        self.SetSizer(sizer)
        sizer.Fit(self)
        self.Layout()   

    def OnAjoutProduit(self, event):
        dlg = DialogAjoutProduit(self.inventaire)

        id_resultat = dlg.ShowModal()

        if id_resultat == wx.ID_OK:
            ligne_inventaire = LigneInventaire.create(inventaire=self.inventaire, produit=dlg.GetProduit())
            self.liste_lignes_inventaire.AddObject(ligne_inventaire)
            self.liste_lignes_inventaire.SelectObject(ligne_inventaire, ensureVisible=True)

        dlg.Destroy()

    def OnModifStock(self, event):
        if not self.inventaire.is_valide:
            self.liste_lignes_inventaire.StartCellEdit(self.liste_lignes_inventaire.GetFocusedRow(), 4)

    def OnEnregistrer(self, event):
        if self.Validate():
            msgbox = wx.MessageBox(u"Sauvegarder l'inventaire ?", u"Confirmation", wx.YES_NO | wx.ICON_QUESTION)

            if msgbox == wx.YES:
                self.inventaire.date = date.today()
                self.inventaire.commentaire = self.text_commentaire.GetValue()

                with DATABASE.transaction():
                    self.inventaire.save()

                event.Skip()
                
    def OnValider(self, event):
        if self.Validate() and self.inventaire.pret_a_valider():
            msgbox = wx.MessageBox(u"Valider l'inventaire ? Il ne sera plus modifiable.", u"Confirmation", wx.YES_NO | wx.ICON_QUESTION)

            if msgbox == wx.YES:
                self.inventaire.is_valide = True
                self.inventaire.date = date.today()

                with DATABASE.transaction():
                    self.inventaire.validation()
                    self.inventaire.save()

                self.__set_properties()

                event.Skip()

    def OnDestroy(self, event):
        if not self.inventaire.is_valide:
            dlg = wx.MessageDialog(parent=None, message=u"Voulez vous sauvegarder l'inventaire ?",
                                   caption=u"Sauvegarde de l'inventaire", style=wx.YES_NO|wx.ICON_QUESTION)
    
            if dlg.ShowModal() == wx.ID_YES:
                self.inventaire.date = date.today()
                self.inventaire.save()
                DATABASE.commit()
            else:
                DATABASE.rollback()
    
            dlg.Destroy()

        event.Skip()
        
    def OnFilter(self, event):
        filtre_texte = Filter.TextSearch(self.liste_lignes_inventaire, text=self.search_nom.GetValue())

        pk_fournisseur = self.combo_box_fournisseur.GetClientData(self.combo_box_fournisseur.GetSelection())

        if pk_fournisseur != 0:
            filtre_fournisseur = Filter.Predicate(lambda x: x.produit.fournisseur.get_id() == pk_fournisseur)
            self.liste_lignes_inventaire.SetFilter(Filter.Chain(filtre_texte, filtre_fournisseur))
        else:
            self.liste_lignes_inventaire.SetFilter(filtre_texte)

        self.liste_lignes_inventaire.RepopulateList()
        event.Skip()
Пример #17
0
class GestionAchats(wx.Panel):
    def __init__(self, parent, adherent=None):
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)

        if adherent:
            self.adherent = adherent
        else:
            self.adherent = Adherent.select().where(Adherent.id == 1).get()

        self.label_total_achats = wx.StaticText(
            self, -1, "Total des achats du mois en cours :")
        self.label_total_achats_v = wx.StaticText(self, -1, u"XX.XX €")
        self.label_solde = wx.StaticText(self, -1, u"Solde :")
        self.label_solde_v = wx.StaticText(self, -1, u"XX.XX €")
        self.static_line = wx.StaticLine(self, -1)
        self.bouton_ajout_achat = wx.Button(self, -1, "Nouvel achat")
        self.bouton_ajout_credit = wx.Button(self, -1, "Nouveau paiement")
        self.label_info = wx.StaticText(
            self, -1,
            u"Note : Le dernier achat et le dernier paiement sont modifiable le jour même."
        )

        self.notebook_achats = wx.Notebook(self, -1, style=0)

        #Page "Dernieres produits achetés"
        self.panel_page_achat_mois = wx.Panel(self.notebook_achats, -1)
        self.label_mois_recherche = wx.StaticText(self.panel_page_achat_mois,
                                                  -1, u"Achats du mois de ")
        self.combobox_choix_mois = wx.ComboBox(self.panel_page_achat_mois, -1)
        self.label_total_mois = wx.StaticText(
            self.panel_page_achat_mois, -1,
            u"Total des achats du mois : XX.XX €")
        self.liste_achats_mois = ObjectListView(
            self.panel_page_achat_mois,
            -1,
            style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)
        """def date_achat(ligne_achat):
            return ligne_achat.achat.date.strftime("%d-%m-%y")

        def ref_GASE_nom(ligne_achat):
            return "%s - %s" % (ligne_achat.produit.ref_GASE, ligne_achat.produit.nom)
        
        self.liste_achats_mois.SetColumns([
            ColumnDefn("Ref GASE - Nom", "left", -1, ref_GASE_nom, minimumWidth=250, groupKeyGetter=date_achat),
            ColumnDefn("Prix", "left", -1, "produit.prix_vente_format", minimumWidth=100),
            ColumnDefn(u"Quantité", "left", -1, "quantite_format", minimumWidth=70),
            ColumnDefn(u"Total", "right", -1, "prix_total", stringConverter=u"%.2f €", minimumWidth=70, isSpaceFilling=True)
        ])"""

        self.liste_achats_mois.SetColumns([
            ColumnDefn("Date",
                       "center",
                       -1,
                       "achat.date",
                       stringConverter="%d-%m-%y",
                       minimumWidth=70),
            ColumnDefn("Ref GASE",
                       "center",
                       -1,
                       "produit.ref_GASE",
                       minimumWidth=70),
            ColumnDefn("Nom", "left", -1, "produit.nom", minimumWidth=100),
            ColumnDefn("Prix",
                       "left",
                       -1,
                       "produit.prix_vente_format",
                       minimumWidth=100),
            ColumnDefn(u"Quantité",
                       "left",
                       -1,
                       "quantite_format",
                       minimumWidth=70),
            ColumnDefn(u"Total",
                       "right",
                       -1,
                       "prix_total",
                       stringConverter=u"%.2f €",
                       minimumWidth=70,
                       isSpaceFilling=True)
        ])

        self.liste_achats_mois.SetEmptyListMsg("Aucuns achat pour ce mois")
        self.liste_achats_mois.AutoSizeColumns()

        self.notebook_achats.AddPage(self.panel_page_achat_mois,
                                     u"Achats du mois")

        #Page "Achats"
        self.panel_page_achats = wx.Panel(self.notebook_achats, -1)

        self.liste_achats = ObjectListView(
            self.panel_page_achats,
            -1,
            style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL,
            sortable=False)

        self.liste_achats.SetColumns([
            ColumnDefn("Date",
                       "left",
                       -1,
                       "date",
                       stringConverter="Achat du %d-%m-%y",
                       minimumWidth=100),
            ColumnDefn(u"Total",
                       "right",
                       -1,
                       "total",
                       stringConverter=u"%.2f €",
                       minimumWidth=100,
                       isSpaceFilling=True)
        ])

        def rowFormatterAchats(listItem, achat):
            if achat.is_achat_du_jour() and (
                    achat == self.liste_achats.GetObjectAt(0)):
                listItem.SetBackgroundColour("#CCFFCC")

        self.liste_achats.rowFormatter = rowFormatterAchats
        self.liste_achats.AutoSizeColumns()

        self.liste_lignes_achat = ObjectListView(
            self.panel_page_achats,
            -1,
            style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)

        self.liste_lignes_achat.SetColumns([
            ColumnDefn("Ref GASE",
                       "left",
                       -1,
                       "produit.ref_GASE",
                       minimumWidth=70),
            ColumnDefn("Nom", "left", -1, "produit.nom", minimumWidth=100),
            ColumnDefn("Prix",
                       "left",
                       -1,
                       "produit.prix_vente_format",
                       minimumWidth=100),
            ColumnDefn(u"Quantité",
                       "left",
                       -1,
                       "quantite_format",
                       minimumWidth=70),
            ColumnDefn(u"Total",
                       "right",
                       -1,
                       "prix_total",
                       stringConverter=u"%.2f €",
                       minimumWidth=70,
                       isSpaceFilling=True)
        ])

        self.liste_lignes_achat.AutoSizeColumns()
        self.liste_lignes_achat.SortBy(1)

        self.notebook_achats.AddPage(self.panel_page_achats, "Achats")

        #Page "Cotisations"
        self.panel_page_cotisations = wx.Panel(self.notebook_achats, -1)
        self.liste_cotisations = ObjectListView(
            self.panel_page_cotisations,
            -1,
            style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_SINGLE_SEL)

        def cotisation_mois_annee(cotisation):
            mois = [
                'Janvier', u'Février', 'Mars', 'Avril', 'Mai', 'Juin',
                'Juillet', u'Août', 'Septembre', 'Octobre', 'Novembre',
                u'Décembre'
            ]

            return "%s %i" % (mois[cotisation.date.month - 1],
                              cotisation.date.year)

        self.liste_cotisations.SetColumns([
            ColumnDefn("Cotisation de",
                       "left",
                       -1,
                       cotisation_mois_annee,
                       minimumWidth=100),
            ColumnDefn(u"Réglée le", "left", -1, "date", minimumWidth=100),
            ColumnDefn(u"Montant",
                       "left",
                       -1,
                       "montant",
                       stringConverter=u"%.2f €",
                       minimumWidth=70,
                       isSpaceFilling=True)
        ])

        self.notebook_achats.AddPage(self.panel_page_cotisations,
                                     "Cotisations")

        #Page "Paiements"
        self.panel_page_credits = wx.Panel(self.notebook_achats, -1)
        self.liste_credits = wx.ListCtrl(self.panel_page_credits,
                                         -1,
                                         style=wx.LC_REPORT | wx.SUNKEN_BORDER)

        self.notebook_achats.AddPage(self.panel_page_credits, "Paiements")

        self.__set_properties()
        self.__set_valeurs()
        self.__do_layout()

        self.combobox_choix_mois.Bind(wx.EVT_COMBOBOX, self.OnChoixMois)
        self.bouton_ajout_achat.Bind(wx.EVT_BUTTON, self.OnAjoutAchat)
        self.liste_achats.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnDetailsAchat)
        self.liste_achats.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnModifAchat)
        #self.liste_achats_mois.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnDetailsAchat)
        self.liste_achats_mois.Disable()

    def __set_properties(self):
        self.label_solde_v.SetLabel(u"%.2f €" % self.adherent.solde)
        if self.adherent.solde >= 0:
            self.label_solde_v.SetForegroundColour("#00AA00")
        else:
            self.label_solde_v.SetForegroundColour("#DD0000")

    def __set_valeurs(self):
        try:
            #requete en brut pour pouvoir séelctionner les mois et les années des achats
            requete = "SELECT strftime('%Y', date) as annee, "
            requete += "strftime('%m', date) as mois "
            requete += "FROM achats "
            requete += "WHERE adherent_id = %i " % self.adherent.id
            requete += "GROUP  BY annee, mois "
            requete += "ORDER  BY annee, mois DESC"

            # Liste des mois en français
            mois = [
                'Janvier', u'Février', 'Mars', 'Avril', 'Mai', 'Juin',
                'Juillet', u'Août', 'Septembre', 'Octobre', 'Novembre',
                u'Décembre'
            ]

            mois_courant = (str(datetime.today().year),
                            str(datetime.today().month))

            #on ajoute en premier le mois courant
            self.combobox_choix_mois.Append(
                "%s %s" % (mois[int(mois_courant[1]) - 1], mois_courant[0]),
                mois_courant)
            self.combobox_choix_mois.SetSelection(0)

            #on ajoute tous les mois où il y a eu des achats
            for date in DATABASE.execute_sql(requete):
                if date != mois_courant:
                    self.combobox_choix_mois.Append(
                        "%s %s" % (mois[int(date[1]) - 1], date[0]), date)

            self.OnChoixMois(None)

            achats = Achat.select().where(
                Achat.adherent == self.adherent).order_by(Achat.date.desc())
            self.liste_achats.SetObjects([a for a in achats])

            cotisations = Cotisation.select().where(
                Cotisation.adherent == self.adherent).order_by(
                    Cotisation.date.desc())
            self.liste_cotisations.SetObjects([c for c in cotisations])

        except BaseException as ex:
            print ex

    def __do_layout(self):
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer_panel_page_cotisations = wx.BoxSizer(wx.HORIZONTAL)
        sizer_panel_page_credits = wx.BoxSizer(wx.HORIZONTAL)
        sizer_panel_page_achats = wx.BoxSizer(wx.HORIZONTAL)
        sizer_panel_page_achat_mois = wx.BoxSizer(wx.VERTICAL)
        sizer_toolbar = wx.BoxSizer(wx.HORIZONTAL)
        sizer_boutons = wx.BoxSizer(wx.HORIZONTAL)

        grid_infos = wx.GridSizer(2, 2, 5, 5)
        grid_infos.Add(self.label_total_achats, 0, 0, 0)
        grid_infos.Add(self.label_total_achats_v, 0, 0, 0)
        grid_infos.Add(self.label_solde, 0, 0, 0)
        grid_infos.Add(self.label_solde_v, 0, 0, 0)

        sizer.Add(grid_infos, 0, wx.ALL, 5)
        sizer.Add(self.static_line, 0, wx.ALL | wx.EXPAND, 10)

        sizer_boutons.Add(self.bouton_ajout_achat, 0, 0, 0)
        sizer_boutons.Add(self.bouton_ajout_credit, 0, wx.LEFT, 20)

        sizer.Add(sizer_boutons, 0, wx.EXPAND, 0)
        sizer.Add(self.label_info, 0, wx.ALL, 5)

        sizer_toolbar.Add(self.label_mois_recherche, 0,
                          wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5)
        sizer_toolbar.Add(self.combobox_choix_mois, 0, 0, 0)
        sizer_toolbar.Add((1, 1), 1, wx.EXPAND, 0)
        sizer_toolbar.Add(self.label_total_mois, 0,
                          wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5)

        sizer_panel_page_achat_mois.Add(sizer_toolbar, 0, wx.ALL | wx.EXPAND,
                                        5)
        sizer_panel_page_achat_mois.Add(self.liste_achats_mois, 1,
                                        wx.ALL | wx.EXPAND, 5)

        self.panel_page_achat_mois.SetSizer(sizer_panel_page_achat_mois)

        sizer_panel_page_achats.Add(self.liste_achats, 1, wx.ALL | wx.EXPAND,
                                    5)
        sizer_panel_page_achats.Add(self.liste_lignes_achat, 2,
                                    wx.ALL | wx.EXPAND, 5)

        self.panel_page_achats.SetSizer(sizer_panel_page_achats)

        sizer_panel_page_cotisations.Add(self.liste_cotisations, 1,
                                         wx.ALL | wx.EXPAND, 5)
        self.panel_page_cotisations.SetSizer(sizer_panel_page_cotisations)

        sizer_panel_page_credits.Add(self.liste_credits, 1, wx.ALL | wx.EXPAND,
                                     5)
        self.panel_page_credits.SetSizer(sizer_panel_page_credits)

        sizer.Add(self.notebook_achats, 1, wx.EXPAND, 0)

        self.SetSizer(sizer)
        sizer.Fit(self)

    def OnAjoutAchat(self, event):
        fiche_achat = FicheAchat(self)

        x, y = self.GetSize()
        fiche_achat.SetSize((x - 50, y - 50))

        if fiche_achat.ShowModal() == wx.ID_SAVE:
            achats = Achat.select().where(
                Achat.adherent == self.adherent).order_by(Achat.date.desc())
            self.liste_achats.SetObjects([a for a in achats])
            self.liste_achats.AutoSizeColumns()

            self.liste_lignes_achat.DeleteAllItems()
            self.OnChoixMois(event)

    def OnModifAchat(self, event):
        achat = self.liste_achats.GetSelectedObject()
        #vérification que c'est bien le dernier achat
        if self.liste_achats.GetSelectedObject(
        ) == self.liste_achats.GetObjectAt(0):
            if achat.is_achat_du_jour():
                fiche_achat = FicheAchat(
                    self, achat=self.liste_achats.GetSelectedObject())

                x, y = self.GetSize()
                fiche_achat.SetSize((x - 50, y - 50))

                if fiche_achat.ShowModal() == wx.ID_SAVE:
                    achat = fiche_achat.GetAchat()

                    self.OnDetailsAchat(event)
                    self.OnChoixMois(event)
                    self.liste_achats.RefreshObject(achat)

    def OnChoixMois(self, event):
        """Mets à jour la liste des achats du mois sélectionné """
        date = self.combobox_choix_mois.GetClientData(
            self.combobox_choix_mois.GetSelection())

        date_mois = datetime(int(date[0]), int(date[1]), 1)
        date_mois_suivant = date_mois + relativedelta(months=+1)

        lignes_achat = LigneAchat.select().join(Achat).where(
            (Achat.adherent == self.adherent) & (Achat.date >= date_mois)
            & (Achat.date < date_mois_suivant)).order_by(Achat.date.asc())

        self.liste_achats_mois.SetObjects([la for la in lignes_achat])

        achats = Achat.select().where(
            (Achat.adherent == self.adherent) & (Achat.date >= date_mois)
            & (Achat.date < date_mois_suivant)).order_by(Achat.date.asc())

        total_mois = 0

        for a in achats:
            total_mois += a.total

        self.label_total_mois.SetLabel(u"Total des achats du mois : %.2f €" %
                                       total_mois)

    def OnDetailsAchat(self, event):
        self.achat = self.liste_achats.GetSelectedObject()
        self.liste_lignes_achat.SetObjects(
            [la for la in self.achat.lignes_achat])
Пример #18
0
class FicheCommande(wx.Panel):
    def __init__(self, parent, commande=None):
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)

        if commande == None:
            commande = Commande.create()

        self.commande = commande

        self.sizer_commande_staticbox = wx.StaticBox(self, -1, "Commande")
        self.sizer_fournisseur_produits_staticbox = wx.StaticBox(
            self, -1, "Liste des produits")
        self.label_titre_commande = wx.StaticText(self, -1, "Commande pour ")
        self.bouton_infos_fournisseur = wx.Button(
            self, -1, "Afficher les infos du fournisseur")
        self.label_date_commande = wx.StaticText(self, -1,
                                                 "Date de la commande :")
        self.datepicker_date_commande = wx.DatePickerCtrl(self, -1)
        self.label_FiltreRecherche = wx.StaticText(self, -1,
                                                   "Recherche sur le nom :")
        self.text_ctrl_FiltreRecherche = wx.TextCtrl(self, -1, "")
        self.liste_produits = ObjectListView(self,
                                             -1,
                                             style=wx.LC_REPORT
                                             | wx.SUNKEN_BORDER)
        self.label_total = wx.StaticText(self, -1, "Total de la commande :")
        self.label_total_valeur = wx.StaticText(self,
                                                -1,
                                                u"0.00 ¤",
                                                style=wx.ALIGN_RIGHT)
        self.liste_lignes_commande = ObjectListView(self,
                                                    -1,
                                                    style=wx.LC_REPORT
                                                    | wx.SUNKEN_BORDER)
        self.bouton_Sauvegarder = wx.Button(self, -1,
                                            "Enregistrer la commande")

        self.liste_produits.SetColumns([
            ColumnDefn("Ref GASE", "left", -1, "ref_GASE", minimumWidth=100),
            ColumnDefn("Nom", "left", -1, "nom", minimumWidth=100),
            ColumnDefn("Prix TTC",
                       "right",
                       -1,
                       "prix_achat_TTC",
                       stringConverter=u"%.2f ¤",
                       minimumWidth=100),
            ColumnDefn("Conditionnement",
                       "left",
                       -1,
                       "conditionnement_format",
                       isSpaceFilling=True,
                       minimumWidth=200)
        ])
        self.liste_produits.SetEmptyListMsg("Ce fournisseur n'a aucun produit")
        self.liste_produits.AutoSizeColumns()

        self.liste_lignes_commande.SetColumns([
            ColumnDefn("Ref Fournisseur",
                       "left",
                       -1,
                       "produit.ref_fournisseur",
                       minimumWidth=120),
            ColumnDefn("Nom", "left", -1, "produit.nom", minimumWidth=100),
            ColumnDefn(u"Quantité",
                       "left",
                       -1,
                       "quantite_commandee_conditionnement",
                       minimumWidth=150),
            ColumnDefn("Total TTC",
                       "right",
                       -1,
                       "prix_total_commande_ttc",
                       stringConverter=u"%s ¤",
                       isSpaceFilling=True,
                       minimumWidth=100)
        ])
        self.liste_lignes_commande.AutoSizeColumns()

        self.liste_lignes_commande.SetEmptyListMsg(
            "La commande ne contient aucun produit")

        self.__set_properties()
        self.__set_values()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.OnInfosFournisseur,
                  self.bouton_infos_fournisseur)
        self.Bind(wx.EVT_BUTTON, self.OnSauvegarder, self.bouton_Sauvegarder)
        self.Bind(wx.EVT_TEXT, self.OnFilter, self.text_ctrl_FiltreRecherche)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnAjoutProduit,
                  self.liste_produits)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnModifProduit,
                  self.liste_lignes_commande)
        self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy, self)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: NouvelleCommande.__set_properties
        self.label_titre_commande.SetFont(
            wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.sizer_fournisseur_produits_staticbox.SetFont(
            wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.label_total.SetFont(
            wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.sizer_commande_staticbox.SetFont(
            wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.text_ctrl_FiltreRecherche.SetMinSize((200, -1))
        # end wxGlade

    def __set_values(self):
        if self.commande.fournisseur:
            self.SetFournisseur(self.commande.fournisseur)

            date = wx.DateTime()
            date.Set(self.commande.date_commande.day,
                     self.commande.date_commande.month - 1,
                     self.commande.date_commande.year)
            self.datepicker_date_commande.SetValue(date)

            self.liste_lignes_commande.SetObjects(
                [lc for lc in self.commande.lignes_commande])
            self.label_total_valeur.SetLabel(
                u"%.2f ¤" % self.commande.total_commande_TTC())

    def __do_layout(self):
        # begin wxGlade: NouvelleCommande.__do_layout
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer_boutons = wx.BoxSizer(wx.HORIZONTAL)
        sizer_entete = wx.BoxSizer(wx.HORIZONTAL)
        sizer_date_commande = wx.BoxSizer(wx.HORIZONTAL)
        sizer_commande = wx.StaticBoxSizer(self.sizer_commande_staticbox,
                                           wx.VERTICAL)
        sizer_fournisseur_produits = wx.StaticBoxSizer(
            self.sizer_fournisseur_produits_staticbox, wx.HORIZONTAL)
        sizer_ligne_total = wx.BoxSizer(wx.HORIZONTAL)
        sizer_liste_produits = wx.BoxSizer(wx.VERTICAL)
        sizer_fitre_recherche = wx.BoxSizer(wx.HORIZONTAL)

        sizer_entete.Add(self.label_titre_commande, 1, wx.EXPAND, 0)
        sizer_entete.Add(self.bouton_infos_fournisseur, 0, wx.EXPAND, 0)
        sizer.Add(sizer_entete, 0, wx.TOP | wx.BOTTOM | wx.EXPAND, 10)

        sizer_date_commande.Add(self.label_date_commande, 0,
                                wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 6)
        sizer_date_commande.Add(self.datepicker_date_commande, 0, 0, 0)
        sizer.Add(sizer_date_commande, 0, wx.EXPAND, 0)

        sizer_fitre_recherche.Add(self.label_FiltreRecherche, 0,
                                  wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 6)
        sizer_fitre_recherche.Add(self.text_ctrl_FiltreRecherche, 0, 0, 0)
        sizer_liste_produits.Add(sizer_fitre_recherche, 0,
                                 wx.BOTTOM | wx.EXPAND, 6)
        sizer_liste_produits.Add(self.liste_produits, 1, wx.EXPAND, 0)
        sizer_fournisseur_produits.Add(sizer_liste_produits, 1, wx.EXPAND, 0)
        sizer.Add(sizer_fournisseur_produits, 1, wx.TOP | wx.EXPAND, 10)

        sizer_ligne_total.Add(self.label_total, 0, wx.EXPAND | wx.RIGHT, 20)
        sizer_ligne_total.Add(self.label_total_valeur, 0, wx.ALIGN_RIGHT, 0)

        sizer_commande.Add(sizer_ligne_total, 0, wx.ALIGN_RIGHT | wx.BOTTOM, 6)
        sizer_commande.Add(self.liste_lignes_commande, 1, wx.EXPAND, 0)
        sizer.Add(sizer_commande, 1, wx.EXPAND, 0)

        sizer_boutons.Add(self.bouton_Sauvegarder, 0, 0, 0)
        sizer.Add(sizer_boutons, 0, wx.TOP | wx.ALIGN_CENTER_HORIZONTAL, 6)
        self.SetSizer(sizer)
        sizer.Fit(self)
        # end wxGlade

    def __update_total(self):
        self.label_total_valeur.SetLabel(u"%.2f ¤" %
                                         self.commande.total_commande_TTC())
        self.Layout()

    def SetFournisseur(self, fournisseur):
        self.commande.fournisseur = fournisseur

        self.label_titre_commande.SetLabel("Commande pour " +
                                           self.commande.fournisseur.nom)

        try:
            produits = Produit.select().where(
                (Produit.fournisseur == fournisseur)
                & (Produit.retrait == False))
            self.liste_produits.SetObjects([p for p in produits])
            self.liste_produits.AutoSizeColumns()

        except BaseException as ex:
            print ex

        self.Layout()

    def OnFilter(self, event):
        filtre_texte = Filter.TextSearch(
            self.liste_produits,
            text=self.text_ctrl_FiltreRecherche.GetValue())
        self.liste_produits.SetFilter(filtre_texte)
        self.liste_produits.RepopulateList()

    def OnInfosFournisseur(self,
                           event):  # wxGlade: NouvelleCommande.<event_handler>
        message = ""
        message += self.commande.fournisseur.nom + "\n\n"
        message += self.commande.fournisseur.adresse + "\n"
        message += self.commande.fournisseur.code_postal + " " + \
                   self.commande.fournisseur.ville + "\n\n"
        message += u"Tel fixe : " + self.commande.fournisseur.telephone_fixe + "\n"
        message += u"Tel portable : " + self.commande.fournisseur.telephone_portable + "\n"
        message += u"Email : " + self.commande.fournisseur.email + "\n\n"
        message += u"Nom du contact : " + self.commande.fournisseur.nom_contact + "\n\n"
        message += "Remarques : \n\n"

        message += fill(self.commande.fournisseur.remarques, 50)

        dlg = GMD.GenericMessageDialog(self, message,
                                       self.commande.fournisseur.nom,
                                       wx.OK | wx.ICON_INFORMATION)

        dlg.Fit()
        dlg.ShowModal()
        dlg.Destroy()

    def OnAjoutProduit(self, event):
        deja_ajoute = False
        produit_selectionne = self.liste_produits.GetSelectedObject()

        for lc_liste in self.liste_lignes_commande.GetObjects():
            if lc_liste.produit.get_id() == produit_selectionne.get_id():
                deja_ajoute = True
                break

        if deja_ajoute == False:
            lc = LigneCommande(commande=self.commande,
                               produit=produit_selectionne)

            dlg = DialogChoixQuantite(lc)

            if dlg.ShowModal() == wx.ID_OK:
                if dlg.GetQuantite() != 0:
                    lc.quantite_commandee = dlg.GetQuantite()
                    lc.save()
                    self.liste_lignes_commande.AddObject(lc)
                    self.liste_lignes_commande.AutoSizeColumns()

                    #Mise à jour du total de la commande
                    self.__update_total()

            dlg.Destroy()

    def OnModifProduit(self, event):
        lc_selectionnee = self.liste_lignes_commande.GetSelectedObject()

        dlg = DialogChoixQuantite(lc_selectionnee)

        id_resultat = dlg.ShowModal()

        if id_resultat == wx.ID_OK and dlg.GetQuantite() != 0:
            lc_selectionnee.quantite_commandee = dlg.GetQuantite()
            lc_selectionnee.save()
            self.liste_lignes_commande.RefreshObject(lc_selectionnee)
            self.liste_lignes_commande.AutoSizeColumns()
        elif id_resultat == wx.ID_DELETE or dlg.GetQuantite() == 0:
            self.liste_lignes_commande.RemoveObject(lc_selectionnee)
            self.liste_lignes_commande.RefreshObject(lc_selectionnee)
            lc_selectionnee.delete_instance()
            self.liste_lignes_commande.AutoSizeColumns()

        #Mise à jour du total de la commande
        self.__update_total()

        dlg.Destroy()

    def OnSauvegarder(self, event):
        try:
            date_commande = self.datepicker_date_commande.GetValue()
            print datetime(date_commande.GetYear(),
                           date_commande.GetMonth() + 1,
                           date_commande.GetDay())

            self.commande.date_commande = datetime(
                date_commande.GetYear(),
                date_commande.GetMonth() + 1, date_commande.GetDay())

            self.commande.save()
            DATABASE.commit()
            wx.MessageBox(u"La commande a été enregistrée", "Notification")
        except BaseException as ex:
            wx.MessageBox(u"Problème lors de l'enregistrement : %s" % ex,
                          "Erreur")

    def OnDestroy(self, event):
        if self.commande.fournisseur != None:
            dlg = wx.MessageDialog(
                parent=None,
                message=u"Voulez vous sauvegarder la commande ?",
                caption=u"Sauvegarde de la commande",
                style=wx.YES_NO | wx.ICON_QUESTION)

            if dlg.ShowModal() == wx.ID_YES:
                self.OnSauvegarder(None)
            else:
                DATABASE.rollback()

            dlg.Destroy()

        event.Skip()