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

chore: move policy tax rates to policy key #36784

Merged
merged 50 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ecda0af
add taxRates propTypes to policy key
teneeto Feb 19, 2024
b5e8ed9
use policy propTypes temp_confirmation list
teneeto Feb 19, 2024
9c57826
use policy propTypes on money request confirmation list
teneeto Feb 19, 2024
b74b585
use taxRates from policy key
teneeto Feb 19, 2024
bf33e31
remove policyTaxRates props and ONYX key
teneeto Feb 19, 2024
3ca147b
use taxRates from policy key
teneeto Feb 19, 2024
8e10b1f
remove policyTaxRates props and ONYX key
teneeto Feb 19, 2024
77347eb
get taxRates with lodashGet
teneeto Feb 19, 2024
081ca79
remove unused import
teneeto Feb 19, 2024
3c26cf6
use taxRates from policy key for IOURequestStepAmount
teneeto Feb 19, 2024
1e88b6f
remove policyTaxRates props and ONYX key for IOURequestStepAmount
teneeto Feb 19, 2024
079bac4
add taxRates propTypes to policy for IOURequestStepAmount
teneeto Feb 19, 2024
2a248c3
get policy from ONYX for IOURequestStepAmount
teneeto Feb 19, 2024
614502a
remove policyTaxRates props and ONYX key for IOURequestStepTaxAmountPage
teneeto Feb 19, 2024
108fd3e
add taxRates propTypes to policy for IOURequestStepTaxAmountPage
teneeto Feb 19, 2024
697bc85
add comments for taxRates field on policy proptypes
teneeto Feb 19, 2024
b051dc4
add comments for taxRates field on policy proptypes for IOURequestSte…
teneeto Feb 19, 2024
80ce551
use taxRates from policy key for IOURequestStepTaxRatePage
teneeto Feb 19, 2024
f4deedf
remove policyTaxRates props and ONYX key for IOURequestStepTaxRatePage
teneeto Feb 19, 2024
52e15ef
add taxRates propTypes to policy for IOURequestStepTaxRatePage
teneeto Feb 19, 2024
401cdec
update policy onyx request key for IOURequestStepTaxRatePage
teneeto Feb 19, 2024
c8434b2
update policy onyx request key for IOURequestStepTaxAmountPage
teneeto Feb 19, 2024
59f6200
remove tax rates types and keys
teneeto Feb 21, 2024
a90b409
Merge branch 'main' of github.com:teneeto/Expensify into chore/36171/…
teneeto Feb 21, 2024
5b30df8
update tax Picker Prop Types
teneeto Feb 22, 2024
7c38ea8
use taxRates from policy
teneeto Feb 22, 2024
c93638a
add missing import
teneeto Feb 22, 2024
158afd9
update getFiltered options for taxRates
teneeto Feb 22, 2024
11157b7
change all policyTaxRates variables to taxRates
teneeto Feb 22, 2024
8e38637
pass taxRates as props
teneeto Feb 22, 2024
591179d
update taxPicker propTypes
teneeto Feb 22, 2024
a76c179
update taxPicker props
teneeto Feb 22, 2024
d730c2d
update more policyTaxRates to taxRates only
teneeto Feb 22, 2024
8e2eefd
add taxRates types to Policy
teneeto Feb 22, 2024
ff40828
remove policy taxRates types
teneeto Feb 22, 2024
6248765
update Policy TaxRate types
teneeto Feb 22, 2024
aaa5d57
export policy tax rates types from onyx types
teneeto Feb 22, 2024
f81d547
update OptionsListUtils TaxRate Types
teneeto Feb 22, 2024
e0dab41
update Tax Rates types
teneeto Feb 22, 2024
d3842c9
fix prettier
teneeto Feb 22, 2024
fa62bd0
update OptionListUtilsTest var names
teneeto Feb 22, 2024
6a8239a
Merge branch 'main' of github.com:teneeto/Expensify into chore/36171/…
teneeto Feb 22, 2024
7823561
add policy defaults
teneeto Feb 23, 2024
7332ede
add policy defaults
teneeto Feb 23, 2024
d6f8cb7
add comments to ONYX Props
teneeto Feb 23, 2024
ebd910a
add comments to ONYX Props
teneeto Feb 23, 2024
71be744
update comments
teneeto Feb 23, 2024
71fd0cd
update comments
teneeto Feb 23, 2024
1283b12
update comments
teneeto Feb 23, 2024
697f7e1
Merge branch 'main' of github.com:teneeto/Expensify into chore/36171/…
teneeto Feb 26, 2024
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
2 changes: 0 additions & 2 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ const ONYXKEYS = {
POLICY_CATEGORIES: 'policyCategories_',
POLICY_RECENTLY_USED_CATEGORIES: 'policyRecentlyUsedCategories_',
POLICY_TAGS: 'policyTags_',
POLICY_TAX_RATE: 'policyTaxRates_',
POLICY_RECENTLY_USED_TAGS: 'policyRecentlyUsedTags_',
POLICY_REPORT_FIELDS: 'policyReportFields_',
WORKSPACE_INVITE_MEMBERS_DRAFT: 'workspaceInviteMembersDraft_',
Expand Down Expand Up @@ -469,7 +468,6 @@ type OnyxCollectionValuesMapping = {
[ONYXKEYS.COLLECTION.SELECTED_TAB]: string;
[ONYXKEYS.COLLECTION.PRIVATE_NOTES_DRAFT]: string;
[ONYXKEYS.COLLECTION.NEXT_STEP]: OnyxTypes.ReportNextStep;
[ONYXKEYS.COLLECTION.POLICY_TAX_RATE]: string[];
};

type OnyxValuesMapping = {
Expand Down
19 changes: 8 additions & 11 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as ReceiptUtils from '@libs/ReceiptUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import {iouDefaultProps, iouPropTypes} from '@pages/iou/propTypes';
import {policyPropTypes} from '@pages/workspace/withPolicy';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -41,7 +42,6 @@ import SettlementButton from './SettlementButton';
import ShowMoreButton from './ShowMoreButton';
import Switch from './Switch';
import tagPropTypes from './tagPropTypes';
import taxPropTypes from './taxPropTypes';
import Text from './Text';
import transactionPropTypes from './transactionPropTypes';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from './withCurrentUserPersonalDetails';
Expand Down Expand Up @@ -167,8 +167,8 @@ const propTypes = {
policyTags: tagPropTypes,

/* Onyx Props */
/** Collection of tax rates attached to a policy */
policyTaxRates: taxPropTypes,
/** The policy of the report */
policy: policyPropTypes.policy,

/** Holds data related to Money Request view state, rather than the underlying Money Request data. */
iou: iouPropTypes,
Expand Down Expand Up @@ -206,7 +206,6 @@ const defaultProps = {
shouldShowSmartScanFields: true,
isPolicyExpenseChat: false,
iou: iouDefaultProps,
policyTaxRates: {},
teneeto marked this conversation as resolved.
Show resolved Hide resolved
};

function MoneyRequestConfirmationList(props) {
Expand All @@ -228,6 +227,7 @@ function MoneyRequestConfirmationList(props) {
const {unit, rate, currency} = props.mileageRate;
const distance = lodashGet(transaction, 'routes.route0.distance', 0);
const shouldCalculateDistanceAmount = props.isDistanceRequest && props.iouAmount === 0;
const taxRates = lodashGet(props.policy, 'taxRates', {});

// A flag for showing the categories field
const shouldShowCategories = props.isPolicyExpenseChat && (props.iouCategory || OptionsListUtils.hasEnabledOptions(_.values(props.policyCategories)));
Expand Down Expand Up @@ -262,8 +262,8 @@ function MoneyRequestConfirmationList(props) {
);
const formattedTaxAmount = CurrencyUtils.convertToDisplayString(props.transaction.taxAmount, props.iouCurrencyCode);

const defaultTaxKey = props.policyTaxRates.defaultExternalID;
const defaultTaxName = (defaultTaxKey && `${props.policyTaxRates.taxes[defaultTaxKey].name} (${props.policyTaxRates.taxes[defaultTaxKey].value}) • ${translate('common.default')}`) || '';
const defaultTaxKey = taxRates.defaultExternalID;
const defaultTaxName = (defaultTaxKey && `${taxRates.taxes[defaultTaxKey].name} (${taxRates.taxes[defaultTaxKey].value}) • ${translate('common.default')}`) || '';
const taxRateTitle = (props.transaction.taxRate && props.transaction.taxRate.text) || defaultTaxName;

const isFocused = useIsFocused();
Expand Down Expand Up @@ -814,7 +814,7 @@ function MoneyRequestConfirmationList(props) {
<MenuItemWithTopDescription
shouldShowRightIcon={!props.isReadOnly}
title={taxRateTitle}
description={props.policyTaxRates.name}
description={taxRates.name}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() =>
Expand All @@ -831,7 +831,7 @@ function MoneyRequestConfirmationList(props) {
<MenuItemWithTopDescription
shouldShowRightIcon={!props.isReadOnly}
title={formattedTaxAmount}
description={props.policyTaxRates.name}
description={taxRates.name}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() =>
Expand Down Expand Up @@ -886,9 +886,6 @@ export default compose(
policy: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
},
policyTaxRates: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAX_RATE}${policyID}`,
},
iou: {
key: ONYXKEYS.IOU,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import * as ReceiptUtils from '@libs/ReceiptUtils';
import * as ReportUtils from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
import * as TransactionUtils from '@libs/TransactionUtils';
import {policyPropTypes} from '@pages/workspace/withPolicy';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -41,7 +42,6 @@ import ReceiptEmptyState from './ReceiptEmptyState';
import SettlementButton from './SettlementButton';
import Switch from './Switch';
import tagPropTypes from './tagPropTypes';
import taxPropTypes from './taxPropTypes';
import Text from './Text';
import transactionPropTypes from './transactionPropTypes';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from './withCurrentUserPersonalDetails';
Expand Down Expand Up @@ -161,8 +161,8 @@ const propTypes = {
policyTags: tagPropTypes,

/* Onyx Props */
/** Collection of tax rates attached to a policy */
policyTaxRates: taxPropTypes,
/** The policy of the report */
policy: policyPropTypes.policy,

/** Transaction that represents the money request */
transaction: transactionPropTypes,
Expand Down Expand Up @@ -197,7 +197,6 @@ const defaultProps = {
isDistanceRequest: false,
shouldShowSmartScanFields: true,
isPolicyExpenseChat: false,
policyTaxRates: {},
teneeto marked this conversation as resolved.
Show resolved Hide resolved
};

function MoneyTemporaryForRefactorRequestConfirmationList({
Expand Down Expand Up @@ -238,7 +237,6 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
session: {accountID},
shouldShowSmartScanFields,
transaction,
policyTaxRates,
}) {
const theme = useTheme();
const styles = useThemeStyles();
Expand All @@ -252,6 +250,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
const {unit, rate, currency} = mileageRate;
const distance = lodashGet(transaction, 'routes.route0.distance', 0);
const shouldCalculateDistanceAmount = isDistanceRequest && iouAmount === 0;
const taxRates = lodashGet(policy, 'taxRates', {});

// A flag for showing the categories field
const shouldShowCategories = isPolicyExpenseChat && (iouCategory || OptionsListUtils.hasEnabledOptions(_.values(policyCategories)));
Expand Down Expand Up @@ -286,8 +285,8 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
);
const formattedTaxAmount = CurrencyUtils.convertToDisplayString(transaction.taxAmount, iouCurrencyCode);

const defaultTaxKey = policyTaxRates.defaultExternalID;
const defaultTaxName = (defaultTaxKey && `${policyTaxRates.taxes[defaultTaxKey].name} (${policyTaxRates.taxes[defaultTaxKey].value}) • ${translate('common.default')}`) || '';
const defaultTaxKey = taxRates.defaultExternalID;
const defaultTaxName = (defaultTaxKey && `${taxRates.taxes[defaultTaxKey].name} (${taxRates.taxes[defaultTaxKey].value}) • ${translate('common.default')}`) || '';
Comment on lines +289 to +290
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we ignore here the foreignTaxDefault value?

const taxRateTitle = (transaction.taxRate && transaction.taxRate.text) || defaultTaxName;

const isFocused = useIsFocused();
Expand Down Expand Up @@ -783,10 +782,10 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
{
item: (
<MenuItemWithTopDescription
key={`${policyTaxRates.name}${taxRateTitle}`}
key={`${taxRates.name}${taxRateTitle}`}
shouldShowRightIcon={!isReadOnly}
title={taxRateTitle}
description={policyTaxRates.name}
description={taxRates.name}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_TAX_RATE.getRoute(iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams()))}
Expand All @@ -800,10 +799,10 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
{
item: (
<MenuItemWithTopDescription
key={`${policyTaxRates.name}${formattedTaxAmount}`}
key={`${taxRates.name}${formattedTaxAmount}`}
shouldShowRightIcon={!isReadOnly}
title={formattedTaxAmount}
description={policyTaxRates.name}
description={taxRates.name}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams()))}
Expand Down Expand Up @@ -932,8 +931,5 @@ export default compose(
policy: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
},
policyTaxRates: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAX_RATE}${policyID}`,
},
}),
)(MoneyTemporaryForRefactorRequestConfirmationList);
15 changes: 5 additions & 10 deletions src/pages/iou/request/step/IOURequestStepAmount.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ const propTypes = {
/** The transaction object being modified in Onyx */
transaction: transactionPropTypes,

/* Onyx Props */
/** Collection of tax rates attached to a policy */
policyTaxRates: taxPropTypes,

/** The policy of the report */
policy: PropTypes.shape({
/**
Expand All @@ -51,13 +47,15 @@ const propTypes = {
tax: PropTypes.shape({
trackingEnabled: PropTypes.bool,
}),

/** Collection of tax rates attached to a policy */
taxRates: taxPropTypes,
}),
};

const defaultProps = {
report: {},
transaction: {},
policyTaxRates: {},
policy: {},
};

Expand All @@ -73,7 +71,6 @@ function IOURequestStepAmount({
},
transaction,
transaction: {currency},
policyTaxRates,
policy,
}) {
const {translate} = useLocalize();
Expand All @@ -83,6 +80,7 @@ function IOURequestStepAmount({
const originalCurrency = useRef(null);
const iouRequestType = getRequestType(transaction);

const taxRates = lodashGet(policy, 'taxRates', {});
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report));
const isTaxTrackingEnabled = isPolicyExpenseChat && lodashGet(policy, 'tax.trackingEnabled', policy.isTaxTrackingEnabled);

Expand Down Expand Up @@ -130,7 +128,7 @@ function IOURequestStepAmount({
const amountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(Number.parseFloat(amount));

if ((iouRequestType === CONST.IOU.REQUEST_TYPE.MANUAL || backTo) && isTaxTrackingEnabled) {
const taxAmount = getTaxAmount(transaction, policyTaxRates.defaultValue, amountInSmallestCurrencyUnits);
const taxAmount = getTaxAmount(transaction, taxRates.defaultValue, amountInSmallestCurrencyUnits);
const taxAmountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(Number.parseFloat(taxAmount));
IOU.setMoneyRequestTaxAmount(transaction.transactionID, taxAmountInSmallestCurrencyUnits);
}
Expand Down Expand Up @@ -185,9 +183,6 @@ export default compose(
withWritableReportOrNotFound,
withFullTransactionOrNotFound,
withOnyx({
policyTaxRates: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAX_RATE}${report ? report.policyID : '0'}`,
},
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`,
},
Expand Down
21 changes: 13 additions & 8 deletions src/pages/iou/request/step/IOURequestStepTaxAmountPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {useFocusEffect} from '@react-navigation/native';
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useCallback, useEffect, useRef} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -35,15 +37,17 @@ const propTypes = {
/** The transaction object being modified in Onyx */
transaction: transactionPropTypes,

/* Onyx Props */
teneeto marked this conversation as resolved.
Show resolved Hide resolved
/** Collection of tax rates attached to a policy */
policyTaxRates: taxPropTypes,
/** The policy of the report */
policy: PropTypes.shape({
/** Collection of tax rates attached to a policy */
taxRates: taxPropTypes,
}),
};

const defaultProps = {
report: {},
transaction: {},
policyTaxRates: {},
policy: {},
};

const getTaxAmount = (transaction, defaultTaxValue) => {
Expand All @@ -58,7 +62,7 @@ function IOURequestStepTaxAmountPage({
transaction,
transaction: {currency},
report,
policyTaxRates,
policy,
}) {
const {translate} = useLocalize();
const styles = useThemeStyles();
Expand All @@ -69,6 +73,7 @@ function IOURequestStepTaxAmountPage({

const isSaveButtonPressed = useRef(false);
const originalCurrency = useRef(null);
const taxRates = lodashGet(policy, 'taxRates', {});

useEffect(() => {
if (transaction.originalCurrency) {
Expand Down Expand Up @@ -140,7 +145,7 @@ function IOURequestStepTaxAmountPage({
isEditing={isEditing}
currency={currency}
amount={transaction.taxAmount}
taxAmount={getTaxAmount(transaction, policyTaxRates.defaultValue)}
taxAmount={getTaxAmount(transaction, taxRates.defaultValue)}
transaction={transaction}
ref={(e) => (textInput.current = e)}
onCurrencyButtonPress={navigateToCurrencySelectionPage}
Expand Down Expand Up @@ -177,8 +182,8 @@ export default compose(
withWritableReportOrNotFound,
withFullTransactionOrNotFound,
withOnyx({
policyTaxRates: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAX_RATE}${report ? report.policyID : '0'}`,
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`,
},
}),
)(IOURequestStepTaxAmountPage);
Loading
Loading