Exemplo n.º 1
0
def edit_user(request, pk):
    user = User.objects.get(id=pk)
    allow_customer_roles = customer_roles(request.user)
    allow_supplier_roles = supplier_roles(request.user)
    allow_transaction_roles = transaction_roles(request.user)
    allow_inventory_roles = inventory_roles(request.user)

    if request.method == 'POST':
        form = UserUpdateForm(request.POST, instance=user)
        if form.is_valid():
            form.save()
            messages.success(request, f'User Profile has been updated!')
            return redirect('user-list')
    else:
        form = UserUpdateForm(instance=user)

    return render(
        request, 'user/edit_user.html', {
            'form': form,
            'allow_customer_roles': allow_customer_roles,
            'allow_supplier_roles': allow_supplier_roles,
            'allow_transaction_roles': allow_transaction_roles,
            'allow_inventory_roles': allow_inventory_roles,
            'allow_report_roles': report_roles(request.user),
            'is_superuser': request.user.is_superuser
        })
Exemplo n.º 2
0
def new_item_stock(request):
    allow_customer_roles = customer_roles(request.user)
    allow_supplier_roles = supplier_roles(request.user)
    allow_transaction_roles = transaction_roles(request.user)
    allow_inventory_roles = inventory_roles(request.user)
    return render(
        request, 'inventory/new_item_stock.html', {
            'allow_customer_roles': allow_customer_roles,
            'allow_supplier_roles': allow_supplier_roles,
            'allow_transaction_roles': allow_transaction_roles,
            'allow_inventory_roles': allow_inventory_roles,
            'allow_report_roles': report_roles(request.user),
            'is_superuser': request.user.is_superuser
        })
Exemplo n.º 3
0
def user_list(request):
    allow_customer_roles = customer_roles(request.user)
    allow_supplier_roles = supplier_roles(request.user)
    allow_transaction_roles = transaction_roles(request.user)
    allow_inventory_roles = inventory_roles(request.user)
    all_user = User.objects.all()
    return render(
        request, 'user/users.html', {
            'all_user': all_user,
            'allow_customer_roles': allow_customer_roles,
            'allow_supplier_roles': allow_supplier_roles,
            'allow_transaction_roles': allow_transaction_roles,
            'allow_inventory_roles': allow_inventory_roles,
            'allow_report_roles': report_roles(request.user),
            'is_superuser': request.user.is_superuser
        })
Exemplo n.º 4
0
def categories(request):
    permission = inventory_form_roles(request.user)
    allow_customer_roles = customer_roles(request.user)
    allow_supplier_roles = supplier_roles(request.user)
    allow_transaction_roles = transaction_roles(request.user)
    allow_inventory_roles = inventory_roles(request.user)
    main_categories = Category.objects.all()
    sub_categories = SubCategory.objects.all()
    return render(
        request, 'inventory/category_and_type.html', {
            'allow_customer_roles': allow_customer_roles,
            'allow_supplier_roles': allow_supplier_roles,
            'allow_transaction_roles': allow_transaction_roles,
            'allow_inventory_roles': allow_inventory_roles,
            'allow_report_roles': report_roles(request.user),
            'is_superuser': request.user.is_superuser,
            'main_categories': main_categories,
            'sub_categories': sub_categories
        })
