Skip to content

Commit

Permalink
feat: auto enable accounting period (#1073)
Browse files Browse the repository at this point in the history
* feat: auto enable accounting period

* shouldEnableAccountingPeriod

* xero helperService

* shouldEnableAccountingPeriod

* orgService changes

* lint fix

* fix unit tests

* lint fix
  • Loading branch information
anishfyle authored Nov 18, 2024
1 parent 936b0f3 commit 3f73147
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class NetsuiteAdvancedSettingModel extends HelperUtility {
});
}

static mapAPIResponseToFormGroup(advancedSettings: NetsuiteAdvancedSettingGet, isSkipExportEnabled: boolean, adminEmails: EmailOption[]): FormGroup {
static mapAPIResponseToFormGroup(advancedSettings: NetsuiteAdvancedSettingGet, isSkipExportEnabled: boolean, adminEmails: EmailOption[], shouldEnableAccountingPeriod: boolean): FormGroup {
const level: DefaultDestinationAttribute[] = this.getDefaultLevelOptions();
const findObjectByDestinationId = (id: string) => level?.find(item => item.id === id) || null;
return new FormGroup({
Expand All @@ -137,7 +137,7 @@ export class NetsuiteAdvancedSettingModel extends HelperUtility {
netsuiteClass: new FormControl(advancedSettings?.general_mappings.netsuite_class?.id ? advancedSettings?.general_mappings.netsuite_class : null),
netsuiteClassLevel: new FormControl(advancedSettings?.general_mappings.netsuite_class_level ? findObjectByDestinationId(advancedSettings?.general_mappings.netsuite_class_level) : this.getDefaultLevelOptions()[0]),
useEmployeeClass: new FormControl(advancedSettings?.general_mappings.use_employee_class ? advancedSettings?.general_mappings.use_employee_class : false),
changeAccountingPeriod: new FormControl(advancedSettings?.configuration.change_accounting_period),
changeAccountingPeriod: new FormControl(shouldEnableAccountingPeriod ? true : advancedSettings?.configuration.change_accounting_period),
autoCreateVendors: new FormControl(advancedSettings?.configuration.auto_create_destination_entity),
singleCreditLineJE: new FormControl(advancedSettings?.configuration.je_single_credit_line),
exportSchedule: new FormControl(advancedSettings?.workspace_schedules?.enabled ? true : false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ export class QBOAdvancedSettingModel extends HelperUtility {
});
}

static mapAPIResponseToFormGroup(advancedSettings: QBOAdvancedSettingGet, isSkipExportEnabled: boolean, adminEmails: EmailOption[]): FormGroup {
static mapAPIResponseToFormGroup(advancedSettings: QBOAdvancedSettingGet, isSkipExportEnabled: boolean, adminEmails: EmailOption[], shouldEnableAccountingPeriod: boolean): FormGroup {
return new FormGroup({
paymentSync: new FormControl(advancedSettings?.workspace_general_settings.sync_fyle_to_qbo_payments ? QBOPaymentSyncDirection.FYLE_TO_QBO : advancedSettings?.workspace_general_settings.sync_qbo_to_fyle_payments ? QBOPaymentSyncDirection.QBO_TO_FYLE : null),
billPaymentAccount: new FormControl(advancedSettings?.general_mappings.bill_payment_account?.id ? advancedSettings?.general_mappings.bill_payment_account : null),
changeAccountingPeriod: new FormControl(advancedSettings?.workspace_general_settings.change_accounting_period),
changeAccountingPeriod: new FormControl(shouldEnableAccountingPeriod ? true : advancedSettings?.workspace_general_settings.change_accounting_period),
singleCreditLineJE: new FormControl(advancedSettings?.workspace_general_settings.je_single_credit_line),
autoCreateVendors: new FormControl(advancedSettings?.workspace_general_settings.auto_create_destination_entity),
autoCreateMerchantsAsVendors: new FormControl(advancedSettings?.workspace_general_settings.auto_create_merchants_as_vendors),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class XeroAdvancedSettingModel extends HelperUtility{
});
}

static mapAPIResponseToFormGroup(advancedSettings: XeroAdvancedSettingGet, adminEmails: EmailOption[], destinationAttribute: DestinationAttribute[]): FormGroup {
static mapAPIResponseToFormGroup(advancedSettings: XeroAdvancedSettingGet, adminEmails: EmailOption[], destinationAttribute: DestinationAttribute[], shouldEnableAccountingPeriod: boolean): FormGroup {
let paymentSync = '';
if (advancedSettings.workspace_general_settings.sync_fyle_to_xero_payments) {
paymentSync = PaymentSyncDirection.FYLE_TO_XERO;
Expand All @@ -106,7 +106,7 @@ export class XeroAdvancedSettingModel extends HelperUtility{
return new FormGroup({
paymentSync: new FormControl(paymentSync),
billPaymentAccount: new FormControl(advancedSettings.general_mappings.payment_account.id ? findObjectByDestinationId(destinationAttribute, advancedSettings.general_mappings.payment_account.id) : null),
changeAccountingPeriod: new FormControl(advancedSettings.workspace_general_settings.change_accounting_period),
changeAccountingPeriod: new FormControl(shouldEnableAccountingPeriod ? true : advancedSettings.workspace_general_settings.change_accounting_period),
autoCreateVendors: new FormControl(advancedSettings.workspace_general_settings.auto_create_destination_entity),
exportSchedule: new FormControl(advancedSettings.workspace_schedules?.enabled ? true : false),
exportScheduleFrequency: new FormControl(advancedSettings.workspace_schedules?.enabled ? advancedSettings.workspace_schedules.interval_hours : 1),
Expand Down
7 changes: 7 additions & 0 deletions src/app/core/services/common/helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ export class HelperService {

@Output() oauthCallbackUrl: EventEmitter<string> = new EventEmitter();

private readonly AUTO_ENABLE_ACCOUNTING_PERIOD_DATE = new Date('DEPLOY DATE ANISH');

constructor(
private apiService: ApiService,
private router: Router,
private storageService: StorageService
) {}

shouldAutoEnableAccountingPeriod(workspaceCreatedAt: Date): boolean {
const createdAt = new Date(workspaceCreatedAt);
return createdAt >= this.AUTO_ENABLE_ACCOUNTING_PERIOD_DATE;
}

get apiBaseUrl(): string {
return this.storageService.get('cluster-domain') || environment.cluster_domain_api_url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AppName, AutoMapEmployeeOptions, ConfigurationCta, EmployeeFieldMapping
import { NetsuiteConfiguration } from 'src/app/core/models/netsuite/db/netsuite-workspace-general-settings.model';
import { NetsuiteAdvancedSettingGet, NetsuiteAdvancedSettingModel } from 'src/app/core/models/netsuite/netsuite-configuration/netsuite-advanced-settings.model';
import { NetSuiteExportSettingModel } from 'src/app/core/models/netsuite/netsuite-configuration/netsuite-export-setting.model';
import { Org } from 'src/app/core/models/org/org.model';
import { ConfigurationService } from 'src/app/core/services/common/configuration.service';
import { HelperService } from 'src/app/core/services/common/helper.service';
import { IntegrationsToastService } from 'src/app/core/services/common/integrations-toast.service';
Expand All @@ -20,6 +21,7 @@ import { WorkspaceService } from 'src/app/core/services/common/workspace.service
import { NetsuiteAdvancedSettingsService } from 'src/app/core/services/netsuite/netsuite-configuration/netsuite-advanced-settings.service';
import { NetsuiteConnectorService } from 'src/app/core/services/netsuite/netsuite-core/netsuite-connector.service';
import { NetsuiteHelperService } from 'src/app/core/services/netsuite/netsuite-core/netsuite-helper.service';
import { OrgService } from 'src/app/core/services/org/org.service';

@Component({
selector: 'app-netsuite-advanced-settings',
Expand Down Expand Up @@ -96,6 +98,8 @@ export class NetsuiteAdvancedSettingsComponent implements OnInit {

isTaxGroupSyncAllowed: boolean;

org: Org = this.orgService.getCachedOrg();

constructor(
private advancedSettingsService: NetsuiteAdvancedSettingsService,
private configurationService: ConfigurationService,
Expand All @@ -106,7 +110,8 @@ export class NetsuiteAdvancedSettingsComponent implements OnInit {
private router: Router,
private skipExportService: SkipExportService,
private toastService: IntegrationsToastService,
private workspaceService: WorkspaceService
private workspaceService: WorkspaceService,
private orgService: OrgService
) { }

isOptional(): string {
Expand Down Expand Up @@ -283,7 +288,7 @@ export class NetsuiteAdvancedSettingsComponent implements OnInit {

const isSkipExportEnabled = expenseFiltersGet.count > 0;

this.advancedSettingForm = NetsuiteAdvancedSettingModel.mapAPIResponseToFormGroup(this.advancedSetting, isSkipExportEnabled, this.adminEmails);
this.advancedSettingForm = NetsuiteAdvancedSettingModel.mapAPIResponseToFormGroup(this.advancedSetting, isSkipExportEnabled, this.adminEmails, this.helper.shouldAutoEnableAccountingPeriod(this.org.created_at));
this.skipExportForm = SkipExportModel.setupSkipExportForm(this.expenseFilters, [], this.conditionFieldOptions);
this.isLoading = false;
this.setupFormWatchers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { FyleField, IntegrationField } from 'src/app/core/models/db/mapping.mode
import { AppName, AutoMapEmployeeOptions, ConfigurationCta, ConfigurationWarningEvent, DefaultImportFields, EmployeeFieldMapping, ExpenseGroupingFieldOption, InputType, NameInJournalEntry, QBOCorporateCreditCardExpensesObject, QBOField, QBOReimbursableExpensesObject, ToastSeverity } from 'src/app/core/models/enum/enum.model';
import { ConfigurationWarningOut } from 'src/app/core/models/misc/configuration-warning.model';
import { OnboardingStepper } from 'src/app/core/models/misc/onboarding-stepper.model';
import { Org } from 'src/app/core/models/org/org.model';
import { QBOAdvancedSettingModel } from 'src/app/core/models/qbo/qbo-configuration/qbo-advanced-setting.model';
import { QBOCloneSetting, QBOCloneSettingModel } from 'src/app/core/models/qbo/qbo-configuration/qbo-clone-setting.model';
import { QBOEmployeeSettingModel } from 'src/app/core/models/qbo/qbo-configuration/qbo-employee-setting.model';
Expand All @@ -24,6 +25,7 @@ import { HelperService } from 'src/app/core/services/common/helper.service';
import { IntegrationsToastService } from 'src/app/core/services/common/integrations-toast.service';
import { MappingService } from 'src/app/core/services/common/mapping.service';
import { WorkspaceService } from 'src/app/core/services/common/workspace.service';
import { OrgService } from 'src/app/core/services/org/org.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';
Expand Down Expand Up @@ -153,6 +155,8 @@ export class QboCloneSettingsComponent implements OnInit {

splitExpenseGroupingOptions = QBOExportSettingModel.getSplitExpenseGroupingOptions();

org: Org = this.orgService.getCachedOrg();

scheduleIntervalHours: SelectFormOption[] = [...Array(24).keys()].map(day => {
return {
label: (day + 1).toString(),
Expand Down Expand Up @@ -198,7 +202,8 @@ export class QboCloneSettingsComponent implements OnInit {
private qboImportSettingsService: QboImportSettingsService,
private router: Router,
private toastService: IntegrationsToastService,
private workspaceService: WorkspaceService
private workspaceService: WorkspaceService,
private orgService: OrgService
) { }

resetCloneSetting(): void {
Expand Down Expand Up @@ -502,7 +507,7 @@ export class QboCloneSettingsComponent implements OnInit {
}

this.billPaymentAccounts = destinationAttributes.BANK_ACCOUNT.map((option: DestinationAttribute) => QBOExportSettingModel.formatGeneralMappingPayload(option));
this.advancedSettingForm = QBOAdvancedSettingModel.mapAPIResponseToFormGroup(this.cloneSetting.advanced_configurations, false, this.adminEmails);
this.advancedSettingForm = QBOAdvancedSettingModel.mapAPIResponseToFormGroup(this.cloneSetting.advanced_configurations, false, this.adminEmails, this.helperService.shouldAutoEnableAccountingPeriod(this.org.created_at));

this.setupAdvancedSettingFormWatcher();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { mockQboAdvancedSettings, mockSkipExportSettings, mockCustomFields, mock
import { AutoMapEmployeeOptions, EmployeeFieldMapping, NameInJournalEntry, Operator, QBOCorporateCreditCardExpensesObject, QBOOnboardingState, QBOReimbursableExpensesObject, ToastSeverity } from 'src/app/core/models/enum/enum.model';
import { AdvancedSettingsModel, ExpenseFilter, SkipExportModel } from 'src/app/core/models/common/advanced-settings.model';
import { GroupedDestinationAttribute } from 'src/app/core/models/db/destination-attribute.model';
import { orgMockData } from 'src/app/core/services/org/org.fixture';
import { OrgService } from 'src/app/core/services/org/org.service';

describe('QboAdvancedSettingsComponent', () => {
let component: QboAdvancedSettingsComponent;
Expand All @@ -30,17 +32,22 @@ describe('QboAdvancedSettingsComponent', () => {
let toastService: jasmine.SpyObj<IntegrationsToastService>;
let workspaceService: jasmine.SpyObj<WorkspaceService>;
let router: jasmine.SpyObj<Router>;
let orgService: jasmine.SpyObj<OrgService>;

beforeEach(async () => {
const advancedSettingsServiceSpy = jasmine.createSpyObj('QboAdvancedSettingsService', ['getAdvancedSettings', 'postAdvancedSettings']);
const configurationServiceSpy = jasmine.createSpyObj('ConfigurationService', ['getAdditionalEmails']);
const helperServiceSpy = jasmine.createSpyObj('HelperService', ['setConfigurationSettingValidatorsAndWatchers', 'handleSkipExportFormInAdvancedSettingsUpdates']);
const helperServiceSpy = jasmine.createSpyObj('HelperService', ['setConfigurationSettingValidatorsAndWatchers', 'handleSkipExportFormInAdvancedSettingsUpdates', 'shouldAutoEnableAccountingPeriod']);
const qboHelperServiceSpy = jasmine.createSpyObj('QboHelperService', ['refreshQBODimensions']);
const mappingServiceSpy = jasmine.createSpyObj('MappingService', ['getGroupedDestinationAttributes']);
const skipExportServiceSpy = jasmine.createSpyObj('SkipExportService', ['getExpenseFilter', 'getExpenseFields', 'postExpenseFilter', 'deleteExpenseFilter']);
const toastServiceSpy = jasmine.createSpyObj('IntegrationsToastService', ['displayToastMessage']);
const workspaceServiceSpy = jasmine.createSpyObj('WorkspaceService', ['getWorkspaceGeneralSettings', 'setOnboardingState']);
const routerSpy = jasmine.createSpyObj('Router', ['navigate']);
const orgServiceSpy = jasmine.createSpyObj('OrgService', ['getCachedOrg']);

orgServiceSpy.getCachedOrg.and.returnValue(orgMockData);
helperServiceSpy.shouldAutoEnableAccountingPeriod.and.returnValue(false);

await TestBed.configureTestingModule({
declarations: [ QboAdvancedSettingsComponent ],
Expand All @@ -55,7 +62,8 @@ describe('QboAdvancedSettingsComponent', () => {
{ provide: SkipExportService, useValue: skipExportServiceSpy },
{ provide: IntegrationsToastService, useValue: toastServiceSpy },
{ provide: WorkspaceService, useValue: workspaceServiceSpy },
{ provide: Router, useValue: routerSpy }
{ provide: Router, useValue: routerSpy },
{ provide: OrgService, useValue: orgServiceSpy }
]
}).compileComponents();

Expand All @@ -70,6 +78,7 @@ describe('QboAdvancedSettingsComponent', () => {
toastService = TestBed.inject(IntegrationsToastService) as jasmine.SpyObj<IntegrationsToastService>;
workspaceService = TestBed.inject(WorkspaceService) as jasmine.SpyObj<WorkspaceService>;
router = TestBed.inject(Router) as jasmine.SpyObj<Router>;
orgService = TestBed.inject(OrgService) as jasmine.SpyObj<OrgService>;

component.advancedSettingForm = new FormBuilder().group({
paymentSync: [null],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AdvancedSettingsModel, ConditionField, EmailOption, ExpenseFilterPayloa
import { SelectFormOption } from 'src/app/core/models/common/select-form-option.model';
import { DefaultDestinationAttribute, DestinationAttribute } from 'src/app/core/models/db/destination-attribute.model';
import { AppName, AutoMapEmployeeOptions, ConfigurationCta, EmployeeFieldMapping, NameInJournalEntry, QBOCorporateCreditCardExpensesObject, QBOOnboardingState, QBOPaymentSyncDirection, QBOReimbursableExpensesObject, ToastSeverity } from 'src/app/core/models/enum/enum.model';
import { Org } from 'src/app/core/models/org/org.model';
import { QBOWorkspaceGeneralSetting } from 'src/app/core/models/qbo/db/workspace-general-setting.model';
import { QBOAdvancedSettingGet, QBOAdvancedSettingModel } from 'src/app/core/models/qbo/qbo-configuration/qbo-advanced-setting.model';
import { QBOExportSettingModel } from 'src/app/core/models/qbo/qbo-configuration/qbo-export-setting.model';
Expand All @@ -16,6 +17,7 @@ import { IntegrationsToastService } from 'src/app/core/services/common/integrati
import { MappingService } from 'src/app/core/services/common/mapping.service';
import { SkipExportService } from 'src/app/core/services/common/skip-export.service';
import { WorkspaceService } from 'src/app/core/services/common/workspace.service';
import { OrgService } from 'src/app/core/services/org/org.service';
import { QboAdvancedSettingsService } from 'src/app/core/services/qbo/qbo-configuration/qbo-advanced-settings.service';
import { QboHelperService } from 'src/app/core/services/qbo/qbo-core/qbo-helper.service';

Expand Down Expand Up @@ -79,6 +81,8 @@ export class QboAdvancedSettingsComponent implements OnInit {

isSkipExportFormInvalid: boolean;

org: Org = this.orgService.getCachedOrg();

constructor(
private advancedSettingsService: QboAdvancedSettingsService,
private configurationService: ConfigurationService,
Expand All @@ -88,7 +92,8 @@ export class QboAdvancedSettingsComponent implements OnInit {
private router: Router,
private skipExportService: SkipExportService,
private toastService: IntegrationsToastService,
private workspaceService: WorkspaceService
private workspaceService: WorkspaceService,
private orgService: OrgService
) { }


Expand Down Expand Up @@ -241,7 +246,7 @@ export class QboAdvancedSettingsComponent implements OnInit {

const isSkipExportEnabled = expenseFiltersGet.count > 0;

this.advancedSettingForm = QBOAdvancedSettingModel.mapAPIResponseToFormGroup(this.advancedSetting, isSkipExportEnabled, this.adminEmails);
this.advancedSettingForm = QBOAdvancedSettingModel.mapAPIResponseToFormGroup(this.advancedSetting, isSkipExportEnabled, this.adminEmails, this.helper.shouldAutoEnableAccountingPeriod(this.org.created_at));
this.skipExportForm = SkipExportModel.setupSkipExportForm(this.expenseFilters, [], this.conditionFieldOptions);

this.setupFormWatchers();
Expand Down
Loading

0 comments on commit 3f73147

Please sign in to comment.