Skip to content

Commit

Permalink
fix: Billable field not auto-filling the default value (#2628)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmkarJ13 authored Dec 4, 2023
1 parent 1651e9d commit af24455
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/app/core/services/expense-fields.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { OrgCategory } from '../models/v1/org-category.model';
import { AuthService } from './auth.service';
import { DateService } from './date.service';
import { SpenderPlatformV1ApiService } from './spender-platform-v1-api.service';
import { cloneDeep } from 'lodash';

@Injectable({
providedIn: 'root',
Expand All @@ -20,7 +21,7 @@ export class ExpenseFieldsService {
constructor(
private spenderPlatformV1ApiService: SpenderPlatformV1ApiService,
private authService: AuthService,
private dateService: DateService,
private dateService: DateService
) {}

@Cacheable()
Expand All @@ -33,10 +34,10 @@ export class ExpenseFieldsService {
is_enabled: 'eq.true',
is_custom: 'eq.false',
},
}),
})
),
map((res) => this.transformFrom(res.data)),
map((res) => this.dateService.fixDates(res)),
map((res) => this.dateService.fixDates(res))
);
}

Expand Down Expand Up @@ -131,14 +132,14 @@ export class ExpenseFieldsService {
expenseFieldMap[expenseField.column_name] = expenseFieldsList;
});
return expenseFieldMap;
}),
})
);
}

filterByOrgCategoryId(
tfcMap: Partial<ExpenseFieldsMap>,
fields: string[],
orgCategory: OrgCategory,
orgCategory: OrgCategory
): Observable<Partial<ExpenseFieldsObj>> {
const orgCategoryId = orgCategory && orgCategory.id;
return of(fields).pipe(
Expand Down Expand Up @@ -171,7 +172,7 @@ export class ExpenseFieldsService {
}
return filteredField;
})
.filter((filteredField) => !!filteredField),
.filter((filteredField) => !!filteredField)
),
switchMap((fields) => from(fields)),
map((field) => ({
Expand All @@ -180,7 +181,7 @@ export class ExpenseFieldsService {
reduce((acc, curr) => {
acc[curr.field] = curr;
return acc;
}, {}),
}, {})
);
}

Expand All @@ -194,7 +195,7 @@ export class ExpenseFieldsService {
To handle both case added this, it can take the type based on use case, but, ideally, we should have a single type of response
*/
getDefaultTxnFieldValues(
txnFields: Partial<ExpenseFieldsMap> | Partial<ExpenseFieldsObj>,
txnFields: Partial<ExpenseFieldsMap> | Partial<ExpenseFieldsObj>
): Partial<DefaultTxnFieldValues> {
const defaultValues = {};
for (const configurationColumn in txnFields) {
Expand All @@ -210,7 +211,8 @@ export class ExpenseFieldsService {
}

private formatBillableFields(expenseFields: ExpenseField[]): ExpenseField[] {
return expenseFields.map((field) => {
const expenseFieldsCopy = cloneDeep(expenseFields);
return expenseFieldsCopy.map((field) => {
if (!field.is_custom && field.field_name.toLowerCase() === 'billable') {
field.default_value = field.default_value === 'true';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { txnFieldsData2 } from 'src/app/core/mock-data/expense-field-obj.data';
import { defaultTxnFieldValuesData2 } from 'src/app/core/mock-data/default-txn-field-values.data';
import { orgSettingsCCCDisabled } from 'src/app/core/mock-data/org-settings.data';
import { ExpenseType } from 'src/app/core/enums/expense-type.enum';
import { expectedProjectsResponse } from 'src/app/core/test-data/projects.spec.data';

export function TestCases1(getTestBed) {
return describe('add-edit-per-diem test cases set 1', () => {
Expand Down Expand Up @@ -553,12 +554,13 @@ export function TestCases1(getTestBed) {
);
expenseFieldsService.filterByOrgCategoryId.and.returnValue(of(mockTxnFieldData));
expenseFieldsService.getDefaultTxnFieldValues.and.returnValue(defaultTxnFieldValuesData2);
component.fg.controls.project.setValue(expectedProjectsResponse[0]);
component.fg.controls.purpose.setValue('');
component.fg.controls.costCenter.setValue(null);
component.fg.controls.from_dt.setValue('2023-01-01');
component.fg.controls.num_days.setValue(32);
component.fg.controls.to_dt.setValue('2023-02-02');
component.fg.controls.billable.setValue(true);
component.fg.controls.billable.setValue(null);

component.setupTfcDefaultValues();

Expand All @@ -572,6 +574,7 @@ export function TestCases1(getTestBed) {
expect(expenseFieldsService.getDefaultTxnFieldValues).toHaveBeenCalledOnceWith(mockTxnFieldData);
expect(component.fg.controls.costCenter.value).toEqual(15818);
expect(component.fg.controls.purpose.value).toEqual('test_term');
expect(component.fg.controls.billable.value).toEqual(true);
});

it('getPaymentModes(): should get payment modes', (done) => {
Expand Down
9 changes: 8 additions & 1 deletion src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,14 @@ export class AddEditPerDiemPage implements OnInit {
for (const defaultValueColumn in defaultValues) {
if (defaultValues.hasOwnProperty(defaultValueColumn)) {
const control = keyToControlMap[defaultValueColumn];
if (!control.value && defaultValueColumn !== 'billable') {
if (!control.value && !control.touched && defaultValueColumn !== 'billable') {
control.patchValue(defaultValues[defaultValueColumn]);
} else if (
defaultValueColumn === 'billable' &&
this.fg.controls.project.value &&
(control.value === undefined || control.value === null) &&
!control.touched
) {
control.patchValue(defaultValues[defaultValueColumn]);
}
}
Expand Down

0 comments on commit af24455

Please sign in to comment.