Beispiel #1
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)
Beispiel #2
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()
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)
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:
Beispiel #5
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)
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()
Beispiel #7
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()