Ejemplo n.º 1
0
def article_add(request):
    brand = helper_session_brand_pk(request)
    if request.method == 'POST':
        form = FormAddArticle(brand, data=request.POST)

        if form.is_valid():
            article = form.save(commit=False)
            article.code = helper_generate_code()
            pk_sizecategory = article.product.product_category.sizecategory.pk
            article.user = request.user
            article.brand = brand
            article.save()
            messages.success(request, 'Article successfully added')
            data_context_redirect = {
                'pk_article': article.pk,
                'pk_sizecategory': pk_sizecategory
            }
            return HttpResponseRedirect(
                reverse('aplinventory:articledetail_add',
                        kwargs=data_context_redirect))
    else:
        form = FormAddArticle(brand)

    data_context = {'form': form}
    return render(request, 'aplinventory/article/article_add.html',
                  data_context)
Ejemplo n.º 2
0
def articledetail_list_popup(request):
    brand = helper_session_brand_pk(request)
    articledetails = ArticleDetail.objects.filter(article__keep=False, brand=brand)

    query = ''
    if 'query' in request.GET:
        query = request.GET.get('query')
        articledetails = articledetails.filter(
        article__keep=False,
        # size__name__contains=query,
        article__name__icontains=query,
        brand=brand)

    paginator = Paginator(articledetails, 10)
    page = request.GET.get('page')

    try:
        articledetails = paginator.page(page)
    except PageNotAnInteger:
        articledetails = paginator.page(1)
    except EmptyPage:
        articledetails = paginator.page(paginator.num_pages)


    data_context = {
        'articledetails': articledetails, 
        'brand': brand,
        'query': query}

    return render(request, 'aplinventory/articledetail/popup/articledetail_list_popup.html', data_context)
Ejemplo n.º 3
0
def size_add(request, pk_sizecategory):
    brand = helper_session_brand_pk(request)
    sizecategory = get_object_or_404(SizeCategory, pk=pk_sizecategory)
    sizes = Size.objects.filter(size_category=sizecategory)
    if request.method == 'POST':
        form = FormAddSize(data=request.POST)
        if form.is_valid():
            size = form.save(commit=False)
            size.user = request.user
            size.brand = brand
            size.size_category = sizecategory

            # Handling size same. integrity error ...
            try:
                size.save()
                messages.success(request, 'Size successfully added')
            except IntegrityError:
                messages.warning(request, 'Size not be same !')

            return HttpResponseRedirect(
                reverse('aplinventory:size_add',
                        kwargs={'pk_sizecategory': pk_sizecategory}))
    else:
        form = FormAddSize()

    data_context = {'form': form, 'sizecategory': sizecategory, 'sizes': sizes}
    return render(request, 'aplinventory/size/size_add.html', data_context)
Ejemplo n.º 4
0
 def get(self, request, size_category_pk):
     brand = helper_session_brand_pk(request)
     size_category = get_object_or_404(SizeCategory, pk=size_category_pk)
     form = self.form_size_category_change(instance=size_category)
     self.data_context['form'] = form
     self.data_context['size_category'] = size_category
     return render(request, self.template, self.data_context)
Ejemplo n.º 5
0
def invoiceweb_list(request):
    brand = helper_session_brand_pk(request)
    if request.user.is_superuser:
        invoices = Invoice.objects.exclude(
            Q(transactiondetail=None) | Q(shipping=None)
            | Q(billing=None)).order_by('-invoice_date')
    else:
        invoices = Invoice.objects.distinct().filter(
            transactiondetail__article_brand_name=brand.name).exclude(
                Q(transactiondetail=None) | Q(shipping=None)
                | Q(billing=None)).order_by('-invoice_date')
    form = FormSearchInvoice()

    # =================================
    # Pencarian invoice dari input text
    # =================================
    if 'query' in request.GET:
        form = FormSearchInvoice(request.GET)

        if form.is_valid():
            cd = form.cleaned_data
            invoices = invoices.filter(
                Q(invoice_number__icontains=cd['query'])
                | Q(user__username__icontains=cd['query'])
                | Q(transactiondetail__article_name__icontains=cd['query'])
                | Q(category__abbv__icontains=cd['query'][0])).distinct()

    # =================================================
    # Filter invoice dari tombol filter (Version 1.0.0)
    # =================================================
    if 'status' in request.GET:
        data_status = request.GET.get('status')
        invoicestatus = get_object_or_404(InvoiceStatus, abbv=data_status)
        invoices = invoices.filter(status=invoicestatus)

    # ================================
    # Paginasi halaman (Version 1.0.0)
    # ================================
    paginator = Paginator(invoices, 20)
    page = request.GET.get('page')
    try:
        invoices = paginator.page(page)
    except PageNotAnInteger:
        invoices = paginator.page(1)
    except EmptyPage:
        invoices = paginator.page(paginator.num_pages)

    data_context = {
        'invoices': invoices,
        'form': form,
        'total_count': invoices
    }
    return render(request, 'apltransaction/invoice/invoiceweb_list.html',
                  data_context)
