Skip to content

Commit

Permalink
onboarding state implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh619-sudo committed Oct 11, 2023
1 parent 74ec664 commit 5c31b3f
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
19 changes: 19 additions & 0 deletions apps/workspaces/migrations/0033_workspace_onboarding_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.1.14 on 2023-10-10 11:39

import apps.workspaces.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('workspaces', '0032_configuration_name_in_journal_entry'),
]

operations = [
migrations.AddField(
model_name='workspace',
name='onboarding_state',
field=models.CharField(choices=[('CONNECTION', 'CONNECTION'), ('MAP_EMPLOYEES', 'MAP_EMPLOYEES'), ('EXPORT_SETTINGS', 'EXPORT_SETTINGS'), ('IMPORT_SETTINGS', 'IMPORT_SETTINGS'), ('ADVANCED_CONFIGURATION', 'ADVANCED_CONFIGURATION'), ('COMPLETE', 'COMPLETE')], default=apps.workspaces.models.get_default_onboarding_state, help_text='Onboarding status of the workspace', max_length=50, null=True),
),
]
14 changes: 14 additions & 0 deletions apps/workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
User = get_user_model()


ONBOARDING_STATE_CHOICES = (
('CONNECTION', 'CONNECTION'),
('MAP_EMPLOYEES', 'MAP_EMPLOYEES'),
('EXPORT_SETTINGS', 'EXPORT_SETTINGS'),
('IMPORT_SETTINGS', 'IMPORT_SETTINGS'),
('ADVANCED_CONFIGURATION', 'ADVANCED_CONFIGURATION'),
('COMPLETE', 'COMPLETE'),
)


def get_default_onboarding_state():
return 'CONNECTION'

class Workspace(models.Model):
"""
Workspace model
Expand All @@ -29,6 +42,7 @@ class Workspace(models.Model):
created_at = models.DateTimeField(auto_now_add=True, help_text='Created at datetime')
updated_at = models.DateTimeField(auto_now=True, help_text='Updated at datetime')
employee_exported_at = models.DateTimeField(auto_now_add=True, help_text='Employee exported to Fyle at datetime')
onboarding_state = models.CharField(max_length=50, choices=ONBOARDING_STATE_CHOICES, default=get_default_onboarding_state, help_text='Onboarding status of the workspace', null=True)

class Meta:
db_table = 'workspaces'
Expand Down
115 changes: 115 additions & 0 deletions scripts/sql/scripts/019-add-onboarding-state.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
-- Create a view for joined on all settings tables to figure out onboarding progress
create or replace view all_settings_view as
select
w.id as workspace_id,
wgs.id as configuration_id,
gm.id as general_mappings_id,
qc.id as netsuite_creds_id
from workspaces w
left join
configurations wgs on w.id = wgs.workspace_id
left join
netsuite_credentials qc on qc.workspace_id = w.id
left join
general_mappings gm on gm.workspace_id = w.id
where w.onboarding_state = 'CONNECTION';

begin; -- Start Transaction Block

-- Count of all workspaces where qbo creds are present, configuration is present and general mappings are present
select
'QC=TRUE, C=TRUE, GM=TRUE' as setting, count(*)
from all_settings_view
where
configuration_id is not null and general_mappings_id is not null and netsuite_creds_id is not null;

--- Update all of the above to have onboarding state set to 'COMPLETE'
update workspaces
set
onboarding_state = 'COMPLETE'
where id in (
select
workspace_id
from all_settings_view
where
configuration_id is not null and general_mappings_id is not null and netsuite_creds_id is not null
);

-- Count of all workspaces where qbo creds are present, configuration is present and general mappings are not present
select
'QC=TRUE, C=TRUE, GM=FALSE' as settings, count(*)
from all_settings_view
where
configuration_id is not null and general_mappings_id is null and netsuite_creds_id is not null;

--- Update all of the above to have onboarding state set to 'EXPORT_SETTINGS'
update workspaces
set
onboarding_state = 'EXPORT_SETTINGS'
where id in (
select
workspace_id
from all_settings_view
where
configuration_id is not null and general_mappings_id is not null and netsuite_creds_id is not null
);


-- Count of all workspaces where qbo creds are present, configuration is not present and general mappings are not present
select
'QC=TRUE, C=FALSE, GM=FALSE' as settings, count(*)
from all_settings_view
where
configuration_id is null and general_mappings_id is null and netsuite_creds_id is not null;

--- Update all of the above to have onboarding state set to 'MAP_EMPLOYEES'
update workspaces
set
onboarding_state = 'MAP_EMPLOYEES'
where id in (
select
workspace_id
from all_settings_view
where
configuration_id is null and general_mappings_id is not null and netsuite_creds_id is not null
);


-- Count of all workspaces where qbo creds is not present, configuration is present and general mappings is present
select
'QC=FALSE, C=TRUE, GM=TRUE' as settings, count(*)
from all_settings_view
where
configuration_id is not null and general_mappings_id is not null and netsuite_creds_id is null;

--- Update all of the above to have onboarding state set to 'COMPLETE'
update workspaces
set
onboarding_state = 'COMPLETE'
where id in (
select
workspace_id
from all_settings_view
where
configuration_id is not null and general_mappings_id is not null and netsuite_creds_id is null
);


-- Count of all workspaces where qbo creds are not present, configuration is present and general mappings are not present
select
'QC=FALSE, C=TRUE, GM=FALSE' as settings, count(*)
from all_settings_view
where
configuration_id is not null and general_mappings_id is not null and netsuite_creds_id is null;

--- Update all of the above to have onboarding state set to 'EXPORT_SETTINGS'
update workspaces
set
onboarding_state = 'EXPORT_SETTINGS'
where id in (
select
workspace_id
from all_settings_view
where
configuration_id is not null and general_mappings_id is null and netsuite_creds_id is null
);

0 comments on commit 5c31b3f

Please sign in to comment.