Exemplo n.º 5
0
def edit_item(request, pk):
    allow_customer_roles = customer_roles(request.user)
    allow_supplier_roles = supplier_roles(request.user)
    allow_transaction_roles = transaction_roles(request.user)
    allow_inventory_roles = inventory_roles(request.user)
    all_detail = Add_products.objects.filter(id=pk).first()
    main_categories = Category.objects.all()
    sub_categories = SubCategory.objects.filter(
        main_category_id=all_detail.main_category_id)
    if request.method == "POST":
        main_category = request.POST.get('main_category')
        sub_category = request.POST.get('sub_category')
        size = request.POST.get('size')
        product_desc = request.POST.get('product_desc')
        select_unit = request.POST['unit']
        opening_stock = request.POST.get('opening_stock')
        main = Category.objects.filter(id=main_category).first()
        sub = SubCategory.objects.filter(id=sub_category).first()
        product_name = main.main + " " + sub.sub + " " + size
        all_detail.sub_category_id = sub
        all_detail.sub_category = sub.sub
        all_detail.size = size
        all_detail.product_name = product_name
        all_detail.product_desc = product_desc
        all_detail.unit = select_unit
        all_detail.opening_stock = opening_stock
        all_detail.save()
    return render(
        request, 'inventory/edit_item.html', {
            'all_detail': all_detail,
            'pk': pk,
            'allow_customer_roles': allow_customer_roles,
            'allow_supplier_roles': allow_supplier_roles,
            'allow_transaction_roles': allow_transaction_roles,
            'allow_inventory_roles': allow_inventory_roles,
            'allow_report_roles': report_roles(request.user),
            'is_superuser': request.user.is_superuser,
            'main_categories': main_categories,
            'sub_categories': sub_categories
        })
Exemplo n.º 6
0
def item_stock(request):
    permission = inventory_form_roles(request.user)
    allow_customer_roles = customer_roles(request.user)
    allow_supplier_roles = supplier_roles(request.user)
    allow_transaction_roles = transaction_roles(request.user)
    allow_inventory_roles = inventory_roles(request.user)
    cursor = connection.cursor()
    cursor.execute(
        '''Select itemID,Size,item_code, item_name,Item_description,Unit,Size,SUM(quantity) As qty, main_category, sub_category From (
                    Select 'Opening Stock' As TranType,ID As ItemID, Size,Product_Code As Item_Code,Product_Name As Item_name,Product_desc As Item_description,Unit As unit,Opening_Stock as Quantity, main_category, sub_category
                    From inventory_add_products
                    union all
                    Select 'Purchase' As TranType,P.ID As ItemID,P.Size,P.Product_Code,P.Product_name,P.Product_desc,P.unit,Quantity,P.main_category, P.sub_category
                    From transaction_purchasedetail H Inner join inventory_add_products P On H.item_id_id = P.id
                    union All
                    Select 'Purchase Return' As TranType,P.ID As ItemID,P.Size,P.Product_Code,P.Product_name,P.Product_desc,P.unit,Quantity * -1,P.main_category, P.sub_category
                    From transaction_purchasereturndetail H Inner join inventory_add_products P On H.item_id_id = P.id
                    union all
                    Select 'Sale' As TranType,P.ID AS ItemID,P.Size,P.Product_Code,P.Product_name,P.Product_desc,P.unit,Quantity * -1,P.main_category, P.sub_category
                    From transaction_saledetail H Inner join inventory_add_products P On H.item_id_id = P.id
                    union all
                    Select 'Sale Return' As TranType,P.ID AS ItemID,P.Size,P.Product_Code,P.Product_name,P.Product_desc,P.unit,Quantity,P.main_category, P.sub_category
                    From transaction_salereturndetail H Inner join inventory_add_products P On H.item_id_id = P.id
                    ) As tblTemp
                    Group by Item_Code
                    ''')
    row = cursor.fetchall()
    return render(
        request, 'inventory/item_stock.html', {
            'row': row,
            'allow_customer_roles': allow_customer_roles,
            'allow_supplier_roles': allow_supplier_roles,
            'allow_transaction_roles': allow_transaction_roles,
            'permission': permission,
            'allow_inventory_roles': allow_inventory_roles,
            'allow_report_roles': report_roles(request.user),
            'is_superuser': request.user.is_superuser
        })
