예제 #1
0
def change_request(request):
    """
    This view enables the user to add a change request or view a change request put by him
    Argument: Http Request
    Return: Render change_form.html
    """
    if request.method == 'POST':
        sessiondata = ChangeRequestForm(request.POST)
        purchase_order_of_session = sessiondata.data['purchase_order']
        session = sessiondata.data['session']
        object = VoucherId.objects.filter(session_id = session).\
        filter(purchase_order_of_session = purchase_order_of_session).values()
        if object:
            voucherid = VoucherId.objects.\
            filter(purchase_order_of_session=purchase_order_of_session,\
            session_id=session).values('purchase_order_id')
            for value in voucherid:
                purchase_order = value['purchase_order_id']
            bill = Bill.objects.values('grand_total').\
            get(purchase_order=purchase_order)
            surcharge = TaxesApplied.objects.values('surcharge__tax_name',\
                'id','tax').filter(purchase_order_id = purchase_order)
            details = VoucherId.objects.values\
            ('purchase_order__buyer__first_name',\
                'purchase_order__buyer__last_name',
                'purchase_order__buyer__customer__address__street_address',\
                'purchase_order__buyer__customer__title',
                'purchase_order__buyer__customer__address__district',\
                'purchase_order__mode_of_payment__method',
                'purchase_order__cheque_dd_number',\
                'purchase_order__cheque_dd_date').\
                filter(purchase_order_of_session=purchase_order_of_session)[0]
            session_data = FinancialSession.objects.values(\
                'session_start_date','session_end_date').get(id=session)
            messages = "Order" + " : " + purchase_order_of_session +\
            " and Session" + " : " + str(session_data['session_start_date']) +\
            ":" + str(session_data['session_end_date'])
            request_status = request_notify()
            return render(request,'catalog/change_form.html',\
                {'details': details,'order_id':purchase_order_of_session,\
                'session':session,'surcharge':surcharge,'bill':bill,\
                'messages':messages, 'request':request_status})
        else:
            form = ChangeRequestForm()
            errors = "No such purchase order number in selected session"
            request_status = request_notify()
            temp = {"form" : form , "errors" : errors,\
            'request':request_status}

            return render(request, 'catalog/change_request.html', temp)
    else:
        form = ChangeRequestForm()
        request_status = request_notify()
        return render(request, 'catalog/change_request.html', \
            {'form':form,'request':request_status})
예제 #2
0
 def view_results(self, request):
     """
     Converting data from dict to list form so that it can be render 
     easily.
     Calling template to be rendered.
     Argument:Http Request
     Return:Render Search Result
     """
     generated_data_list = []
     for data in self.details:
         temporary = []
         for field in self.fields_list:
             temporary.append(data[field])
         generated_data_list.append(temporary)
     flag = 0
     suspense_flag = 0
     if 'proforma' in request.GET:
         flag = 1
     if 'Client' not in request.GET and 'proforma' not in request.GET:
         try:
             voucherid = VoucherId.objects.values('purchase_order').\
             filter(purchase_order_of_session=self.title)[0]
             suspense = SuspenseOrder.objects.filter(
                 purchase_order=voucherid['purchase_order'])
             if suspense:
                 suspense_flag = 1
         except:
             pass
     request_status = request_notify()
     temp = {'client':self.selected_fields_client,
         'order':self.selected_fields_order, 'result':generated_data_list,
         'title':self.title,'order_id':self.purchase_order_id,
         'records':self.results,'request':request_status, 'flag':flag,\
         'suspense_flag':suspense_flag}
     return render(request, 'reports/search_result.html', temp)
예제 #3
0
def index(request):
    """
    It lists all the products and the user can select any product
    and can add them to the cart.
    Argument: Http Request
    Return: Render index.html
    """
    """error = {}
    categorylist = Category.objects.all()

    if categorylist.count() == 0:
        nocategory = True
        return render(request, 'catalog.html', {'nocategory': nocategory})
    productlist = Product.objects.all();

    if productlist.count() == 0:
        noproduct = True
        return render(request, 'catalog.html', {'noproduct': noproduct})

    return render(request,'catalog.html', {'productlist': productlist,
               'categorylist': categorylist})

    pass"""
    request_status = request_notify()
    return render(request, 'index.html', {'request': request_status})
