def get_user_facture(biere_user, count=False): if type(biere_user) is User: biere_user = BiereUser(id=biere_user.id) if type(biere_user) is BiereUser: return biere_user.get_facture(count) return False
def facture_summary(number=10, template="default.html"): #if type(user) is User: # user = BiereUser(id=user.id) #if type(user) is BiereUser: # return user.show_user_facture(GET) # Get Facture based on the number needed user = BiereUser.as_current_user() client = user.is_restricted_user() if client: factures = Facture.objects.filter(Client=client).order_by("-Date")[0:number] else: factures = Facture.objects.all().order_by("-Date")[0:number] return render_to_string("snippets/facture_summary/"+template, {'factures':factures, 'number': number})
def CreerFacture(request): created = False facture = False # Special case for restricted users, see README for more user = BiereUser.as_current_user() client = user.is_restricted_user() if client: facture = Facture() facture.Client = client d = datetime.today() facture.Note = "Facture du " + str(d.year) +'/'+ str(d.month) +'/'+ str(d.day) facture.save() return HttpResponseRedirect('/factures/'+ str(facture.id)+'/') # There is a new commande to create if request.method == 'POST': factureform = FactureForm(request.POST) if factureform.is_valid(): bill = factureform.save( commit=False ) bill.User = request.user bill.save() created = True facture = bill else: try: if request.GET['client']: id = int(request.GET['client']) factureform = FactureForm(initial={'Client': id}) else: factureform = FactureForm() except Exception as e: print e factureform = FactureForm() facture = Facture() commande = False produits = False return render_to_response('facture/new.html', {'created':created, 'factureform': factureform, 'user': request.user, 'facture': facture })