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

[P2P Distance] Rate currency doesn't match expense currency #50142

Merged
merged 8 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ function MoneyRequestConfirmationList({
const prevRate = usePrevious(rate);

const currency = (mileageRate as MileageRate)?.currency ?? policyCurrency;
const prevCurrency = usePrevious(currency);

// A flag for showing the categories field
const shouldShowCategories = (isPolicyExpenseChat || isTypeInvoice) && (!!iouCategory || OptionsListUtils.hasEnabledOptions(Object.values(policyCategories ?? {})));
Expand Down Expand Up @@ -292,7 +293,7 @@ function MoneyRequestConfirmationList({
const distance = TransactionUtils.getDistanceInMeters(transaction, unit);
const prevDistance = usePrevious(distance);

const shouldCalculateDistanceAmount = isDistanceRequest && (iouAmount === 0 || prevRate !== rate || prevDistance !== distance);
const shouldCalculateDistanceAmount = isDistanceRequest && (iouAmount === 0 || prevRate !== rate || prevDistance !== distance || prevCurrency !== currency);

const hasRoute = TransactionUtils.hasRoute(transaction, isDistanceRequest);
const isDistanceRequestWithPendingRoute = isDistanceRequest && (!hasRoute || !rate) && !isMovingTransactionFromTrackExpense;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
const hasRoute = TransactionUtils.hasRoute(transactionBackup ?? transaction, isDistanceRequest);
const rateID = TransactionUtils.getRateID(transaction) ?? '-1';

const currency = policy ? policy.outputCurrency : PolicyUtils.getPersonalPolicy()?.outputCurrency ?? CONST.CURRENCY.USD;
const currency = transactionCurrency ?? CONST.CURRENCY.USD;

const mileageRate = TransactionUtils.isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(currency) : distanceRates[rateID] ?? {};
const {unit} = mileageRate;
Expand Down
3 changes: 1 addition & 2 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ import type {
PayerSettledParams,
PaySomeoneParams,
ReconciliationWorksParams,
ReimbursementRateParams,
RemovedFromApprovalWorkflowParams,
RemovedTheRequestParams,
RemoveMemberPromptParams,
Expand Down Expand Up @@ -1015,7 +1014,7 @@ const translations = {
changed: 'changed',
removed: 'removed',
transactionPending: 'Transaction pending.',
chooseARate: ({unit}: ReimbursementRateParams) => `Select a workspace reimbursement rate per ${unit}`,
chooseARate: 'Select a workspace reimbursement rate per mile or kilometer',
unapprove: 'Unapprove',
unapproveReport: 'Unapprove report',
headsUp: 'Heads up!',
Expand Down
3 changes: 1 addition & 2 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ import type {
PayerSettledParams,
PaySomeoneParams,
ReconciliationWorksParams,
ReimbursementRateParams,
RemovedFromApprovalWorkflowParams,
RemovedTheRequestParams,
RemoveMemberPromptParams,
Expand Down Expand Up @@ -1010,7 +1009,7 @@ const translations = {
changed: 'cambió',
removed: 'eliminó',
transactionPending: 'Transacción pendiente.',
chooseARate: ({unit}: ReimbursementRateParams) => `Selecciona una tasa de reembolso por ${unit} del espacio de trabajo`,
chooseARate: 'Selecciona una tasa de reembolso por milla o kilómetro para el espacio de trabajo',
unapprove: 'Desaprobar',
unapproveReport: 'Anular la aprobación del informe',
headsUp: 'Atención!',
Expand Down
5 changes: 1 addition & 4 deletions src/languages/params.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {OnyxInputOrEntry, ReportAction} from '@src/types/onyx';
import type {DelegateRole} from '@src/types/onyx/Account';
import type {AllConnectionName, ConnectionName, PolicyConnectionSyncStage, SageIntacctMappingName, Unit} from '@src/types/onyx/Policy';
import type {AllConnectionName, ConnectionName, PolicyConnectionSyncStage, SageIntacctMappingName} from '@src/types/onyx/Policy';
import type {ViolationDataType} from '@src/types/onyx/TransactionViolation';

type AddressLineParams = {
Expand Down Expand Up @@ -279,8 +279,6 @@ type LogSizeAndDateParams = {size: number; date: string};

type HeldRequestParams = {comment: string};

type ReimbursementRateParams = {unit: Unit};

type ChangeFieldParams = {oldValue?: string; newValue: string; fieldName: string};

type ChangePolicyParams = {fromPolicy: string; toPolicy: string};
Expand Down Expand Up @@ -648,7 +646,6 @@ export type {
PayerPaidAmountParams,
PayerPaidParams,
PayerSettledParams,
ReimbursementRateParams,
RemovedTheRequestParams,
RenamedRoomActionParams,
ReportArchiveReasonsClosedParams,
Expand Down
9 changes: 6 additions & 3 deletions src/pages/iou/request/step/IOURequestStepDistanceRate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ function IOURequestStepDistanceRate({

const currentRateID = TransactionUtils.getRateID(transaction) ?? '-1';

const transactionCurrency = TransactionUtils.getCurrency(transaction);

const rates = DistanceRequestUtils.getMileageRates(policy, false, currentRateID);

const navigateBack = () => {
Expand All @@ -61,15 +63,16 @@ function IOURequestStepDistanceRate({
const sections = Object.values(rates)
.sort((rateA, rateB) => (rateA?.rate ?? 0) - (rateB?.rate ?? 0))
.map((rate) => {
const rateForDisplay = DistanceRequestUtils.getRateForDisplay(rate.unit, rate.rate, rate.currency, translate, toLocaleDigit);
const isSelected = currentRateID ? currentRateID === rate.customUnitRateID : rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE;

const rateForDisplay = DistanceRequestUtils.getRateForDisplay(rate.unit, rate.rate, isSelected ? transactionCurrency : rate.currency, translate, toLocaleDigit);
return {
text: rate.name ?? rateForDisplay,
alternateText: rate.name ? rateForDisplay : '',
keyForList: rate.customUnitRateID,
value: rate.customUnitRateID,
isDisabled: !rate.enabled,
isSelected: currentRateID ? currentRateID === rate.customUnitRateID : rate.name === CONST.CUSTOM_UNITS.DEFAULT_RATE,
isSelected,
};
});

Expand Down Expand Up @@ -108,7 +111,7 @@ function IOURequestStepDistanceRate({
shouldShowWrapper
testID={IOURequestStepDistanceRate.displayName}
>
<Text style={[styles.mh5, styles.mv4]}>{translate('iou.chooseARate', {unit})}</Text>
<Text style={[styles.mh5, styles.mv4]}>{translate('iou.chooseARate')}</Text>

<SelectionList
sections={[{data: sections}]}
Expand Down
Loading