def new_job(request): # LOGGEDIN, ADMIN form = new_job_form if request.method == 'POST': form = new_job_form(request.POST) if form.is_valid(): Name = form.cleaned_data['Name'] Email = form.cleaned_data['Email'] Phone = form.cleaned_data['Phone'] Address = form.cleaned_data['Address'] Note = form.cleaned_data['Note'] job_id = re.sub('\s+', '', Address) job = Jobs.objects.create(name=Name, email=Email, phone=Phone, address=Address, job_id=job_id) Notes.objects.create(Title='First Note', Text=Note, job=job) return redirect(reverse('job', kwargs={'job_id': job_id})) if check_permissions(request, 2) == True: pass else: return check_permissions(request, 2) return check_and_render(request, 'Jobs/new_job_form.html', {'form': form})
def update_job(request, job_id, status): # LOGGEDIN ADMIN if request.method == 'GET': if check_permissions(request, 2) == True: pass else: return check_permissions(request, 2) job = Jobs.objects.get(job_id=job_id) if status == 'ongoing': job.status = status job.save() return redirect(reverse('job', kwargs={'job_id': job.job_id})) elif status == 'completed': job.status = status job.save() return redirect(reverse('job', kwargs={'job_id': job.job_id})) elif status == 'quote': job.status = status job.save() return redirect(reverse('job', kwargs={'job_id': job.job_id})) else: return HttpResponse('How about no?')
def schedule_item(request, function, pk): scheduled_item = Scheduled_items.objects.get(pk=pk) job = scheduled_item.job if request.method == 'POST': if check_permissions(request, 2) == True: pass else: return check_permissions(request, 2) if function == 'update': form = update_scheduled_item_date_form(request.POST) if form.is_valid(): scheduled_item.date_1=form.cleaned_data['update_date_1'] scheduled_item.save() if form.cleaned_data['update_date_2']: scheduled_item.date_2=form.cleaned_data['update_date_2'] scheduled_item.save() elif function == 'delete': if check_permissions(request, 3) == True: pass else: return check_permissions(request, 3) scheduled_item.delete() else: return HttpResponse('how about no?') return redirect(reverse('job', kwargs={'job_id':job.job_id}))
def delete(request, model=None, pk=None): if request.session['logged_in'] == True: if check_permissions(request, 3) == True: pass else: return check_permissions(request, 3) if request.META['SERVER_NAME'] == 'testserver': previous_page = reverse('homepage') # this is what happens in the unit tests. The redirect is tested in the FTs else: previous_page = request.META['HTTP_REFERER'] # does note exist when unit testing if model and pk: if model == 'Shopping_list_items': item = Shopping_list_items.objects.filter(pk=pk).first() item.delete() elif model == 'Acquired_Item': item = Items.objects.filter(pk=pk).first() # REFRACT - del buttons on 'acquired items' should go straight to delete model=Items item.delete() elif model == 'Items': item = Items.objects.filter(pk=pk).first() item.delete() elif model == 'Notes': item = Notes.objects.filter(pk=pk).first() item.delete() return redirect(previous_page) return redirect(reverse('homepage')) # this is the redirect for all the non-job object deletions
def purchase_order(request, job_id=None): #SNAGGING, CONDITIONAL VALIDATION if request.method == 'POST': if check_permissions(request, 2) == True: pass else: return check_permissions(request, 2) form = purchase_order_form(request.POST) if form.is_valid(): supplier = form.cleaned_data['Supplier'] supplier_ref = form.cleaned_data['Supplier_ref'] new_purchase_order = Purchase_orders.objects.create(supplier=supplier, supplier_ref=supplier_ref) for number in range(1, 11): if form.cleaned_data[f'item_{number}_description'] != '': description = form.cleaned_data[f'item_{number}_description'] fullname = form.cleaned_data[f'item_{number}_fullname'] price = form.cleaned_data[f'item_{number}_price'] job = form.cleaned_data[f'item_{number}_job'] delivery_location = form.cleaned_data[f'item_{number}_delivery_location'] delivery_date = form.cleaned_data[f'item_{number}_delivery_date'] quantity = form.cleaned_data[f'item_{number}_quantity'] status='ORDERED' order_date = settings.NOW PO = new_purchase_order job = job Items.objects.create( description = description, fullname = fullname, delivery_location = delivery_location, price = price, status = status, order_date = order_date, delivery_date = delivery_date, quantity = quantity, PO=PO, job=job ) else: pass if job_id: return redirect(reverse('job', kwargs={'job_id':job_id})) else: return redirect(reverse('homepage')) else: print(form.errors) else: return HttpResponse('how about no?')
def mark_showroom(request, pk): if check_permissions(request, 1) == True: pass else: return check_permissions(request, 1) item = Items.objects.filter(pk=pk).first() item.status='IN SHOWROOM' item.save() return redirect(reverse('homepage'))
def reject_delivery(request, pk): # VALIDATION if request.method == 'POST': if check_permissions(request, 1) == True: pass else: return check_permissions(request, 1) form = reject_delivery_form(request.POST) item = Items.objects.filter(pk=pk).first() job = item.job if form.is_valid(): if form.cleaned_data['reschedule_date']: # item has been rescheduled note_text = form.cleaned_data['note'] reschedule_date = form.cleaned_data['reschedule_date'] item.delivery_date = reschedule_date item.save() Notes.objects.create( Title = f'ITEM REJECTED - {item.description}', Text = f'{note_text} || rescheduled for delivery on {reschedule_date}', job = job ) messages.add_message(request, messages.INFO, f'{item.description} rejected') return redirect(reverse('homepage')) elif form.cleaned_data['reschedule_date'] == None: # item is totally cancelled note_text = form.cleaned_data['note'] item.delete() Notes.objects.create( Title = f'ITEM REJECTED - {item.description}', Text = f'{note_text} || NOT RESCHEDULED', job=job ) messages.add_message(request, messages.INFO, f'{item.description} rejected') return redirect(reverse('homepage')) else: print(form.errors)
def new_schedule_item(request, job_id): if request.method == 'POST': if check_permissions(request, 2) == True: pass else: return check_permissions(request, 2) form = new_scheduled_item_form(request.POST) if form.is_valid(): description = form.cleaned_data['description'] date_1 = form.cleaned_data['date_1'] date_2 = form.cleaned_data['date_2'] quantity = form.cleaned_data['quantity'] job = Jobs.objects.filter(job_id=job_id).first() if date_2 == None: date_2 = date_1 date_1_string = date_1.strftime('%Y/%d/%m') new_schedule_item_message = f'"{description}" successfully scheduled for {date_1_string}' else: date_1_string = date_1.strftime('%Y/%d/%m') date_2_string = date_2.strftime('%Y/%d/%m') new_schedule_item_message = f'"{description}" successfully scheduled for {date_1_string} - {date_2_string}' Scheduled_items.objects.create( description = description, date_1 = date_1, date_2 = date_2, quantity = quantity, job = job ) messages.add_message(request, messages.INFO, new_schedule_item_message) return redirect(reverse('job', kwargs={'job_id':job_id})) else: print(form.errors) else: return HttpResponse('how about no?')
def update_PO_supplier_ref(request, pk): if request.method == 'POST': if check_permissions(request, 3) == True: pass else: return check_permissions(request, 3) form = update_PO_supplier_ref_form(request.POST) if form.is_valid(): PO = Purchase_orders.objects.filter(pk=pk).first() new_ref = form.cleaned_data['new_supplier_ref'] PO.supplier_ref = new_ref PO.save() return redirect(reverse('purchase_orders', kwargs={'order_no':PO.id}))
def purchase_orders(request, order_no=None): if order_no: purchase_order = Purchase_orders.objects.filter(id=order_no).first() purchase_order_no = purchase_order.id+4000 item_list = [] for item in Items.objects.filter(PO=purchase_order): item_list.append(item) context = { 'purchase_order':purchase_order, 'item_list':item_list, 'purchase_order_no':purchase_order_no, 'update_PO_supplier_ref_form':update_PO_supplier_ref_form } if check_permissions(request, 2) == True: pass else: return check_permissions(request, 2) return check_and_render(request, 'Item_Flow/purchase_order.html', context) if request.method == 'POST': form = purchase_order_choice_form(request.POST) if form.is_valid(): purchase_order = form.cleaned_data['purchase_order_number'] return redirect(reverse('purchase_orders', kwargs={'order_no':purchase_order.id})) context = { 'purchase_order_choice_form':purchase_order_choice_form } if check_permissions(request, 2) == True: pass else: return check_permissions(request, 2) return check_and_render(request, 'Item_Flow/purchase_orders.html', context)
def delete_job(request): if check_permissions(request, 3) == True: pass else: return check_permissions(request, 3) context = {'delete_job_form': delete_job_form} if request.method == 'POST': form = delete_job_form(request.POST) if form.is_valid(): delete_job_address = form.cleaned_data['job_deletion_selection'] security_field_1 = form.cleaned_data['security_field_1'] security_field_2 = form.cleaned_data['security_field_2'] if str(delete_job_address) == str(security_field_1) == str( security_field_2): job = Jobs.objects.filter(address=delete_job_address).first() Shopping_list_items_to_delete = Shopping_list_items.objects.filter( job=job) Acquired_items_to_delete = Items.objects.filter( job=job).filter(status='ACQUIRED') Notes_to_delete = Notes.objects.filter(job=job) Schedule_items_to_delete = Scheduled_items.objects.filter( job=job) for item in Shopping_list_items_to_delete: item.delete() for item in Acquired_items_to_delete: item.delete() for item in Notes_to_delete: item.delete() for item in Schedule_items_to_delete: item.delete() Purchase_order_items_left = Items.objects.filter(job=job) for item in Purchase_order_items_left: item.job = None item.description = f'{item.description} --> {job.address}' item.save() job.delete() messages.add_message(request, messages.INFO, f'{job.address} JOB DELETED') return redirect(reverse('homepage')) else: messages.add_message( request, messages.INFO, 'security fields did not match, nothing deleted') return redirect(reverse('delete_job')) else: print(form.errors) # for test debugging return check_and_render(request, 'Jobs/delete_job.html', context)