def verify_order(request, pk=None): order = get_object_or_404(models.Order, pk=pk) form = AuthenticateForm(request.POST) if form.is_valid(): order.status = 'order' order.validated_by = form.cleaned_data['user'] order.save() return HttpResponseRedirect('/inventory/order-detail/{}'.format(pk))
class OrderDetailView( ContextMixin, ConfigMixin, MultiPageDocument, DetailView): model = models.Order template_name = os.path.join('inventory', 'order', 'detail.html') extra_context = { 'title': 'Purchase Order', 'form': AuthenticateForm() } page_length=20 def get_multipage_queryset(self): self.get_object() return models.OrderItem.objects.filter(order=self.object) def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) context['pdf_link'] =True if self.object.status == "draft": context['actions'] = [ { 'name': 'Verify Order', 'url': '/inventory/order/{}/verify'.format( self.object.pk) }, ] context['title'] = "Purchase Order(Draft)" return context
def equipment_requisition_authorize(request, pk=None): req = get_object_or_404(models.EquipmentRequisition, pk=pk) redirect_path = reverse_lazy('services:equipment-requisition-detail', kwargs={'pk': pk}) form = AuthenticateForm(request.POST) if form.is_valid(): usr = form.cleaned_data['user'] authenticated = authenticate(username=usr.username, password=form.cleaned_data['password']) if authenticated: if not hasattr(usr, 'employee'): return HttpResponseRedirect(redirect_path) req.authorized_by = usr.employee req.save() return HttpResponseRedirect( reverse_lazy('services:equipment-requisition-list')) return HttpResponse(request.path)
class QuotaionDetailView(ContextMixin, ConfigMixin, MultiPageDocument, DetailView): model = Invoice template_name = os.path.join("invoicing", "quotation", 'detail.html') page_length = 16 extra_context = {'pdf_link': True, 'validate_form': AuthenticateForm()} def get_multipage_queryset(self): return InvoiceLine.objects.filter(invoice=Invoice.objects.get( pk=self.kwargs['pk']))
def verify_invoice(request, pk=None): inv = get_object_or_404(Invoice, pk=pk) if inv.status == "quotation": inv.draft = False inv.save() return HttpResponseRedirect( '/invoicing/quotation-detail/{}'.format(pk)) form = AuthenticateForm(request.POST) if form.is_valid(): inv.draft = False inv.save() if inv.status == "invoice": inv.create_entry() inv.invoice_validated_by = form.cleaned_data['user'] inv.save() return HttpResponseRedirect('/invoicing/invoice-detail/{}'.format(pk))
def equipment_requisition_release(request, pk=None): req = get_object_or_404(models.EquipmentRequisition, pk=pk) redirect_path = reverse_lazy('services:equipment-requisition-detail', kwargs={'pk': pk}) form = AuthenticateForm(request.POST) if form.is_valid(): usr = form.cleaned_data['user'] authenticated = authenticate(username=usr.username, password=form.cleaned_data['password']) if authenticated: if not hasattr(usr, 'employee'): messages.info( request, 'The selected user cannot authorize/release a requisition') return HttpResponseRedirect( f"/services/equipment-requisition-auth-view/{pk}") req.released_by = usr.employee req.save() return HttpResponseRedirect(redirect_path) messages.info(request, 'The form submitted was invalid') return HttpResponseRedirect( f"/services/equipment-requisition-auth-view/{pk}")
def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) context['authorize_form'] = AuthenticateForm() context['release_form'] = AuthenticateForm() return context