Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: retain receipt when editing, remove code for advance wallet id, set unspecified category id #3245

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/core/models/v1/transaction.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@ export interface Transaction {
status: ExpenseTransactionStatus;
corporate_card_nickname?: string;
}[];
file_ids: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class ExpensesService {
}

// transform public transaction to expense payload for /post expenses
transformTo(transaction: Partial<Transaction>, fileIds: string[]): Partial<Expense> {
transformTo(transaction: Partial<Transaction>): Partial<Expense> {
const expense: Partial<Expense> = {
id: transaction.id,
spent_at: transaction.txn_dt,
Expand Down Expand Up @@ -323,7 +323,7 @@ export class ExpensesService {
commute_details_id: transaction.commute_details_id,
hotel_is_breakfast_provided: transaction.hotel_is_breakfast_provided,
advance_wallet_id: transaction.advance_wallet_id,
file_ids: fileIds,
file_ids: transaction.file_ids,
report_id: transaction.report_id,
travel_classes: [],
};
Expand Down
7 changes: 4 additions & 3 deletions src/app/core/services/transaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class TransactionService {
@CacheBuster({
cacheBusterNotifier: expensesCacheBuster$,
})
upsert(transaction: Partial<Transaction>, fileIds: string[] = []): Observable<Partial<Transaction>> {
upsert(transaction: Partial<Transaction>): Observable<Partial<Transaction>> {
/** Only these fields will be of type text & custom fields */
const fieldsToCheck = ['purpose', 'vendor', 'train_travel_class', 'bus_travel_class'];

Expand Down Expand Up @@ -180,7 +180,7 @@ export class TransactionService {

const transactionCopy = this.utilityService.discardRedundantCharacters(transaction, fieldsToCheck);

const expensePayload = this.expensesService.transformTo(transactionCopy, fileIds);
const expensePayload = this.expensesService.transformTo(transactionCopy);
return this.expensesService.post(expensePayload).pipe(map((result) => this.transformExpense(result.data).tx));
})
);
Expand All @@ -205,7 +205,8 @@ export class TransactionService {
}
} else {
const fileIds = fileObjs.map((fileObj) => fileObj.id);
return this.upsert(txn, fileIds);
txn.file_ids = fileIds;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only during createTxnWithFiles do we have to set the file_ids in the add/edit flow. In other scenarios of the add/edit, the file_ids will be already present.

return this.upsert(txn);
}
})
);
Expand Down
36 changes: 13 additions & 23 deletions src/app/fyle/add-edit-expense/add-edit-expense.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@

pendingTransactionAllowedToReportAndSplit = true;

allCategories$: Observable<OrgCategory[]>;

activeCategories$: Observable<OrgCategory[]>;

selectedCategory$: Observable<OrgCategory>;
Expand Down Expand Up @@ -1236,12 +1238,6 @@
);
}

getActiveCategories(): Observable<OrgCategory[]> {
const allCategories$ = this.categoriesService.getAll();

return allCategories$.pipe(map((catogories) => this.categoriesService.filterRequired(catogories)));
}

getInstaFyleImageData(): Observable<Partial<InstaFyleImageData>> {
if (this.activatedRoute.snapshot.params.dataUrl && this.activatedRoute.snapshot.params.canExtractData !== 'false') {
const dataUrl = this.activatedRoute.snapshot.params.dataUrl as string;
Expand Down Expand Up @@ -2977,7 +2973,10 @@
}

ionViewWillEnter(): void {
this.activeCategories$ = this.getActiveCategories().pipe(shareReplay(1));
this.allCategories$ = this.categoriesService.getAll().pipe(shareReplay(1));
this.activeCategories$ = this.allCategories$
.pipe(map((catogories) => this.categoriesService.filterRequired(catogories)))
.pipe(shareReplay(1));

this.initClassObservables();

Expand Down Expand Up @@ -3497,6 +3496,7 @@
customProperties: standardisedCustomProperties$,
attachments: attachements$,
orgSettings: this.orgSettingsService.get(),
allCategories: this.allCategories$,
}).pipe(
map((res) => {
const etxn: Partial<UnflattenedTransaction> = res.etxn;
Expand All @@ -3509,6 +3509,9 @@
}
return customProperty;
});
const unspecifiedCategory = res.allCategories.find(
(category) => category.fyle_category?.toLowerCase() === 'unspecified'
);

const formValues = this.getFormValues();

Expand Down Expand Up @@ -3545,7 +3548,8 @@
amount = etxn.tx.user_amount;
}

//TODO: Add depenedent fields to custom_properties array once APIs are available
const category_id = this.getOrgCategoryID() || unspecifiedCategory.id;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setting unspecified category as the default category.