Exemplo n.º 7
0
def register(request):
    allow_customer_roles = customer_roles(request.user)
    allow_supplier_roles = supplier_roles(request.user)
    allow_transaction_roles = transaction_roles(request.user)
    allow_inventory_roles = inventory_roles(request.user)
    if request.method == 'POST':
        form = RegistrationFrom(request.POST)
        if form.is_valid():
            form.save()
            username = request.POST.getlist('username')[0]
            user = User.objects.get(username=username)
            for i in range(11, 16):
                roles = UserRoles.objects.create(user_id=user,
                                                 form_name="Customer",
                                                 form_id=0,
                                                 child_form=i)
                roles.save()

            for i in range(21, 26):
                roles = UserRoles.objects.create(user_id=user,
                                                 form_name="Supplier",
                                                 form_id=0,
                                                 child_form=i)
                roles.save()

            for i in range(31, 41):
                if i == 40:
                    roles = UserRoles.objects.create(user_id=user,
                                                     form_name="Transaction",
                                                     form_id=0,
                                                     child_form=310)
                    roles.save()
                else:
                    roles = UserRoles.objects.create(user_id=user,
                                                     form_name="Transaction",
                                                     form_id=0,
                                                     child_form=i)
                    roles.save()

            roles = UserRoles.objects.create(user_id=user,
                                             form_name="Inventory",
                                             form_id=0,
                                             child_form=41)
            roles.save()

            roles = UserRoles.objects.create(user_id=user,
                                             form_name="Reports",
                                             form_id=0,
                                             child_form=0)
            roles.save()

            messages.success(
                request,
                f'Your account has been created! You are now able to log in')
            return redirect('login')
    else:
        form = RegistrationFrom
    return render(
        request, 'user/register.html', {
            'form': form,
            'allow_customer_roles': allow_customer_roles,
            'allow_supplier_roles': allow_supplier_roles,
            'allow_transaction_roles': allow_transaction_roles,
            'allow_inventory_roles': allow_inventory_roles,
            'allow_report_roles': report_roles(request.user),
            'is_superuser': request.user.is_superuser
        })
