-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Handle tax for split requests #40240
Changes from all commits
c611187
c7ec5f2
8cb3a49
bb6d480
98e0e40
477b381
ec48476
bd20eed
de50156
c3db0c8
c667482
cdfb3ad
78bf98a
776856c
6dd21cb
c7d8b42
787c520
d136b4a
c671c7a
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,9 +39,6 @@ type IOURequestStepAmountOnyxProps = { | |
/** Whether the confirmation step should be skipped */ | ||
skipConfirmation: OnyxEntry<boolean>; | ||
|
||
/** The draft transaction object being modified in Onyx */ | ||
draftTransaction: OnyxEntry<OnyxTypes.Transaction>; | ||
|
||
/** Personal details of all users */ | ||
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>; | ||
|
||
|
@@ -67,7 +64,6 @@ function IOURequestStepAmount({ | |
currentUserPersonalDetails, | ||
splitDraftTransaction, | ||
skipConfirmation, | ||
draftTransaction, | ||
}: IOURequestStepAmountProps) { | ||
const {translate} = useLocalize(); | ||
const textInput = useRef<BaseTextInputRef | null>(null); | ||
|
@@ -78,8 +74,9 @@ function IOURequestStepAmount({ | |
const isEditing = action === CONST.IOU.ACTION.EDIT; | ||
const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT; | ||
const isEditingSplitBill = isEditing && isSplitBill; | ||
const {amount: transactionAmount} = ReportUtils.getTransactionDetails(isEditingSplitBill && !isEmptyObject(splitDraftTransaction) ? splitDraftTransaction : transaction) ?? {amount: 0}; | ||
const {currency: originalCurrency} = ReportUtils.getTransactionDetails(isEditing ? draftTransaction : transaction) ?? {currency: CONST.CURRENCY.USD}; | ||
const currentTransaction = isEditingSplitBill && !isEmptyObject(splitDraftTransaction) ? splitDraftTransaction : transaction; | ||
const {amount: transactionAmount} = ReportUtils.getTransactionDetails(currentTransaction) ?? {amount: 0}; | ||
const {currency: originalCurrency} = ReportUtils.getTransactionDetails(currentTransaction) ?? {currency: CONST.CURRENCY.USD}; | ||
const currency = CurrencyUtils.isValidCurrencyCode(selectedCurrency) ? selectedCurrency : originalCurrency; | ||
|
||
// For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace request, as | ||
|
@@ -269,25 +266,25 @@ function IOURequestStepAmount({ | |
} | ||
|
||
// If the value hasn't changed, don't request to save changes on the server and just close the modal | ||
const transactionCurrency = TransactionUtils.getCurrency(transaction); | ||
if (newAmount === TransactionUtils.getAmount(transaction) && currency === transactionCurrency) { | ||
const transactionCurrency = TransactionUtils.getCurrency(currentTransaction); | ||
if (newAmount === TransactionUtils.getAmount(currentTransaction) && currency === transactionCurrency) { | ||
Navigation.dismissModal(); | ||
return; | ||
} | ||
|
||
// If currency has changed, then we get the default tax rate based on currency, otherwise we use the current tax rate selected in transaction, if we have it. | ||
const transactionTaxCode = ReportUtils.getTransactionDetails(currentTransaction)?.taxCode; | ||
const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, currentTransaction, currency) ?? ''; | ||
const taxCode = (currency !== transactionCurrency ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode; | ||
const taxPercentage = TransactionUtils.getTaxValue(policy, currentTransaction, taxCode) ?? ''; | ||
const taxAmount = CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(taxPercentage, newAmount)); | ||
|
||
if (isSplitBill) { | ||
IOU.setDraftSplitTransaction(transactionID, {amount: newAmount, currency}); | ||
IOU.setDraftSplitTransaction(transactionID, {amount: newAmount, currency, taxCode, taxAmount}); | ||
Navigation.goBack(backTo); | ||
return; | ||
} | ||
|
||
// If currency has changed, then we get the default tax rate based on currency, otherwise we use the current tax rate selected in transaction, if we have it. | ||
const transactionTaxCode = transaction?.taxCode ?? ''; | ||
const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction, currency) ?? ''; | ||
const taxCode = (currency !== transactionCurrency ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode; | ||
const taxPercentage = TransactionUtils.getTaxValue(policy, transaction, taxCode) ?? ''; | ||
const taxAmount = CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(taxPercentage, newAmount)); | ||
|
||
IOU.updateMoneyRequestAmountAndCurrency({transactionID, transactionThreadReportID: reportID, currency, amount: newAmount, taxAmount, policy, taxCode}); | ||
Navigation.dismissModal(); | ||
}; | ||
|
@@ -326,12 +323,6 @@ const IOURequestStepAmountWithOnyx = withOnyx<IOURequestStepAmountProps, IOURequ | |
return `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`; | ||
}, | ||
}, | ||
draftTransaction: { | ||
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.
|
||
key: ({route}) => { | ||
const transactionID = route.params.transactionID ?? 0; | ||
return `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`; | ||
}, | ||
}, | ||
skipConfirmation: { | ||
key: ({route}) => { | ||
const transactionID = route.params.transactionID ?? 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,9 @@ function IOURequestStepParticipants({ | |
const participants = transaction?.participants; | ||
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
const selectedReportID = useRef<string>(reportID); | ||
|
||
// We need to set selectedReportID if user has navigated back from confirmation page and navigates to confirmation page with already selected participant | ||
const selectedReportID = useRef<string>(participants?.length === 1 ? participants[0]?.reportID ?? reportID : reportID); | ||
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. Bug was
Let me know if you think this is not the correct way and should use separate hook or may be something else. Open to other solutions. |
||
const numberOfParticipants = useRef(participants?.length ?? 0); | ||
const iouRequestType = TransactionUtils.getRequestType(transaction); | ||
const isSplitRequest = iouType === CONST.IOU.TYPE.SPLIT; | ||
|
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 mostly think this was pre optimization. When the user updates transactionAmount, previousTransactionAmount was not being changed, and we we were not setting updated taxAmount in Onyx
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.
No, this introduced a bug where taxAmount is not being updated in draft transaction. looking...
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.
This is fixed now with latest commit - c671c7a