Skip to content

Commit

Permalink
Import settings QBO fields to be dynamic (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin1111 authored Feb 16, 2024
1 parent b4a1958 commit b8f3841
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,15 @@ export type QBOImportSettingGet = {


export class QBOImportSettingModel extends ImportSettingsModel {
static getQBOFields(): IntegrationField[] {
return [
{
attribute_type: QBOField.CLASS,
display_name: 'Class'
},
{
attribute_type: QBOField.DEPARTMENT,
display_name: 'Department'
},
{
attribute_type: QBOField.CUSTOMER,
display_name: 'Customer'
}
];
}

static getChartOfAccountTypesList(): string[] {
return [
'Expense', 'Other Expense', 'Fixed Asset', 'Cost of Goods Sold', 'Current Liability', 'Equity',
'Other Current Asset', 'Other Current Liability', 'Long Term Liability', 'Current Asset', 'Income', 'Other Income'
];
}

static mapAPIResponseToFormGroup(importSettings: QBOImportSettingGet | null): FormGroup {
const expenseFieldsArray = importSettings?.mapping_settings ? this.constructFormArray(importSettings.mapping_settings, this.getQBOFields()) : [];
static mapAPIResponseToFormGroup(importSettings: QBOImportSettingGet | null, qboFields: IntegrationField[]): FormGroup {
const expenseFieldsArray = importSettings?.mapping_settings ? this.constructFormArray(importSettings.mapping_settings, qboFields) : [];
return new FormGroup({
importCategories: new FormControl(importSettings?.workspace_general_settings.import_categories ?? false),
expenseFields: new FormArray(expenseFieldsArray),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CacheBuster, Cacheable } from 'ts-cacheable';
import { Observable, Subject } from 'rxjs';
import { QBOImportSettingGet, QBOImportSettingPost } from 'src/app/core/models/qbo/qbo-configuration/qbo-import-setting.model';
import { ApiService } from '../../common/api.service';
import { IntegrationField } from 'src/app/core/models/db/mapping.model';

const qboImportSettingGetCache$ = new Subject<void>();

Expand Down Expand Up @@ -32,4 +33,8 @@ export class QboImportSettingsService {
postImportSettings(importSettingsPayload: QBOImportSettingPost): Observable<QBOImportSettingGet> {
return this.apiService.put(`/v2/workspaces/${this.workspaceId}/import_settings/`, importSettingsPayload);
}

getQBOFields(): Observable<IntegrationField[]> {
return this.apiService.get(`/workspaces/${this.workspaceId}/qbo/fields/`, {});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { MappingService } from 'src/app/core/services/common/mapping.service';
import { WorkspaceService } from 'src/app/core/services/common/workspace.service';
import { QboConnectorService } from 'src/app/core/services/qbo/qbo-configuration/qbo-connector.service';
import { QboExportSettingsService } from 'src/app/core/services/qbo/qbo-configuration/qbo-export-settings.service';
import { QboImportSettingsService } from 'src/app/core/services/qbo/qbo-configuration/qbo-import-settings.service';

@Component({
selector: 'app-qbo-clone-settings',
Expand Down Expand Up @@ -167,6 +168,7 @@ export class QboCloneSettingsComponent implements OnInit {
public helperService: HelperService,
private mappingService: MappingService,
private qboConnectorService: QboConnectorService,
private qboImportSettingsService: QboImportSettingsService,
private router: Router,
private toastService: IntegrationsToastService,
private workspaceService: WorkspaceService
Expand Down Expand Up @@ -361,8 +363,9 @@ export class QboCloneSettingsComponent implements OnInit {
this.mappingService.getGroupedDestinationAttributes(destinationAttributes, 'v1', 'qbo'),
this.mappingService.getFyleFields('v1'),
this.qboConnectorService.getQBOCredentials(),
this.configurationService.getAdditionalEmails()
]).subscribe(([cloneSetting, destinationAttributes, fyleFieldsResponse, qboCredentials, adminEmails]) => {
this.configurationService.getAdditionalEmails(),
this.qboImportSettingsService.getQBOFields()
]).subscribe(([cloneSetting, destinationAttributes, fyleFieldsResponse, qboCredentials, adminEmails, qboFields]) => {
this.cloneSetting = cloneSetting;

// Employee Settings
Expand Down Expand Up @@ -401,15 +404,15 @@ export class QboCloneSettingsComponent implements OnInit {


// Import Settings
this.qboFields = QBOImportSettingModel.getQBOFields();
this.qboFields = qboFields;
this.taxCodes = destinationAttributes.TAX_CODE.map((option: DestinationAttribute) => QBOExportSettingModel.formatGeneralMappingPayload(option));
this.isImportMerchantsAllowed = !cloneSetting.advanced_configurations.workspace_general_settings.auto_create_merchants_as_vendors;

if (qboCredentials && qboCredentials.country !== 'US') {
this.isTaxGroupSyncAllowed = true;
}

this.importSettingForm = QBOImportSettingModel.mapAPIResponseToFormGroup(cloneSetting.import_settings);
this.importSettingForm = QBOImportSettingModel.mapAPIResponseToFormGroup(cloneSetting.import_settings, this.qboFields);
this.fyleFields = fyleFieldsResponse;
this.fyleFields.push({ attribute_type: 'custom_field', display_name: 'Create a Custom Field', is_dependent: true });
this.setupImportSettingFormWatcher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ export class QboOnboardingConnectorComponent implements OnInit, OnDestroy {
disconnectQbo(): void {
this.isLoading = true;
this.qboConnectorService.disconnectQBOConnection().subscribe(() => {
this.showDisconnectQBO = false;
this.qboCompanyName = null;
this.getSettings();
this.router.navigate(['/integrations/qbo/onboarding/landing']);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ export class QboImportSettingsComponent implements OnInit {
this.mappingService.getFyleFields('v1'),
this.workspaceService.getWorkspaceGeneralSettings(),
this.qboConnectorService.getQBOCredentials(),
this.mappingService.getDestinationAttributes(QBOField.TAX_CODE, 'v1', 'qbo')
]).subscribe(([importSettingsResponse, fyleFieldsResponse, workspaceGeneralSettings, qboCredentials, taxCodes]) => {
this.qboFields = QBOImportSettingModel.getQBOFields();
this.mappingService.getDestinationAttributes(QBOField.TAX_CODE, 'v1', 'qbo'),
this.importSettingService.getQBOFields()
]).subscribe(([importSettingsResponse, fyleFieldsResponse, workspaceGeneralSettings, qboCredentials, taxCodes, qboFields]) => {
this.qboFields = qboFields;
this.importSettings = importSettingsResponse;
this.workspaceGeneralSettings = workspaceGeneralSettings;
this.taxCodes = taxCodes.map((option: DestinationAttribute) => QBOExportSettingModel.formatGeneralMappingPayload(option));
Expand All @@ -211,7 +212,7 @@ export class QboImportSettingsComponent implements OnInit {
this.isTaxGroupSyncAllowed = true;
}

this.importSettingForm = QBOImportSettingModel.mapAPIResponseToFormGroup(this.importSettings);
this.importSettingForm = QBOImportSettingModel.mapAPIResponseToFormGroup(this.importSettings, this.qboFields);
this.fyleFields = fyleFieldsResponse;
this.fyleFields.push({ attribute_type: 'custom_field', display_name: 'Create a Custom Field', is_dependent: true });
this.setupFormWatchers();
Expand Down

0 comments on commit b8f3841

Please sign in to comment.