Exemplo n.º 8
0
def user_roles(request, pk):
    allow_customer_roles = customer_roles(request.user)
    allow_supplier_roles = supplier_roles(request.user)
    allow_transaction_roles = transaction_roles(request.user)
    allow_inventory_roles = inventory_roles(request.user)
    user = User.objects.filter(id=pk)
    user_id = User.objects.get(id=pk)
    user_id = Q(user_id=pk)

    form_name = Q(form_name="Customer")
    allow_role = UserRoles.objects.filter(user_id, form_name).all()

    form_name_supplier = Q(form_name="Supplier")
    allow_role_supplier = UserRoles.objects.filter(user_id,
                                                   form_name_supplier).all()

    form_name_transaction = Q(form_name="Transaction")
    allow_role_transaction = UserRoles.objects.filter(
        user_id, form_name_transaction).all()

    form_name_inventory = Q(form_name="Inventory")
    allow_role_inventory = UserRoles.objects.filter(user_id,
                                                    form_name_inventory).all()

    form_name_reports = Q(form_name="Reports")
    allow_role_reports = UserRoles.objects.filter(user_id,
                                                  form_name_reports).all()

    if request.method == "POST":
        form_id = request.POST.getlist('customer')
        if form_id:
            form_id = 1
        else:
            form_id = 0

        form_id_reports = request.POST.getlist('Reports')
        if form_id_reports:
            form_id_reports = 5
        else:
            form_id_reports = 0

        for i, value in enumerate(allow_role_reports):
            value.form_id = form_id_reports
            value.save()

        display = request.POST.getlist('display[]')
        add = request.POST.getlist('add[]')
        edit = request.POST.getlist('edit[]')
        delete = request.POST.getlist('delete[]')
        c_print = request.POST.getlist('c_print[]')

        s_display = request.POST.getlist('s_display[]')
        s_add = request.POST.getlist('s_add[]')
        s_edit = request.POST.getlist('s_edit[]')
        s_delete = request.POST.getlist('s_delete[]')
        s_print = request.POST.getlist('s_print[]')

        t_display = request.POST.getlist('t_display[]')
        t_add = request.POST.getlist('t_add[]')
        t_edit = request.POST.getlist('t_edit[]')
        t_delete = request.POST.getlist('t_delete[]')
        t_print = request.POST.getlist('t_print[]')
        t_return = request.POST.getlist('t_return[]')

        i_display = request.POST.getlist('i_display[]')
        i_add = request.POST.getlist('i_add[]')
        i_edit = request.POST.getlist('i_edit[]')
        i_delete = request.POST.getlist('i_delete[]')
        i_shop = request.POST.getlist('i_shop[]')

        form_id_i = request.POST.getlist('Inventory')
        if form_id_i:
            form_id_i = 4
        else:
            form_id_i = 0

        for i, value in enumerate(allow_role_inventory):
            if i == 0:
                i_matching_display = [
                    c for c in i_display if "i_inventory_display" in c
                ]
                i_matching_add = [c for c in i_add if "i_inventory_add" in c]
                i_matching_edit = [
                    c for c in i_edit if "i_inventory_edit" in c
                ]
                i_matching_delete = [
                    c for c in i_delete if "i_inventory_delete" in c
                ]
                i_matching_shop = [
                    c for c in i_shop if "i_inventory_shop" in c
                ]

                if i_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if i_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if i_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if i_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if i_matching_shop:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()

            value.form_id = form_id_i
            value.save()

        for i, value in enumerate(allow_role):
            value.form_id = form_id
            value.save()
            if i == 0:
                matching_display = [c for c in display if "c_rfq_display" in c]
                matching_add = [c for c in add if "c_rfq_add" in c]
                matching_edit = [c for c in edit if "c_rfq_edit" in c]
                matching_delete = [c for c in delete if "c_rfq_delete" in c]
                matching_print = [c for c in c_print if "c_rfq_print" in c]

                if matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()
            elif i == 1:
                matching_display = [
                    c for c in display if "c_quotation_display" in c
                ]
                matching_add = [c for c in add if "c_quotation_add" in c]
                matching_edit = [c for c in edit if "c_quotation_edit" in c]
                matching_delete = [
                    c for c in delete if "c_quotation_delete" in c
                ]
                matching_print = [
                    c for c in c_print if "c_quotation_print" in c
                ]

                if matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()
            elif i == 2:
                matching_display = [c for c in display if "c_po_display" in c]
                matching_add = [c for c in add if "c_po_add" in c]
                matching_edit = [c for c in edit if "c_po_edit" in c]
                matching_delete = [c for c in delete if "c_po_delete" in c]
                matching_print = [c for c in c_print if "c_po_print" in c]

                if matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()
            elif i == 3:
                matching_display = [c for c in display if "c_dc_display" in c]
                matching_add = [c for c in add if "c_dc_add" in c]
                matching_edit = [c for c in edit if "c_dc_edit" in c]
                matching_delete = [c for c in delete if "c_dc_delete" in c]
                matching_print = [c for c in c_print if "c_dc_print" in c]

                if matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()

            elif i == 4:
                matching_display = [c for c in display if "c_mrn_display" in c]
                matching_add = [c for c in add if "c_mrn_add" in c]
                matching_edit = [c for c in edit if "c_mrn_edit" in c]
                matching_delete = [c for c in delete if "c_mrn_delete" in c]
                matching_print = [c for c in c_print if "c_mrn_print" in c]

                if matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()

                value.r_print = 0
                value.save()

            value.form_id = form_id
            value.save()

        form_id_s = request.POST.getlist('Supplier')
        if form_id_s:
            form_id_s = 2
        else:
            form_id_s = 0

        for i, value in enumerate(allow_role_supplier):
            if i == 0:
                s_matching_display = [
                    c for c in s_display if "s_rfq_display" in c
                ]
                s_matching_add = [c for c in s_add if "s_rfq_add" in c]
                s_matching_edit = [c for c in s_edit if "s_rfq_edit" in c]
                s_matching_delete = [
                    c for c in s_delete if "s_rfq_delete" in c
                ]
                s_matching_print = [c for c in s_print if "s_rfq_print" in c]

                if s_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if s_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if s_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if s_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if s_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()
            elif i == 1:
                s_matching_display = [
                    c for c in s_display if "s_quotation_display" in c
                ]
                s_matching_add = [c for c in s_add if "s_quotation_add" in c]
                s_matching_edit = [
                    c for c in s_edit if "s_quotation_edit" in c
                ]
                s_matching_delete = [
                    c for c in s_delete if "s_quotation_delete" in c
                ]
                s_matching_print = [
                    c for c in s_print if "s_quotation_print" in c
                ]

                if s_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()

                if s_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if s_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if s_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if s_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()
            elif i == 2:
                s_matching_display = [
                    c for c in s_display if "s_po_display" in c
                ]
                s_matching_add = [c for c in s_add if "s_po_add" in c]
                s_matching_edit = [c for c in s_edit if "s_po_edit" in c]
                s_matching_delete = [c for c in s_delete if "s_po_delete" in c]
                s_matching_print = [c for c in s_print if "s_po_print" in c]

                if s_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()

                if s_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if s_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if s_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if s_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()
            elif i == 3:
                s_matching_display = [
                    c for c in s_display if "s_dc_display" in c
                ]
                s_matching_add = [c for c in s_add if "s_dc_add" in c]
                s_matching_edit = [c for c in s_edit if "s_dc_edit" in c]
                s_matching_delete = [c for c in s_delete if "s_dc_delete" in c]
                s_matching_print = [c for c in s_print if "s_dc_print" in c]

                if s_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if s_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if s_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if s_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if s_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()

            elif i == 4:
                s_matching_display = [
                    c for c in s_display if "s_mrn_display" in c
                ]
                s_matching_add = [c for c in s_add if "s_mrn_add" in c]
                s_matching_edit = [c for c in s_edit if "s_mrn_edit" in c]
                s_matching_delete = [
                    c for c in s_delete if "s_mrn_delete" in c
                ]
                s_matching_print = [c for c in s_print if "s_mrn_print" in c]

                if s_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if s_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if s_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if s_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()

                    value.r_print = 0
                    value.save()

            value.form_id = form_id_s
            value.save()

        form_id_t = request.POST.getlist('Transaction')
        if form_id_t:
            form_id_t = 3
        else:
            form_id_t = 0

        for i, value in enumerate(allow_role_transaction):
            if i == 0:
                t_matching_display = [
                    c for c in t_display if "t_coa_display" in c
                ]
                t_matching_add = [c for c in t_add if "t_coa_add" in c]
                t_matching_edit = [c for c in t_edit if "t_coa_edit" in c]
                t_matching_delete = [
                    c for c in t_delete if "t_coa_delete" in c
                ]
                t_matching_print = [c for c in t_print if "t_coa_print" in c]

                if t_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if t_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if t_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if t_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if t_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()

            elif i == 1:
                t_matching_display = [
                    c for c in t_display if "t_purchase_display" in c
                ]
                t_matching_add = [c for c in t_add if "t_purchase_add" in c]
                t_matching_edit = [c for c in t_edit if "t_purchase_edit" in c]
                t_matching_delete = [
                    c for c in t_delete if "t_purchase_delete" in c
                ]
                t_matching_print = [
                    c for c in t_print if "t_purchase_print" in c
                ]
                t_matching_return = [
                    c for c in t_return if "t_purchase_return" in c
                ]

                if t_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if t_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if t_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if t_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if t_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()
                if t_matching_return:
                    value.r_return = 1
                    value.save()
                else:
                    value.r_return = 0
                    value.save()

            elif i == 2:
                t_matching_display = [
                    c for c in t_display if "t_pr_display" in c
                ]
                t_matching_add = [c for c in t_add if "t_pr_add" in c]
                t_matching_edit = [c for c in t_edit if "t_pr_edit" in c]
                t_matching_delete = [c for c in t_delete if "t_pr_delete" in c]
                t_matching_print = [c for c in t_print if "t_pr_print" in c]

                if t_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()

                if t_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if t_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if t_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if t_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()
            elif i == 3:
                t_matching_display = [
                    c for c in t_display if "t_sale_display" in c
                ]
                t_matching_add = [c for c in t_add if "t_sale_add" in c]
                t_matching_edit = [c for c in t_edit if "t_sale_edit" in c]
                t_matching_delete = [
                    c for c in t_delete if "t_sale_delete" in c
                ]
                t_matching_print = [c for c in t_print if "t_sale_print" in c]
                t_matching_return = [
                    c for c in t_return if "t_sale_return" in c
                ]

                if t_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if t_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if t_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if t_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if t_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()
                if t_matching_return:
                    value.r_return = 1
                    value.save()
                else:
                    value.r_return = 0
                    value.save()

            elif i == 4:
                t_matching_display = [
                    c for c in t_display if "t_sr_display" in c
                ]
                t_matching_add = [c for c in t_add if "t_sr_add" in c]
                t_matching_edit = [c for c in t_edit if "t_sr_edit" in c]
                t_matching_delete = [c for c in t_delete if "t_sr_delete" in c]
                t_matching_print = [c for c in t_print if "t_sr_print" in c]

                if t_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if t_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if t_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if t_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()

                if t_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()

            if i == 5:
                t_matching_display = [
                    c for c in t_display if "t_jv_display" in c
                ]
                t_matching_add = [c for c in t_add if "t_jv_add" in c]
                t_matching_edit = [c for c in t_edit if "t_jv_edit" in c]
                t_matching_delete = [c for c in t_delete if "t_jv_delete" in c]
                t_matching_print = [c for c in t_print if "t_jv_print" in c]

                if t_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if t_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if t_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if t_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if t_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()
            elif i == 6:
                t_matching_display = [
                    c for c in t_display if "t_brv_display" in c
                ]
                t_matching_add = [c for c in t_add if "t_brv_add" in c]
                t_matching_edit = [c for c in t_edit if "t_brv_edit" in c]
                t_matching_delete = [
                    c for c in t_delete if "t_brv_delete" in c
                ]
                t_matching_print = [c for c in t_print if "t_brv_print" in c]

                if t_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()

                if t_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if t_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if t_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if t_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()
            elif i == 7:
                t_matching_display = [
                    c for c in t_display if "t_crv_display" in c
                ]
                t_matching_add = [c for c in t_add if "t_crv_add" in c]
                t_matching_edit = [c for c in t_edit if "t_crv_edit" in c]
                t_matching_delete = [
                    c for c in t_delete if "t_crv_delete" in c
                ]
                t_matching_print = [c for c in t_print if "t_crv_print" in c]

                if t_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if t_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if t_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if t_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if t_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()
            elif i == 8:
                t_matching_display = [
                    c for c in t_display if "t_bpv_display" in c
                ]
                t_matching_add = [c for c in t_add if "t_bpv_add" in c]
                t_matching_edit = [c for c in t_edit if "t_bpv_edit" in c]
                t_matching_delete = [
                    c for c in t_delete if "t_bpv_delete" in c
                ]
                t_matching_print = [c for c in t_print if "t_bpv_print" in c]

                if t_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()

                if t_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if t_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if t_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()
                if t_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()

            elif i == 9:
                t_matching_display = [
                    c for c in t_display if "t_cpv_display" in c
                ]
                t_matching_add = [c for c in t_add if "t_cpv_add" in c]
                t_matching_edit = [c for c in t_edit if "t_cpv_edit" in c]
                t_matching_delete = [
                    c for c in t_delete if "t_cpv_delete" in c
                ]
                t_matching_print = [c for c in t_print if "t_cpv_print" in c]

                if t_matching_display:
                    value.display = 1
                    value.save()
                else:
                    value.display = 0
                    value.save()
                if t_matching_add:
                    value.add = 1
                    value.save()
                else:
                    value.add = 0
                    value.save()
                if t_matching_edit:
                    value.edit = 1
                    value.save()
                else:
                    value.edit = 0
                    value.save()
                if t_matching_delete:
                    value.delete = 1
                    value.save()
                else:
                    value.delete = 0
                    value.save()

                if t_matching_print:
                    value.r_print = 1
                    value.save()
                else:
                    value.r_print = 0
                    value.save()

            value.form_id = form_id_t
            value.save()
    return render(
        request, 'user/user_roles.html', {
            'user': user,
            'allow_role': allow_role,
            'allow_role_supplier': allow_role_supplier,
            'allow_role_transaction': allow_role_transaction,
            'allow_role_inventory': allow_role_inventory,
            'allow_role_reports': allow_role_reports,
            'allow_customer_roles': allow_customer_roles,
            'allow_supplier_roles': allow_supplier_roles,
            'allow_transaction_roles': allow_transaction_roles,
            'allow_inventory_roles': allow_inventory_roles,
            'allow_report_roles': report_roles(request.user),
            'is_superuser': request.user.is_superuser
        })
