Skip to content

Commit

Permalink
Merge pull request #48105 from etCoderDysto/default-label
Browse files Browse the repository at this point in the history
fix: "Default" label changes to "Workspace currency default" after changing tax code
  • Loading branch information
puneetlath authored Aug 28, 2024
2 parents 5356ff8 + 20b446e commit 920edc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/libs/actions/TaxRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,17 @@ function renamePolicyTax(policyID: string, taxID: string, newName: string) {
function setPolicyTaxCode(policyID: string, oldTaxCode: string, newTaxCode: string) {
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
const originalTaxRate = {...policy?.taxRates?.taxes[oldTaxCode]};
const oldDefaultExternalID = policy?.taxRates?.defaultExternalID;
const oldForeignTaxDefault = policy?.taxRates?.foreignTaxDefault;
const onyxData: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
taxRates: {
defaultExternalID: oldTaxCode === policy?.taxRates?.defaultExternalID ? newTaxCode : policy?.taxRates?.defaultExternalID,
defaultExternalID: oldTaxCode === oldDefaultExternalID ? newTaxCode : oldDefaultExternalID,
foreignTaxDefault: oldTaxCode === oldForeignTaxDefault ? newTaxCode : oldForeignTaxDefault,
taxes: {
[oldTaxCode]: null,
[newTaxCode]: {
Expand All @@ -514,7 +517,8 @@ function setPolicyTaxCode(policyID: string, oldTaxCode: string, newTaxCode: stri
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
taxRates: {
defaultExternalID: oldTaxCode === policy?.taxRates?.defaultExternalID ? newTaxCode : policy?.taxRates?.defaultExternalID,
defaultExternalID: oldTaxCode === oldDefaultExternalID ? newTaxCode : oldDefaultExternalID,
foreignTaxDefault: oldTaxCode === oldForeignTaxDefault ? newTaxCode : oldForeignTaxDefault,
taxes: {
[oldTaxCode]: null,
[newTaxCode]: {
Expand All @@ -535,7 +539,8 @@ function setPolicyTaxCode(policyID: string, oldTaxCode: string, newTaxCode: stri
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
taxRates: {
defaultExternalID: policy?.taxRates?.defaultExternalID,
defaultExternalID: oldDefaultExternalID,
foreignTaxDefault: oldForeignTaxDefault,
taxes: {
[newTaxCode]: null,
[oldTaxCode]: {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/taxes/WorkspaceEditTaxPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function WorkspaceEditTaxPage({
const currentTaxID = PolicyUtils.getCurrentTaxID(policy, taxID);
const currentTaxRate = currentTaxID && policy?.taxRates?.taxes?.[currentTaxID];
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
const canEditTaxRate = policy && PolicyUtils.canEditTaxRate(policy, taxID);
const canEditTaxRate = policy && PolicyUtils.canEditTaxRate(policy, currentTaxID ?? taxID);
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);

const shouldShowDeleteMenuItem = canEditTaxRate && !hasAccountingConnections;
Expand Down

0 comments on commit 920edc8

Please sign in to comment.