예제 #4
0
def voucher_show(request):
    """
    This function shows the number of vouchers generated for a particular 
    order
    Argument:Http Request
    Return:Render Voucher Show
    """
    id = request.GET['order_id']
    purchase_order = PurchaseOrder.objects.get(id=id)
    voucher_no_list = []
    voucher_obj_distinct = []
    temp_voucherid = VoucherId.objects.values('voucher_no').\
    filter(purchase_order=purchase_order)[0]
    message = 'Voucher'
    if temp_voucherid['voucher_no'] == 0:
        message = "No voucher to display"
    voucherid = VoucherId.objects.values('purchase_order','purchased_item',\
        'voucher_no', 'session','purchase_order_of_session').\
    filter(purchase_order = purchase_order)
    for value in voucherid:
        if value['voucher_no'] not in voucher_no_list:
            voucher_no_list.append(value['voucher_no'])
            voucher_obj_distinct.append(value)
    suspense_order = SuspenseOrder.objects.values('voucher', 'session_id_id').\
    filter(purchase_order=id, is_cleared=1)
    request_status = request_notify()
    return render(request, 'voucher/voucher_show.html', {\
        'voucherid' : voucher_obj_distinct, 'suspense_order':suspense_order,\
        'request':request_status, 'message':message})
예제 #5
0
def select_note(request):
    """
    View to handle selection of extra notes while adding quoted order.
    argument: Http Request.
    returns: Render form for selection of note form.
    """
    quoted_order_id = request.session.get('quoted_order_id')
    form = SelectNoteForm(initial={'quoted_order': quoted_order_id})
    request_status = request_notify()
    return render(request, 'bills/select_note.html', \
        {'form':form, 'request':request_status})
예제 #6
0
def proforma_details(request):
    """
    displays the details of the proforma order of the client
    Argument:Http Request
    Return:Render Proforma Details
    """

    order_id = request.GET['order_id']
    quotes = QuotedItem.objects.filter(quoted_order__id=order_id)
    request_status = request_notify()
    return render(request,'reports/proforma_details.html',\
        {'quotes':quotes,'order_id':order_id,'request':request_status})
예제 #7
0
def details(request):
    """
    displays the details of the purchase of the client
    Argument:Http Request
    Return:Render Order Details
    """

    order_id = request.GET['order_id']
    purchases = PurchasedItem.objects.filter(purchase_order__id=order_id)
    request_status = request_notify()
    return render(request,'reports/history_details.html',\
        {'purchases':purchases,'order_id':order_id,'request':request_status})
예제 #8
0
def list_saved_registers(request):
    """
    List saved registers
    Argument:Http Request
    Return:Render List of Registers
    """
    local_url = settings.LOCAL_URL
    list_of_registers = SavedRegisters.objects.\
    values('title','selected_fields')
    request_status = request_notify()
    return render(request,'reports/list_of_registers.html', \
        {'list_of_registers':list_of_registers,'local_url': local_url,\
        'request':request_status})
예제 #9
0
def search_form(request):
    """
    View to display "search.html" i.e. the search interface or form.
    
    First it'll check which type of request is i.e; 'search' request or 
    'generate register' request. On the basis of that, it'll assign code
    to search_type_code which will be used in template.

    It'll raise an exception if anyone give invalid value in 'type'.
    Argument:Http Request
    Return:Render Search
    """
    try:
        if request.GET['type'] == 'search':
            submit_url = reverse('search_result')
            search_type_code = '1'
            client_form = ClientForm()
            order_form = OrderForm()
            request_status = request_notify()
            temp = {'client_form':client_form,'order_form':order_form, 
            'code':search_type_code,
            'url':submit_url,
            'request':request_status    }
        elif request.GET['type'] == 'register':
            submit_url = reverse('view_register')
            search_type_code = '2'
            client_form = ClientForm()
            order_form = OrderForm()
            add_constraints=  AddConstraints()
            request_status = request_notify()
            temp = {'client_form':client_form,'order_form':order_form, 
            'add_constraints':add_constraints,'code':search_type_code,
            'url':submit_url,
            'request':request_status    }
        else:
            return HttpResponse('<h1>Page not found</h1>')
    except:
        return HttpResponse('<h1>Invalid URL</h1>')
    return render(request, 'reports/search.html',temp)
예제 #10
0
def list_products(request):
    """
    This view lists products for viewing purpose
    Argument: Http Request
    Return: Render catalog page
    """
    if request.method == 'POST':
        form = ProductListForm(request.POST)
        if form.is_valid():
            select_lab = request.POST['select_lab']
            root_name = Category.objects.get(id=select_lab)
            all_products = Product.objects.filter(
                category__parent__parent=select_lab)
            work_type = Category.objects.filter(parent=select_lab)
            category = Category.objects.filter(parent__parent=select_lab)
            result = []
            for work in work_type:
                temp = []
                temp.append(work.name)
                work_type_category = Category.objects.filter(parent=work.id)
                temp.append(work_type_category)
                products = Product.objects.filter(
                    category__parent__parent=select_lab)
                temp.append(products)
                result.append(temp)
            return render(request, 'catalog/list_products.html', {
                'result': result,
                'root_name': root_name
            })

            # all_products = Product.objects.filter(category__parent__parent=select_lab)
            # all_categories=Category.objects.filter().order_by('name')
            # products_dict = { }
            # for one_category in all_categories:
            #     if one_category.is_leaf_node():
            #         one_category_dict = {}
            #         products_list = Product.objects.filter(category=one_category)
            #         attributes_dict = { }
            #         for one_product in products_list:
            #             attributes_list = Catalog.objects.filter(product = one_product)
            #             attributes_dict[one_product] = attributes_list
            #         one_category_dict[one_category.name] = attributes_dict
            #         products_dict[one_category.id] = one_category_dict
            # return render(request,'catalog/list_products.html',{'nodes':all_categories, \
            #     'products_dict':products_dict})
    else:
        form = ProductListForm()
        request_status = request_notify()
        return render(request,'catalog/product_list_form.html', \
        {'form':form,'request':request_status})
