Repository navigation
Fix new individual invoice after one is paid as a business #54138
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
Changes from all commits
bac1302
59d79fa
0afdca3
3054897
401f5de
3d11b6c
03c9bf9
0c6e50d
a2bbb54
410868e
57ba052
e6d5a92
2ada6b8
3e4e033
4516d8f
17d298a
5fefb6c
b62ad1b
7275ccf
68cabf2
b89a319
55572c3
3e56f47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ import GoogleTagManager from '@libs/GoogleTagManager'; | |
| import * as IOUUtils from '@libs/IOUUtils'; | ||
| import * as LocalePhoneNumber from '@libs/LocalePhoneNumber'; | ||
| import * as Localize from '@libs/Localize'; | ||
| import Log from '@libs/Log'; | ||
| import isSearchTopmostCentralPane from '@libs/Navigation/isSearchTopmostCentralPane'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import * as NextStepUtils from '@libs/NextStepUtils'; | ||
|
|
@@ -65,6 +66,7 @@ import type * as OnyxTypes from '@src/types/onyx'; | |
| import type {Attendee, Participant, Split} from '@src/types/onyx/IOU'; | ||
| import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon'; | ||
| import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; | ||
| import type {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report'; | ||
| import type ReportAction from '@src/types/onyx/ReportAction'; | ||
| import type {OnyxData} from '@src/types/onyx/Request'; | ||
| import type {SearchPolicy, SearchReport, SearchTransaction} from '@src/types/onyx/SearchResults'; | ||
|
|
@@ -2071,6 +2073,25 @@ function getDeleteTrackExpenseInformation( | |
| return {parameters, optimisticData, successData, failureData, shouldDeleteTransactionThread, chatReport}; | ||
| } | ||
|
|
||
| /** | ||
| * Get the invoice receiver type based on the receiver participant. | ||
| * @param receiverParticipant The participant who will receive the invoice or the invoice receiver object directly. | ||
| * @returns The invoice receiver type. | ||
| */ | ||
| function getReceiverType(receiverParticipant: Participant | InvoiceReceiver | undefined): InvoiceReceiverType { | ||
| if (!receiverParticipant) { | ||
| Log.warn('getReceiverType called with no receiverParticipant'); | ||
| return CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL; | ||
| } | ||
| if ('type' in receiverParticipant && receiverParticipant.type) { | ||
| return receiverParticipant.type; | ||
| } | ||
| if ('policyID' in receiverParticipant && receiverParticipant.policyID) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
See the bug mentioned in this proposal: #70004 (comment). |
||
| return CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS; | ||
| } | ||
| return CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL; | ||
| } | ||
|
|
||
| /** Gathers all the data needed to create an invoice. */ | ||
| function getSendInvoiceInformation( | ||
| transaction: OnyxEntry<OnyxTypes.Transaction>, | ||
|
|
@@ -2086,17 +2107,18 @@ function getSendInvoiceInformation( | |
| const {amount = 0, currency = '', created = '', merchant = '', category = '', tag = '', taxCode = '', taxAmount = 0, billable, comment, participants} = transaction ?? {}; | ||
| const trimmedComment = (comment?.comment ?? '').trim(); | ||
| const senderWorkspaceID = participants?.find((participant) => participant?.isSender)?.policyID ?? '-1'; | ||
| const receiverParticipant = participants?.find((participant) => participant?.accountID) ?? invoiceChatReport?.invoiceReceiver; | ||
| const receiverParticipant: Participant | InvoiceReceiver | undefined = participants?.find((participant) => participant?.accountID) ?? invoiceChatReport?.invoiceReceiver; | ||
| const receiverAccountID = receiverParticipant && 'accountID' in receiverParticipant && receiverParticipant.accountID ? receiverParticipant.accountID : -1; | ||
| let receiver = ReportUtils.getPersonalDetailsForAccountID(receiverAccountID); | ||
| let optimisticPersonalDetailListAction = {}; | ||
| const receiverType = getReceiverType(receiverParticipant); | ||
|
|
||
| // STEP 1: Get existing chat report OR build a new optimistic one | ||
| let isNewChatReport = false; | ||
| let chatReport = !isEmptyObject(invoiceChatReport) && invoiceChatReport?.reportID ? invoiceChatReport : null; | ||
|
|
||
| if (!chatReport) { | ||
| chatReport = ReportUtils.getInvoiceChatByParticipants(senderWorkspaceID, receiverAccountID) ?? null; | ||
| chatReport = ReportUtils.getInvoiceChatByParticipants(receiverAccountID, receiverType, senderWorkspaceID) ?? null; | ||
| } | ||
|
|
||
| if (!chatReport) { | ||
|
|
@@ -6896,7 +6918,7 @@ function getPayMoneyRequestParams( | |
| } | ||
|
|
||
| if (ReportUtils.isIndividualInvoiceRoom(chatReport) && payAsBusiness && activePolicyID) { | ||
| const existingB2BInvoiceRoom = ReportUtils.getInvoiceChatByParticipants(chatReport.policyID ?? '', activePolicyID); | ||
| const existingB2BInvoiceRoom = ReportUtils.getInvoiceChatByParticipants(activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS, chatReport.policyID); | ||
| if (existingB2BInvoiceRoom) { | ||
| chatReport = existingB2BInvoiceRoom; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback< | |
| }; | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| private_isArchived: unknown; | ||
| welcomeMessage: unknown; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this comment is strange. The whole thing is pretty confusing. It's just listing all the fields in the report and asserting that they're in the report type. I don't find any value in that because it's totally circular. I found the related issue, and the goal there is to move client only keys out of the report type. So now I understand the purpose. It also doesn't really make sense to limit that to the OpenApp call, I think OpenReport is also a valid way to tell which keys come from the server. I checked the response and I see that welcomeMessage is returned but state is not, so I'll remove state. Thanks for pointing this out. |
||
| }, | ||
| PolicyReportField['fieldID'] | ||
| >; | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess optional chaining was troubling here 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the type narrowing seems to be necessary because the receiverParticipant is a combination of two types.