Exemplo n.º 1
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())
Exemplo n.º 2
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)
Exemplo n.º 3
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))
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
0
def create_bill(finish=True):
    """Create a bill
    """
    table = 'T%d' % random.randint(10, 25)
    bill = Facture(table=Table.objects.get(nom=table))
    bill.save()
    produits_bar = [biere, pomme, abricot]
    produits_guests = [salade, buffet, entrecote, pave]
    payments = ['CB', 'Espece', 'Cheque']
    if random.randint(1, 2) == 1:
        # guests part
        produits = produits_guests
        bill.couverts = random.randint(1, 15)
    else:
        produits = produits_bar
    nb_produits = random.randint(1, 6)
    for i in xrange(nb_produits):
        # random number of products
        nb_max = len(produits) - 1
        produit = produits[random.randint(0, nb_max)]
        sold = ProduitVendu(produit=produit)
        sold.save()
        bill.add_product(sold)
    #nouveau_menu = ProduitVendu(produit=entree_plat)
    #nouveau_menu.save()
    #for produit in [salade, pave]:
    #sold = ProduitVendu(produit=produit)
    #sold.save()
    #nouveau_menu.contient.add(sold)
    #nouveau_menu.save()
    bill.update()
    if finish:
        nb_max = len(payments) - 1
        name = payments[random.randint(0, nb_max)]
        type_payment = PaiementType.objects.get(nom=name)
        bill.add_payment(type_payment, bill.total_ttc)
    return bill
Exemplo n.º 8
0
 def create_bill(finish=True):
     """Create a bill
     """
     table = 'T%d' % random.randint(10, 25)
     bill = Facture(table=Table.objects.get(nom=table))
     bill.save()
     produits_bar = [biere, pomme, abricot]
     produits_guests = [salade, buffet, entrecote, pave]
     payments = ['CB', 'Espece', 'Cheque']
     if random.randint(1, 2) == 1:
         # guests part
         produits = produits_guests
         bill.couverts = random.randint(1, 15)
     else:
         produits = produits_bar
     nb_produits = random.randint(1, 6)
     for i in xrange(nb_produits):
         # random number of products
         nb_max = len(produits) - 1
         produit = produits[random.randint(0, nb_max)]
         sold = ProduitVendu(produit=produit)
         sold.save()
         bill.add_product(sold)
     # nouveau_menu = ProduitVendu(produit=entree_plat)
     # nouveau_menu.save()
     # for produit in [salade, pave]:
         # sold = ProduitVendu(produit=produit)
         # sold.save()
         # nouveau_menu.contient.add(sold)
     # nouveau_menu.save()
     bill.update()
     if finish:
         nb_max = len(payments) - 1
         name = payments[random.randint(0, nb_max)]
         type_payment = PaiementType.objects.get(nom=name)
         bill.add_payment(type_payment, bill.total_ttc)
     return bill
