diff --git a/.DS_Store b/.DS_Store index 1758272..57d0347 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/workx/.DS_Store b/workx/.DS_Store index 0d45dc9..bacb587 100644 Binary files a/workx/.DS_Store and b/workx/.DS_Store differ diff --git a/workx/user/__init__.py b/workx/accounts/__init__.py similarity index 100% rename from workx/user/__init__.py rename to workx/accounts/__init__.py diff --git a/workx/accounts/__pycache__/__init__.cpython-311.pyc b/workx/accounts/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..76d71cd Binary files /dev/null and b/workx/accounts/__pycache__/__init__.cpython-311.pyc differ diff --git a/workx/accounts/__pycache__/admin.cpython-311.pyc b/workx/accounts/__pycache__/admin.cpython-311.pyc new file mode 100644 index 0000000..1312480 Binary files /dev/null and b/workx/accounts/__pycache__/admin.cpython-311.pyc differ diff --git a/workx/accounts/__pycache__/apps.cpython-311.pyc b/workx/accounts/__pycache__/apps.cpython-311.pyc new file mode 100644 index 0000000..27d88f6 Binary files /dev/null and b/workx/accounts/__pycache__/apps.cpython-311.pyc differ diff --git a/workx/accounts/__pycache__/form.cpython-311.pyc b/workx/accounts/__pycache__/form.cpython-311.pyc new file mode 100644 index 0000000..9b78b20 Binary files /dev/null and b/workx/accounts/__pycache__/form.cpython-311.pyc differ diff --git a/workx/accounts/__pycache__/models.cpython-311.pyc b/workx/accounts/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000..b63266a Binary files /dev/null and b/workx/accounts/__pycache__/models.cpython-311.pyc differ diff --git a/workx/accounts/__pycache__/serializers.cpython-311.pyc b/workx/accounts/__pycache__/serializers.cpython-311.pyc new file mode 100644 index 0000000..0dc7733 Binary files /dev/null and b/workx/accounts/__pycache__/serializers.cpython-311.pyc differ diff --git a/workx/accounts/__pycache__/views.cpython-311.pyc b/workx/accounts/__pycache__/views.cpython-311.pyc new file mode 100644 index 0000000..92b404f Binary files /dev/null and b/workx/accounts/__pycache__/views.cpython-311.pyc differ diff --git a/workx/user/admin.py b/workx/accounts/admin.py similarity index 100% rename from workx/user/admin.py rename to workx/accounts/admin.py diff --git a/workx/user/apps.py b/workx/accounts/apps.py similarity index 62% rename from workx/user/apps.py rename to workx/accounts/apps.py index 36cce4c..3e3c765 100644 --- a/workx/user/apps.py +++ b/workx/accounts/apps.py @@ -1,6 +1,6 @@ from django.apps import AppConfig -class UserConfig(AppConfig): +class AccountsConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' - name = 'user' + name = 'accounts' diff --git a/workx/accounts/form.py b/workx/accounts/form.py new file mode 100644 index 0000000..cc8dc5e --- /dev/null +++ b/workx/accounts/form.py @@ -0,0 +1,7 @@ +from django import forms +from .models import Account + +class AccountForm(forms.ModelForm): + class Meta: + model = Account + exclude = () # \ No newline at end of file diff --git a/workx/accounts/migrations/0001_initial.py b/workx/accounts/migrations/0001_initial.py new file mode 100644 index 0000000..d341f2a --- /dev/null +++ b/workx/accounts/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# Generated by Django 4.1.9 on 2023-07-17 23:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Account', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ('address', models.CharField(max_length=200)), + ('phone_number', models.CharField(max_length=20)), + ('email', models.EmailField(max_length=254)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('total_revenue', models.DecimalField(decimal_places=2, default=0, max_digits=10)), + ('total_expenses', models.DecimalField(decimal_places=2, default=0, max_digits=10)), + ('total_investments', models.DecimalField(decimal_places=2, default=0, max_digits=10)), + ], + ), + ] diff --git a/workx/accounts/migrations/0002_client_expense_income_project_reimbursement_and_more.py b/workx/accounts/migrations/0002_client_expense_income_project_reimbursement_and_more.py new file mode 100644 index 0000000..edf0fd0 --- /dev/null +++ b/workx/accounts/migrations/0002_client_expense_income_project_reimbursement_and_more.py @@ -0,0 +1,72 @@ +# Generated by Django 4.1.9 on 2023-07-18 11:13 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0001_initial'), + ('employee', '0002_alter_employee_user'), + ('accounts', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Client', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ], + ), + migrations.CreateModel( + name='Expense', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('category', models.CharField(choices=[('Food', 'Food'), ('Fuel', 'Fuel'), ('Traveling', 'Traveling'), ('Gifts', 'Gifts')], max_length=100)), + ('title', models.CharField(max_length=100)), + ('bill_number', models.CharField(max_length=100)), + ('date', models.DateField()), + ('reimbursement', models.BooleanField()), + ('bank_account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='common.bankdetails')), + ('employee', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='employee.employee')), + ], + ), + migrations.CreateModel( + name='Income', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('type', models.CharField(choices=[('Invoice', 'Invoice'), ('Dividend', 'Dividend')], max_length=10)), + ('title', models.CharField(max_length=100)), + ('invoice_number', models.CharField(max_length=100)), + ('date', models.DateField()), + ('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounts.client')), + ], + ), + migrations.CreateModel( + name='Project', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ], + ), + migrations.CreateModel( + name='Reimbursement', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=100)), + ('rate', models.DecimalField(decimal_places=2, max_digits=10)), + ('quantity', models.PositiveIntegerField()), + ('status', models.CharField(max_length=10)), + ], + ), + migrations.DeleteModel( + name='Account', + ), + migrations.AddField( + model_name='income', + name='project', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounts.project'), + ), + ] diff --git a/workx/user/migrations/__init__.py b/workx/accounts/migrations/__init__.py similarity index 100% rename from workx/user/migrations/__init__.py rename to workx/accounts/migrations/__init__.py diff --git a/workx/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc b/workx/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 0000000..d68dcb3 Binary files /dev/null and b/workx/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/workx/accounts/migrations/__pycache__/0002_client_expense_income_project_reimbursement_and_more.cpython-311.pyc b/workx/accounts/migrations/__pycache__/0002_client_expense_income_project_reimbursement_and_more.cpython-311.pyc new file mode 100644 index 0000000..297c24f Binary files /dev/null and b/workx/accounts/migrations/__pycache__/0002_client_expense_income_project_reimbursement_and_more.cpython-311.pyc differ diff --git a/workx/accounts/migrations/__pycache__/__init__.cpython-311.pyc b/workx/accounts/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..504cef4 Binary files /dev/null and b/workx/accounts/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/workx/accounts/models.py b/workx/accounts/models.py new file mode 100644 index 0000000..083b2ae --- /dev/null +++ b/workx/accounts/models.py @@ -0,0 +1,76 @@ +from django.db import models + +# Create your models here. +from employee.models import Employee +from common.models import BankDetails + +class Client(models.Model): + name = models.CharField(max_length=100) + # Other fields for client information + + def __str__(self): + return self.name + + +class Project(models.Model): + name = models.CharField(max_length=100) + # Other fields for project information + + def __str__(self): + return self.name + + +class Income(models.Model): + TYPE_CHOICES = [ + ('Invoice', 'Invoice'), + ('Dividend', 'Dividend'), + ] + + type = models.CharField(max_length=10, choices=TYPE_CHOICES) + title = models.CharField(max_length=100) + invoice_number = models.CharField(max_length=100) + date = models.DateField() + client = models.ForeignKey(Client, on_delete=models.CASCADE) + project = models.ForeignKey(Project, on_delete=models.CASCADE) + # Other fields specific to income + + def __str__(self): + return self.title + + +class Expense(models.Model): + CATEGORY_CHOICES = [ + ('Food', 'Food'), + ('Fuel', 'Fuel'), + ('Traveling', 'Traveling'), + ('Gifts', 'Gifts'), + # Other expense categories + ] + + category = models.CharField(max_length=100, choices=CATEGORY_CHOICES) + title = models.CharField(max_length=100) + bill_number = models.CharField(max_length=100) + date = models.DateField() + employee = models.ForeignKey(Employee, on_delete=models.CASCADE) + bank_account = models.ForeignKey(BankDetails, on_delete=models.CASCADE) + reimbursement = models.BooleanField() + # Other fields specific to expenses + + def __str__(self): + return self.title + + +class Reimbursement(models.Model): + STATUS_CHOICES=[ + ('Paid','Paid'), + ('Due', 'Due'), + ('Overdue', 'Overdue'), + ] + title = models.CharField(max_length=100) + rate = models.DecimalField(max_digits=10, decimal_places=2) + quantity = models.PositiveIntegerField() + status = models.CharField(max_length=10, choices=STATUS_CHOICES) # Paid, Due, Overdue + # Other fields specific to reimbursements + + def __str__(self): + return self.title diff --git a/workx/accounts/serializers.py b/workx/accounts/serializers.py new file mode 100644 index 0000000..973f8a8 --- /dev/null +++ b/workx/accounts/serializers.py @@ -0,0 +1,19 @@ +from rest_framework import serializers +from .models import Income, Expense, Reimbursement + +class IncomeSerializer(serializers.ModelSerializer): + class Meta: + model = Income + fields = '__all__' + + +class ExpenseSerializer(serializers.ModelSerializer): + class Meta: + model = Expense + fields = '__all__' + + +class ReimbursementSerializer(serializers.ModelSerializer): + class Meta: + model = Reimbursement + fields = '__all__' diff --git a/workx/user/tests.py b/workx/accounts/tests.py similarity index 100% rename from workx/user/tests.py rename to workx/accounts/tests.py diff --git a/workx/accounts/views.py b/workx/accounts/views.py new file mode 100644 index 0000000..c504766 --- /dev/null +++ b/workx/accounts/views.py @@ -0,0 +1,17 @@ +from rest_framework import viewsets +from .models import Income, Expense, Reimbursement +from .serializers import IncomeSerializer, ExpenseSerializer, ReimbursementSerializer + +class IncomeViewSet(viewsets.ModelViewSet): + queryset = Income.objects.all() + serializer_class = IncomeSerializer + + +class ExpenseViewSet(viewsets.ModelViewSet): + queryset = Expense.objects.all() + serializer_class = ExpenseSerializer + + +class ReimbursementViewSet(viewsets.ModelViewSet): + queryset = Reimbursement.objects.all() + serializer_class = ReimbursementSerializer diff --git a/workx/authUser/__pycache__/view.cpython-311.pyc b/workx/authUser/__pycache__/view.cpython-311.pyc deleted file mode 100644 index 13d1b91..0000000 Binary files a/workx/authUser/__pycache__/view.cpython-311.pyc and /dev/null differ diff --git a/workx/authUser/view.py b/workx/authUser/view.py deleted file mode 100644 index 1bcef9d..0000000 --- a/workx/authUser/view.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.shortcuts import render -from django.contrib import messages -from django.shortcuts import redirect - - -def signup_redirect(request): - messages.error(request, "Something wrong here, it may be that you already have account!") - return redirect("homepage") \ No newline at end of file diff --git a/workx/client/__pycache__/__init__.cpython-311.pyc b/workx/client/__pycache__/__init__.cpython-311.pyc index dd0c002..8c9419f 100644 Binary files a/workx/client/__pycache__/__init__.cpython-311.pyc and b/workx/client/__pycache__/__init__.cpython-311.pyc differ diff --git a/workx/client/__pycache__/admin.cpython-311.pyc b/workx/client/__pycache__/admin.cpython-311.pyc index 9854d1f..666abca 100644 Binary files a/workx/client/__pycache__/admin.cpython-311.pyc and b/workx/client/__pycache__/admin.cpython-311.pyc differ diff --git a/workx/client/__pycache__/apps.cpython-311.pyc b/workx/client/__pycache__/apps.cpython-311.pyc index 9ae5302..7ac6321 100644 Binary files a/workx/client/__pycache__/apps.cpython-311.pyc and b/workx/client/__pycache__/apps.cpython-311.pyc differ diff --git a/workx/client/__pycache__/models.cpython-311.pyc b/workx/client/__pycache__/models.cpython-311.pyc index 0cef9df..d80416c 100644 Binary files a/workx/client/__pycache__/models.cpython-311.pyc and b/workx/client/__pycache__/models.cpython-311.pyc differ diff --git a/workx/common/__pycache__/__init__.cpython-311.pyc b/workx/common/__pycache__/__init__.cpython-311.pyc index b2f08df..a15a50d 100644 Binary files a/workx/common/__pycache__/__init__.cpython-311.pyc and b/workx/common/__pycache__/__init__.cpython-311.pyc differ diff --git a/workx/common/__pycache__/admin.cpython-311.pyc b/workx/common/__pycache__/admin.cpython-311.pyc index 9636734..57a35ba 100644 Binary files a/workx/common/__pycache__/admin.cpython-311.pyc and b/workx/common/__pycache__/admin.cpython-311.pyc differ diff --git a/workx/common/__pycache__/apps.cpython-311.pyc b/workx/common/__pycache__/apps.cpython-311.pyc index d1165ea..83c8089 100644 Binary files a/workx/common/__pycache__/apps.cpython-311.pyc and b/workx/common/__pycache__/apps.cpython-311.pyc differ diff --git a/workx/common/__pycache__/models.cpython-311.pyc b/workx/common/__pycache__/models.cpython-311.pyc index 30ea921..a7d063c 100644 Binary files a/workx/common/__pycache__/models.cpython-311.pyc and b/workx/common/__pycache__/models.cpython-311.pyc differ diff --git a/workx/common/__pycache__/serializers.cpython-311.pyc b/workx/common/__pycache__/serializers.cpython-311.pyc index ded7e15..35af4f2 100644 Binary files a/workx/common/__pycache__/serializers.cpython-311.pyc and b/workx/common/__pycache__/serializers.cpython-311.pyc differ diff --git a/workx/common/migrations/0001_initial.py b/workx/common/migrations/0001_initial.py new file mode 100644 index 0000000..fb012b1 --- /dev/null +++ b/workx/common/migrations/0001_initial.py @@ -0,0 +1,48 @@ +# Generated by Django 4.1.9 on 2023-07-17 22:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Address', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('address_line_1', models.CharField(max_length=200)), + ('address_line_2', models.CharField(blank=True, max_length=200)), + ('city', models.CharField(max_length=50)), + ('state', models.CharField(max_length=50)), + ('zip_code', models.CharField(max_length=10)), + ('country', models.CharField(max_length=50)), + ], + options={ + 'db_table': 'address', + }, + ), + migrations.CreateModel( + name='BankDetails', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('beneficiary_name', models.CharField(max_length=50)), + ('bank_name', models.CharField(max_length=50)), + ('account_number', models.CharField(max_length=20)), + ('ifsc_code', models.CharField(max_length=20)), + ('branch_name', models.CharField(max_length=50)), + ('upi_id', models.CharField(blank=True, max_length=50)), + ], + ), + migrations.CreateModel( + name='NatureOfBusiness', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50)), + ], + ), + ] diff --git a/workx/common/migrations/__init__.py b/workx/common/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/workx/common/migrations/__pycache__/0001_initial.cpython-311.pyc b/workx/common/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 0000000..7fe61a9 Binary files /dev/null and b/workx/common/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/workx/common/migrations/__pycache__/__init__.cpython-311.pyc b/workx/common/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..f634680 Binary files /dev/null and b/workx/common/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/workx/company/__pycache__/__init__.cpython-311.pyc b/workx/company/__pycache__/__init__.cpython-311.pyc index 69c81a2..c34bd8f 100644 Binary files a/workx/company/__pycache__/__init__.cpython-311.pyc and b/workx/company/__pycache__/__init__.cpython-311.pyc differ diff --git a/workx/company/__pycache__/admin.cpython-311.pyc b/workx/company/__pycache__/admin.cpython-311.pyc index b6f64e0..d6ed812 100644 Binary files a/workx/company/__pycache__/admin.cpython-311.pyc and b/workx/company/__pycache__/admin.cpython-311.pyc differ diff --git a/workx/company/__pycache__/apps.cpython-311.pyc b/workx/company/__pycache__/apps.cpython-311.pyc index d176182..730057b 100644 Binary files a/workx/company/__pycache__/apps.cpython-311.pyc and b/workx/company/__pycache__/apps.cpython-311.pyc differ diff --git a/workx/company/__pycache__/form.cpython-311.pyc b/workx/company/__pycache__/form.cpython-311.pyc index a544433..7c011e6 100644 Binary files a/workx/company/__pycache__/form.cpython-311.pyc and b/workx/company/__pycache__/form.cpython-311.pyc differ diff --git a/workx/company/__pycache__/models.cpython-311.pyc b/workx/company/__pycache__/models.cpython-311.pyc index 4c7c09f..bce67e7 100644 Binary files a/workx/company/__pycache__/models.cpython-311.pyc and b/workx/company/__pycache__/models.cpython-311.pyc differ diff --git a/workx/company/__pycache__/serializers.cpython-311.pyc b/workx/company/__pycache__/serializers.cpython-311.pyc index aad0d6c..d410f51 100644 Binary files a/workx/company/__pycache__/serializers.cpython-311.pyc and b/workx/company/__pycache__/serializers.cpython-311.pyc differ diff --git a/workx/company/__pycache__/views.cpython-311.pyc b/workx/company/__pycache__/views.cpython-311.pyc index aa504c4..367ce0e 100644 Binary files a/workx/company/__pycache__/views.cpython-311.pyc and b/workx/company/__pycache__/views.cpython-311.pyc differ diff --git a/workx/company/migrations/0001_initial.py b/workx/company/migrations/0001_initial.py new file mode 100644 index 0000000..793e574 --- /dev/null +++ b/workx/company/migrations/0001_initial.py @@ -0,0 +1,47 @@ +# Generated by Django 4.1.9 on 2023-07-19 21:26 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('common', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Company', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('legal_name', models.CharField(max_length=256)), + ('trade_name', models.CharField(max_length=256)), + ('cin', models.CharField(max_length=64)), + ('cin_proof', models.FileField(null=True, upload_to='company_proofs/')), + ('gstin', models.CharField(max_length=16)), + ('gstin_proof', models.FileField(null=True, upload_to='company_proofs/')), + ('date_of_incorporation', models.DateField()), + ('date_of_incorporation_proof', models.FileField(null=True, upload_to='company_proofs/')), + ('pan', models.CharField(max_length=16)), + ('pan_proof', models.FileField(null=True, upload_to='company_proofs/')), + ('iec', models.CharField(max_length=16)), + ('iec_proof', models.FileField(null=True, upload_to='company_proofs/')), + ('msme_code', models.CharField(max_length=64)), + ('msme_proof', models.FileField(null=True, upload_to='company_proofs/')), + ('provident_fund_code_number', models.CharField(max_length=32)), + ('provident_fund_code_number_proof', models.FileField(null=True, upload_to='company_proofs/')), + ('se_registration_number', models.CharField(max_length=32)), + ('se_registration_number_proof', models.FileField(null=True, upload_to='company_proofs/')), + ('phone_number', models.CharField(max_length=13)), + ('support_email', models.EmailField(max_length=254, null=True, unique=True)), + ('address', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='common.address')), + ('nature_of_business', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='common.natureofbusiness')), + ], + options={ + 'db_table': 'company', + }, + ), + ] diff --git a/workx/company/migrations/__init__.py b/workx/company/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/workx/company/migrations/__pycache__/0001_initial.cpython-311.pyc b/workx/company/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 0000000..a7b280b Binary files /dev/null and b/workx/company/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/workx/company/migrations/__pycache__/__init__.cpython-311.pyc b/workx/company/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..9456e3e Binary files /dev/null and b/workx/company/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/workx/company/views.py b/workx/company/views.py index c122c04..a3b60fc 100644 --- a/workx/company/views.py +++ b/workx/company/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render -from rest_framework import viewsets +from rest_framework import viewsets, permissions from .models import Company from .form import CompanyForm from .serializers import CompanySerializer @@ -7,6 +7,7 @@ from .serializers import CompanySerializer class CompanyViewSet(viewsets.ModelViewSet): queryset = Company.objects.all() serializer_class = CompanySerializer + permission_classes = [permissions.IsAuthenticated] def perform_create(self, serializer): form_data = self.request.data.get('form') diff --git a/workx/employee/__pycache__/__init__.cpython-311.pyc b/workx/employee/__pycache__/__init__.cpython-311.pyc index 1e47e16..f8b7594 100644 Binary files a/workx/employee/__pycache__/__init__.cpython-311.pyc and b/workx/employee/__pycache__/__init__.cpython-311.pyc differ diff --git a/workx/employee/__pycache__/admin.cpython-311.pyc b/workx/employee/__pycache__/admin.cpython-311.pyc index 432ef34..2c0c4dc 100644 Binary files a/workx/employee/__pycache__/admin.cpython-311.pyc and b/workx/employee/__pycache__/admin.cpython-311.pyc differ diff --git a/workx/employee/__pycache__/apps.cpython-311.pyc b/workx/employee/__pycache__/apps.cpython-311.pyc index 0377123..5dd947c 100644 Binary files a/workx/employee/__pycache__/apps.cpython-311.pyc and b/workx/employee/__pycache__/apps.cpython-311.pyc differ diff --git a/workx/employee/__pycache__/forms.cpython-311.pyc b/workx/employee/__pycache__/forms.cpython-311.pyc index 4ae7ff1..350bae6 100644 Binary files a/workx/employee/__pycache__/forms.cpython-311.pyc and b/workx/employee/__pycache__/forms.cpython-311.pyc differ diff --git a/workx/employee/__pycache__/models.cpython-311.pyc b/workx/employee/__pycache__/models.cpython-311.pyc index c8ca506..8d302aa 100644 Binary files a/workx/employee/__pycache__/models.cpython-311.pyc and b/workx/employee/__pycache__/models.cpython-311.pyc differ diff --git a/workx/employee/__pycache__/permissions.cpython-311.pyc b/workx/employee/__pycache__/permissions.cpython-311.pyc new file mode 100644 index 0000000..032326d Binary files /dev/null and b/workx/employee/__pycache__/permissions.cpython-311.pyc differ diff --git a/workx/employee/__pycache__/serializers.cpython-311.pyc b/workx/employee/__pycache__/serializers.cpython-311.pyc index f193788..8f1e4ce 100644 Binary files a/workx/employee/__pycache__/serializers.cpython-311.pyc and b/workx/employee/__pycache__/serializers.cpython-311.pyc differ diff --git a/workx/employee/__pycache__/views.cpython-311.pyc b/workx/employee/__pycache__/views.cpython-311.pyc index 5da3ef6..b7f03c7 100644 Binary files a/workx/employee/__pycache__/views.cpython-311.pyc and b/workx/employee/__pycache__/views.cpython-311.pyc differ diff --git a/workx/employee/admin.py b/workx/employee/admin.py index bc2e6c5..efcb459 100644 --- a/workx/employee/admin.py +++ b/workx/employee/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin # Register your models here. -from employee.models import Department, Employee +from employee.models import Employee + -admin.site.register(Department) admin.site.register(Employee) \ No newline at end of file diff --git a/workx/employee/migrations/0001_initial.py b/workx/employee/migrations/0001_initial.py new file mode 100644 index 0000000..d1b2f1d --- /dev/null +++ b/workx/employee/migrations/0001_initial.py @@ -0,0 +1,42 @@ +# Generated by Django 4.1.9 on 2023-07-17 22:35 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('common', '__first__'), + ] + + operations = [ + migrations.CreateModel( + name='Role', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50, unique=True)), + ], + ), + migrations.CreateModel( + name='Employee', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=30)), + ('last_name', models.CharField(max_length=30)), + ('personal_email', models.EmailField(max_length=254, unique=True)), + ('official_email', models.EmailField(max_length=254, unique=True)), + ('phone_number', models.CharField(max_length=13)), + ('job_title', models.CharField(max_length=100)), + ('ctc', models.DecimalField(decimal_places=2, max_digits=10)), + ('address', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='common.address')), + ('bank_details', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='common.bankdetails')), + ('role', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='employee.role')), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/workx/employee/migrations/0002_alter_employee_user.py b/workx/employee/migrations/0002_alter_employee_user.py new file mode 100644 index 0000000..2ed2946 --- /dev/null +++ b/workx/employee/migrations/0002_alter_employee_user.py @@ -0,0 +1,21 @@ +# Generated by Django 4.1.9 on 2023-07-17 22:46 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('employee', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='employee', + name='user', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='employee', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/workx/employee/migrations/__init__.py b/workx/employee/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/workx/employee/migrations/__pycache__/0001_initial.cpython-311.pyc b/workx/employee/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 0000000..265d188 Binary files /dev/null and b/workx/employee/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/workx/employee/migrations/__pycache__/0002_alter_employee_user.cpython-311.pyc b/workx/employee/migrations/__pycache__/0002_alter_employee_user.cpython-311.pyc new file mode 100644 index 0000000..067d14d Binary files /dev/null and b/workx/employee/migrations/__pycache__/0002_alter_employee_user.cpython-311.pyc differ diff --git a/workx/employee/migrations/__pycache__/__init__.cpython-311.pyc b/workx/employee/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..c18de7b Binary files /dev/null and b/workx/employee/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/workx/employee/models.py b/workx/employee/models.py index 2513d99..1d4b1de 100644 --- a/workx/employee/models.py +++ b/workx/employee/models.py @@ -1,15 +1,11 @@ from django.db import models from common.models import BankDetails, Address - - -class Department(models.Model): - name = models.CharField(max_length=50) - - def __str__(self): - return self.name +from django.contrib.auth.models import User class Employee(models.Model): - + user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='employee') + # Rest of the fields... + role = models.ForeignKey('Role', on_delete=models.SET_NULL, null=True) first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) personal_email = models.EmailField(unique=True) @@ -17,9 +13,14 @@ class Employee(models.Model): phone_number = models.CharField(max_length=13) address = models.ForeignKey(Address, on_delete=models.SET_NULL, null=True) job_title = models.CharField(max_length=100) - department = models.ManyToManyField(Department) ctc = models.DecimalField(max_digits=10, decimal_places=2) bank_details = models.OneToOneField(BankDetails, on_delete=models.CASCADE) def __str__(self): return f"{self.first_name} {self.last_name}" + +class Role(models.Model): + name = models.CharField(max_length=50, unique=True) + + def __str__(self): + return self.name diff --git a/workx/employee/permissions.py b/workx/employee/permissions.py new file mode 100644 index 0000000..450e850 --- /dev/null +++ b/workx/employee/permissions.py @@ -0,0 +1,45 @@ +from rest_framework import permissions + +def has_permission(self, request, view): + if request.user.is_authenticated: + try: + employee = request.user.employee + return employee is not None and employee.role is not None + except Employee.DoesNotExist: + return False + return False +from .models import Employee + +class EmployeeAPIPermission(permissions.BasePermission): + def has_permission(self, request, view): + if request.method in permissions.SAFE_METHODS: + return True # Allow GET requests for all users + + user = request.user + if user.is_authenticated and user.role: + role_name = user.role.name + if role_name == 'Admin': + return True # Allow CRUD operations for Admin role + elif role_name == 'Employee' and request.method in ['GET', 'PUT']: + return True # Allow GET and PUT requests for Employee role + + return False + +from rest_framework import permissions + + +class GoogleAuthenticatedPermission(permissions.BasePermission): + def has_permission(self, request, view): + # Check if the user is authenticated + if not request.user.is_authenticated: + return False + + # Check if the user is authenticated with a Google account + if 'email' not in request.session: + return False + + # Perform additional checks if needed + # For example, verify the email in request.session with the email from id_token_data + + return True + diff --git a/workx/employee/serializers.py b/workx/employee/serializers.py index e0a5948..4df4888 100644 --- a/workx/employee/serializers.py +++ b/workx/employee/serializers.py @@ -1,12 +1,29 @@ from rest_framework import serializers from common.serializers import BankDetailsSerializer, AddressSerializer -from .models import Employee +from .models import Employee,Role +from common.models import BankDetails, Address class EmployeeSerializer(serializers.ModelSerializer): - address = AddressSerializer() bank_details = BankDetailsSerializer() + address = AddressSerializer() class Meta: model = Employee - fields = '__all__' \ No newline at end of file + fields = '__all__' + + def create(self, validated_data): + bank_details_data = validated_data.pop('bank_details') + address_data = validated_data.pop('address') + + bank_details = BankDetails.objects.create(**bank_details_data) + address = Address.objects.create(**address_data) + + employee = Employee.objects.create(bank_details=bank_details, address=address, **validated_data) + return employee + + +class RoleSerializer(serializers.ModelSerializer): + class Meta: + model = Role + fields = '__all__' \ No newline at end of file diff --git a/workx/employee/views.py b/workx/employee/views.py index 1506d3f..5a3bc0e 100644 --- a/workx/employee/views.py +++ b/workx/employee/views.py @@ -1,25 +1,27 @@ -from rest_framework import viewsets +from rest_framework import viewsets,permissions from .models import Employee from .serializers import EmployeeSerializer from .forms import EmployeeForm +from rest_framework import generics, permissions +from .models import Role +from .serializers import RoleSerializer +from .permissions import EmployeeAPIPermission,GoogleAuthenticatedPermission -class EmployeeViewSet(viewsets.ModelViewSet): +class RoleListCreateAPIView(generics.ListCreateAPIView): + queryset = Role.objects.all() + serializer_class = RoleSerializer + permission_classes = [permissions.IsAuthenticated, permissions.IsAdminUser] + + +class EmployeeListCreateAPIView(generics.ListCreateAPIView): + queryset = Employee.objects.all() + serializer_class = EmployeeSerializer + permission_classes = [permissions.IsAuthenticated| EmployeeAPIPermission] + +class EmployeeRetrieveUpdateAPIView(generics.RetrieveUpdateAPIView): queryset = Employee.objects.all() serializer_class = EmployeeSerializer + permission_classes = [permissions.IsAuthenticated | EmployeeAPIPermission] - def perform_create(self, serializer): - form_data = self.request.data.get('form') - form = EmployeeForm(form_data) - if form.is_valid(): - employee = serializer.save() - form.instance = employee - form.save() - def perform_update(self, serializer): - form_data = self.request.data.get('form') - form = EmployeeForm(form_data, instance=serializer.instance) - if form.is_valid(): - employee = serializer.save() - form.instance = employee - form.save() diff --git a/workx/google_auth/__init__.py b/workx/google_auth/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/workx/google_auth/__pycache__/__init__.cpython-311.pyc b/workx/google_auth/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..7e64916 Binary files /dev/null and b/workx/google_auth/__pycache__/__init__.cpython-311.pyc differ diff --git a/workx/google_auth/__pycache__/admin.cpython-311.pyc b/workx/google_auth/__pycache__/admin.cpython-311.pyc new file mode 100644 index 0000000..b8e5a5f Binary files /dev/null and b/workx/google_auth/__pycache__/admin.cpython-311.pyc differ diff --git a/workx/google_auth/__pycache__/apps.cpython-311.pyc b/workx/google_auth/__pycache__/apps.cpython-311.pyc new file mode 100644 index 0000000..64c8e73 Binary files /dev/null and b/workx/google_auth/__pycache__/apps.cpython-311.pyc differ diff --git a/workx/google_auth/__pycache__/models.cpython-311.pyc b/workx/google_auth/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000..fb1ca21 Binary files /dev/null and b/workx/google_auth/__pycache__/models.cpython-311.pyc differ diff --git a/workx/google_auth/__pycache__/urls.cpython-311.pyc b/workx/google_auth/__pycache__/urls.cpython-311.pyc new file mode 100644 index 0000000..8da82f8 Binary files /dev/null and b/workx/google_auth/__pycache__/urls.cpython-311.pyc differ diff --git a/workx/google_auth/__pycache__/views.cpython-311.pyc b/workx/google_auth/__pycache__/views.cpython-311.pyc new file mode 100644 index 0000000..eaf3102 Binary files /dev/null and b/workx/google_auth/__pycache__/views.cpython-311.pyc differ diff --git a/workx/google_auth/admin.py b/workx/google_auth/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/workx/google_auth/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/workx/google_auth/apps.py b/workx/google_auth/apps.py new file mode 100644 index 0000000..3eb01b8 --- /dev/null +++ b/workx/google_auth/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class GoogleAuthConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'google_auth' diff --git a/workx/google_auth/migrations/__init__.py b/workx/google_auth/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/workx/google_auth/migrations/__pycache__/__init__.cpython-311.pyc b/workx/google_auth/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..9b1569c Binary files /dev/null and b/workx/google_auth/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/workx/user/models.py b/workx/google_auth/models.py similarity index 52% rename from workx/user/models.py rename to workx/google_auth/models.py index d49766e..71a8362 100644 --- a/workx/user/models.py +++ b/workx/google_auth/models.py @@ -1,3 +1,3 @@ from django.db import models -# Create your models here. \ No newline at end of file +# Create your models here. diff --git a/workx/google_auth/tests.py b/workx/google_auth/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/workx/google_auth/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/workx/google_auth/urls.py b/workx/google_auth/urls.py new file mode 100644 index 0000000..da0e58d --- /dev/null +++ b/workx/google_auth/urls.py @@ -0,0 +1,9 @@ +from django.urls import path +from . import views + +app_name = 'google_auth' + +urlpatterns = [ + path('login/', views.login, name='login'), + path('callback/', views.callback, name='callback'), +] \ No newline at end of file diff --git a/workx/google_auth/views.py b/workx/google_auth/views.py new file mode 100644 index 0000000..27981da --- /dev/null +++ b/workx/google_auth/views.py @@ -0,0 +1,34 @@ + + +from django.shortcuts import redirect +from google.oauth2 import id_token +from django.conf import settings +from django.urls import reverse_lazy +import requests +from google.auth.transport import requests as google_requests + +def login(request): + # Redirect the user to the Google authentication URL + redirect_uri = request.build_absolute_uri(reverse_lazy('google_auth:callback')) + authorization_url = f'https://accounts.google.com/o/oauth2/auth?response_type=code&client_id={settings.GOOGLE_OAUTH2_CLIENT_ID}&redirect_uri={redirect_uri}&scope=openid%20email%20profile' + return redirect(authorization_url) + +def callback(request): + authorization_code = request.GET.get('code') + token_url = 'https://oauth2.googleapis.com/token' + redirect_uri = request.build_absolute_uri(reverse_lazy('google_auth:callback')) + token_request_data = { + 'code': authorization_code, + 'client_id': settings.GOOGLE_OAUTH2_CLIENT_ID, + 'client_secret': settings.GOOGLE_OAUTH2_CLIENT_SECRET, + 'redirect_uri': redirect_uri, + 'grant_type': 'authorization_code' + } + token_response = requests.post(token_url, data=token_request_data) + token_response_data = token_response.json() + id_token_data = id_token.verify_oauth2_token( + token_response_data['id_token'], + google_requests.Request(), + settings.GOOGLE_OAUTH2_CLIENT_ID + ) + return redirect('http://127.0.0.1:8000') diff --git a/workx/templates/home.html b/workx/templates/home.html new file mode 100644 index 0000000..755ac57 --- /dev/null +++ b/workx/templates/home.html @@ -0,0 +1,12 @@ + + + + Home + + + +