//TODO: Add dependent fields to custom_properties array once APIs are available
return {
tx: {
...etxn.tx,
Expand All @@ -3562,7 +3566,7 @@
project_id: this.getProjectID(),
tax_amount: this.getTaxAmount(),
tax_group_id: this.getTaxGroupID(),
org_category_id: this.getOrgCategoryID(),
org_category_id: category_id,
fyle_category: this.getFyleCategory(),
policy_amount: null,
vendor: this.getDisplayName(),
Expand Down Expand Up @@ -4036,10 +4040,7 @@
report: Report;
};

// NOTE: This double call is done as certain fields will not be present in return of upsert call. policy_amount in this case.
return this.transactionService.upsert(etxn.tx as Transaction).pipe(
switchMap((txn) => this.expensesService.getExpenseById(txn.id)),
map((expense) => this.transactionService.transformExpense(expense).tx),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not using the result of this double call for checking policy_amount and other fields

switchMap((tx) => {
const selectedReportId = reportControl.report?.id;
const criticalPolicyViolated = this.getIsPolicyExpense(etxn as unknown as Expense);
Expand Down Expand Up @@ -4082,17 +4083,6 @@
} else {
return of(txn);
}
}),
switchMap((txn) => {
if (txn.id && txn.advance_wallet_id !== etxn.tx.advance_wallet_id) {
const expense = {
id: txn.id,
advance_wallet_id: etxn.tx.advance_wallet_id,
};
return this.expensesService.post(expense).pipe(map(() => txn));
} else {
return of(txn);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

advance_wallet_id will be already set in the normal POST flow. We don't need this additional call

}
})
);
})
Expand Down Expand Up @@ -4561,7 +4551,7 @@
return this.vendorOptions?.find((option) => option.toLowerCase() === vendor.toLowerCase()) || null;
}

attachReceipts(data: { type: string; dataUrl: string | ArrayBuffer; actionSource?: string }): void {

Check failure on line 4554 in src/app/fyle/add-edit-expense/add-edit-expense.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Member attachReceipts should be declared before all private instance method definitions
if (data) {
const fileInfo = {
type: data.type,
Expand Down Expand Up @@ -4669,7 +4659,7 @@
}
}

async uploadFileCallback(file: File): Promise<void> {

Check failure on line 4662 in src/app/fyle/add-edit-expense/add-edit-expense.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Member uploadFileCallback should be declared before all private instance method definitions
let fileData: { type: string; dataUrl: string | ArrayBuffer; actionSource: string };
if (file) {
if (file.size < MAX_FILE_SIZE) {
Expand All @@ -4687,12 +4677,12 @@
}
}

async onChangeCallback(nativeElement: HTMLInputElement): Promise<void> {

Check failure on line 4680 in src/app/fyle/add-edit-expense/add-edit-expense.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Member onChangeCallback should be declared before all private instance method definitions
const file = nativeElement.files[0];
this.uploadFileCallback(file);
}

async addAttachments(event: Event): Promise<void> {

Check failure on line 4685 in src/app/fyle/add-edit-expense/add-edit-expense.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Member addAttachments should be declared before all private instance method definitions
event.stopPropagation();

if (this.platform.is('ios')) {
Expand Down Expand Up @@ -4762,7 +4752,7 @@
}
}

getReceiptExtension(name: string): string | null {

Check failure on line 4755 in src/app/fyle/add-edit-expense/add-edit-expense.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Member getReceiptExtension should be declared before all private instance method definitions
let res: string = null;

if (name) {
Expand All @@ -4777,7 +4767,7 @@
return res;
}

getReceiptDetails(file: FileObject): { type: string; thumbnail: string } {

Check failure on line 4770 in src/app/fyle/add-edit-expense/add-edit-expense.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Member getReceiptDetails should be declared before all private instance method definitions
const ext = this.getReceiptExtension(file.name);
const res = {
type: 'unknown',
Expand All @@ -4795,7 +4785,7 @@
return res;
}

viewAttachments(): void {

Check failure on line 4788 in src/app/fyle/add-edit-expense/add-edit-expense.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Member viewAttachments should be declared before all private instance method definitions
const attachements$ = this.getExpenseAttachments(this.mode);

from(this.loaderService.showLoader())
Expand Down Expand Up @@ -4851,7 +4841,7 @@
});
}

getDeleteReportParams(

Check failure on line 4844 in src/app/fyle/add-edit-expense/add-edit-expense.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Member getDeleteReportParams should be declared before all private instance method definitions
config: { header: string; body: string; ctaText: string; ctaLoadingText: string },
removeExpenseFromReport: boolean = false,
reportId?: string
Expand Down Expand Up @@ -4886,7 +4876,7 @@
};
}

async deleteExpense(reportId?: string): Promise<void> {

Check failure on line 4879 in src/app/fyle/add-edit-expense/add-edit-expense.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Member deleteExpense should be declared before all private instance method definitions
const removeExpenseFromReport = reportId && this.isRedirectedFromReport;
const header = removeExpenseFromReport ? 'Remove Expense' : 'Delete Expense';
const body = removeExpenseFromReport
Expand Down Expand Up @@ -4930,7 +4920,7 @@
}
}

async openCommentsModal(): Promise<void> {

Check failure on line 4923 in src/app/fyle/add-edit-expense/add-edit-expense.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

Member openCommentsModal should be declared before all private instance method definitions
const etxn = await this.etxn$.toPromise();

const modal = await this.modalController.create({
Expand Down
Loading