Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 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)
    product = get_object_or_404(Produit, pk=product_id)
    product_sell = ProduitVendu(produit=product)
    product_sell.save()
    bill.add_product(product_sell)
    if product.est_un_menu():
        category = product_sell.getFreeCategorie()
        redirect_url = '/bill/%s/sold/%s/category/%s/select/' % (bill_id,
                                                                 product_sell.id,
                                                                 category.id)
        return HttpResponseRedirect(redirect_url)
    if product.choix_cuisson:
        redirect_url = '/bill/%s/sold/%s/cooking/' % (bill_id,
                                                      product_sell.id)
        return HttpResponseRedirect(redirect_url)
#    messages.add_message(request, messages.SUCCESS, "%s ok" % product.nom)
    redirect_url = '/bill/%s/category/%s/' % (bill_id,
                                              product.categorie.id)
    return HttpResponseRedirect(redirect_url)
Exemplo n.º 8
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.º 9
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)
    product_sell = ProduitVendu(produit=product)
    product_sell.made_with = product_sell.produit.categorie
    product_sell.save()
    menu = get_object_or_404(ProduitVendu, pk=sold_id)
    menu.contient.add(product_sell)
    if product.choix_cuisson:
        redirect_url = '/bill/%s/sold/%s/%s/cooking/' % (bill_id,
                                                         menu.id,
                                                         product_sell.id)
        return HttpResponseRedirect(redirect_url)
    category = menu.getFreeCategorie()
    if category:
        redirect_url = '/bill/%s/sold/%s/category/%s/select/' % (bill_id,
                                                                 menu.id,
                                                                 category.id)
        return HttpResponseRedirect(redirect_url)
    redirect_url = '/bill/%s/category/%s/' % (bill_id,
                                              menu.produit.categorie.id)
    return HttpResponseRedirect(redirect_url)
Exemplo n.º 10
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.º 11
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.º 12
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.º 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
            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()
                            sub.date = facture.date_creation
                            sub.save()
#                            product.addProduit(self.db.getProductById(row2[0]))
Exemplo n.º 15
0
        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()
                            sub.date = facture.date_creation
                            sub.save()
Exemplo n.º 16
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)