예제 #11
0
def history(request):
    """
    displays the purchase history of the client
    Argument:Http Request
    Return:Render Purchase History
    """

    user_id = request.GET['user_id']
    purchases = VoucherId.objects.values('purchase_order',\
        'purchase_order_of_session','purchase_order__mode_of_payment__method',\
        'purchase_order__date_time').\
        filter(purchase_order__buyer__id=user_id)
    proformas = QuotedOrderofSession.objects.values('quoted_order',\
        'quoted_order_session', 'quoted_order__date_time').\
        filter(quoted_order__buyer__id=user_id)
    request_status = request_notify()
    return render(request,'reports/purchase_history.html',\
        {'purchases':purchases,'proformas':proformas,'request':request_status})
예제 #12
0
def order_added_success(request):
    """
    This view displays Success message after order is successfully added
    Argument: Http Request
    Return: Render order_added_success.html
    """
    order_id = request.session.get('purchase_order_id')
    details = VoucherId.objects.values('purchase_order__buyer__first_name',\
        'purchase_order__buyer__last_name',
        'purchase_order__buyer__customer__address__street_address',\
        'purchase_order__buyer__customer__title',
        'purchase_order__buyer__customer__address__district',\
        'purchase_order__mode_of_payment__method',
        'purchase_order__cheque_dd_number',\
        'purchase_order__cheque_dd_date',
        'receipt_no_of_session').filter(purchase_order=order_id)[0]
    suspense_flag = 0
    suspense = SuspenseOrder.objects.filter(purchase_order=order_id)
    if suspense:
        suspense_flag = 1
    request_status = request_notify()
    return render(request,'catalog/order_added_success.html',\
        {'details': details,'order_id':order_id,'request':request_status,\
        'suspense_flag':suspense_flag})
예제 #13
0
 def view_register(self, request):
     """
     Converting data from dict to list form so that it can be 
     render easily.
     Calling template to be rendered.
     """
     generated_data_list = []
     try:
         details = self.details
     except:
         details = self.client_details
     for data in details:
         temporary = []
         if self.surcharge:
             try:
                 data['bill__grand_total']
             except:
                 error_type = "Insufficient fields"
                 error = "Total must be included in field list"
                 temp = {'type': error_type, 'message': error}
                 return render(request, 'error_page.html', temp)
         for field in self.fields_list:
             temporary.append(data[field])
         tax_pos = 0
         for val in request.GET.getlist('surcharges'):
             tax = TaxesApplied.objects.values_list('tax', flat = True).\
             filter(purchase_order = data['id']).filter(surcharge = val)
             try:
                 self.total_taxes[tax_pos] = self.total_taxes[tax_pos] + \
                 tax[0]
             except:
                 pass
             if tax:
                 temporary[-1:-1] = tax
             else:
                 temporary[-1:-1] = ['None']
             tax_pos = tax_pos + 1
         generated_data_list.append(temporary)
     number_of_fields = len(self.selected_fields_order) + len(self.\
         selected_fields_client)
     if ('Total With Taxes' in self.selected_fields_order \
         and 'Total Without Taxes' in self.selected_fields_order):
         number_of_fields -= 1
         number_of_fields = number_of_fields - self.decrement_field
     request_status = request_notify()
     temp = {'client':self.selected_fields_client,
         'order':self.selected_fields_order, 'result':generated_data_list,
         'title':self.title, 'number_of_fields':number_of_fields,'get_data':
         self.get_data, 'save_option': self.save_option,\
         'request':request_status}
     try:
         temp['grand_total'] = self.grand_total_list
     except:
         pass
     try:
         self.selected_fields_order[-1:-1] = self.surcharge
         temp['surcharge'] = self.surcharge
         self.grand_total_list[-1:-1] = self.total_taxes
     except:
         pass
     return render(request, 'reports/generated_register.html', temp)