first push

This commit is contained in:
2025-05-23 14:44:12 +08:00
commit abefd1b19b
817 changed files with 580289 additions and 0 deletions
View File
+30
View File
@@ -0,0 +1,30 @@
from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin
from .models import *
# Register your models here.
@admin.register(Organization)
class SupportAdmin(SimpleHistoryAdmin):
list_display = ['name', 'website', 'created_at']
@admin.register(Location)
class SupportAdmin(SimpleHistoryAdmin):
list_display = ['office_name', 'address',
'organization', 'is_deleted', 'created_at']
@admin.register(Department)
class SupportAdmin(SimpleHistoryAdmin):
list_display = ['name', 'organization', 'is_deleted', 'created_at']
@admin.register(ProductType)
class SupportAdmin(SimpleHistoryAdmin):
list_display = ['name', 'organization', 'is_deleted', 'created_at']
@admin.register(ProductCategory)
class SupportAdmin(SimpleHistoryAdmin):
list_display = ['name', 'organization', 'is_deleted', 'created_at']
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class DashboardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'dashboard'
+158
View File
@@ -0,0 +1,158 @@
from dataclasses import fields
from django import forms
from .models import Location, Address, ProductType, Department, ProductCategory
class LocationForm(forms.ModelForm):
office_name = forms.CharField(required=True, widget=forms.TextInput(
attrs={'autocomplete': 'off', 'class': 'form-control',
'placeholder': 'Office Name'}
))
contact_person_name = forms.CharField(required=True, widget=forms.TextInput(
attrs={'autocomplete': 'off', 'class': 'form-control',
'placeholder': 'Contact Person Name'}
))
contact_person_email = forms.EmailField(required=True, widget=forms.EmailInput(
attrs={'autocomplete': 'off', 'class': 'form-control',
'placeholder': 'Contact Person Email'}
))
contact_person_phone = forms.IntegerField(required=True, widget=forms.NumberInput(
attrs={'autocomplete': 'off', 'class': 'form-control',
'placeholder': 'Contact Person Phone'}
))
def clean_office_name(self):
office_name = self.cleaned_data.get('office_name')
return office_name.title()
def clean_contact_person_name(self):
contact_person_name = self.cleaned_data.get('contact_person_name')
return contact_person_name.title()
def clean_contact_person_email(self):
contact_person_email = self.cleaned_data.get('contact_person_email')
return contact_person_email.lower()
class Meta:
model = Location
fields = ['office_name', 'contact_person_name',
'contact_person_email', 'contact_person_phone']
class AddressForm(forms.ModelForm):
address_line_one = forms.CharField(required=True, widget=forms.Textarea(
attrs={'autocomplete': 'off', 'class': 'form-control',
'placeholder': 'Address Line 1', 'rows': '2'}
))
address_line_two = forms.CharField(required=True, widget=forms.Textarea(
attrs={'autocomplete': 'off', 'class': 'form-control',
'placeholder': 'Address Line 2', 'rows': '2'}
))
country = forms.CharField(required=True, widget=forms.TextInput(
attrs={'autocomplete': 'off',
'class': 'form-control', 'placeholder': 'Country'}
))
state = forms.CharField(required=True, widget=forms.TextInput(
attrs={'autocomplete': 'off',
'class': 'form-control', 'placeholder': 'State'}
))
city = forms.CharField(required=True, widget=forms.TextInput(
attrs={'autocomplete': 'off',
'class': 'form-control', 'placeholder': 'City'}
))
pin_code = forms.CharField(required=True, widget=forms.TextInput(
attrs={'autocomplete': 'off', 'class': 'form-control',
'placeholder': 'Zip Code'}
))
def clean_country(self):
country = self.cleaned_data.get('country')
return country.title()
def clean_state(self):
state = self.cleaned_data.get('state')
return state.title()
def clean_city(self):
city = self.cleaned_data.get('city')
return city.title()
class Meta:
model = Address
fields = ['address_line_one', 'address_line_two',
'country', 'state', 'city', 'pin_code']
class ProductTypeForm(forms.ModelForm):
name = forms.CharField(required=True, widget=forms.TextInput(
attrs={'autocomplete': 'off', 'class': 'form-control',
'placeholder': 'Type Name'}
))
def __init__(self, *args, **kwargs):
self._organization = kwargs.pop('organization', None)
self._pk = kwargs.pop('pk', None)
super(ProductTypeForm, self).__init__(*args, **kwargs)
def clean_name(self):
name = self.cleaned_data.get('name')
if ProductType.undeleted_objects.filter(name__iexact=name, organization=self._organization).exclude(pk=self._pk).exists():
raise forms.ValidationError('Name must be unique!')
return name
class Meta:
model = ProductType
fields = ['name']
class DepartmentForm(forms.ModelForm):
name = forms.CharField(required=True, widget=forms.TextInput(
attrs={'autocomplete': 'off', 'class': 'form-control', 'placeholder': 'Department Name'}
))
contact_person_name = forms.CharField(required=True, widget=forms.TextInput(
attrs={'autocomplete': 'off', 'class': 'form-control', 'placeholder': 'Contact Person Name'}
))
contact_person_email = forms.EmailField(required=True, widget=forms.EmailInput(
attrs={'autocomplete': 'off', 'class': 'form-control', 'placeholder': 'Contact Person Email'}
))
contact_person_phone = forms.IntegerField(required=True, widget=forms.NumberInput(
attrs={'autocomplete': 'off', 'class': 'form-control', 'placeholder': 'Contact Person Phone'}
))
def clean_contact_person_name(self):
contact_person_name = self.cleaned_data.get('contact_person_name')
return contact_person_name.title()
def clean_contact_person_email(self):
contact_person_email = self.cleaned_data.get('contact_person_email')
return contact_person_email.lower()
class Meta:
model = Department
fields = ['name', 'contact_person_name',
'contact_person_email', 'contact_person_phone']
class ProductCategoryForm(forms.ModelForm):
name = forms.CharField(required=True, widget=forms.TextInput(
attrs={'autocomplete': 'off', 'class': 'form-control',
'placeholder': 'Category Name'}
))
def __init__(self, *args, **kwargs):
self._organization = kwargs.pop('organization', None)
self._pk = kwargs.pop('pk', None)
super(ProductCategoryForm, self).__init__(*args, **kwargs)
def clean_name(self):
name = self.cleaned_data.get('name')
if ProductCategory.undeleted_objects.filter(name__iexact=name, organization=self._organization).exclude(pk=self._pk).exists():
raise forms.ValidationError('Name must be unique!')
return name
class Meta:
model = ProductCategory
fields = ['name']
+139
View File
@@ -0,0 +1,139 @@
# Generated by Django 3.2 on 2022-05-27 06:01
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Department',
fields=[
('status', models.IntegerField(default=1)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('created_by', models.IntegerField()),
('updated_by', models.IntegerField()),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(blank=True, max_length=255, null=True)),
('contact_person_name', models.CharField(blank=True, max_length=255, null=True)),
('contact_person_email', models.CharField(blank=True, max_length=255, null=True)),
('contact_person_phone', models.CharField(blank=True, max_length=255, null=True)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Organization',
fields=[
('status', models.IntegerField(default=1)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('created_by', models.IntegerField()),
('updated_by', models.IntegerField()),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(blank=True, max_length=255, null=True)),
('website', models.CharField(blank=True, max_length=255, null=True)),
('email', models.CharField(blank=True, max_length=255, null=True)),
('phone', models.CharField(blank=True, max_length=255, null=True)),
('currency', models.CharField(blank=True, max_length=255, null=True)),
('date_format', models.CharField(blank=True, max_length=255, null=True)),
('logo', models.ImageField(blank=True, max_length=255, null=True, upload_to='')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='ProductType',
fields=[
('status', models.IntegerField(default=1)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('created_by', models.IntegerField()),
('updated_by', models.IntegerField()),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(blank=True, max_length=255, null=True)),
('organization', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='dashboard.organization')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='ProductCategory',
fields=[
('status', models.IntegerField(default=1)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('created_by', models.IntegerField()),
('updated_by', models.IntegerField()),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(blank=True, max_length=255, null=True)),
('organization', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='dashboard.organization')),
('product_category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='dashboard.producttype')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Location',
fields=[
('status', models.IntegerField(default=1)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('created_by', models.IntegerField()),
('updated_by', models.IntegerField()),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('office_name', models.CharField(blank=True, max_length=255, null=True)),
('address_line_one', models.CharField(blank=True, max_length=255, null=True)),
('address_line_two', models.CharField(blank=True, max_length=255, null=True)),
('country', models.IntegerField()),
('state', models.IntegerField()),
('city', models.CharField(blank=True, max_length=255, null=True)),
('pin_code', models.CharField(blank=True, max_length=255, null=True)),
('contact_person_name', models.CharField(blank=True, max_length=255, null=True)),
('contact_person_phone', models.CharField(blank=True, max_length=255, null=True)),
('organization', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='dashboard.organization')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Employee',
fields=[
('status', models.IntegerField(default=1)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('created_by', models.IntegerField()),
('updated_by', models.IntegerField()),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(blank=True, max_length=255, null=True)),
('employee_id', models.CharField(blank=True, max_length=45, null=True)),
('email', models.CharField(blank=True, max_length=255, null=True)),
('phone', models.CharField(blank=True, max_length=45, null=True)),
('departments', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='dashboard.department')),
('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='dashboard.location')),
('organization', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='dashboard.organization')),
('reporting_manager', models.ForeignKey(blank=True, db_column='reporting_manager', null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='dashboard.employee')),
],
options={
'abstract': False,
},
),
migrations.AddField(
model_name='department',
name='organization',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='dashboard.organization'),
),
]
@@ -0,0 +1,73 @@
# Generated by Django 3.2 on 2022-06-21 13:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='department',
name='created_by',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='department',
name='updated_by',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='employee',
name='created_by',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='employee',
name='updated_by',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='location',
name='created_by',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='location',
name='updated_by',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='organization',
name='created_by',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='organization',
name='updated_by',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='productcategory',
name='created_by',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='productcategory',
name='updated_by',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='producttype',
name='created_by',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='producttype',
name='updated_by',
field=models.CharField(blank=True, max_length=255, null=True),
),
]
@@ -0,0 +1,64 @@
# Generated by Django 3.2 on 2022-07-03 18:43
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0002_auto_20220621_1350'),
]
operations = [
migrations.CreateModel(
name='Address',
fields=[
('status', models.IntegerField(default=1)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('created_by', models.CharField(blank=True, max_length=255, null=True)),
('updated_by', models.CharField(blank=True, max_length=255, null=True)),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('address_line_one', models.TextField(blank=True, null=True)),
('address_line_two', models.TextField(blank=True, null=True)),
('country', models.CharField(blank=True, max_length=255, null=True)),
('state', models.CharField(blank=True, max_length=255, null=True)),
('city', models.CharField(blank=True, max_length=255, null=True)),
('pin_code', models.CharField(blank=True, max_length=255, null=True)),
],
options={
'abstract': False,
},
),
migrations.RemoveField(
model_name='location',
name='address_line_one',
),
migrations.RemoveField(
model_name='location',
name='address_line_two',
),
migrations.RemoveField(
model_name='location',
name='city',
),
migrations.RemoveField(
model_name='location',
name='country',
),
migrations.RemoveField(
model_name='location',
name='pin_code',
),
migrations.RemoveField(
model_name='location',
name='state',
),
migrations.AddField(
model_name='location',
name='address',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='dashboard.address'),
),
]
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2022-07-05 13:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0003_auto_20220703_1843'),
]
operations = [
migrations.AddField(
model_name='location',
name='contact_person_email',
field=models.EmailField(blank=True, max_length=255, null=True),
),
]
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2022-07-05 18:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0004_location_contact_person_email'),
]
operations = [
migrations.AlterField(
model_name='organization',
name='logo',
field=models.ImageField(blank=True, null=True, upload_to='logos'),
),
]
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2022-08-30 07:25
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0005_alter_organization_logo'),
]
operations = [
migrations.RenameField(
model_name='productcategory',
old_name='product_category',
new_name='product_type',
),
]
@@ -0,0 +1,17 @@
# Generated by Django 3.2 on 2022-09-21 11:04
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0006_rename_product_category_productcategory_product_type'),
]
operations = [
migrations.RemoveField(
model_name='productcategory',
name='product_type',
),
]
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2022-09-28 09:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0007_remove_productcategory_product_type'),
]
operations = [
migrations.AddField(
model_name='producttype',
name='is_deleted',
field=models.BooleanField(default=False),
),
]
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2022-09-29 07:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0008_producttype_is_deleted'),
]
operations = [
migrations.AddField(
model_name='producttype',
name='deleted',
field=models.BooleanField(default=False),
),
]
@@ -0,0 +1,17 @@
# Generated by Django 3.2 on 2022-09-29 07:49
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0009_producttype_deleted'),
]
operations = [
migrations.RemoveField(
model_name='producttype',
name='deleted',
),
]
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2022-09-29 10:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0010_remove_producttype_deleted'),
]
operations = [
migrations.AddField(
model_name='location',
name='is_deleted',
field=models.BooleanField(default=False),
),
]
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2022-09-29 10:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0010_remove_producttype_deleted'),
]
operations = [
migrations.AddField(
model_name='productcategory',
name='is_deleted',
field=models.BooleanField(default=False),
),
]
@@ -0,0 +1,14 @@
# Generated by Django 3.2 on 2022-09-29 13:55
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0011_location_is_deleted'),
('dashboard', '0011_productcategory_is_deleted'),
]
operations = [
]
@@ -0,0 +1,14 @@
# Generated by Django 3.2 on 2022-09-30 05:13
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0011_location_is_deleted'),
('dashboard', '0011_productcategory_is_deleted'),
]
operations = [
]
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2022-09-29 13:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0012_merge_20220929_1355'),
]
operations = [
migrations.AddField(
model_name='department',
name='is_deleted',
field=models.BooleanField(default=False),
),
]
@@ -0,0 +1,14 @@
# Generated by Django 3.2 on 2022-10-06 11:12
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0012_merge_20220930_0513'),
('dashboard', '0013_department_is_deleted'),
]
operations = [
]
@@ -0,0 +1,16 @@
# Generated by Django 3.2 on 2022-10-13 12:20
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0014_merge_20221006_1112'),
]
operations = [
migrations.DeleteModel(
name='Employee',
),
]
@@ -0,0 +1,19 @@
# Generated by Django 3.2 on 2022-12-12 13:17
import dashboard.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0015_delete_employee'),
]
operations = [
migrations.AlterField(
model_name='organization',
name='logo',
field=models.ImageField(blank=True, null=True, upload_to=dashboard.models.path_and_rename),
),
]
@@ -0,0 +1,20 @@
# Generated by Django 3.2 on 2022-12-13 13:08
import dashboard.models
from django.db import migrations
import django_resized.forms
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0016_alter_organization_logo'),
]
operations = [
migrations.AlterField(
model_name='organization',
name='logo',
field=django_resized.forms.ResizedImageField(blank=True, crop=None, force_format='JPEG', keep_meta=True, null=True, quality=75, scale=None, size=[1024, 768], upload_to=dashboard.models.path_and_rename),
),
]
@@ -0,0 +1,43 @@
# Generated by Django 3.2 on 2023-01-04 09:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0017_alter_organization_logo'),
]
operations = [
migrations.AlterField(
model_name='address',
name='status',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='department',
name='status',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='location',
name='status',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='organization',
name='status',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='productcategory',
name='status',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='producttype',
name='status',
field=models.BooleanField(default=True),
),
]
@@ -0,0 +1,159 @@
# Generated by Django 3.2 on 2023-01-05 08:13
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import simple_history.models
import uuid
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('dashboard', '0018_auto_20230104_1455'),
]
operations = [
migrations.CreateModel(
name='HistoricalProductType',
fields=[
('status', models.BooleanField(default=True)),
('created_at', models.DateTimeField(blank=True, editable=False)),
('updated_at', models.DateTimeField(blank=True, editable=False)),
('created_by', models.CharField(blank=True, max_length=255, null=True)),
('updated_by', models.CharField(blank=True, max_length=255, null=True)),
('is_deleted', models.BooleanField(default=False)),
('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False)),
('name', models.CharField(blank=True, max_length=255, null=True)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('organization', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='dashboard.organization')),
],
options={
'verbose_name': 'historical product type',
'verbose_name_plural': 'historical product types',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='HistoricalProductCategory',
fields=[
('status', models.BooleanField(default=True)),
('created_at', models.DateTimeField(blank=True, editable=False)),
('updated_at', models.DateTimeField(blank=True, editable=False)),
('created_by', models.CharField(blank=True, max_length=255, null=True)),
('updated_by', models.CharField(blank=True, max_length=255, null=True)),
('is_deleted', models.BooleanField(default=False)),
('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False)),
('name', models.CharField(blank=True, max_length=255, null=True)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('organization', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='dashboard.organization')),
],
options={
'verbose_name': 'historical product category',
'verbose_name_plural': 'historical product categorys',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='HistoricalOrganization',
fields=[
('status', models.BooleanField(default=True)),
('created_at', models.DateTimeField(blank=True, editable=False)),
('updated_at', models.DateTimeField(blank=True, editable=False)),
('created_by', models.CharField(blank=True, max_length=255, null=True)),
('updated_by', models.CharField(blank=True, max_length=255, null=True)),
('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False)),
('name', models.CharField(blank=True, max_length=255, null=True)),
('website', models.CharField(blank=True, max_length=255, null=True)),
('email', models.CharField(blank=True, max_length=255, null=True)),
('phone', models.CharField(blank=True, max_length=255, null=True)),
('currency', models.CharField(blank=True, max_length=255, null=True)),
('date_format', models.CharField(blank=True, max_length=255, null=True)),
('logo', models.TextField(blank=True, max_length=100, null=True)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'historical organization',
'verbose_name_plural': 'historical organizations',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='HistoricalLocation',
fields=[
('status', models.BooleanField(default=True)),
('created_at', models.DateTimeField(blank=True, editable=False)),
('updated_at', models.DateTimeField(blank=True, editable=False)),
('created_by', models.CharField(blank=True, max_length=255, null=True)),
('updated_by', models.CharField(blank=True, max_length=255, null=True)),
('is_deleted', models.BooleanField(default=False)),
('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False)),
('office_name', models.CharField(blank=True, max_length=255, null=True)),
('contact_person_name', models.CharField(blank=True, max_length=255, null=True)),
('contact_person_email', models.EmailField(blank=True, max_length=255, null=True)),
('contact_person_phone', models.CharField(blank=True, max_length=255, null=True)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('address', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='dashboard.address')),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('organization', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='dashboard.organization')),
],
options={
'verbose_name': 'historical location',
'verbose_name_plural': 'historical locations',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='HistoricalDepartment',
fields=[
('status', models.BooleanField(default=True)),
('created_at', models.DateTimeField(blank=True, editable=False)),
('updated_at', models.DateTimeField(blank=True, editable=False)),
('created_by', models.CharField(blank=True, max_length=255, null=True)),
('updated_by', models.CharField(blank=True, max_length=255, null=True)),
('is_deleted', models.BooleanField(default=False)),
('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False)),
('name', models.CharField(blank=True, max_length=255, null=True)),
('contact_person_name', models.CharField(blank=True, max_length=255, null=True)),
('contact_person_email', models.CharField(blank=True, max_length=255, null=True)),
('contact_person_phone', models.CharField(blank=True, max_length=255, null=True)),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('organization', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='dashboard.organization')),
],
options={
'verbose_name': 'historical department',
'verbose_name_plural': 'historical departments',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]
View File
+132
View File
@@ -0,0 +1,132 @@
import uuid
from django.db import models
import os
from uuid import uuid4
from django_resized import ResizedImageField
from simple_history.models import HistoricalRecords
def path_and_rename(instance, filename):
upload_to = 'logo/'
ext = filename.split('.')[-1]
if instance.pk:
filename = '{}.{}'.format(instance.pk, ext)
else:
filename = '{}.{}'.format(uuid4().hex, ext)
return os.path.join(upload_to, filename)
class TimeStampModel(models.Model):
status = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
created_by = models.CharField(max_length=255, blank=True, null=True)
updated_by = models.CharField(max_length=255, blank=True, null=True)
class Meta:
abstract = True
class RestoreManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(is_deleted=True)
class SoftDeleteManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(is_deleted=False)
class SoftDeleteModel(models.Model):
is_deleted = models.BooleanField(default=False)
objects = models.Manager()
undeleted_objects = SoftDeleteManager()
deleted_objects = RestoreManager()
def soft_delete(self):
self.is_deleted = True
self.save()
def restore(self):
self.is_deleted = False
self.save()
class Meta:
abstract = True
class Department(TimeStampModel, SoftDeleteModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=255, blank=True, null=True)
contact_person_name = models.CharField(max_length=255, blank=True, null=True)
contact_person_email = models.CharField(max_length=255, blank=True, null=True)
contact_person_phone = models.CharField(max_length=255, blank=True, null=True)
organization = models.ForeignKey('Organization', models.DO_NOTHING, blank=True, null=True)
history = HistoricalRecords()
def __str__(self):
return self.name
class Location(TimeStampModel, SoftDeleteModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
organization = models.ForeignKey('Organization', models.DO_NOTHING, blank=True, null=True)
office_name = models.CharField(max_length=255, blank=True, null=True)
contact_person_name = models.CharField(max_length=255, blank=True, null=True)
contact_person_email = models.EmailField(max_length=255, blank=True, null=True)
contact_person_phone = models.CharField(max_length=255, blank=True, null=True)
address = models.ForeignKey('Address', on_delete=models.CASCADE, blank=True, null=True)
history = HistoricalRecords()
def __str__(self):
return f'{self.office_name} - {self.address}'
class Organization(TimeStampModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=255, blank=True, null=True)
website = models.CharField(max_length=255, blank=True, null=True)
email = models.CharField(max_length=255, blank=True, null=True)
phone = models.CharField(max_length=255, blank=True, null=True)
currency = models.CharField(max_length=255, blank=True, null=True)
date_format = models.CharField(max_length=255, blank=True, null=True)
logo = ResizedImageField(upload_to=path_and_rename, blank=True, null=True)
history = HistoricalRecords()
def __str__(self):
return self.name
class ProductType(TimeStampModel, SoftDeleteModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=255, blank=True, null=True)
organization = models.ForeignKey(Organization, models.DO_NOTHING, blank=True, null=True)
history = HistoricalRecords()
def __str__(self):
return self.name
class ProductCategory(TimeStampModel, SoftDeleteModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=255, blank=True, null=True)
organization = models.ForeignKey(Organization, models.DO_NOTHING, blank=True, null=True)
history = HistoricalRecords()
def __str__(self):
return self.name
class Address(TimeStampModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
address_line_one = models.TextField(blank=True, null=True)
address_line_two = models.TextField(blank=True, null=True)
country = models.CharField(max_length=255, blank=True, null=True)
state = models.CharField(max_length=255, blank=True, null=True)
city = models.CharField(max_length=255, blank=True, null=True)
pin_code = models.CharField(max_length=255, blank=True, null=True)
# def __str__(self):
# return f'{self.address_line_one}, {self.address_line_two}, {self.country}, {self.state}, {self.city}, {self.pin_code}'
+365
View File
@@ -0,0 +1,365 @@
from django.test import TestCase
from .models import Address,Location,Organization,ProductType,ProductCategory,Department
# Create your tests here.
class Asseto_test_address(TestCase):
def setUp(self):
Address.objects.create(
country = "India",
state = "Rajasthan",
address_line_one = "testline 1",
address_line_two = "testline 2",
city = "Jaipur",
pin_code = "302001"
)
def test_product_category(self):
print("Address Testing Start")
address = Address.objects.get(country="India")
self.assertEqual(address.state, "Rajasthan")
print("Address Testing Successful\n")
class Asseto_test_location(TestCase):
def setUp(self):
self.user_organization = Organization.objects.create(
name="Organization 1",
website="asseto.com",
phone="1234567890",
email="asseto@asseto.com",
currency="INR",
date_format="dd-mm-yyyy",
logo = "logo.png"
)
self.user_address=Address.objects.create(
address_line_one = "Address line 1",
address_line_two = "Address line 2",
country = "India",
state="West Bengal",
city = "Kolkata",
pin_code = "700018",
)
self.location=Location.objects.create(
office_name = "Office 1",
address = self.user_address,
contact_person_name = "Person 1",
contact_person_email = "person1@asseto.com",
contact_person_phone = "1234567890",
organization = self.user_organization,
)
self.location.save()
self.edit_address=Address.objects.create(
address_line_one = "Address line 1",
address_line_two = "Address line 2",
country = "India",
state="West Bengal",
city = "Kolkata",
pin_code = "700018",
)
self.edit_organization = Organization.objects.create(name='Organization 1', website='www.example.com', email='organization@example.com', phone='1234567890')
self.edit_location = Location.objects.create(
office_name="Test Office",
contact_person_name="John Doe",
contact_person_email="johndoe@example.com",
contact_person_phone="1234567890",
address=self.edit_address,
organization=self.edit_organization,
)
self.product_category=ProductCategory.objects.create(
name="Category 1",
organization=self.edit_organization,
)
self.product_type=ProductType.objects.create(
name="Type 1",
organization=self.edit_organization
)
def test_location(self):
print("Location Testing Start")
# location = Location.objects.get(office_name="Office 1")
self.assertEqual(self.location.contact_person_name, "Person 1")
self.assertEqual(self.location.contact_person_email, "person1@asseto.com")
self.assertEqual(self.location.contact_person_phone, "1234567890")
self.assertEqual(self.location.office_name,'Office 1')
self.assertEqual(self.location.address.address_line_one,'Address line 1')
self.assertEqual(self.location.address.address_line_two,'Address line 2')
self.assertEqual(self.location.address.country,'India')
self.assertEqual(self.location.address.state,'West Bengal')
self.assertEqual(self.location.address.city,'Kolkata')
self.assertEqual(self.location.address.pin_code,'700018')
print("Location Testing Successful\n")
class Asseto_test_producttype(TestCase):
def setUp(self):
user_organization = Organization.objects.create(
name="Organization 1",
website="asseto.com",
phone="1234567890",
email="asseto@asseto.com",
currency="INR",
date_format="dd-mm-yyyy",
logo = "logo.png"
)
ProductType.objects.create(
name="Type 1",
organization=user_organization,
)
def test_product_type(self):
print("Product Type Testing Start")
type = ProductType.objects.get(name="Type 1")
self.assertEqual(type.name, "Type 1")
# self.assertEqual(type.organization.name, "Organization 1")
print("Product Category Testing Successful\n")
class Asseto_test_four(TestCase):
def setUp(self):
user_organization = Organization.objects.create(
name="Organization 1",
website="asseto.com",
phone="1234567890",
email="asseto@asseto.com",
currency="INR",
date_format="dd-mm-yyyy",
logo = "logo.png"
)
ProductCategory.objects.create(
name="Category 1",
organization=user_organization,
)
def test_product_category(self):
print("Testing Product Category Start")
category = ProductCategory.objects.get(name="Category 1")
self.assertEqual(category.name, "Category 1")
self.assertEqual(category.organization.name, "Organization 1")
print("Product Category Testing Successful\n")
class Asseto_test_five(TestCase):
def setUp(self):
user_organization = Organization.objects.create(
name="Organization 1",
website="asseto.com",
phone="1234567890",
email="asseto@asseto.com",
currency="INR",
date_format="dd-mm-yyyy",
logo = "logo.png"
)
Department.objects.create(
name="Department 1",
organization=user_organization,
contact_person_name = "Person 1",
contact_person_email = "person1@asseto.com",
contact_person_phone = "1234567890",
)
# print("setup product category")
def test_product_category(self):
print("Testing Product Category Start")
department = Department.objects.get(name="Department 1")
self.assertEqual(department.name, "Department 1")
self.assertEqual(department.organization.name, "Organization 1")
self.assertEqual(department.contact_person_name, "Person 1")
self.assertEqual(department.contact_person_email, "person1@asseto.com")
self.assertEqual(department.contact_person_phone, "1234567890")
print("Testing Product Category Successful\n")
class EditDepartmentTest(TestCase):
def setUp(self):
self.organization = Organization.objects.create(name='Organization 1', website='www.example.com', email='organization@example.com', phone='1234567890')
self.department = Department.objects.create(name='Department 1', contact_person_name='Contact Person 1', contact_person_email='contactperson1@example.com',
contact_person_phone='1112223333', organization=self.organization)
def test_edit_department(self):
# Edit the department
print("Testing Edit Department Start")
self.department.name = 'New Department'
self.department.contact_person_name = 'New Contact Person'
self.department.contact_person_email = 'newcontactperson@example.com'
self.department.contact_person_phone = '4445556666'
self.department.save()
# Check that the changes were saved correctly
self.assertEqual(self.department.name, 'New Department')
self.assertEqual(self.department.contact_person_name, 'New Contact Person')
self.assertEqual(self.department.contact_person_email, 'newcontactperson@example.com')
self.assertEqual(self.department.contact_person_phone, '4445556666')
print("Testing Edit Department Successful\n")
# def test_edit_department_with_same_info(self):
# # Edit the department with same information
# self.department.name = 'Department 1'
# self.department.contact_person_name = 'Contact Person 1'
# self.department.contact_person_email = 'contactperson1@example.com'
# self.department.contact_person_phone = '1112223333'
# self.department.save()
# # Check that the changes were saved correctly
# self.assertEqual(self.department.name, 'Department 1')
# self.assertEqual(self.department.contact_person_name, 'Contact Person 1')
# self.assertEqual(self.department.contact_person_email, 'contactperson1@example.com')
# self.assertEqual(self.department.contact_person_phone, '1112223333')
def test_edit_department_organization(self):
# Edit the organization of the department
print("Testing Deapartment Organization Start")
new_organization = Organization.objects.create(name='New Organization', website='www.newexample.com', email='neworganization@example.com', phone='5556667777')
self.department.organization = new_organization
self.department.save()
# Check that the changes were saved correctly
self.assertEqual(self.department.organization.name, 'New Organization')
self.assertEqual(self.department.organization.website, 'www.newexample.com')
self.assertEqual(self.department.organization.email, 'neworganization@example.com')
self.assertEqual(self.department.organization.phone, '5556667777')
print("Testing Deapartment Organization Successful\n")
class EditProductTypeTest(TestCase):
def setUp(self):
self.organization = Organization.objects.create(name='Organization 1', website='www.example.com', email='organization@example.com', phone='1234567890')
self.product_type = ProductType.objects.create(name='Product Type 1', organization=self.organization)
def test_edit_product_type(self):
# Edit the product type
print("Testing Product Type Start")
self.product_type.name = 'New Product Type'
self.product_type.save()
# Check that the changes were saved correctly
self.assertEqual(self.product_type.name, 'New Product Type')
print("Testing Product Type Successful\n")
# def test_edit_product_type_with_same_info(self):
# # Edit the product type with same information
# self.product_type.name = 'Product Type 1'
# self.product_type.save()
# # Check that the changes were saved correctly
# self.assertEqual(self.product_type.name, 'Product Type 1')
class EditProductCategoryTest(TestCase):
def setUp(self):
self.organization = Organization.objects.create(name='Organization 1',
website='www.example.com', email='organization@example.com',
phone='1234567890')
self.product_category = ProductCategory.objects.create(name='Product Category 1', organization=self.organization)
def test_edit_product_category(self):
print("Testing Product Category Start")
self.product_category.name = 'New Product category'
self.product_category.save()
# Check that the changes were saved correctly
self.assertEqual(self.product_category.name, 'New Product category')
print("Testing Product Category Successful\n")
# def test_edit_product_type_with_same_info(self):
# # Edit the product type with same information
# self.product_category.name = 'Product Category 1'
# self.product_category.save()
# # Check that the changes were saved correctly
# self.assertEqual(self.product_category.name, 'Product Category 1')
class TestEditLocation(TestCase):
def setUp(self):
self.address=Address.objects.create(
address_line_one = "Address line 1",
address_line_two = "Address line 2",
country = "India",
state="West Bengal",
city = "Kolkata",
pin_code = "700018",
)
self.organization = Organization.objects.create(name='Organization 1', website='www.example.com', email='organization@example.com', phone='1234567890')
self.location = Location.objects.create(
office_name="Test Office",
contact_person_name="John Doe",
contact_person_email="johndoe@example.com",
contact_person_phone="1234567890",
address=self.address,
organization=self.organization,
)
self.product_category=ProductCategory.objects.create(
name="Category 1",
organization=self.organization,
)
self.product_type=ProductType.objects.create(
name="Type 1",
organization=self.organization
)
# def test_edit_location_with_same_info(self):
def test_edit_location(self):
# Test editing the office name
print("Testing Edit Location Start")
self.location.office_name = "New Office Name"
self.location.contact_person_name = "Jane Doe"
self.location.contact_person_email = "johndoe@example.com"
self.location.contact_person_phone = "9876543210"
self.location.address.address_line_one = "New Address Line 1"
self.location.address.address_line_two = "New Address Line 2"
self.location.address.country = "New Country"
self.location.address.state = "New State"
self.location.address.city = "New City"
self.location.address.pin_code = "123456"
self.location.organization.name = "New Organization"
self.location.organization.website = "www.newexample.com"
self.location.organization.email = "neworganization@example.com"
self.location.organization.phone = "5556667777"
self.location.save()
# Check that the changes were saved correctly
self.assertEqual(self.location.office_name, "New Office Name")
self.assertEqual(self.location.contact_person_name, "Jane Doe")
self.assertEqual(self.location.contact_person_email, "johndoe@example.com")
self.assertEqual(self.location.contact_person_phone, "9876543210")
self.assertEqual(self.location.address.address_line_one, "New Address Line 1")
self.assertEqual(self.location.address.address_line_two, "New Address Line 2")
self.assertEqual(self.location.address.country, "New Country")
self.assertEqual(self.location.address.state, "New State")
self.assertEqual(self.location.address.city, "New City")
self.assertEqual(self.location.address.pin_code, "123456")
self.assertEqual(self.location.organization.name, "New Organization")
self.assertEqual(self.location.organization.website, "www.newexample.com")
self.assertEqual(self.location.organization.email, "neworganization@example.com")
self.assertEqual(self.location.organization.phone, "5556667777")
print("Testing Edit Location Successful\n")
# def test_edit_location_invalid_data(self):
# # Test that editing with invalid data raises a ValidationError
# new_office_name = "" # Empty string is not allowed
# with self.assertRaises(ValidationError):
# self.location.office_name = new_office_name
# self.location.save()
def test_delete_location(self):
print("Testing Delete Location Start")
self.location.delete()
with self.assertRaises(Location.DoesNotExist):
Location.objects.get(id=self.location.id)
address=Address.objects.get(city=self.location.address.city)
organization=Organization.objects.get(id=self.location.organization.id)
self.assertIsNotNone(organization)
self.assertIsNotNone(address)
print("Testing Delete Location Successful\n")
def test_delete_product_category(self):
print("Testing Delete Product Category Start")
self.product_category.delete()
organization=Organization.objects.get(id=self.product_category.organization.id)
self.assertIsNotNone(organization)
print("Testing Delete Product Category Successful\n")
def test_delete_product_type(self):
print("Testing Delete Product Type Start")
self.product_type.delete()
organization=Organization.objects.get(id=self.product_type.organization.id)
self.assertIsNotNone(organization)
print("Testing Delete Product Type Successful\n")
+43
View File
@@ -0,0 +1,43 @@
from django.urls import path
from . import views
app_name = 'dashboard'
urlpatterns = [
# location urls
path('locations/list', views.locations, name='locations'),
path('locations/add', views.add_location, name='add_location'),
path('locations/details/<uuid:id>', views.location_details, name='location_details'),
path('locations/update/<uuid:id>', views.update_location, name='update_location'),
path('locations/delete/<uuid:id>', views.delete_location, name='delete_location'),
path('locations/status/<uuid:id>', views.location_status, name='location_status'),
path('locations/search/<str:page>', views.search_location, name='search_location'),
# department urls
path('departments/list', views.departments, name='departments'),
path('departments/detail/<uuid:id>', views.department_details, name='department_details'),
path('departments/updates/<uuid:id>', views.update_department, name='update_department'),
path('departments/add', views.add_department, name='add_department'),
path('departments/delete/<uuid:id>', views.delete_department, name='delete_department'),
path('departments/status/<uuid:id>', views.department_status, name='department_status'),
path('departments/search/<str:page>', views.search_department, name='search_department'),
# product type urls
path('product-types/list', views.product_type_list, name='product_type_list'),
path('product-types/add', views.add_product_type, name='add_product_type'),
path('product-types/details/<uuid:id>', views.product_type_details, name='product_type_details'),
path('product-types/update/<uuid:id>', views.update_product_type, name='update_product_type'),
path('product-types/delete/<uuid:id>', views.delete_product_type, name='delete_product_type'),
path('product-types/status/<uuid:id>', views.product_type_status, name='product_type_status'),
path('product-types/search/<str:page>', views.search_product_type, name='search_product_type'),
# product category urls
path('product-categories/list', views.product_category_list, name='product_category_list'),
path('product-categories/add', views.add_product_category,name='add_product_category'),
path('product-categories/details/<uuid:id>', views.product_category_details, name='product_category_details'),
path('product-categories/delete/<uuid:id>', views.delete_product_category, name='delete_product_category'),
path('product-categories/update/<uuid:id>', views.update_product_category, name='update_product_category'),
path('product-categories/status/<uuid:id>', views.product_category_status, name='product_category_status'),
path('product-categories/search/<str:page>', views.search_product_category, name='search_product_category'),
]
+4
View File
@@ -0,0 +1,4 @@
from .location_views import *
from .department_views import *
from .product_type_views import *
from .product_category_views import *
+154
View File
@@ -0,0 +1,154 @@
from django.shortcuts import render
from django.contrib import messages
from dashboard.models import Department
from django.core.paginator import Paginator
from django.shortcuts import render, redirect
from dashboard.forms import DepartmentForm
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.decorators import user_passes_test
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404
from django.db.models import Q
PAGE_SIZE = 10
ORPHANS = 1
def check_admin(user):
return user.is_superuser
def manage_access(user):
permissions_list = [
'authentication.edit_department',
'authentication.add_department',
'authentication.delete_department',
]
for permission in permissions_list:
if user.has_perm(permission):
return True
return False
@login_required
@user_passes_test(manage_access)
def departments(request):
department_list = Department.undeleted_objects.filter(
organization=request.user.organization).order_by('-created_at')
paginator = Paginator(department_list, PAGE_SIZE, orphans=ORPHANS)
page_number = request.GET.get('page')
page_object = paginator.get_page(page_number)
department_form = DepartmentForm()
context = {
'sidebar': 'admin',
'submenu': 'department',
'page_object': page_object,
'department_form': department_form,
'title': 'Departments'
}
return render(request, 'dashboard/departments/list.html', context=context)
@login_required
@user_passes_test(check_admin)
def department_details(request, id):
department = get_object_or_404(
Department.undeleted_objects, pk=id, organization=request.user.organization)
history_list = department.history.all()
paginator = Paginator(history_list, 5, orphans=1)
page_number = request.GET.get('page')
page_object = paginator.get_page(page_number)
context = {'sidebar': 'admin', 'page_object': page_object,
'submenu': 'department', 'department': department, 'title': 'Department - Details'}
return render(request, 'dashboard/departments/detail.html', context=context)
@login_required
@permission_required('authentication.add_department')
def add_department(request):
form = DepartmentForm(request.POST or None)
if request.method == "POST":
if form.is_valid():
department = form.save(commit=False)
department.organization = request.user.organization
department.save()
messages.success(request, 'Department added successfully')
return HttpResponse(status=204)
context = {"form": form, "modal_title": "Add Department"}
return render(request, 'dashboard/departments/department-modal.html', context=context)
@login_required
@permission_required('authentication.edit_department')
def update_department(request, id):
department = get_object_or_404(
Department.undeleted_objects, pk=id, organization=request.user.organization)
form = DepartmentForm(
request.POST or None, instance=department)
if request.method == "POST":
if form.is_valid():
form.save()
messages.success(request, 'Department updated successfully')
return HttpResponse(status=204)
context = {"form": form, "modal_title": "Update Department"}
return render(request, 'dashboard/departments/department-modal.html', context=context)
@login_required
@permission_required('authentication.delete_department')
def delete_department(request, id):
if request.method == 'POST':
department = get_object_or_404(
Department.undeleted_objects, pk=id, organization=request.user.organization)
department.status = False
department.soft_delete()
history_id = department.history.first().history_id
department.history.filter(pk=history_id).update(history_type='-')
messages.success(request, 'Department deleted successfully')
return redirect(request.META.get('HTTP_REFERER'))
return redirect('/')
@user_passes_test(check_admin)
def department_status(request, id):
if request.method == "POST":
department = get_object_or_404(
Department.undeleted_objects, pk=id, organization=request.user.organization)
department.status = False if department.status else True
department.save()
return HttpResponse(status=204)
@login_required
def search_department(request, page):
search_text = request.GET.get('search_text').strip()
if search_text:
return render(request, 'dashboard/departments/departments-data.html', {
'page_object': Department.undeleted_objects.filter(Q(organization=request.user.organization) & (Q(
name__icontains=search_text) | Q(contact_person_name__icontains=search_text) | Q(contact_person_email__icontains=search_text) | Q(contact_person_phone__icontains=search_text)
)).order_by('-created_at')[:10]
})
department_list = Department.undeleted_objects.filter(
organization=request.user.organization).order_by('-created_at')
paginator = Paginator(department_list, PAGE_SIZE, orphans=ORPHANS)
page_number = page
page_object = paginator.get_page(page_number)
return render(request, 'dashboard/departments/departments-data.html', {'page_object': page_object})
+169
View File
@@ -0,0 +1,169 @@
from django.shortcuts import render, redirect
from dashboard.models import Location, Address
from dashboard.forms import LocationForm, AddressForm
from django.contrib import messages
from django.core.paginator import Paginator
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.decorators import user_passes_test
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404
from django.db.models import Q
PAGE_SIZE = 10
ORPHANS = 1
def check_admin(user):
return user.is_superuser
def manage_access(user):
permissions_list = [
'authentication.add_location',
'authentication.edit_location',
'authentication.delete_location',
'authentication.view_location',
]
for permission in permissions_list:
if user.has_perm(permission):
return True
return False
@login_required
@user_passes_test(manage_access)
def locations(request):
location_list = Location.undeleted_objects.filter(
organization=request.user.organization).order_by('-created_at')
paginator = Paginator(location_list, PAGE_SIZE, orphans=ORPHANS)
page_number = request.GET.get('page')
page_object = paginator.get_page(page_number)
context = {
'sidebar': 'admin',
'submenu': 'location',
'page_object': page_object,
'title': 'Locations'
}
return render(request, 'dashboard/locations/list.html', context=context)
@login_required
@permission_required('authentication.view_location')
def location_details(request, id):
location = get_object_or_404(
Location.undeleted_objects, pk=id, organization=request.user.organization)
history_list = location.history.all()
paginator = Paginator(history_list, 5, orphans=1)
page_number = request.GET.get('page')
page_object = paginator.get_page(page_number)
context = {'sidebar': 'admin', 'submenu': 'location', 'page_object': page_object,
'location': location, 'title': 'Location - Details'}
return render(request, 'dashboard/locations/detail.html', context=context)
@login_required
@permission_required('authentication.add_location')
def add_location(request):
address_form = AddressForm(request.POST or None)
location_form = LocationForm(request.POST or None)
if request.method == "POST":
if address_form.is_valid() and location_form.is_valid():
address = address_form.save()
location = location_form.save(commit=False)
location.address = address
location.organization = request.user.organization
location.save()
messages.success(request, 'Location added successfully')
return HttpResponse(status=204)
context = {
'address_form': address_form,
'location_form': location_form,
}
return render(request, 'dashboard/locations/add-location-modal.html', context=context)
@login_required
@permission_required('authentication.edit_location')
def update_location(request, id):
if Location.objects.filter(pk=id).exists():
location = get_object_or_404(
Location.undeleted_objects, pk=id, organization=request.user.organization)
address = get_object_or_404(Address, pk=location.address.id)
location_form = LocationForm(request.POST or None, instance=location)
address_form = AddressForm(request.POST or None, instance=address)
if request.method == "POST":
if location_form.is_valid() and address_form.is_valid():
location_form.save()
address_form.save()
messages.success(request, 'Location updated successfully')
return redirect('dashboard:locations')
context = {'sidebar': 'admin', 'submenu': 'location', 'location_form': location_form,
'address_form': address_form, 'location': location, 'title': 'Location - Update'}
else:
return redirect('/admin/locations/list')
return render(request, 'dashboard/locations/update-location.html', context=context)
@login_required
@permission_required('authentication.delete_location')
def delete_location(request, id):
if request.method == 'POST':
location = get_object_or_404(
Location.undeleted_objects, pk=id, organization=request.user.organization)
location.status = False
location.soft_delete()
history_id = location.history.first().history_id
location.history.filter(pk=history_id).update(history_type='-')
messages.success(request, 'Location deleted successfully')
return redirect('dashboard:locations')
@user_passes_test(check_admin)
def location_status(request, id):
if request.method == "POST":
location = get_object_or_404(
Location.undeleted_objects, pk=id, organization=request.user.organization)
location.status = False if location.status else True
location.save()
return HttpResponse(status=204)
@login_required
def search_location(request, page):
search_text = request.GET.get('search_text').strip()
if search_text:
return render(request, 'dashboard/locations/locations-data.html', {
'page_object': Location.undeleted_objects.filter(Q(organization=request.user.organization) & (Q(
office_name__icontains=search_text) | Q(contact_person_name__icontains=search_text) | Q(contact_person_email__icontains=search_text) | Q(contact_person_phone__icontains=search_text)
| Q(address__address_line_one__icontains=search_text) | Q(address__address_line_two__icontains=search_text) | Q(address__country__icontains=search_text) | Q(address__state__icontains=search_text)
| Q(address__city__icontains=search_text) | Q(address__pin_code__icontains=search_text)
)).order_by('-created_at')[:10]
})
location_list = Location.undeleted_objects.filter(
organization=request.user.organization).order_by('-created_at')
paginator = Paginator(location_list, PAGE_SIZE, orphans=ORPHANS)
page_number = page
page_object = paginator.get_page(page_number)
return render(request, 'dashboard/locations/locations-data.html', {'page_object': page_object})
+153
View File
@@ -0,0 +1,153 @@
from django.shortcuts import render, redirect
from dashboard.forms import ProductCategoryForm
from django.contrib import messages
from dashboard.models import ProductCategory, ProductType
from django.core.paginator import Paginator
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.decorators import user_passes_test
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404
from django.db.models import Q
PAGE_SIZE = 10
ORPHANS = 1
def check_admin(user):
return user.is_superuser
def manage_access(user):
permissions_list = [
'authentication.delete_product_category',
'authentication.edit_product_category',
'authentication.add_product_category',
]
for permission in permissions_list:
if user.has_perm(permission):
return True
return False
@login_required
@user_passes_test(manage_access)
def product_category_list(request):
all_product_category_list = ProductCategory.undeleted_objects.filter(
organization=request.user.organization).order_by('-created_at')
paginator = Paginator(all_product_category_list,
PAGE_SIZE, orphans=ORPHANS)
page_number = request.GET.get('page')
page_object = paginator.get_page(page_number)
context = {
'sidebar': 'admin',
'submenu': 'product_category',
'page_object': page_object,
'title': 'Product Categories'
}
return render(request, 'dashboard/product_category/list.html', context=context)
@login_required
@permission_required('authentication.add_product_category')
def add_product_category(request):
form = ProductCategoryForm(organization=request.user.organization)
if request.method == "POST":
form = ProductCategoryForm(
request.POST, organization=request.user.organization)
if form.is_valid():
pc = form.save(commit=False)
pc.organization = request.user.organization
pc.save()
messages.success(
request, 'Product Category added successfully')
return HttpResponse(status=204)
context = {'form': form, "modal_title": "Add Product Category"}
return render(request, 'dashboard/product_category/product-category-modal.html', context)
@login_required
@user_passes_test(check_admin)
def product_category_details(request, id):
product_category = get_object_or_404(
ProductCategory.undeleted_objects, pk=id, organization=request.user.organization)
history_list = product_category.history.all()
paginator = Paginator(history_list, 5, orphans=1)
page_number = request.GET.get('page')
page_object = paginator.get_page(page_number)
context = {'sidebar': 'admin', 'page_object': page_object,
'submenu': 'product_category', 'product_category': product_category, 'title': 'Product Category - Details'}
return render(request, 'dashboard/product_category/detail.html', context=context)
@login_required
@permission_required('authentication.delete_product_category')
def delete_product_category(request, id):
if request.method == 'POST':
product_category = get_object_or_404(
ProductCategory.undeleted_objects, pk=id, organization=request.user.organization)
product_category.status = False
product_category.soft_delete()
history_id = product_category.history.first().history_id
product_category.history.filter(pk=history_id).update(history_type='-')
messages.success(request, 'Product Category deleted successfully')
return redirect(request.META.get('HTTP_REFERER'))
@login_required
@permission_required('authentication.edit_product_category')
def update_product_category(request, id):
product_category = get_object_or_404(
ProductCategory.undeleted_objects, pk=id, organization=request.user.organization)
form = ProductCategoryForm(request.POST or None, instance=product_category,
organization=request.user.organization, pk=product_category.id)
if request.method == "POST":
if form.is_valid():
form.save()
messages.success(request, 'Product Category updated successfully')
return HttpResponse(status=204)
context = {'form': form, "modal_title": "Update Product Category"}
return render(request, 'dashboard/product_category/product-category-modal.html', context)
@user_passes_test(check_admin)
def product_category_status(request, id):
if request.method == "POST":
product_category = get_object_or_404(
ProductCategory.undeleted_objects, pk=id, organization=request.user.organization)
product_category.status = False if product_category.status else True
product_category.save()
return HttpResponse(status=204)
@login_required
def search_product_category(request, page):
search_text = request.GET.get('search_text').strip()
if search_text:
return render(request, 'dashboard/product_category/product-categories-data.html', {
'page_object': ProductCategory.undeleted_objects.filter(Q(organization=request.user.organization) & Q(name__icontains=search_text)).order_by('-created_at')[:10]
})
product_categories = ProductCategory.undeleted_objects.filter(
organization=request.user.organization).order_by('-created_at')
paginator = Paginator(product_categories, PAGE_SIZE, orphans=ORPHANS)
page_number = page
page_object = paginator.get_page(page_number)
return render(request, 'dashboard/product_category/product-categories-data.html', {'page_object': page_object})
+155
View File
@@ -0,0 +1,155 @@
from django.shortcuts import render, redirect
from dashboard.forms import ProductTypeForm
from django.contrib import messages
from dashboard.models import ProductType
from django.core.paginator import Paginator
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.decorators import user_passes_test
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404
from django.db.models import Q
PAGE_SIZE = 10
ORPHANS = 1
def check_admin(user):
return user.is_superuser
def manage_access(user):
permissions_list = [
'authentication.delete_product_type',
'authentication.edit_product_type',
'authentication.add_product_type',
]
for permission in permissions_list:
if user.has_perm(permission):
return True
return False
@login_required
@user_passes_test(manage_access)
def product_type_list(request):
all_product_type_list = ProductType.undeleted_objects.filter(
organization=request.user.organization).order_by('-created_at')
paginator = Paginator(all_product_type_list, PAGE_SIZE, orphans=ORPHANS)
page_number = request.GET.get('page')
page_object = paginator.get_page(page_number)
product_type = ProductTypeForm(organization=request.user.organization)
context = {
'sidebar': 'admin',
'submenu': 'product_type',
'product_type': product_type,
'page_object': page_object,
'title': 'Product Types'
}
return render(request, 'dashboard/product_type/list.html', context=context)
@login_required
@permission_required('authentication.add_product_type')
def add_product_type(request):
form = ProductTypeForm(organization=request.user.organization)
if request.method == "POST":
form = ProductTypeForm(
request.POST, organization=request.user.organization)
if form.is_valid():
pt = form.save(commit=False)
pt.organization = request.user.organization
pt.save()
messages.success(
request, 'Product Type added successfully')
return HttpResponse(status=204)
context = {'form': form, "modal_title": "Add Product Type"}
return render(request, 'dashboard/product_type/product-type-modal.html', context)
@login_required
@user_passes_test(check_admin)
def product_type_details(request, id):
product_type = get_object_or_404(
ProductType.undeleted_objects, pk=id, organization=request.user.organization)
history_list = product_type.history.all()
paginator = Paginator(history_list, 5, orphans=1)
page_number = request.GET.get('page')
page_object = paginator.get_page(page_number)
context = {'sidebar': 'admin', 'page_object': page_object,
'submenu': 'product_type', 'product_type': product_type, 'title': 'Product Type - Details'}
return render(request, 'dashboard/product_type/detail.html', context=context)
@login_required
@permission_required('authentication.delete_product_type')
def delete_product_type(request, id):
if request.method == 'POST':
product_type = get_object_or_404(
ProductType.undeleted_objects, pk=id, organization=request.user.organization)
product_type.status = False
product_type.soft_delete()
history_id = product_type.history.first().history_id
product_type.history.filter(pk=history_id).update(history_type='-')
messages.success(request, 'Product Type deleted successfully')
return redirect(request.META.get('HTTP_REFERER'))
@user_passes_test(check_admin)
def product_type_status(request, id):
if request.method == "POST":
product_type = get_object_or_404(
ProductType.undeleted_objects, pk=id, organization=request.user.organization)
product_type.status = False if product_type.status else True
product_type.save()
return HttpResponse(status=204)
@login_required
@permission_required('authentication.edit_product_type')
def update_product_type(request, id):
product_type = get_object_or_404(
ProductType.undeleted_objects, pk=id, organization=request.user.organization)
form = ProductTypeForm(request.POST or None, instance=product_type,
organization=request.user.organization, pk=product_type.id)
if request.method == "POST":
if form.is_valid():
form.save()
messages.success(request, 'Product Type updated successfully')
return HttpResponse(status=204)
context = {'form': form, "modal_title": "Update Product Type"}
return render(request, 'dashboard/product_type/product-type-modal.html', context)
@login_required
def search_product_type(request, page):
search_text = request.GET.get('search_text').strip()
if search_text:
return render(request, 'dashboard/product_type/product-types-data.html', {
'page_object': ProductType.undeleted_objects.filter(Q(organization=request.user.organization) & Q(name__icontains=search_text)).order_by('-created_at')[:10]
})
product_type_list = ProductType.undeleted_objects.filter(
organization=request.user.organization).order_by('-created_at')
paginator = Paginator(product_type_list, PAGE_SIZE, orphans=ORPHANS)
page_number = page
page_object = paginator.get_page(page_number)
return render(request, 'dashboard/product_type/product-types-data.html', {'page_object': page_object})