Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added organization types #56

Merged
merged 4 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion buildly/management/commands/loadinitialdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db import transaction

from core.models import ROLE_VIEW_ONLY, ROLE_ORGANIZATION_ADMIN, ROLE_WORKFLOW_ADMIN, ROLE_WORKFLOW_TEAM, \
Organization, CoreUser, CoreGroup
Organization, CoreUser, CoreGroup, OrganizationType

logger = logging.getLogger(__name__)

Expand All @@ -27,6 +27,11 @@ def __init__(self, *args, **kwargs):
self._su_group = None
self._default_org = None

def _create_organization_types(self):
if settings.ORGANIZATION_TYPES:
for organization_type in settings.ORGANIZATION_TYPES:
OrganizationType.objects.get_or_create(name=organization_type)

def _create_default_organization(self):
if settings.DEFAULT_ORG:
self._default_org, _ = Organization.objects.get_or_create(name=settings.DEFAULT_ORG)
Expand Down Expand Up @@ -73,5 +78,6 @@ def _create_user(self):
@transaction.atomic
def handle(self, *args, **options):
self._create_groups()
self._create_organization_types()
self._create_default_organization()
self._create_user()
9 changes: 9 additions & 0 deletions buildly/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,12 @@
SWAGGER_SETTINGS = {
'DEFAULT_INFO': 'gateway.urls.swagger_info',
}

ORGANIZATION_TYPES = [
'Logistics Provider',
'Packer',
'Producer',
'Receiver',
'Shipper',
'Warehouse'
]
3 changes: 2 additions & 1 deletion buildly/tests/test_loadinitialdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.management import call_command
from django.test import TransactionTestCase, override_settings

from core.models import CoreGroup, CoreUser, Organization
from core.models import CoreGroup, CoreUser, Organization, OrganizationType


class DevNull(object):
Expand Down Expand Up @@ -34,6 +34,7 @@ def test_full_initial_data(self):
call_command('loadinitialdata', *args, **opts)

assert CoreGroup.objects.filter(name='Global Admin', is_global=True, permissions=15).count() == 1
assert OrganizationType.objects.filter().count() >= 6
assert Organization.objects.filter(name=settings.DEFAULT_ORG).count() == 1
assert CoreUser.objects.filter(is_superuser=True).count() == 1

Expand Down
11 changes: 9 additions & 2 deletions core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext_lazy as _

from core.models import CoreUser, CoreGroup, CoreSites, EmailTemplate, Industry, LogicModule, Organization, Consortium
from core.models import CoreUser, CoreGroup, CoreSites, EmailTemplate, \
Industry, LogicModule, Organization, OrganizationType, Consortium


class LogicModuleAdmin(admin.ModelAdmin):
Expand All @@ -17,8 +18,13 @@ class CoreSitesAdmin(admin.ModelAdmin):
search_fields = ('name',)


class OrganizationTypeAdmin(admin.ModelAdmin):
list_display = ('name',)
display = 'Organization Type'


class OrganizationAdmin(admin.ModelAdmin):
list_display = ('name', 'create_date', 'edit_date')
list_display = ('name', 'organization_type', 'create_date', 'edit_date')
display = 'Organization'


Expand Down Expand Up @@ -64,6 +70,7 @@ class EmailTemplateAdmin(admin.ModelAdmin):

admin.site.register(LogicModule, LogicModuleAdmin)
admin.site.register(Organization, OrganizationAdmin)
admin.site.register(OrganizationType, OrganizationTypeAdmin)
admin.site.register(CoreGroup, CoreGroupAdmin)
admin.site.register(CoreUser, CoreUserAdmin)
admin.site.register(CoreSites, CoreSitesAdmin)
Expand Down
30 changes: 30 additions & 0 deletions core/migrations/0007_organization_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 2.2.10 on 2021-06-04 06:40

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('core', '0006_consortium'),
]

operations = [
migrations.CreateModel(
name='OrganizationType',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, help_text='Organization type', max_length=255, verbose_name='Name')),
],
options={
'verbose_name_plural': 'Organization Types',
'ordering': ('name',),
},
),
migrations.AddField(
model_name='organization',
name='organization_type',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='core.OrganizationType'),
),
]
21 changes: 21 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ def save(self, *args, **kwargs):
def __str__(self):
return self.name

class OrganizationType(models.Model):
"""
Allows organization to be of multiple types.
Supported types are:
1. Logistics Provider
2. Packer
3. Producer
4. Receiver
5. Shipper
6. Warehouse
"""
name = models.CharField("Name", max_length=255, blank=True, help_text="Organization type")

class Meta:
ordering = ('name',)
verbose_name_plural = "Organization Types"

def __str__(self):
return str(self.name)

class Organization(models.Model):
"""
Expand All @@ -96,6 +115,8 @@ class Organization(models.Model):
phone = models.CharField(max_length=20, blank=True, null=True)
allow_import_export = models.BooleanField('To allow import export functionality', default=False)
radius = models.FloatField(max_length=20, blank=True, null=True)
organization_type = models.ForeignKey(OrganizationType,on_delete=models.CASCADE,null=True)

class Meta:
ordering = ('name',)
verbose_name_plural = "Organizations"
Expand Down
1 change: 1 addition & 0 deletions core/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_org_serializer(request_factory, org):
'industries',
'allow_import_export',
'radius',
'organization_type'
]
assert set(data.keys()) == set(keys)

Expand Down