Redirecting...

+ + \ No newline at end of file diff --git a/workx/user/views.py b/workx/user/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/workx/user/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/workx/workx/__pycache__/__init__.cpython-311.pyc b/workx/workx/__pycache__/__init__.cpython-311.pyc index 8821219..c8b271a 100644 Binary files a/workx/workx/__pycache__/__init__.cpython-311.pyc and b/workx/workx/__pycache__/__init__.cpython-311.pyc differ diff --git a/workx/workx/__pycache__/settings.cpython-311.pyc b/workx/workx/__pycache__/settings.cpython-311.pyc index 24f471a..5f30359 100644 Binary files a/workx/workx/__pycache__/settings.cpython-311.pyc and b/workx/workx/__pycache__/settings.cpython-311.pyc differ diff --git a/workx/workx/__pycache__/urls.cpython-311.pyc b/workx/workx/__pycache__/urls.cpython-311.pyc index b50aab0..5b54d6e 100644 Binary files a/workx/workx/__pycache__/urls.cpython-311.pyc and b/workx/workx/__pycache__/urls.cpython-311.pyc differ diff --git a/workx/workx/__pycache__/wsgi.cpython-311.pyc b/workx/workx/__pycache__/wsgi.cpython-311.pyc index dbf108d..3d78b8f 100644 Binary files a/workx/workx/__pycache__/wsgi.cpython-311.pyc and b/workx/workx/__pycache__/wsgi.cpython-311.pyc differ diff --git a/workx/workx/settings.py b/workx/workx/settings.py index 1617e8f..521587a 100644 --- a/workx/workx/settings.py +++ b/workx/workx/settings.py @@ -27,27 +27,26 @@ DEBUG = True ALLOWED_HOSTS = ['*'] - +GOOGLE_OAUTH2_CLIENT_ID = "611194092059-kk4bhv18i19cvngmi3335gtvk4nmp25d.apps.googleusercontent.com" +GOOGLE_OAUTH2_CLIENT_SECRET ="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" # Application definition + INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', - 'django.contrib.messages', 'django.contrib.staticfiles', 'company', 'common', + 'accounts', 'employee', 'client', 'rest_framework', - 'django.contrib.sites', - 'allauth', - 'allauth.account', - 'allauth.socialaccount', - 'allauth.socialaccount.providers.google', -] + "django.contrib.messages", + "google_auth", + ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', @@ -79,58 +78,50 @@ TEMPLATES = [ WSGI_APPLICATION = 'workx.wsgi.application' - +# AUTH_PASSWORD_VALIDATORS = [ +# { +# "NAME": "django.contrib.auth.password_validation." +# "UserAttributeSimilarityValidator", +# }, +# { +# "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", +# }, +# { +# "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", +# }, +# { +# "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", +# }, +# ] # Database # https://docs.djangoproject.com/en/4.1/ref/settings/#databases + DATABASES = { 'default': { - 'ENGINE': 'djongo', - 'NAME': 'WorkX', - 'ENFORCE_SCHEMA': True, # Optional: enforce the database schema + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'workxx', + 'USER': 'postgres', + 'PASSWORD': '123456', + 'HOST': 'localhost', + 'PORT': '5432', } } -SITE_ID = 2 - -SOCIALACCOUNT_LOGIN_ON_GET=True -AUTHENTICATION_BACKENDS = [ - 'allauth.account.auth_backends.AuthenticationBackend' - ] -SOCIALACCOUNT_PROVIDERS = { - 'google': { - 'SCOPE': [ - 'profile', - 'email', - ], - 'AUTH_PARAMS': { - 'access_type': 'online', - } - } -} -LOGIN_REDIRECT_URL = '/api/employee/' # Password validation # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] + +# GOOGLE_SSO_SCOPES = [ # default values +# "openid", +# "https://www.googleapis.com/auth/userinfo.email", +# "https://www.googleapis.com/auth/userinfo.profile", +# ] # Internationalization diff --git a/workx/workx/urls.py b/workx/workx/urls.py index fbe1f98..7e43991 100644 --- a/workx/workx/urls.py +++ b/workx/workx/urls.py @@ -15,20 +15,25 @@ Including another URLconf """ from django.contrib import admin from django.urls import path,include -from social_django.urls import urlpatterns as social_django_urls -from employee.views import EmployeeViewSet +from accounts.views import IncomeViewSet,ExpenseViewSet,ReimbursementViewSet +from employee.views import EmployeeListCreateAPIView,EmployeeRetrieveUpdateAPIView,RoleListCreateAPIView from company.views import CompanyViewSet from rest_framework import routers -from authUser.view import signup_redirect +from google_auth.views import login, callback + router = routers.DefaultRouter() -router.register(r'employee', EmployeeViewSet) router.register(r'company', CompanyViewSet) +router.register(r'accounts/income', IncomeViewSet) +router.register(r'accounts/reimbursement', ReimbursementViewSet) +router.register(r'accounts/expense', ExpenseViewSet) + urlpatterns = [ path('admin/', admin.site.urls), - path('api/', include(router.urls)), - path("", include("allauth.urls")), - path('social/signup/', signup_redirect, name='signup_redirect'), - -] + path('', include(router.urls)), + path('employees/', EmployeeListCreateAPIView.as_view(), name='employee-list-create'), + path('employees//', EmployeeRetrieveUpdateAPIView.as_view(), name='employee-retrieve-update'), + path('roles/', RoleListCreateAPIView.as_view(), name='role-list-create'), + path('google-auth/', include('google_auth.urls')), + ]