Skip to content

Commit

Permalink
Merge pull request #40307 from Expensify/neil-TransactionCustomUnit
Browse files Browse the repository at this point in the history
Get distance from transaction vs route
  • Loading branch information
luacmartins authored Apr 30, 2024
2 parents 942c851 + 2859ec2 commit e138a59
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function MoneyRequestConfirmationList({

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

const distance = transaction?.routes?.route0?.distance ?? 0;
const distance = TransactionUtils.getDistance(transaction);
const taxRates = policy?.taxRates ?? null;

// A flag for showing the categories field
Expand Down
6 changes: 3 additions & 3 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ function MoneyRequestView({

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

const mileageRate = TransactionUtils.isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(currency) : distanceRates[rateID as string] ?? {};
const mileageRate = TransactionUtils.isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(currency) : distanceRates[rateID] ?? {};
const {unit} = mileageRate;
const rate = (transaction?.comment?.customUnit?.defaultP2PRate as number) ?? mileageRate.rate;
const rate = transaction?.comment?.customUnit?.defaultP2PRate ?? mileageRate.rate;

const distance = DistanceRequestUtils.convertToDistanceInMeters((transaction?.comment?.customUnit?.quantity as number) ?? 0, unit);
const distance = DistanceRequestUtils.convertToDistanceInMeters(TransactionUtils.getDistance(transaction), unit);
const rateToDisplay = DistanceRequestUtils.getRateForDisplay(unit, rate, currency, translate, toLocaleDigit, isOffline);
const distanceToDisplay = DistanceRequestUtils.getDistanceForDisplay(hasRoute, distance, unit, rate, translate);
let merchantTitle = isEmptyMerchant ? '' : transactionMerchant;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ function getMerchant(transaction: OnyxEntry<Transaction>): string {
return transaction?.modifiedMerchant ? transaction.modifiedMerchant : transaction?.merchant ?? '';
}

function getDistance(transaction: Transaction): number {
return transaction?.routes?.route0?.distance ?? 0;
function getDistance(transaction: Transaction | null): number {
return transaction?.comment?.customUnit?.quantity ?? 0;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/types/onyx/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,20 @@ type Comment = {
waypoints?: WaypointCollection;
isLoading?: boolean;
type?: string;
customUnit?: Record<string, unknown>;
customUnit?: TransactionCustomUnit;
source?: string;
originalTransactionID?: string;
splits?: Split[];
};

type TransactionCustomUnit = {
customUnitID?: string;
customUnitRateID?: string;
quantity?: number;
name?: string;
defaultP2PRate?: number;
};

type GeometryType = 'LineString';

type Geometry = {
Expand Down

0 comments on commit e138a59

Please sign in to comment.