From 5c31b3f4b93e219b4b76ac5fe62e3b8cd9560391 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Wed, 11 Oct 2023 13:26:46 +0530 Subject: [PATCH] onboarding state implementation --- .../0033_workspace_onboarding_state.py | 19 +++ apps/workspaces/models.py | 14 +++ .../sql/scripts/019-add-onboarding-state.sql | 115 ++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 apps/workspaces/migrations/0033_workspace_onboarding_state.py create mode 100644 scripts/sql/scripts/019-add-onboarding-state.sql diff --git a/apps/workspaces/migrations/0033_workspace_onboarding_state.py b/apps/workspaces/migrations/0033_workspace_onboarding_state.py new file mode 100644 index 00000000..e4fdbf14 --- /dev/null +++ b/apps/workspaces/migrations/0033_workspace_onboarding_state.py @@ -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), + ), + ] diff --git a/apps/workspaces/models.py b/apps/workspaces/models.py index eb7a503c..c501b73f 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -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 @@ -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' diff --git a/scripts/sql/scripts/019-add-onboarding-state.sql b/scripts/sql/scripts/019-add-onboarding-state.sql new file mode 100644 index 00000000..c70bdd6f --- /dev/null +++ b/scripts/sql/scripts/019-add-onboarding-state.sql @@ -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 +);