def update(request): """Update statistics """ if Stat().update(): messages.add_message(request, messages.SUCCESS, "Les données sont à jour") else: messages.add_message(request, messages.ERROR, "Les données ne peuvent être mis à jour") return redirect("manager")
def daily(request): """Show stats for a day """ context = {'menu_manager': True, } date = datetime.datetime.now() if request.method == 'POST': try: year = int(request.POST.get('date_year')) month = int(request.POST.get('date_month')) day = int(request.POST.get('date_day')) date = datetime.datetime(year, month, day) except: messages.add_message(request, messages.ERROR, "La date saisie n'est pas valide.") context['date_form'] = DateForm({'date': date, }) context['date'] = date context = Stat().get_data_for_day(context) check_for_outputs(request, context) return render(request, 'stats/home.html', context)
def monthly(request): """Show stats for a month """ context = {'menu_manager': True, } date = datetime.datetime.now() year = date.year month = date.month if request.method == 'POST': try: year = int(request.POST.get('year')) month = int(request.POST.get('month')) except: messages.add_message(request, messages.ERROR, "La date saisie n'est pas valide.") context['month_form'] = MonthForm({'year': year, 'month': month}) context['month'] = month context['year'] = year context = Stat().get_data_for_month(context) check_for_outputs(request, context) return render(request, 'stats/home.html', context)
def weekly(request): """Show stats for a week """ context = {'menu_manager': True, } date = datetime.datetime.now() year = date.year week = date.isocalendar()[1] if request.method == 'POST': try: year = int(request.POST.get('year')) week = int(request.POST.get('week')) except: messages.add_message(request, messages.ERROR, "La date saisie n'est pas valide.") context['week_form'] = WeekForm({'year': year, 'week': week}) context['week'] = week context['year'] = year context = Stat().get_data_for_week(context) check_for_outputs(request, context) return render(request, 'stats/home.html', context)
def handle(self, *args, **options): for year in args: before = datetime.datetime.now() self.stdout.write("[%s] delete stats before update" % datetime.datetime.now().strftime("%H:%M")) Stat.objects.filter(year=year).delete() self.stdout.write( "[%s] change status for bills" % datetime.datetime.now().strftime("%H:%M")) begin = "%s-01-01 00:00:00" % year end = "%s-12-31 23:59:59" % year bills = Facture.objects.filter(date_creation__gte=begin, date_creation__lt=end) for bill in bills.iterator(): bill.saved_in_stats = False bill.save() self.stdout.write("[%s] compute stats" % datetime.datetime.now().strftime("%H:%M")) Stat().update() after = datetime.datetime.now() diff = after - before time = "" if diff.seconds > 3600: # more than a hour hour = diff.seconds / 3600 mn = (diff.seconds % 3600) / 60 time = "%dh %dm" % (hour, mn) else: mn = diff.seconds / 60 sec = diff.seconds % 60 time = "%dm %ds" % (mn, sec) self.stdout.write( "[%s] updated %d bills in %s" % (year, bills.count(), time))
year = int(input("Quelle année mettre à jour (ex: 2013) ? ")) before = datetime.datetime.now() print "[%s] delete stats before update" % datetime.datetime.now().strftime("%H:%M") Stat.objects.filter(year=year).delete() print "[%s] change status for bills" % datetime.datetime.now().strftime("%H:%M") bills = Facture.objects.filter(date_creation__gte="%d-01-01 00:00:00" % year, date_creation__lt="%d-12-31 23:59:59" % year) for bill in bills.iterator(): bill.saved_in_stats = False bill.save() print "[%s] compute stats" % datetime.datetime.now().strftime("%H:%M") Stat().update() after = datetime.datetime.now() diff = after - before time = "" if diff.seconds > 3600: # more than a hour hour = diff.seconds / 3600 mn = (diff.seconds % 3600) / 60 time = "%dh %dm" % (hour, mn) else: mn = diff.seconds / 60 sec = diff.seconds % 60 time = "%dm %ds" % (mn, sec) print "[%d] updated %d bills in %s" % (year, bills.count(), time)
def handle(self, *args, **options): Stat().update()
def handle(self, *args, **options): create_users() create_payment() # Montant de la surtaxe Config(key="price_surcharge", value="0.20").save() create_tables() # TVA vat_alcool = VAT(name="alcool") vat_alcool.set_tax("20") vat_alcool.save() vat_onsite = VAT(name="sur place") vat_onsite.set_tax("10") vat_onsite.save() vat_takeaway = VAT(name="à emporter") vat_takeaway.set_tax("7") vat_takeaway.save() # Options Option(name="A_Frites").save() Option(name="A_Salade").save() Option(name="S_Creme").save() Option(name="A_Haricots").save() Option(name="S_Mayo").save() # Notes Note(message="Pas de sel").save() Note(message="Sans champignon").save() # # Data example # on entre les nouveaux produits, les prix sont TTC jus = Categorie(nom="Jus", priorite=25, surtaxable=False, disable_surtaxe=False, made_in_kitchen=False, color="#44b3dc", vat_onsite=vat_onsite, vat_takeaway=vat_takeaway) jus.save() abricot = Produit(nom="jus abricot", prix="2.80", choix_cuisson=False, categorie=jus) abricot.save() pomme = Produit(nom="jus pomme", prix="2.80", choix_cuisson=False, categorie=jus) pomme.save() bieres = Categorie(nom="Bieres", priorite=2, surtaxable=False, disable_surtaxe=False, made_in_kitchen=False, color="#ea97b5", vat_onsite=vat_alcool, vat_takeaway=vat_alcool) bieres.save() biere = Produit(nom="biere 50cl", prix="2.80", choix_cuisson=False, categorie=bieres) biere.save() entrees = Categorie(nom="Entrees", priorite=5, surtaxable=False, disable_surtaxe=False, made_in_kitchen=True, color="#ff9f00", vat_onsite=vat_onsite, vat_takeaway=vat_takeaway) entrees.save() salade = Produit(nom="salade normande", prix="3.40", choix_cuisson=False, categorie=entrees) salade.save() buffet = Produit(nom="buffet", prix="6.40", choix_cuisson=False, categorie=entrees) buffet.save() plat = Categorie(nom="Plat", priorite=10, surtaxable=False, disable_surtaxe=False, made_in_kitchen=True, color="#c9a100", vat_onsite=vat_onsite, vat_takeaway=vat_takeaway) plat.save() entrecote = Produit(nom="entrecote", prix="8.40", choix_cuisson=True, categorie=plat) entrecote.save() pave = Produit(nom="pave de saumon", prix="9.40", choix_cuisson=False, categorie=plat) pave.save() # pour les menu menu = Categorie(nom="Menu", priorite=22, surtaxable=False, disable_surtaxe=False, made_in_kitchen=False, color="#88f027", vat_onsite=vat_onsite, vat_takeaway=vat_takeaway) menu.save() entree_plat = Produit(nom="Menu Entree/Plat", prix="13.40", choix_cuisson=False, categorie=menu) entree_plat.save() entree_plat.categories_ok.add(entrees) entree_plat.categories_ok.add(plat) entree_plat.produits_ok.add(salade) entree_plat.produits_ok.add(entrecote) entree_plat.produits_ok.add(pave) entree_plat.save() # mis a jour des TTC et TVA for product in Produit.objects.all(): product.update_vats(keep_clone=False) 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 range(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 # on ajoute des données pour avoir des jolies graphiques de # démonstrations now = datetime.datetime.now() for month in range(1, 13): for i in range(20): day = random.randint(1, 28) bill = create_bill() bill.date_creation = datetime.datetime(now.year, month, day) bill.save() # Création d'une dizaine de facture for i in range(15): bill = create_bill(finish=False) if i % 2: bill.update_kitchen() bill.print_ticket_kitchen() Stat().update()