Skip to content

Commit 3f73147

Browse files
authored
feat: auto enable accounting period (#1073)
* feat: auto enable accounting period * shouldEnableAccountingPeriod * xero helperService * shouldEnableAccountingPeriod * orgService changes * lint fix * fix unit tests * lint fix
1 parent 936b0f3 commit 3f73147

File tree

10 files changed

+61
-19
lines changed

10 files changed

+61
-19
lines changed

src/app/core/models/netsuite/netsuite-configuration/netsuite-advanced-settings.model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class NetsuiteAdvancedSettingModel extends HelperUtility {
122122
});
123123
}
124124

125-
static mapAPIResponseToFormGroup(advancedSettings: NetsuiteAdvancedSettingGet, isSkipExportEnabled: boolean, adminEmails: EmailOption[]): FormGroup {
125+
static mapAPIResponseToFormGroup(advancedSettings: NetsuiteAdvancedSettingGet, isSkipExportEnabled: boolean, adminEmails: EmailOption[], shouldEnableAccountingPeriod: boolean): FormGroup {
126126
const level: DefaultDestinationAttribute[] = this.getDefaultLevelOptions();
127127
const findObjectByDestinationId = (id: string) => level?.find(item => item.id === id) || null;
128128
return new FormGroup({
@@ -137,7 +137,7 @@ export class NetsuiteAdvancedSettingModel extends HelperUtility {
137137
netsuiteClass: new FormControl(advancedSettings?.general_mappings.netsuite_class?.id ? advancedSettings?.general_mappings.netsuite_class : null),
138138
netsuiteClassLevel: new FormControl(advancedSettings?.general_mappings.netsuite_class_level ? findObjectByDestinationId(advancedSettings?.general_mappings.netsuite_class_level) : this.getDefaultLevelOptions()[0]),
139139
useEmployeeClass: new FormControl(advancedSettings?.general_mappings.use_employee_class ? advancedSettings?.general_mappings.use_employee_class : false),
140-
changeAccountingPeriod: new FormControl(advancedSettings?.configuration.change_accounting_period),
140+
changeAccountingPeriod: new FormControl(shouldEnableAccountingPeriod ? true : advancedSettings?.configuration.change_accounting_period),
141141
autoCreateVendors: new FormControl(advancedSettings?.configuration.auto_create_destination_entity),
142142
singleCreditLineJE: new FormControl(advancedSettings?.configuration.je_single_credit_line),
143143
exportSchedule: new FormControl(advancedSettings?.workspace_schedules?.enabled ? true : false),

src/app/core/models/qbo/qbo-configuration/qbo-advanced-setting.model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ export class QBOAdvancedSettingModel extends HelperUtility {
9292
});
9393
}
9494

95-
static mapAPIResponseToFormGroup(advancedSettings: QBOAdvancedSettingGet, isSkipExportEnabled: boolean, adminEmails: EmailOption[]): FormGroup {
95+
static mapAPIResponseToFormGroup(advancedSettings: QBOAdvancedSettingGet, isSkipExportEnabled: boolean, adminEmails: EmailOption[], shouldEnableAccountingPeriod: boolean): FormGroup {
9696
return new FormGroup({
9797
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),
9898
billPaymentAccount: new FormControl(advancedSettings?.general_mappings.bill_payment_account?.id ? advancedSettings?.general_mappings.bill_payment_account : null),
99-
changeAccountingPeriod: new FormControl(advancedSettings?.workspace_general_settings.change_accounting_period),
99+
changeAccountingPeriod: new FormControl(shouldEnableAccountingPeriod ? true : advancedSettings?.workspace_general_settings.change_accounting_period),
100100
singleCreditLineJE: new FormControl(advancedSettings?.workspace_general_settings.je_single_credit_line),
101101
autoCreateVendors: new FormControl(advancedSettings?.workspace_general_settings.auto_create_destination_entity),
102102
autoCreateMerchantsAsVendors: new FormControl(advancedSettings?.workspace_general_settings.auto_create_merchants_as_vendors),

src/app/core/models/xero/xero-configuration/xero-advanced-settings.model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class XeroAdvancedSettingModel extends HelperUtility{
9595
});
9696
}
9797

98-
static mapAPIResponseToFormGroup(advancedSettings: XeroAdvancedSettingGet, adminEmails: EmailOption[], destinationAttribute: DestinationAttribute[]): FormGroup {
98+
static mapAPIResponseToFormGroup(advancedSettings: XeroAdvancedSettingGet, adminEmails: EmailOption[], destinationAttribute: DestinationAttribute[], shouldEnableAccountingPeriod: boolean): FormGroup {
9999
let paymentSync = '';
100100
if (advancedSettings.workspace_general_settings.sync_fyle_to_xero_payments) {
101101
paymentSync = PaymentSyncDirection.FYLE_TO_XERO;
@@ -106,7 +106,7 @@ export class XeroAdvancedSettingModel extends HelperUtility{
106106
return new FormGroup({
107107
paymentSync: new FormControl(paymentSync),
108108
billPaymentAccount: new FormControl(advancedSettings.general_mappings.payment_account.id ? findObjectByDestinationId(destinationAttribute, advancedSettings.general_mappings.payment_account.id) : null),
109-
changeAccountingPeriod: new FormControl(advancedSettings.workspace_general_settings.change_accounting_period),
109+
changeAccountingPeriod: new FormControl(shouldEnableAccountingPeriod ? true : advancedSettings.workspace_general_settings.change_accounting_period),
110110
autoCreateVendors: new FormControl(advancedSettings.workspace_general_settings.auto_create_destination_entity),
111111
exportSchedule: new FormControl(advancedSettings.workspace_schedules?.enabled ? true : false),
112112
exportScheduleFrequency: new FormControl(advancedSettings.workspace_schedules?.enabled ? advancedSettings.workspace_schedules.interval_hours : 1),

src/app/core/services/common/helper.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@ export class HelperService {
2727

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

30+
private readonly AUTO_ENABLE_ACCOUNTING_PERIOD_DATE = new Date('DEPLOY DATE ANISH');
31+
3032
constructor(
3133
private apiService: ApiService,
3234
private router: Router,
3335
private storageService: StorageService
3436
) {}
3537

38+
shouldAutoEnableAccountingPeriod(workspaceCreatedAt: Date): boolean {
39+
const createdAt = new Date(workspaceCreatedAt);
40+
return createdAt >= this.AUTO_ENABLE_ACCOUNTING_PERIOD_DATE;
41+
}
42+
3643
get apiBaseUrl(): string {
3744
return this.storageService.get('cluster-domain') || environment.cluster_domain_api_url;
3845
}

src/app/integrations/netsuite/netsuite-shared/netsuite-advanced-settings/netsuite-advanced-settings.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AppName, AutoMapEmployeeOptions, ConfigurationCta, EmployeeFieldMapping
1111
import { NetsuiteConfiguration } from 'src/app/core/models/netsuite/db/netsuite-workspace-general-settings.model';
1212
import { NetsuiteAdvancedSettingGet, NetsuiteAdvancedSettingModel } from 'src/app/core/models/netsuite/netsuite-configuration/netsuite-advanced-settings.model';
1313
import { NetSuiteExportSettingModel } from 'src/app/core/models/netsuite/netsuite-configuration/netsuite-export-setting.model';
14+
import { Org } from 'src/app/core/models/org/org.model';
1415
import { ConfigurationService } from 'src/app/core/services/common/configuration.service';
1516
import { HelperService } from 'src/app/core/services/common/helper.service';
1617
import { IntegrationsToastService } from 'src/app/core/services/common/integrations-toast.service';
@@ -20,6 +21,7 @@ import { WorkspaceService } from 'src/app/core/services/common/workspace.service
2021
import { NetsuiteAdvancedSettingsService } from 'src/app/core/services/netsuite/netsuite-configuration/netsuite-advanced-settings.service';
2122
import { NetsuiteConnectorService } from 'src/app/core/services/netsuite/netsuite-core/netsuite-connector.service';
2223
import { NetsuiteHelperService } from 'src/app/core/services/netsuite/netsuite-core/netsuite-helper.service';
24+
import { OrgService } from 'src/app/core/services/org/org.service';
2325

2426
@Component({
2527
selector: 'app-netsuite-advanced-settings',
@@ -96,6 +98,8 @@ export class NetsuiteAdvancedSettingsComponent implements OnInit {
9698

9799
isTaxGroupSyncAllowed: boolean;
98100

101+
org: Org = this.orgService.getCachedOrg();
102+
99103
constructor(
100104
private advancedSettingsService: NetsuiteAdvancedSettingsService,
101105
private configurationService: ConfigurationService,
@@ -106,7 +110,8 @@ export class NetsuiteAdvancedSettingsComponent implements OnInit {
106110
private router: Router,
107111
private skipExportService: SkipExportService,
108112
private toastService: IntegrationsToastService,
109-
private workspaceService: WorkspaceService
113+
private workspaceService: WorkspaceService,
114+
private orgService: OrgService
110115
) { }
111116

112117
isOptional(): string {
@@ -283,7 +288,7 @@ export class NetsuiteAdvancedSettingsComponent implements OnInit {
283288

284289
const isSkipExportEnabled = expenseFiltersGet.count > 0;
285290

286-
this.advancedSettingForm = NetsuiteAdvancedSettingModel.mapAPIResponseToFormGroup(this.advancedSetting, isSkipExportEnabled, this.adminEmails);
291+
this.advancedSettingForm = NetsuiteAdvancedSettingModel.mapAPIResponseToFormGroup(this.advancedSetting, isSkipExportEnabled, this.adminEmails, this.helper.shouldAutoEnableAccountingPeriod(this.org.created_at));
287292
this.skipExportForm = SkipExportModel.setupSkipExportForm(this.expenseFilters, [], this.conditionFieldOptions);
288293
this.isLoading = false;
289294
this.setupFormWatchers();

src/app/integrations/qbo/qbo-onboarding/qbo-clone-settings/qbo-clone-settings.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { FyleField, IntegrationField } from 'src/app/core/models/db/mapping.mode
1212
import { AppName, AutoMapEmployeeOptions, ConfigurationCta, ConfigurationWarningEvent, DefaultImportFields, EmployeeFieldMapping, ExpenseGroupingFieldOption, InputType, NameInJournalEntry, QBOCorporateCreditCardExpensesObject, QBOField, QBOReimbursableExpensesObject, ToastSeverity } from 'src/app/core/models/enum/enum.model';
1313
import { ConfigurationWarningOut } from 'src/app/core/models/misc/configuration-warning.model';
1414
import { OnboardingStepper } from 'src/app/core/models/misc/onboarding-stepper.model';
15+
import { Org } from 'src/app/core/models/org/org.model';
1516
import { QBOAdvancedSettingModel } from 'src/app/core/models/qbo/qbo-configuration/qbo-advanced-setting.model';
1617
import { QBOCloneSetting, QBOCloneSettingModel } from 'src/app/core/models/qbo/qbo-configuration/qbo-clone-setting.model';
1718
import { QBOEmployeeSettingModel } from 'src/app/core/models/qbo/qbo-configuration/qbo-employee-setting.model';
@@ -24,6 +25,7 @@ import { HelperService } from 'src/app/core/services/common/helper.service';
2425
import { IntegrationsToastService } from 'src/app/core/services/common/integrations-toast.service';
2526
import { MappingService } from 'src/app/core/services/common/mapping.service';
2627
import { WorkspaceService } from 'src/app/core/services/common/workspace.service';
28+
import { OrgService } from 'src/app/core/services/org/org.service';
2729
import { QboConnectorService } from 'src/app/core/services/qbo/qbo-configuration/qbo-connector.service';
2830
import { QboExportSettingsService } from 'src/app/core/services/qbo/qbo-configuration/qbo-export-settings.service';
2931
import { QboImportSettingsService } from 'src/app/core/services/qbo/qbo-configuration/qbo-import-settings.service';
@@ -153,6 +155,8 @@ export class QboCloneSettingsComponent implements OnInit {
153155

154156
splitExpenseGroupingOptions = QBOExportSettingModel.getSplitExpenseGroupingOptions();
155157

158+
org: Org = this.orgService.getCachedOrg();
159+
156160
scheduleIntervalHours: SelectFormOption[] = [...Array(24).keys()].map(day => {
157161
return {
158162
label: (day + 1).toString(),
@@ -198,7 +202,8 @@ export class QboCloneSettingsComponent implements OnInit {
198202
private qboImportSettingsService: QboImportSettingsService,
199203
private router: Router,
200204
private toastService: IntegrationsToastService,
201-
private workspaceService: WorkspaceService
205+
private workspaceService: WorkspaceService,
206+
private orgService: OrgService
202207
) { }
203208

204209
resetCloneSetting(): void {
@@ -502,7 +507,7 @@ export class QboCloneSettingsComponent implements OnInit {
502507
}
503508

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

507512
this.setupAdvancedSettingFormWatcher();
508513

src/app/integrations/qbo/qbo-shared/qbo-advanced-settings/qbo-advanced-settings.component.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { mockQboAdvancedSettings, mockSkipExportSettings, mockCustomFields, mock
1717
import { AutoMapEmployeeOptions, EmployeeFieldMapping, NameInJournalEntry, Operator, QBOCorporateCreditCardExpensesObject, QBOOnboardingState, QBOReimbursableExpensesObject, ToastSeverity } from 'src/app/core/models/enum/enum.model';
1818
import { AdvancedSettingsModel, ExpenseFilter, SkipExportModel } from 'src/app/core/models/common/advanced-settings.model';
1919
import { GroupedDestinationAttribute } from 'src/app/core/models/db/destination-attribute.model';
20+
import { orgMockData } from 'src/app/core/services/org/org.fixture';
21+
import { OrgService } from 'src/app/core/services/org/org.service';
2022

2123
describe('QboAdvancedSettingsComponent', () => {
2224
let component: QboAdvancedSettingsComponent;
@@ -30,17 +32,22 @@ describe('QboAdvancedSettingsComponent', () => {
3032
let toastService: jasmine.SpyObj<IntegrationsToastService>;
3133
let workspaceService: jasmine.SpyObj<WorkspaceService>;
3234
let router: jasmine.SpyObj<Router>;
35+
let orgService: jasmine.SpyObj<OrgService>;
3336

3437
beforeEach(async () => {
3538
const advancedSettingsServiceSpy = jasmine.createSpyObj('QboAdvancedSettingsService', ['getAdvancedSettings', 'postAdvancedSettings']);
3639
const configurationServiceSpy = jasmine.createSpyObj('ConfigurationService', ['getAdditionalEmails']);
37-
const helperServiceSpy = jasmine.createSpyObj('HelperService', ['setConfigurationSettingValidatorsAndWatchers', 'handleSkipExportFormInAdvancedSettingsUpdates']);
40+
const helperServiceSpy = jasmine.createSpyObj('HelperService', ['setConfigurationSettingValidatorsAndWatchers', 'handleSkipExportFormInAdvancedSettingsUpdates', 'shouldAutoEnableAccountingPeriod']);
3841
const qboHelperServiceSpy = jasmine.createSpyObj('QboHelperService', ['refreshQBODimensions']);
3942
const mappingServiceSpy = jasmine.createSpyObj('MappingService', ['getGroupedDestinationAttributes']);
4043
const skipExportServiceSpy = jasmine.createSpyObj('SkipExportService', ['getExpenseFilter', 'getExpenseFields', 'postExpenseFilter', 'deleteExpenseFilter']);
4144
const toastServiceSpy = jasmine.createSpyObj('IntegrationsToastService', ['displayToastMessage']);
4245
const workspaceServiceSpy = jasmine.createSpyObj('WorkspaceService', ['getWorkspaceGeneralSettings', 'setOnboardingState']);
4346
const routerSpy = jasmine.createSpyObj('Router', ['navigate']);
47+
const orgServiceSpy = jasmine.createSpyObj('OrgService', ['getCachedOrg']);
48+
49+
orgServiceSpy.getCachedOrg.and.returnValue(orgMockData);
50+
helperServiceSpy.shouldAutoEnableAccountingPeriod.and.returnValue(false);
4451

4552
await TestBed.configureTestingModule({
4653
declarations: [ QboAdvancedSettingsComponent ],
@@ -55,7 +62,8 @@ describe('QboAdvancedSettingsComponent', () => {
5562
{ provide: SkipExportService, useValue: skipExportServiceSpy },
5663
{ provide: IntegrationsToastService, useValue: toastServiceSpy },
5764
{ provide: WorkspaceService, useValue: workspaceServiceSpy },
58-
{ provide: Router, useValue: routerSpy }
65+
{ provide: Router, useValue: routerSpy },
66+
{ provide: OrgService, useValue: orgServiceSpy }
5967
]
6068
}).compileComponents();
6169

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

7483
component.advancedSettingForm = new FormBuilder().group({
7584
paymentSync: [null],

src/app/integrations/qbo/qbo-shared/qbo-advanced-settings/qbo-advanced-settings.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { AdvancedSettingsModel, ConditionField, EmailOption, ExpenseFilterPayloa
77
import { SelectFormOption } from 'src/app/core/models/common/select-form-option.model';
88
import { DefaultDestinationAttribute, DestinationAttribute } from 'src/app/core/models/db/destination-attribute.model';
99
import { AppName, AutoMapEmployeeOptions, ConfigurationCta, EmployeeFieldMapping, NameInJournalEntry, QBOCorporateCreditCardExpensesObject, QBOOnboardingState, QBOPaymentSyncDirection, QBOReimbursableExpensesObject, ToastSeverity } from 'src/app/core/models/enum/enum.model';
10+
import { Org } from 'src/app/core/models/org/org.model';
1011
import { QBOWorkspaceGeneralSetting } from 'src/app/core/models/qbo/db/workspace-general-setting.model';
1112
import { QBOAdvancedSettingGet, QBOAdvancedSettingModel } from 'src/app/core/models/qbo/qbo-configuration/qbo-advanced-setting.model';
1213
import { QBOExportSettingModel } from 'src/app/core/models/qbo/qbo-configuration/qbo-export-setting.model';
@@ -16,6 +17,7 @@ import { IntegrationsToastService } from 'src/app/core/services/common/integrati
1617
import { MappingService } from 'src/app/core/services/common/mapping.service';
1718
import { SkipExportService } from 'src/app/core/services/common/skip-export.service';
1819
import { WorkspaceService } from 'src/app/core/services/common/workspace.service';
20+
import { OrgService } from 'src/app/core/services/org/org.service';
1921
import { QboAdvancedSettingsService } from 'src/app/core/services/qbo/qbo-configuration/qbo-advanced-settings.service';
2022
import { QboHelperService } from 'src/app/core/services/qbo/qbo-core/qbo-helper.service';
2123

@@ -79,6 +81,8 @@ export class QboAdvancedSettingsComponent implements OnInit {
7981

8082
isSkipExportFormInvalid: boolean;
8183

84+
org: Org = this.orgService.getCachedOrg();
85+
8286
constructor(
8387
private advancedSettingsService: QboAdvancedSettingsService,
8488
private configurationService: ConfigurationService,
@@ -88,7 +92,8 @@ export class QboAdvancedSettingsComponent implements OnInit {
8892
private router: Router,
8993
private skipExportService: SkipExportService,
9094
private toastService: IntegrationsToastService,
91-
private workspaceService: WorkspaceService
95+
private workspaceService: WorkspaceService,
96+
private orgService: OrgService
9297
) { }
9398

9499

@@ -241,7 +246,7 @@ export class QboAdvancedSettingsComponent implements OnInit {
241246

242247
const isSkipExportEnabled = expenseFiltersGet.count > 0;
243248

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

247252
this.setupFormWatchers();

0 commit comments

Comments
 (0)