Exemplo n.º 9
0
def add_product(request):
    id = request.POST.get('id', False)
    if id:
        sub_categories_list = SubCategory.objects.filter(
            main_category_id=id).all()
        list = serializers.serialize('json', sub_categories_list)
        print("Hamza")
        return JsonResponse({"list": list})
    serial_no = 0
    allow_customer_roles = customer_roles(request.user)
    allow_supplier_roles = supplier_roles(request.user)
    allow_transaction_roles = transaction_roles(request.user)
    allow_inventory_roles = inventory_roles(request.user)
    get_item_code = Add_products.objects.last()
    main_categories = Category.objects.all()
    sub_categories = SubCategory.objects.all()
    if get_item_code:
        get_item_code = get_item_code.product_code
        serial_no = int(get_item_code) + 1
    else:
        serial_no = '1001'
    product_name = request.POST.get('product_name', False)
    product_desc = request.POST.get('product_desc', False)
    type = request.POST.get('type', False)
    size = request.POST.get('size', False)
    if product_name and product_desc and type and size:
        type = request.POST.get('type', False)
        size = request.POST.get('size', False)
        product_name = request.POST.get('product_name', False)
        product_desc = request.POST.get('product_desc', False)
        opening_stock = request.POST.get('opening_stock', False)
        unit = request.POST.get('unit', False)
        main_category_id = Category.objects.filter(main=type).first()
        sub_category_id = SubCategory.objects.filter(sub=size).first()
        return JsonResponse({
            "product_name": product_name,
            "type": type,
            "size": size,
            "product_desc": product_desc,
            'unit': unit,
            'opening_stock': opening_stock,
            'main_category_id': main_category_id.id,
            'sub_category_id': sub_category_id.id
        })
    if request.method == 'POST':
        items = json.loads(request.POST.get('items'))
        for value in items:
            item_code = str(serial_no)
            main_category_id = Category.objects.get(
                id=value["main_category_id"])
            sub_category_id = SubCategory.objects.get(
                id=value["sub_category_id"])
            new_products = Add_products(product_code=item_code,
                                        product_name=value["item_name"],
                                        product_desc=value["item_description"],
                                        unit=value["unit"],
                                        size=value["size"],
                                        type="",
                                        opening_stock=value["opening_stock"],
                                        user_id=request.user,
                                        main_category_id=main_category_id,
                                        sub_category_id=sub_category_id,
                                        main_category=main_category_id.main,
                                        sub_category=sub_category_id.sub)
            new_products.save()
            serial_no = int(serial_no) + 1
        return JsonResponse({"result": "success"})
    return render(
        request, 'inventory/add_product.html', {
            'main_categories': main_categories,
            'sub_categories': sub_categories,
            'allow_customer_roles': allow_customer_roles,
            'allow_supplier_roles': allow_supplier_roles,
            'allow_transaction_roles': allow_transaction_roles,
            'allow_inventory_roles': allow_inventory_roles,
            'allow_report_roles': report_roles(request.user),
            'is_superuser': request.user.is_superuser
        })