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

fix: replace map_employees with export settings #708

Merged
merged 6 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
17 changes: 7 additions & 10 deletions apps/workspaces/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,12 @@ def connect_qbo_oauth(refresh_token, realm_id, workspace_id):
workspace.qbo_realm_id = realm_id

if workspace.onboarding_state == 'CONNECTION':
if settings.BRAND_ID == 'fyle':
workspace.onboarding_state = 'MAP_EMPLOYEES'
elif settings.BRAND_ID == 'co':
workspace.onboarding_state = 'EXPORT_SETTINGS'
workspace_general_settings_instance = WorkspaceGeneralSettings.objects.filter(workspace_id=workspace.id).first()
if not workspace_general_settings_instance:
WorkspaceGeneralSettings.objects.update_or_create(
workspace_id=workspace_id, defaults={'employee_field_mapping': 'VENDOR', 'auto_map_employees': None}
)
anishfyle marked this conversation as resolved.
Show resolved Hide resolved
workspace.onboarding_state = 'EXPORT_SETTINGS'
workspace_general_settings_instance = WorkspaceGeneralSettings.objects.filter(workspace_id=workspace.id).first()
if not workspace_general_settings_instance:
WorkspaceGeneralSettings.objects.update_or_create(
workspace_id=workspace_id, defaults={'employee_field_mapping': 'VENDOR', 'auto_map_employees': None}
)

workspace.save()

Expand Down Expand Up @@ -208,7 +205,7 @@ def setup_e2e_tests(workspace_id: int, connection):
platform.import_fyle_dimensions(import_taxes=True)

# Reset workspace details
workspace.onboarding_state = 'MAP_EMPLOYEES'
workspace.onboarding_state = 'EXPORT_SETTINGS'
workspace.source_synced_at = datetime.now()
workspace.destination_synced_at = datetime.now()
workspace.qbo_realm_id = healthy_token.realm_id
Expand Down
14 changes: 5 additions & 9 deletions apps/workspaces/apis/map_employees/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,16 @@ def update(self, instance, validated_data):

workspace_general_settings_instance = WorkspaceGeneralSettings.objects.filter(workspace_id=instance.id).first()

if workspace_general_settings_instance and (workspace_general_settings_instance.employee_field_mapping != workspace_general_settings['employee_field_mapping']):
workspace_general_settings_instance.reimbursable_expenses_object = None
workspace_general_settings_instance.save()

workspace_general_settings_instance, _ = WorkspaceGeneralSettings.objects.update_or_create(
workspace_id=workspace_id, defaults={'employee_field_mapping': workspace_general_settings['employee_field_mapping'], 'auto_map_employees': workspace_general_settings['auto_map_employees']}
workspace_id=workspace_id,
defaults={
'employee_field_mapping': workspace_general_settings['employee_field_mapping'],
'auto_map_employees': workspace_general_settings['auto_map_employees']
}
)

MapEmployeesTriggers.run_workspace_general_settings_triggers(workspace_general_settings_instance)

if instance.onboarding_state == 'MAP_EMPLOYEES':
instance.onboarding_state = 'EXPORT_SETTINGS'
instance.save()

return instance

def validate(self, data):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.14 on 2024-12-20 11:27

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


class Migration(migrations.Migration):

dependencies = [
('workspaces', '0047_alter_workspacegeneralsettings_change_accounting_period'),
]

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

ONBOARDING_STATE_CHOICES = (
('CONNECTION', 'CONNECTION'),
('MAP_EMPLOYEES', 'MAP_EMPLOYEES'),
('EXPORT_SETTINGS', 'EXPORT_SETTINGS'),
('IMPORT_SETTINGS', 'IMPORT_SETTINGS'),
('ADVANCED_CONFIGURATION', 'ADVANCED_CONFIGURATION'),
Expand Down
2 changes: 1 addition & 1 deletion apps/workspaces/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def post_delete_qbo_connection(workspace_id):
:return: None
"""
workspace = Workspace.objects.get(id=workspace_id)
if workspace.onboarding_state in ('CONNECTION', 'MAP_EMPLOYEES', 'EXPORT_SETTINGS'):
if workspace.onboarding_state in ('CONNECTION', 'EXPORT_SETTINGS'):
EmployeeMapping.objects.filter(workspace_id=workspace_id).delete()
DestinationAttribute.objects.filter(workspace_id=workspace_id).delete()
workspace.onboarding_state = 'CONNECTION'
Expand Down
2 changes: 1 addition & 1 deletion sql/functions/e2e-test-setup-workspace-local.sql
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ BEGIN
-- RAISE NOTICE 'Deleted % workspaces', rcount;

UPDATE workspaces
SET onboarding_state = 'MAP_EMPLOYEES', last_synced_at = null
SET onboarding_state = 'EXPORT_SETTINGS', last_synced_at = null
WHERE id = _workspace_id;

UPDATE last_export_details
Expand Down
3 changes: 2 additions & 1 deletion tests/sql_fixtures/reset_db_fixtures/reset_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34010,7 +34010,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 47, true);
-- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.django_migrations_id_seq', 197, true);
SELECT pg_catalog.setval('public.django_migrations_id_seq', 198, true);


--
Expand Down Expand Up @@ -35915,3 +35915,4 @@ ALTER TABLE ONLY public.workspaces_user
--
-- PostgreSQL database dump complete
--

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def test_map_employees(api_client, test_connection):

workspace = Workspace.objects.get(id=3)
workspace.onboarding_state = 'MAP_EMPLOYEES'
workspace.onboarding_state = 'EXPORT_SETTINGS'
anishfyle marked this conversation as resolved.
Show resolved Hide resolved
workspace.save()

workspace_general_settings_instance = WorkspaceGeneralSettings.objects.filter(workspace_id=3).first()
Expand Down
Loading