Skip to content

Commit

Permalink
onboarding state and script (#425)
Browse files Browse the repository at this point in the history
* onboarding state implementation

* tests migrations

* added onboarding state

* changed comment

* added subsidiary state to onboarding state

* changed script to add subsidiary state and fixed some bug

---------

Co-authored-by: Ashutosh619-sudo <[email protected]>
Co-authored-by: Nilesh Pant <[email protected]>
  • Loading branch information
3 people authored Oct 13, 2023
1 parent 2f5f4e0 commit aa7c231
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 8 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),
),
]
19 changes: 19 additions & 0 deletions apps/workspaces/migrations/0034_auto_20231012_0750.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.1.14 on 2023-10-12 07:50

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


class Migration(migrations.Migration):

dependencies = [
('workspaces', '0033_workspace_onboarding_state'),
]

operations = [
migrations.AlterField(
model_name='workspace',
name='onboarding_state',
field=models.CharField(choices=[('CONNECTION', 'CONNECTION'), ('SUBSIDIARY', 'SUBSIDIARY'), ('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),
),
]
15 changes: 15 additions & 0 deletions apps/workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
User = get_user_model()


ONBOARDING_STATE_CHOICES = (
('CONNECTION', 'CONNECTION'),
('SUBSIDIARY', 'SUBSIDIARY'),
('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 +43,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
99 changes: 99 additions & 0 deletions scripts/sql/scripts/019-add-onboarding-state.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
-- 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,
sm.id as subsidiary_id
from workspaces w
left join
configurations wgs on w.id = wgs.workspace_id
left join
netsuite_credentials nc on qc.workspace_id = w.id
left join
general_mappings gm on gm.workspace_id = w.id
left join
subsidiary_mappings sm on sm.workspace_id = w.id
where w.onboarding_state = 'CONNECTION';

begin; -- Start Transaction Block

-- Count of all workspaces where netsuite are present, configuration is present and general mappings are present
select
'NC=TRUE, C=TRUE, GM=TRUE, SM=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 and subsidiary_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 and subsidiary_id is not null
);

-- Count of all workspaces where netsuite cred is present and general mapping and credentials and subsidiary are not present.
select
'NC=TRUE, C=FALSE, GM=FALSE, SM=FALSE' as setting, count(*)
from all_settings_view
where
configuration_id is null and general_mappings_id is null and netsuite_creds_id is not null and subsidiary_id is null;

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

-- Count of all workspaces where netsuite cred and subsidiary are present, configuration is not present and general mappings are not present
select
'NC=TRUE, C=FALSE, GM=FALSE, SM=TRUE' 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 and subsidiary_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 null and netsuite_creds_id is not null and subsidiary_id is not null
);


-- Count of all workspaces where netsuite are present, configuration is present, subsidiary is present and general mappings are not present
select
'NC=TRUE, C=TRUE, GM=FALSE, SM=TRUE' 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 and subsidiary_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 null and netsuite_creds_id is not null and subsidiary_id is not null
);


18 changes: 10 additions & 8 deletions tests/sql_fixtures/reset_db_fixtures/reset_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- PostgreSQL database dump
--

-- Dumped from database version 15.4 (Debian 15.4-1.pgdg120+1)
-- Dumped by pg_dump version 15.4 (Debian 15.4-1.pgdg100+1)
-- Dumped from database version 15.2 (Debian 15.2-1.pgdg110+1)
-- Dumped by pg_dump version 15.4 (Debian 15.4-2.pgdg100+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand Down Expand Up @@ -1753,7 +1753,8 @@ CREATE TABLE public.workspaces (
source_synced_at timestamp with time zone,
cluster_domain character varying(255),
employee_exported_at timestamp with time zone NOT NULL,
ccc_last_synced_at timestamp with time zone
ccc_last_synced_at timestamp with time zone,
onboarding_state character varying(50)
);


Expand Down Expand Up @@ -7706,6 +7707,7 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin;
162 fyle 0025_auto_20230622_0516 2023-06-22 10:17:05.677561+00
163 django_q 0014_schedule_cluster 2023-07-17 14:43:54.845689+00
164 netsuite 0022_creditcardcharge_department_id 2023-07-26 10:31:38.187076+00
165 workspaces 0033_workspace_onboarding_state 2023-10-11 09:59:47.359324+00
\.


Expand Down Expand Up @@ -11486,10 +11488,10 @@ COPY public.workspace_schedules (id, enabled, start_datetime, interval_hours, wo
-- Data for Name: workspaces; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.workspaces (id, name, fyle_org_id, ns_account_id, last_synced_at, created_at, updated_at, destination_synced_at, source_synced_at, cluster_domain, employee_exported_at, ccc_last_synced_at) FROM stdin;
1 Fyle For Arkham Asylum or79Cob97KSh TSTDRV2089588 2021-11-15 13:12:12.210053+00 2021-11-15 08:46:16.062858+00 2021-11-15 13:12:12.210769+00 2021-11-15 08:56:43.737724+00 2021-11-15 08:55:57.620811+00 https://staging.fyle.tech 2021-09-17 14:32:05.585557+00 \N
2 Fyle For IntacctNew Technologies oraWFQlEpjbb TSTDRV2089588 2021-11-16 04:25:49.067507+00 2021-11-16 04:16:57.840307+00 2021-11-16 04:25:49.067805+00 2021-11-16 04:18:28.233322+00 2021-11-16 04:17:43.950915+00 https://staging.fyle.tech 2021-11-17 14:32:05.585557+00 \N
49 Fyle For intacct-test orHe8CpW2hyN TSTDRV2089588 2021-12-03 11:26:58.663241+00 2021-12-03 11:00:33.634494+00 2021-12-03 11:26:58.664557+00 2021-12-03 11:04:27.847159+00 2021-12-03 11:03:52.560696+00 https://staging.fyle.tech 2021-11-17 14:32:05.585557+00 \N
COPY public.workspaces (id, name, fyle_org_id, ns_account_id, last_synced_at, created_at, updated_at, destination_synced_at, source_synced_at, cluster_domain, employee_exported_at, ccc_last_synced_at, onboarding_state) FROM stdin;
1 Fyle For Arkham Asylum or79Cob97KSh TSTDRV2089588 2021-11-15 13:12:12.210053+00 2021-11-15 08:46:16.062858+00 2021-11-15 13:12:12.210769+00 2021-11-15 08:56:43.737724+00 2021-11-15 08:55:57.620811+00 https://staging.fyle.tech 2021-09-17 14:32:05.585557+00 \N CONNECTION
2 Fyle For IntacctNew Technologies oraWFQlEpjbb TSTDRV2089588 2021-11-16 04:25:49.067507+00 2021-11-16 04:16:57.840307+00 2021-11-16 04:25:49.067805+00 2021-11-16 04:18:28.233322+00 2021-11-16 04:17:43.950915+00 https://staging.fyle.tech 2021-11-17 14:32:05.585557+00 \N CONNECTION
49 Fyle For intacct-test orHe8CpW2hyN TSTDRV2089588 2021-12-03 11:26:58.663241+00 2021-12-03 11:00:33.634494+00 2021-12-03 11:26:58.664557+00 2021-12-03 11:04:27.847159+00 2021-12-03 11:03:52.560696+00 https://staging.fyle.tech 2021-11-17 14:32:05.585557+00 \N CONNECTION
\.


Expand Down Expand Up @@ -11585,7 +11587,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 43, true);
-- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.django_migrations_id_seq', 164, true);
SELECT pg_catalog.setval('public.django_migrations_id_seq', 165, true);


--
Expand Down
1 change: 1 addition & 0 deletions tests/test_workspaces/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"updated_at":"2021-11-10T20:41:37.151696Z",
"employee_exported_at":"2021-11-10T20:41:37.151696Z",
"ccc_last_synced_at": "2021-11-10T20:41:37.151680Z",
"onboarding_state": "COMPLETE",
"user":[
1
]
Expand Down

0 comments on commit aa7c231

Please sign in to comment.