Exemplo n.º 9
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])
Exemplo n.º 10
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())
Exemplo n.º 11
0
class Tests_Bill(TestCase):
    fixtures = ["demo.json"]

    def setUp(self):
        TestCase.setUp(self)
        self.facture = Facture()
        self.facture.save()
        self.plat = ProduitVendu()
        self.plat.produit = Produit.objects.get(nom="entrecote")

    def test_is_empty(self):
        self.assertTrue(self.facture.is_empty())
        self.facture.add_product(self.plat)
        self.assertFalse(self.facture.is_empty())

    def test_add_product(self):
        self.assertTrue(self.facture.is_empty())
        self.facture.add_product(self.plat)
        self.facture.update()
        self.assertTrue(self.plat in self.facture.produits.iterator())
        self.assertEqual(self.plat.produit.prix, self.facture.total_ttc)
        self.assertEqual(self.plat.produit.prix, self.facture.restant_a_payer)

    def test_del_payment(self):
        payment = Paiement()
        montant = 42
        valeur_unitaire = 73
        paymentType = PaiementType()
        payment.montant = 73
        payment.type = paymentType
        payment.valeur_unitaire = Decimal(valeur_unitaire)
        payment.montant = Decimal(montant)
        self.facture.add_payment(paymentType, montant, valeur_unitaire)
        self.facture.del_payment(payment)

    def test_is_valid_payment(self):
        self.assertFalse(self.facture.is_valid_payment(42))
        self.facture.add_product(self.plat)
        self.facture.update()
        self.assertTrue(self.facture.is_valid_payment(42))
        self.facture.restant_a_payer = Decimal("0")
        self.assertFalse(self.facture.is_valid_payment(42))

    def test_rendre_monnaie(self):
        payment = Paiement()
        payment.type = PaiementType()
        payment.montant = Decimal("900")
        self.facture.add_product(self.plat)
        self.facture.update()
        self.facture.rendre_monnaie(payment)
        left = self.facture.total_ttc - Decimal("900")
        self.assertEqual(left, self.facture.paiements.all()[0].montant)

    def test_add_payment(self):
        self.facture.add_product(self.plat)
        self.facture.update()
        self.facture.add_payment(PaiementType.objects.get(nom="CB"), "2")
        restant_a_payer = Decimal(str(self.plat.produit.prix - 2))
        self.assertEqual(self.facture.restant_a_payer, restant_a_payer)
        self.facture.add_payment(PaiementType.objects.get(nom="Espece"), "10")
        self.assertEqual(self.facture.restant_a_payer, Decimal(0))
        montant = Decimal(str(self.plat.produit.prix - 12))
        self.assertEqual(montant, (self.facture.paiements.all()[2]).montant)
        # TODO This is done just to execute more code
        # An assertion should be verified
        self.facture.print_ticket_kitchen()
        self.facture.est_un_repas()
        self.facture.print_ticket()
Exemplo n.º 12
0
class TestsBill(TestCase):
    fixtures = ['demo.json']

    def setUp(self):
        TestCase.setUp(self)
        self.facture = Facture()
        self.facture.save()
        self.plat = ProduitVendu()
        self.plat.produit = Produit.objects.get(nom="entrecote")

    def test_is_empty(self):
        self.assertTrue(self.facture.is_empty())
        self.facture.add_product(self.plat)
        self.assertFalse(self.facture.is_empty())

    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])

    def test_add_product(self):
        self.assertTrue(self.facture.is_empty())
        self.facture.add_product(self.plat)
        self.facture.update()
        self.assertTrue(self.plat in self.facture.produits.iterator())
        self.assertTrue(self.facture.est_un_repas())
        self.assertEqual(self.plat.produit.prix, self.facture.total_ttc)
        self.assertEqual(self.plat.produit.prix, self.facture.restant_a_payer)

    def test_del_payment(self):
        payment = Paiement()
        montant = 42
        valeur_unitaire = 73
        paymentType = PaiementType()
        payment.montant = 73
        payment.type = paymentType
        payment.valeur_unitaire = Decimal(valeur_unitaire)
        payment.montant = Decimal(montant)
        self.facture.add_payment(paymentType, montant, valeur_unitaire)
        self.facture.del_payment(payment)

    def test_is_valid_payment(self):
        self.assertFalse(self.facture.is_valid_payment(42))
        self.facture.add_product(self.plat)
        self.facture.update()
        self.assertTrue(self.facture.is_valid_payment(42))
        self.facture.restant_a_payer = Decimal("0")
        self.assertFalse(self.facture.is_valid_payment(42))

    def test_rendre_monnaie(self):
        payment = Paiement()
        payment.type = PaiementType()
        payment.montant = Decimal("900")
        self.facture.add_product(self.plat)
        self.facture.update()
        self.facture.rendre_monnaie(payment)
        left = self.facture.total_ttc - Decimal("900")
        self.assertEqual(left, self.facture.paiements.all()[0].montant)

    def test_add_payment(self):
        self.facture.add_product(self.plat)
        self.facture.update()
        self.facture.add_payment(PaiementType.objects.get(nom="CB"), "2")
        restant_a_payer = Decimal(str(self.plat.produit.prix - 2))
        self.assertEqual(self.facture.restant_a_payer, restant_a_payer)
        self.facture.add_payment(PaiementType.objects.get(nom="Espece"), "10")
        self.assertEqual(self.facture.restant_a_payer, Decimal(0))
        montant = Decimal(str(self.plat.produit.prix - 12))
        self.assertEqual(montant, (self.facture.paiements.all()[2]).montant)
        # An assertion should be verified
        self.facture.print_ticket_kitchen()
        self.facture.print_ticket()
