Exemplo 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())
Exemplo n.º 2
0
def product_add(request, bill_id, product_id):
    """ Add a product to a bill. If this product contains others products,
    we have to add them too.

    :param request: HttpRequest request
    :param bill_id: Facture
    :param product_id: Produit
    """
    bill = get_object_or_404(Facture, pk=bill_id)
    if not set_edition_status(request, bill):
        LOG.debug("[F%s] bill is already in edition mode" % bill_id)
        return bill_view(request, bill.id)
    product = get_object_or_404(Produit, pk=product_id)

    # how many products to add
    count = int(request.session.get('count', 1))
    LOG.debug("[F%s] get %d X %s" % (bill_id, count, product))
    if count > 1:
        request.session['product_to_add'] = product_id
        request.session['product_count'] = count
        request.session['count'] = 1

    sold = ProduitVendu(produit=product)
    sold.save()
    LOG.debug("[F%s] ProduitVendu(%s) created" % (bill_id, product))
    bill.add_product(sold)
    request.session["products_modified"] = bill_id
    return sold_working(request, bill_id, sold.id)
Exemplo n.º 3
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())
Exemplo n.º 4
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.º 5
0
def subproduct_add(request, bill_id, sold_id, product_id):
    """Add a product to a bill. If this product contains others products,
    we have to add them too."""
    product = get_object_or_404(Produit, pk=product_id)
    sold = ProduitVendu(produit=product)
    sold.made_with = sold.produit.categorie
    sold.save()
    menu = get_object_or_404(ProduitVendu, pk=sold_id)
    menu.contient.add(sold)
    request.session['menu_id'] = menu.id
    return redirect('bill_sold_working', bill_id, sold.id)
Exemplo n.º 6
0
def subproduct_add(request, bill_id, sold_id, product_id):
    """ Add a product to a bill. If this product contains others products,
    we have to add them too.
    TODO
    :param HttpRequest request:
    :param bill_id:
    :type bill_id:
    :param sold_id:
    :type sold_id:
    :param product_id:
    :type product_id:
    """
    product = get_object_or_404(Produit, pk=product_id)
    sold = ProduitVendu(produit=product)
    sold.made_with = sold.produit.categorie
    sold.save()
    menu = get_object_or_404(ProduitVendu, pk=sold_id)
    menu.contient.add(sold)
    request.session['menu_id'] = menu.id
    return sold_working(request, bill_id, sold.id)
Exemplo n.º 7
0
def product_add(request, bill_id, product_id):
    """Add a product to a bill. If this product contains others products,
    we have to add them too.

    """
    bill = get_object_or_404(Facture, pk=bill_id)
    if not set_edition_status(request, bill):
        return redirect('bill_view', bill.id)
    product = get_object_or_404(Produit, pk=product_id)

    # how many products to add
    count = int(request.session.get('count', 1))
    if count > 1:
        request.session['product_to_add'] = product_id
        request.session['product_count'] = count
        request.session['count'] = 1

    sold = ProduitVendu(produit=product)
    sold.save()
    bill.add_product(sold)
    request.session["products_modified"] = bill_id
    return redirect('bill_sold_working', bill_id, sold.id)
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 setUp(self):
     TestCase.setUp(self)
     self.facture = Facture()
     self.facture.save()
     self.plat = ProduitVendu()
     self.plat.produit = Produit.objects.get(nom="entrecote")
Exemplo n.º 10
0
                valeur_unitaire)
            paiement.nb_tickets = int(
                Decimal(paiement.montant) / Decimal(paiement.valeur_unitaire))
        paiement.save()
        facture.paiements.add(paiement)

    cu.execute("select id_produit from factures_produits where id_facture=%d" %
               facture.id)
    # liste des relations des sous produits deja pris
    deja_pris = []
    for [id_produit] in cu.fetchall():
        if produit:
            try:
                produit = Produit_get(id=id_produit)
                vendu = ProduitVendu(produit=produit, \
                        date=facture.date_creation, \
                        facture=facture, \
                        prix=produit.prix)
                vendu.save()
                vendu.date = facture.date_creation
                #                facture.produits.add(vendu)

                sql = "select formules_produits.id_produit,factures_formules.id from factures_formules,formules_produits where factures_formules.id_facture=%d and factures_formules.id_formule_produit=formules_produits.id and formules_produits.id_formule=%d" % (
                    facture.id, produit.id)
                cu.execute(sql)
                for row2 in cu.fetchall():
                    if row2[1] not in deja_pris:
                        if not vendu.isFull():
                            sub = ProduitVendu(
                                    produit=Produit_get(id=row2[0]), \
                                    facture=facture)
                            sub.save()
Exemplo n.º 11
0
#
#    You should have received a copy of the GNU General Public License
#    along with POSSUM.  If not, see <http://www.gnu.org/licenses/>.
#
import sys, os
sys.path.append('/home/pos')
os.environ['DJANGO_SETTINGS_MODULE'] = 'possum.settings'

from possum.base.models import Accompagnement, Sauce, Etat, \
    Categorie, Couleur, Cuisson, Facture, Log, LogType, Paiement, \
    PaiementType, Produit, ProduitVendu, Suivi, Table, Zone

# il faut une categorie
c = Categorie.objects.get(id=1)

for f in Facture.objects.exclude(restant_a_payer=0, produits__isnull=False):
    filter = Produit.objects.filter(prix=f.get_montant())
    count = filter.count()
    if count > 0:
        p = filter[0]
        print p.nom
    else:
        nom = "recuperation ancienne base (%0.2f)" % f.get_montant()
        print nom
        p = Produit(nom=nom, nom_facture=nom, prix=f.get_montant(), actif=False, categorie=c)
        p.save()
    vendu = ProduitVendu(produit=p, facture=f)
    vendu.save()
    f.produits.add(vendu)