Ejemplo n.º 6
0
def invoiceweb_print_all(request):
    brand = helper_session_brand_pk(request)
    if request.method == 'POST':
        # ambil semua invoice dalam bentuk list
        invoices_number = request.POST.getlist('_selected_action')

        invoices = Invoice.objects.filter(invoice_number__in=invoices_number,
                                          category__abbv='W')

        # mengecek apakah status valid..
        # valid berarti sudah berisi item, shipping dan billing.
        valid = True
        for i in invoices:
            # jika transaction belum di isi data tidak valid
            if i.transactiondetail_set.count() == 0:
                valid = False

            # jika shipping belum di isi data tidak valid
            if i.shipping_set.count() == 0:
                valid = False

            # jika billing belum di isi data tidak valid
            if i.billing_set.count() == 0:
                valid = False

        # Jika invoice di seleksi
        if invoices:

            # Jika invoice valid
            if valid:
                data_context = {'invoices': invoices, 'brand': brand}
                return render(
                    request,
                    'apltransaction/invoice/invoiceweb_print_all.html',
                    data_context)

            else:
                messages.warning(
                    request,
                    'Sorry, your invoice not valid. check invoice again !')
        else:
            messages.warning(request, 'Sory, you don\'t selected any item')
    else:
        messages.warning(
            request,
            'Hei {}, f**k youuuu ! this is bad request...you stupid !'.format(
                request.user))

    return HttpResponseRedirect(reverse('apltransaction:invoiceweb_list'))
Ejemplo n.º 7
0
    def post(self, request):
        brand = helper_session_brand_pk(request)
        form = self.form_size_category_add(request.POST)
        if form.is_valid():
            size_category = form.save(commit=False)
            size_category.user = request.user
            size_category.brand = brand
            size_category.status = True
            size_category.save()
            messages.success(request, 'Size Category successfully added')
            return HttpResponseRedirect(
                reverse('aplinventory:size_add',
                        kwargs={'pk_sizecategory': size_category.pk}))

        self.data_context['form'] = form
        return render(request, self.template, self.data_context)
Ejemplo n.º 8
0
def product_add(request):
    brand = helper_session_brand_pk(request)
    if request.method == 'POST':
        form = FormAddProduct(brand, data=request.POST)
        if form.is_valid():
            product = form.save(commit=False)
            product.user = request.user
            product.brand = brand
            product.code = helper_generate_code()
            product.save()
            messages.success(request, 'Product successfully added')
            return HttpResponseRedirect(reverse('aplinventory:product_list'))
    else:
        form = FormAddProduct(brand)
    data_context = {'form': form}
    return render(request, 'aplinventory/product/product_add.html',
                  data_context)
Ejemplo n.º 9
0
    def post(self, request, size_category_pk):
        brand = helper_session_brand_pk(request)
        size_category = get_object_or_404(SizeCategory, pk=size_category_pk)
        form = self.form_size_category_change(instance=size_category,
                                              data=request.POST)

        if form.is_valid():
            size_category = form.save(commit=False)
            size_category.user = request.user
            size_category.save()
            messages.success(request, 'Size Category successfully changed.')
            return HttpResponseRedirect(
                reverse('aplinventory:sizecategory_list'))

        self.data_context['size_category'] = size_category
        self.data_context['form'] = form
        return render(request, self.template, self.data_context)
Ejemplo n.º 10
0
 def get(self, request):
     brand = helper_session_brand_pk(request)
     form = self.form_size_category_add()
     self.data_context['form'] = form
     return render(request, self.template, self.data_context)
Ejemplo n.º 11
0
def size_list(request):
    brand = helper_session_brand_pk(request)
    sizes = Size.objects.all()
    data_context = {'sizes': sizes}
    return render(request, 'aplinventory/size/size_list.html', data_context)