Skip to content

Commit

Permalink
fix: dont use DE if not needed (#3126)
Browse files Browse the repository at this point in the history
  • Loading branch information
madhavmansuriya40 authored Jun 28, 2024
1 parent f19398e commit 07c53f3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/app/fyle/add-edit-expense/add-edit-expense.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ import { corporateCardTransaction } from 'src/app/core/models/platform/v1/cc-tra
import { PlatformFileGenerateUrlsResponse } from 'src/app/core/models/platform/platform-file-generate-urls-response.model';
import { SpenderFileService } from 'src/app/core/services/platform/v1/spender/file.service';

// eslint-disable-next-line
type FormValue = {
currencyObj: {
currency: string;
Expand Down Expand Up @@ -4553,12 +4554,13 @@ export class AddEditExpensePage implements OnInit {
});
return this.expensesService.attachReceiptToExpense(expenseId, fileObj.id);
}),
switchMap(() =>
switchMap((expenseObj: PlatformExpense) =>
editExpenseAttachments$.pipe(
withLatestFrom(this.isConnected$),
map(([attachments, isConnected]) => ({
attachments,
isConnected,
expenseObj,
}))
)
),
Expand All @@ -4567,9 +4569,20 @@ export class AddEditExpensePage implements OnInit {
this.attachmentUploadInProgress = false;
})
)
.subscribe(({ attachments, isConnected }) => {
.subscribe(({ attachments, isConnected, expenseObj }) => {
this.attachedReceiptsCount = attachments;
if (isConnected && this.attachedReceiptsCount === 1) {

// checking if extraction is needed or not
const isDataExtractionNeeded = !(
expenseObj?.amount !== null &&
expenseObj.currency &&
expenseObj.spent_at &&
expenseObj.category_id &&
expenseObj.category.name !== 'Unspecified' &&
expenseObj.merchant
);

if (isConnected && this.attachedReceiptsCount === 1 && isDataExtractionNeeded) {
this.parseFile(
fileInfo as {
type: string;
Expand Down

0 comments on commit 07c53f3

Please sign in to comment.