def create(request): if request.method == 'POST': contacts = ContactList.post_dict(request.POST) form = CustomerForm(request.POST) if form.is_valid(): customer = form.save() msg = customer.contact_list.update_contacts(contacts) if msg: messages.warning(request, msg) History.created_history(customer, request.user) messages.success(request, 'Customer created.') return redirect('customers:update', customer.pk) else: contacts = {} form = CustomerForm() data = { 'contacts': contacts, 'form': form, } return render_to_response( 'customers/create.html', data, context_instance=RequestContext(request), )
def create(request, customer_id): customer = get_object_or_404(Customer, pk=customer_id) if request.method == 'POST': contacts = ContactList.post_dict(request.POST) form = QuotationForm(request.POST) if form.is_valid(): quotation = form.save() msg = quotation.contact_list.update_contacts(contacts) if msg: messages.warning(request, msg) else: messages.success(request, 'Customer created') History.created_history(quotation, request.user) messages.success(request, 'Quotation created.') return redirect('quotations:update', quotation.pk) else: contacts = {} form = QuotationForm(initial={'customer': customer_id}) data = { 'contacts': contacts, 'form': form, } return render_to_response( 'quotations/create.html', data, context_instance=RequestContext(request), )
def history_file_save(request): """ Сохранение данных в базу""" if request.POST: if 'excel_file_data' not in request.session: error_message = 'Данные файла отсуствуют' return JsonResponse({'message': error_message}, status=400) user = request.user upload_save = UploadHistory(user_info=user.last_name + ' ' + user.first_name, file_name=request.FILES["file"], file_path=request.FILES["file"]) History.objects.all().delete() sort = 1 result_data = json.loads(request.session['excel_file_data']) excel_headers_list = json.loads(request.session['excel_headers']) for data in result_data: check_history = History.objects.filter( sa_code=data[excel_headers_list.index('SA_code')]).exists() if not check_history: save_history = History( branch_name=data[excel_headers_list.index('Branch_Name')], sa_code=data[excel_headers_list.index('SA_code')].lower(), full_name=data[excel_headers_list.index('SA_Name')], kpi_val=json.dumps(data[3]), kpi_key=json.dumps(data[4]), progress_val=json.dumps(data[5]), progress_key=json.dumps(data[6]), sort_id=sort) save_history.save() sort += 1 else: error_message = 'У вас дублирующий SA код {} в файле. Исправьте или удалите запись'.format( data[excel_headers_list.index('SA_code')]) return JsonResponse( { 'message': error_message, 'title': 'Ошибка', 'status': 'error' }, status=200) upload_save.save() return JsonResponse( { 'message': 'Данные успешно сохранены', 'title': 'Успешно', 'status': 'success' }, status=200) else: return JsonResponse( { 'message': 'Неподдерживаемый метод get', 'title': 'Ошибка', 'status': 'error' }, status=400)
def update(request, stock_id): stock = get_object_or_404(Stock, pk=stock_id) if request.method == "POST": form = StockForm(request.POST, instance=stock) if form.is_valid(): past_stock = Stock.objects.get(pk=stock_id) updated_stock = form.save() History.updated_history(past_stock, updated_stock, request.user) messages.success(request, "Stock updated.") else: form = StockForm(instance=stock) data = {"form": form, "stock": stock} return render_to_response("stocks/update.html", data, context_instance=RequestContext(request))
def create(request): if request.method == "POST": form = StockForm(request.POST) if form.is_valid(): stock = form.save() History.created_history(stock, request.user) messages.success(request, "Stock created.") if "create" in request.POST: return redirect("stocks:update", stock.pk) else: return redirect("stocks:create") else: form = StockForm() data = {"form": form} return render_to_response("stocks/create.html", data, context_instance=RequestContext(request))
def customer(request): customers = Customer.objects.all() if request.method == 'POST': form = CustomerForm(request.POST) if form.is_valid(): customer = form.save() History.created_history(customer, request.user) return redirect('quotations:create', customer.pk) else: form = CustomerForm() data = { 'customers': customers, 'form': form, } return render_to_response( 'quotations/customer.html', data, context_instance=RequestContext(request), )
def create(request, sale_type, customer_id): customer = get_object_or_404(Customer, pk=customer_id) if request.method == 'POST': form = sale_form(sale_type, request.POST) if form.is_valid(): sale = form.save() History.created_history(sale, request.user) messages.success(request, 'Sale created') return redirect('sales:update', sale_type, sale.pk) else: form = sale_form(sale_type, initial={'customer': customer.pk}) data = { 'form': form, 'sale_type': sale_type, } return render_to_response( 'sales/create.html', data, context_instance=RequestContext(request), )
def update(request, stock_id): stock = get_object_or_404(Stock, pk=stock_id) if request.method == 'POST': form = StockForm(request.POST, instance=stock) if form.is_valid(): past_stock = Stock.objects.get(pk=stock_id) updated_stock = form.save() History.updated_history(past_stock, updated_stock, request.user) messages.success(request, 'Stock updated.') else: form = StockForm(instance=stock) data = { 'form': form, 'stock': stock, } return render_to_response( 'stocks/update.html', data, context_instance=RequestContext(request), )
def create(request): if request.method == 'POST': form = StockForm(request.POST) if form.is_valid(): stock = form.save() History.created_history(stock, request.user) messages.success(request, 'Stock created.') if 'create' in request.POST: return redirect('stocks:update', stock.pk) else: return redirect('stocks:create') else: form = StockForm() data = { 'form': form, } return render_to_response( 'stocks/create.html', data, context_instance=RequestContext(request), )
def create_foreign(request): if request.method == 'POST': contacts = ContactList.post_dict(request.POST) form = ForeignSupplierForm(request.POST) if form.is_valid(): foreign_supplier = form.save() msg = foreign_supplier.contact_list.update_contacts(contacts) if msg: messages.warning(request, msg) History.created_history(foreign_supplier, request.user) messages.success(request, 'Foreign Supplier created.') if '_popup' in request.GET: popup_data = { 'obj': escape(foreign_supplier), 'pk_value': escape(foreign_supplier.id), } return render_to_response( 'home/close_popup.html', popup_data, context_instance=RequestContext(request), ) return redirect('suppliers:update-foreign', foreign_supplier.pk) else: contacts = {} form = ForeignSupplierForm() data = { 'contacts': contacts, 'form': form, } return render_to_response( 'suppliers/foreign/create.html', data, context_instance=RequestContext(request), )
def update_local(request, supplier_id): local_supplier = get_object_or_404(LocalSupplier, pk=supplier_id) initial_data = { 'city': local_supplier.city.name, } if request.method == 'POST': contacts = local_supplier.contact_list.post_dict(request.POST) form = LocalSupplierForm(request.POST, instance=local_supplier) if form.is_valid(): past_supplier = LocalSupplier.objects.get(pk=supplier_id) updated_supplier = form.save() msg = updated_supplier.contact_list.update_contacts(contacts) if msg: messages.warning(request, msg) History.updated_history(past_supplier, updated_supplier, request.user) messages.success(request, 'Local Supplier updated') else: try: contacts = local_supplier.contact_list.get_dict() except AttributeError: local_supplier.save() contacts = {} form = LocalSupplierForm(initial=initial_data, instance=local_supplier) data = { 'contacts': contacts, 'form': form, 'local_supplier': local_supplier, } return render_to_response( 'suppliers/local/update.html', data, context_instance=RequestContext(request), )