Ejemplo n.º 1
0
    def test_free_category(self):
        menu = ProduitVendu()
        menu.produit = Produit.objects.get(nom="biere 50cl")
        menu.save()
        self.assertEqual(None, menu.getFreeCategorie())

        menu.produit = Produit.objects.get(nom="Menu Entree/Plat")
        cat_entrees = Categorie.objects.get(nom="Entrees")
        self.assertEqual(cat_entrees, menu.getFreeCategorie())

        entree = ProduitVendu()
        entree.produit = Produit.objects.get(nom="salade normande")
        entree.save()
        menu.contient.add(entree)
        cat_plats = Categorie.objects.get(nom="Plat")
        self.assertEqual(cat_plats, menu.getFreeCategorie())

        plat = ProduitVendu()
        plat.produit = Produit.objects.get(nom="entrecote")
        plat.save()
        menu.contient.add(plat)
        self.assertEqual(None, menu.getFreeCategorie())

        menu.contient.remove(entree)
        self.assertEqual(cat_entrees, menu.getFreeCategorie())

        menu.contient.add(entree)
        self.assertEqual(None, menu.getFreeCategorie())
Ejemplo n.º 2
0
 def test_add_product_prize(self):
     facture = Facture()
     facture.save()
     plat = ProduitVendu()
     plat.produit = Produit.objects.get(nom="entrecote")
     facture.add_product_prize(plat)
     self.assertEqual(plat.prix, facture.total_ttc)
     self.assertEqual(plat.prix, facture.restant_a_payer)
Ejemplo n.º 3
0
 def test_is_empty(self):
     facture = Facture()
     facture.save()
     self.assertTrue(facture.is_empty())
     plat = ProduitVendu()
     plat.produit = Produit.objects.get(nom="entrecote")
     facture.add_product(plat)
     self.assertFalse(facture.is_empty())
Ejemplo n.º 4
0
 def test_rendre_monnaie(self):
     paiement = Paiement.objects.all()[0]
     facture = Facture()
     facture.save()
     plat = ProduitVendu()
     plat.produit = Produit.objects.get(nom="entrecote")
     facture.add_product(plat)
     facture.rendre_monnaie(paiement)
     self.assertEqual(Decimal("-82.80"), facture.paiements.all()[0].montant)
Ejemplo n.º 5
0
 def test_is_valid_payment(self):
     facture = Facture()
     facture.save()
     self.assertFalse(facture.is_valid_payment(42))
     plat = ProduitVendu()
     plat.produit = Produit.objects.get(nom="entrecote")
     facture.add_product(plat)
     self.assertTrue(facture.is_valid_payment(42))
     facture.restant_a_payer = Decimal("0")
     self.assertFalse(facture.is_valid_payment(42))
Ejemplo n.º 6
0
 def test_del_product(self):
     facture = Facture()
     facture.save()
     plat = ProduitVendu()
     plat.produit = Produit.objects.get(nom="entrecote")
     facture.add_product(plat)
     facture.del_product(plat)
     self.assertTrue(plat not in facture.produits.iterator())
     self.assertEqual(Decimal("0"), facture.total_ttc)
     self.assertEqual(Decimal("0"), facture.restant_a_payer)
Ejemplo n.º 7
0
    def test_is_full(self):
        menu = ProduitVendu()
        menu.produit = Produit.objects.get(nom="biere 50cl")
        menu.save()
        self.assertTrue(menu.isFull())

        menu.produit = Produit.objects.get(nom="Menu Entree/Plat")
        self.assertFalse(menu.isFull())

        plat = ProduitVendu()
        plat.produit = Produit.objects.get(nom="entrecote")
        plat.save()
        menu.contient.add(plat)
        self.assertFalse(menu.isFull())

        entree = ProduitVendu()
        entree.produit = Produit.objects.get(nom="salade normande")
        entree.save()
        menu.contient.add(entree)
        self.assertTrue(menu.isFull())
Ejemplo n.º 8
0
 def test_product_sold_order(self):
     facture = Facture()
     facture.save()
     entree = ProduitVendu()
     entree.produit = Produit.objects.get(nom="salade normande")
     facture.add_product(entree)
     plat = ProduitVendu()
     plat.produit = Produit.objects.get(nom="entrecote")
     facture.add_product(plat)
     entree = ProduitVendu()
     entree.produit = Produit.objects.get(nom="buffet")
     facture.add_product(entree)
     entree = ProduitVendu()
     entree.produit = Produit.objects.get(nom="salade normande")
     facture.add_product(entree)
     liste_triee = facture.reduced_sold_list(facture.produits.all())
     resultat = [str(p.produit) for p in liste_triee]
     attendu = ['buffet', 'salade normande', 'entrecote']
     self.assertEqual(resultat, attendu)
     self.assertEqual([p.count for p in liste_triee], [1, 2, 1])
Ejemplo n.º 9
0
    def test_add_product(self):
        facture = Facture()
        facture.save()
        self.assertTrue(facture.is_empty())

        plat = ProduitVendu()
        plat.produit = Produit.objects.get(nom="entrecote")
        facture.add_product(plat)
        self.assertTrue(plat in facture.produits.iterator())
        self.assertEqual(plat.prix, facture.total_ttc)
        self.assertEqual(plat.prix, facture.restant_a_payer)
Ejemplo n.º 10
0
 def test_add_payment(self):
     facture = Facture()
     facture.save()
     plat = ProduitVendu()
     plat.produit = Produit.objects.get(nom="entrecote")
     facture.add_product(plat)
     facture.add_payment(PaiementType.objects.get(nom="CB"), "2")
     self.assertEqual(facture.restant_a_payer, Decimal(str(plat.prix - 2)))
     facture.add_payment(PaiementType.objects.get(nom="Espece"), "10")
     self.assertEqual(facture.restant_a_payer, Decimal(0))
     self.assertEqual(Decimal(str(plat.prix - 12)), \
                      (facture.paiements.all()[2]).montant)
Ejemplo n.º 11
0
 def test_regroup_produits(self):
     facture = Facture()
     facture.save()
     plat1 = ProduitVendu()
     plat1.produit = Produit.objects.get(nom="entrecote")
     plat2 = ProduitVendu()
     plat2.produit = Produit.objects.get(nom="entrecote")
     plat3 = ProduitVendu()
     plat3.produit = Produit.objects.get(nom="pave de saumon")
     entree = ProduitVendu()
     entree.produit = Produit.objects.get(nom="salade normande")
     menu = ProduitVendu()
     menu.produit = Produit.objects.get(nom="jus abricot")
     facture.add_product(plat1)
     facture.add_product(plat2)
     facture.add_product(plat3)
     facture.add_product(entree)
     facture.add_product(menu)
     resultat = OrderedDict([('salade normande', [(entree.id, entree)]),
                             ('entrecote', [(plat1.id, plat1), \
                                            (plat2.id, plat2)]),
                             ('pave de saumon', [(plat3.id, plat3)]),
                             ('jus abricot', [(menu.id, menu)])])
     self.assertEqual(resultat, facture.regroup_produits())