def edit_invoice(request,invoiceid): inv = get_object_or_404(Expense, pk=invoiceid) proj = inv.project_id projectid = format(proj.id) names= ['Material Purchase','Make Payment','Invoices','Payments'] links = ['/projects/'+projectid+'/purchases','/projects/'+projectid+'/payments','/projects/'+projectid+'/invoices','/projects/'+projectid+'/allpayments'] submenus = create_sub(names,links) context = {'proj_selected':'current'} if len(request.POST) <= 0: data = {"date":inv.date,"invoice_no":inv.invoice_no,"particulars":inv.particulars,"amount":inv.amount,"balance":inv.balance,"paid_details":inv.paid_details, "paid_date":inv.paid_date,"project_id":inv.project_id,"dealer_id":format(inv.dealer_id.id),"category_id":format(inv.category_id.id),"remarks":inv.remarks} form = MaterialForm(data) context.update({'title':'Update Invoice Details','form':form,'submenus':submenus}) return render(request,"edit.html",context) else: form = MaterialForm(request.POST) if form.is_valid(): cd = form.cleaned_data for key in cd: setattr(inv,key,cd.get(key)) inv.save() return HttpResponseRedirect("/projects/"+projectid+"/invoices?success=1") else: context.update({'title':'Update Invoice Details','form':form,'submenus':submenus}) return render(request, "edit.html",context)
def material_purchase(request, projectid): names = ['Material Purchase', 'Make Payment', 'Invoices', 'Payments'] links = [ '/projects/' + projectid + '/purchases', '/projects/' + projectid + '/payments', '/projects/' + projectid + '/invoices', '/projects/' + projectid + '/allpayments' ] submenus = create_sub(names, links) proj = Project.objects.get(pk=projectid) if len(request.POST) <= 0: material_form = MaterialForm() #If the page is loaded after a successful submission success = request.GET.get('success') return render( request, "material.html", { 'proj': proj, 'submenus': submenus, 'success': success, 'form': material_form }) else: material_form = MaterialForm(request.POST) if material_form.is_valid(): obj = material_form.save() obj.project_id = proj obj.save() return HttpResponseRedirect('/projects/' + projectid + '/purchases' + "?success=1") else: return render(request, "material.html", { 'proj': proj, 'form': material_form, 'submenus': submenus })
def edit_invoice(request, invoiceid): inv = get_object_or_404(Expense, pk=invoiceid) proj = inv.project_id projectid = format(proj.id) names = ['Material Purchase', 'Make Payment', 'Invoices', 'Payments'] links = [ '/projects/' + projectid + '/purchases', '/projects/' + projectid + '/payments', '/projects/' + projectid + '/invoices', '/projects/' + projectid + '/allpayments' ] submenus = create_sub(names, links) context = {'proj_selected': 'current'} if len(request.POST) <= 0: data = { "date": inv.date, "invoice_no": inv.invoice_no, "particulars": inv.particulars, "amount": inv.amount, "balance": inv.balance, "paid_details": inv.paid_details, "paid_date": inv.paid_date, "project_id": inv.project_id, "dealer_id": format(inv.dealer_id.id), "category_id": format(inv.category_id.id), "remarks": inv.remarks } form = MaterialForm(data) context.update({ 'title': 'Update Invoice Details', 'form': form, 'submenus': submenus }) return render(request, "edit.html", context) else: form = MaterialForm(request.POST) if form.is_valid(): cd = form.cleaned_data for key in cd: setattr(inv, key, cd.get(key)) inv.save() return HttpResponseRedirect("/projects/" + projectid + "/invoices?success=1") else: context.update({ 'title': 'Update Invoice Details', 'form': form, 'submenus': submenus }) return render(request, "edit.html", context)
def material_purchase(request,projectid): names= ['Material Purchase','Make Payment','Invoices','Payments'] links = ['/projects/'+projectid+'/purchases','/projects/'+projectid+'/payments','/projects/'+projectid+'/invoices','/projects/'+projectid+'/allpayments'] submenus = create_sub(names,links) proj = Project.objects.get(pk=projectid) if len(request.POST) <= 0: material_form = MaterialForm() #If the page is loaded after a successful submission success = request.GET.get('success') return render(request , "material.html", {'proj':proj,'submenus':submenus,'success':success,'form':material_form}) else : material_form = MaterialForm(request.POST) if material_form.is_valid(): obj = material_form.save() obj.project_id = proj obj.save() return HttpResponseRedirect('/projects/'+projectid+'/purchases'+"?success=1") else: return render(request , "material.html", {'proj':proj,'form':material_form,'submenus':submenus})