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

Apply tax rule when selecting category #53332

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b4c8b46
apply tax rule when selecting category
bernhardoj Nov 30, 2024
622fe8b
remove log
bernhardoj Nov 30, 2024
438ad04
lint
bernhardoj Nov 30, 2024
cd23f5f
Merge branch 'main' into fix/53220-apply-tax-rule-for-category
bernhardoj Dec 4, 2024
4f4a302
fix tax amount is negative
bernhardoj Dec 6, 2024
e5634e0
prettier
bernhardoj Dec 6, 2024
fcafe6a
Merge branch 'main' into fix/53220-apply-tax-rule-for-category
bernhardoj Dec 6, 2024
4bce5ff
Merge branch 'main' into fix/53220-apply-tax-rule-for-category
bernhardoj Dec 12, 2024
f4e043d
update the tax when updating the category
bernhardoj Dec 13, 2024
7f8defc
added test
bernhardoj Dec 13, 2024
46746ba
Merge branch 'main' into fix/53220-apply-tax-rule-for-category
bernhardoj Dec 13, 2024
d0f9f65
remove unused import
bernhardoj Dec 13, 2024
91ac31c
simplify code
bernhardoj Dec 13, 2024
d407a92
uncomment
bernhardoj Dec 13, 2024
c1eb97d
lint
bernhardoj Dec 13, 2024
e56425d
Merge branch 'main' into fix/53220-apply-tax-rule-for-category
bernhardoj Dec 17, 2024
e61e858
update comment
bernhardoj Dec 17, 2024
7ab89a2
Merge branch 'main' into fix/53220-apply-tax-rule-for-category
bernhardoj Dec 17, 2024
ba14c49
lint
bernhardoj Dec 17, 2024
8d98c50
more lint
bernhardoj Dec 17, 2024
7cec392
more lint
bernhardoj Dec 17, 2024
2c2e070
more lint
bernhardoj Dec 17, 2024
d39b47b
fix type
bernhardoj Dec 17, 2024
07d9ef8
more lint
bernhardoj Dec 17, 2024
5df0ed9
Merge branch 'main' into fix/53220-apply-tax-rule-for-category
bernhardoj Dec 19, 2024
4de5bae
prettier
bernhardoj Dec 19, 2024
1e1031f
Merge branch 'main' into fix/53220-apply-tax-rule-for-category
bernhardoj Dec 19, 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
8 changes: 8 additions & 0 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3296,13 +3296,21 @@ function updateMoneyRequestCategory(
transactionID: string,
transactionThreadReportID: string,
category: string,
categoryTaxCode: string | undefined,
categoryTaxAmount: number | undefined,
policy: OnyxEntry<OnyxTypes.Policy>,
policyTagList: OnyxEntry<OnyxTypes.PolicyTagLists>,
policyCategories: OnyxEntry<OnyxTypes.PolicyCategories>,
) {
const transactionChanges: TransactionChanges = {
category,
};

if (categoryTaxCode && categoryTaxAmount !== undefined) {
transactionChanges.taxCode = categoryTaxCode;
transactionChanges.taxAmount = categoryTaxAmount;
}

const {params, onyxData} = getUpdateMoneyRequestParams(transactionID, transactionThreadReportID, transactionChanges, policy, policyTagList, policyCategories);
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_CATEGORY, params, onyxData);
}
Expand Down
32 changes: 29 additions & 3 deletions src/pages/iou/request/step/IOURequestStepCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as CategoryUtils from '@libs/CategoryUtils';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
Expand Down Expand Up @@ -68,7 +70,8 @@ function IOURequestStepCategory({
const {translate} = useLocalize();
const isEditing = action === CONST.IOU.ACTION.EDIT;
const isEditingSplitBill = isEditing && iouType === CONST.IOU.TYPE.SPLIT;
const transactionCategory = ReportUtils.getTransactionDetails(isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? splitDraftTransaction : transaction)?.category;
const currentTransaction = isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? splitDraftTransaction : transaction;
const transactionCategory = ReportUtils.getTransactionDetails(currentTransaction)?.category;

// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const reportAction = reportActions?.[report?.parentReportActionID || reportActionID] ?? null;
Expand Down Expand Up @@ -109,24 +112,47 @@ function IOURequestStepCategory({
const categorySearchText = category.searchText ?? '';
const isSelectedCategory = categorySearchText === transactionCategory;
const updatedCategory = isSelectedCategory ? '' : categorySearchText;
const categoryTaxCode = CategoryUtils.getCategoryDefaultTaxRate(policy?.rules?.expenseRules ?? [], updatedCategory, policy?.taxRates?.defaultExternalID);
let categoryTaxPercentage;
let categoryTaxAmount;

if (categoryTaxCode) {
categoryTaxPercentage = TransactionUtils.getTaxValue(policy, currentTransaction, categoryTaxCode);

if (categoryTaxPercentage) {
categoryTaxAmount = CurrencyUtils.convertToBackendAmount(
TransactionUtils.calculateTaxAmount(categoryTaxPercentage, TransactionUtils.getAmount(currentTransaction), TransactionUtils.getCurrency(transaction)),
);
}
}

if (transaction) {
// In the split flow, when editing we use SPLIT_TRANSACTION_DRAFT to save draft value
if (isEditingSplitBill) {
IOU.setDraftSplitTransaction(transaction.transactionID, {category: updatedCategory});
const transactionChanges: TransactionUtils.TransactionChanges = {category: updatedCategory};
if (categoryTaxCode && categoryTaxAmount !== undefined) {
transactionChanges.taxCode = categoryTaxCode;
transactionChanges.taxAmount = categoryTaxAmount;
}
IOU.setDraftSplitTransaction(transaction.transactionID, transactionChanges);
navigateBack();
return;
}

if (isEditing && report) {
IOU.updateMoneyRequestCategory(transaction.transactionID, report.reportID, updatedCategory, policy, policyTags, policyCategories);
IOU.updateMoneyRequestCategory(transaction.transactionID, report.reportID, updatedCategory, categoryTaxCode, categoryTaxAmount, policy, policyTags, policyCategories);
navigateBack();
return;
}
}

IOU.setMoneyRequestCategory(transactionID, updatedCategory);

if (categoryTaxCode && categoryTaxAmount !== undefined) {
IOU.setMoneyRequestTaxRate(transactionID, categoryTaxCode);
IOU.setMoneyRequestTaxAmount(transactionID, categoryTaxAmount);
}

if (action === CONST.IOU.ACTION.CATEGORIZE) {
Navigation.closeAndNavigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, iouType, transactionID, report?.reportID ?? '-1'));
return;
Expand Down
Loading