Exemplo n.º 13
0
                value=random.randint(50, 500)).save()
    MonthlyStat(year=2013, month=month, key='bar_nb',
                value=random.randint(50, 500)).save()
    MonthlyStat(year=2013, month=month, key='bar_average',
                value=random.randint(50, 500)).save()

# Création d'une dizaine de facture
for i in xrange(15):
    table = 'T%d' % random.randint(10, 25)
    f = Facture(table=Table.objects.get(nom=table),
                couverts=random.randint(1, 15))
    f.save()
    for produit in [salade, buffet, entrecote, pave, biere]:
        for j in xrange(3):
            p = ProduitVendu(produit=produit)
            p.save()
            f.add_product(p)
    nouveau_menu = ProduitVendu(produit=entree_plat)
    nouveau_menu.save()
    for produit in [salade, pave]:
        p = ProduitVendu(produit=produit)
        p.save()
        nouveau_menu.contient.add(p)
    nouveau_menu.save()
    if i % 2:
        f.send_in_the_kitchen()

# on sold une facture
type_cb = PaiementType.objects.get(nom='CB')
f.add_payment(type_cb, f.total_ttc)
Exemplo n.º 14
0
class Tests_Bill(TestCase):
    fixtures = ['demo.json']

    def setUp(self):
        TestCase.setUp(self)
        self.facture = Facture()
        self.facture.save()
        self.plat = ProduitVendu()
        self.plat.produit = Produit.objects.get(nom="entrecote")

    def test_is_empty(self):
        self.assertTrue(self.facture.is_empty())
        self.facture.add_product(self.plat)
        self.assertFalse(self.facture.is_empty())

    def test_add_product(self):
        self.assertTrue(self.facture.is_empty())
        self.facture.add_product(self.plat)
        self.facture.update()
        self.assertTrue(self.plat in self.facture.produits.iterator())
        self.assertEqual(self.plat.produit.prix, self.facture.total_ttc)
        self.assertEqual(self.plat.produit.prix, self.facture.restant_a_payer)

    def test_del_payment(self):
        payment = Paiement()
        montant = 42
        valeur_unitaire = 73
        paymentType = PaiementType()
        payment.montant = 73
        payment.type = paymentType
        payment.valeur_unitaire = Decimal(valeur_unitaire)
        payment.montant = Decimal(montant)
        self.facture.add_payment(paymentType, montant, valeur_unitaire)
        self.facture.del_payment(payment)

    def test_is_valid_payment(self):
        self.assertFalse(self.facture.is_valid_payment(42))
        self.facture.add_product(self.plat)
        self.facture.update()
        self.assertTrue(self.facture.is_valid_payment(42))
        self.facture.restant_a_payer = Decimal("0")
        self.assertFalse(self.facture.is_valid_payment(42))

    def test_rendre_monnaie(self):
        payment = Paiement()
        payment.type = PaiementType()
        payment.montant = Decimal("900")
        self.facture.add_product(self.plat)
        self.facture.update()
        self.facture.rendre_monnaie(payment)
        left = self.facture.total_ttc - Decimal("900")
        self.assertEqual(left, self.facture.paiements.all()[0].montant)

    def test_add_payment(self):
        self.facture.add_product(self.plat)
        self.facture.update()
        self.facture.add_payment(PaiementType.objects.get(nom="CB"), "2")
        restant_a_payer = Decimal(str(self.plat.produit.prix - 2))
        self.assertEqual(self.facture.restant_a_payer, restant_a_payer)
        self.facture.add_payment(PaiementType.objects.get(nom="Espece"), "10")
        self.assertEqual(self.facture.restant_a_payer, Decimal(0))
        montant = Decimal(str(self.plat.produit.prix - 12))
        self.assertEqual(montant, (self.facture.paiements.all()[2]).montant)
        # TODO This is done just to execute more code
        # An assertion should be verified
        self.facture.print_ticket_kitchen()
        self.facture.est_un_repas()
        self.facture.print_ticket()