diff --git a/src/languages/de.ts b/src/languages/de.ts index ed73747e2649..210bdf560c2b 100644 --- a/src/languages/de.ts +++ b/src/languages/de.ts @@ -17,6 +17,8 @@ import dedent from '@libs/StringUtils/dedent'; import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; +import {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; +import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { ChangeFieldParams, @@ -1487,6 +1489,32 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Beheben Sie den Fehler beim Entfernungssatz und versuchen Sie es erneut.', AskToExplain: `. Erklären ✨`, + policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { + const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); + const fragments = entries.map(([key, value], i) => { + const isFirst = i === 0; + if (key === 'reimbursable') { + return value ? 'hat die Ausgabe als „erstattungsfähig“ markiert' : 'hat die Ausgabe als „nicht erstattungsfähig“ markiert'; + } + if (key === 'billable') { + return value ? 'hat die Ausgabe als „verrechenbar“ markiert' : 'hat die Ausgabe als „nicht abrechenbar“ markiert'; + } + if (key === 'tax') { + const taxEntry = value as PolicyRulesModifiedFields['tax']; + const taxRateName = taxEntry?.field_id_TAX.name ?? ''; + if (isFirst) { + return `Steuersatz auf „${taxRateName}“ festlegen`; + } + return `Steuersatz zu „${taxRateName}“`; + } + const updatedValue = value as string | boolean; + if (isFirst) { + return `Setzen Sie ${translations.common[key].toLowerCase()} auf „${updatedValue}“`; + } + return `${translations.common[key].toLowerCase()} zu "${updatedValue}"`; + }); + return `${formatList(fragments)} über Workspace-Regeln`; + }, }, transactionMerge: { listPage: { diff --git a/src/languages/en.ts b/src/languages/en.ts index f724200f67cd..8c83f1522cc6 100644 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -6,6 +6,8 @@ import dedent from '@libs/StringUtils/dedent'; import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; +import type {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; +import ObjectUtils from '@src/types/utils/ObjectUtils'; import type { ChangeFieldParams, ConnectionNameParams, @@ -1471,6 +1473,39 @@ const translations = { }, correctDistanceRateError: 'Fix the distance rate error and try again.', AskToExplain: `. Explain ✨`, + policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { + const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); + + const fragments = entries.map(([key, value], i) => { + const isFirst = i === 0; + + if (key === 'reimbursable') { + return value ? 'marked the expense as "reimbursable"' : 'marked the expense as "non-reimbursable"'; + } + + if (key === 'billable') { + return value ? 'marked the expense as "billable"' : 'marked the expense as "non-billable"'; + } + + if (key === 'tax') { + const taxEntry = value as PolicyRulesModifiedFields['tax']; + const taxRateName = taxEntry?.field_id_TAX.name ?? ''; + if (isFirst) { + return `set the tax rate to "${taxRateName}"`; + } + return `tax rate to "${taxRateName}"`; + } + + const updatedValue = value as string | boolean; + if (isFirst) { + return `set the ${translations.common[key].toLowerCase()} to "${updatedValue}"`; + } + + return `${translations.common[key].toLowerCase()} to "${updatedValue}"`; + }); + + return `${formatList(fragments)} via workspace rules`; + }, }, transactionMerge: { listPage: { diff --git a/src/languages/es.ts b/src/languages/es.ts index a2d73c055d3f..38d5ce66965a 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1,6 +1,8 @@ import {CONST as COMMON_CONST} from 'expensify-common'; import dedent from '@libs/StringUtils/dedent'; import CONST from '@src/CONST'; +import type {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; +import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type {CreatedReportForUnapprovedTransactionsParams, PaidElsewhereParams, RoutedDueToDEWParams, SplitDateRangeParams, ViolationsRterParams} from './params'; import type {TranslationDeepObject} from './types'; @@ -1216,6 +1218,39 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Corrige el error de la tasa de distancia y vuelve a intentarlo.', AskToExplain: `. Explicar ✨`, + policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { + const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); + + const fragments = entries.map(([key, value], i) => { + const isFirst = i === 0; + + if (key === 'reimbursable') { + return value ? 'marcó el gasto como "reembolsable"' : 'marcó el gasto como "no reembolsable"'; + } + + if (key === 'billable') { + return value ? 'marcó el gasto como "facturable"' : 'marcó el gasto como "no facturable"'; + } + + if (key === 'tax') { + const taxEntry = value as PolicyRulesModifiedFields['tax']; + const taxRateName = taxEntry?.field_id_TAX.name ?? ''; + if (isFirst) { + return `estableció la tasa de impuesto a "${taxRateName}"`; + } + return `tasa de impuesto a "${taxRateName}"`; + } + + const updatedValue = value as string | boolean; + if (isFirst) { + return `estableció el ${translations.common[key].toLowerCase()} a "${updatedValue}"`; + } + + return `${translations.common[key].toLowerCase()} a "${updatedValue}"`; + }); + + return `${formatList(fragments)} a través de reglas del espacio de trabajo`; + }, }, transactionMerge: { listPage: { diff --git a/src/languages/fr.ts b/src/languages/fr.ts index bc59f040587d..ce2a017085c5 100644 --- a/src/languages/fr.ts +++ b/src/languages/fr.ts @@ -17,6 +17,8 @@ import dedent from '@libs/StringUtils/dedent'; import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; +import {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; +import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { ChangeFieldParams, @@ -1490,6 +1492,32 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Corrigez l’erreur de taux de distance et réessayez.', AskToExplain: `. Expliquer ✨`, + policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { + const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); + const fragments = entries.map(([key, value], i) => { + const isFirst = i === 0; + if (key === 'reimbursable') { + return value ? 'a marqué la dépense comme « remboursable »' : 'a marqué la dépense comme « non remboursable »'; + } + if (key === 'billable') { + return value ? 'a marqué la dépense comme « facturable »' : 'a marqué la dépense comme « non refacturable »'; + } + if (key === 'tax') { + const taxEntry = value as PolicyRulesModifiedFields['tax']; + const taxRateName = taxEntry?.field_id_TAX.name ?? ''; + if (isFirst) { + return `définir le taux de taxe sur « ${taxRateName} »`; + } + return `taux de taxe vers « ${taxRateName} »`; + } + const updatedValue = value as string | boolean; + if (isFirst) { + return `définir ${translations.common[key].toLowerCase()} sur « ${updatedValue} »`; + } + return `${translations.common[key].toLowerCase()} à « ${updatedValue} »`; + }); + return `${formatList(fragments)} via les règles de l’espace de travail`; + }, }, transactionMerge: { listPage: { diff --git a/src/languages/it.ts b/src/languages/it.ts index 4c28dfb3d207..2b1287034056 100644 --- a/src/languages/it.ts +++ b/src/languages/it.ts @@ -17,6 +17,8 @@ import dedent from '@libs/StringUtils/dedent'; import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; +import {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; +import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { ChangeFieldParams, @@ -1484,6 +1486,32 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: "Correggi l'errore nella tariffa della distanza e riprova.", AskToExplain: `. Spiega ✨`, + policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { + const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); + const fragments = entries.map(([key, value], i) => { + const isFirst = i === 0; + if (key === 'reimbursable') { + return value ? 'ha contrassegnato la spesa come "rimborsabile"' : 'ha contrassegnato la spesa come "non rimborsabile"'; + } + if (key === 'billable') { + return value ? 'ha contrassegnato la spesa come "fatturabile"' : 'ha contrassegnato la spesa come "non addebitabile"'; + } + if (key === 'tax') { + const taxEntry = value as PolicyRulesModifiedFields['tax']; + const taxRateName = taxEntry?.field_id_TAX.name ?? ''; + if (isFirst) { + return `imposta l'aliquota fiscale su "${taxRateName}"`; + } + return `aliquota fiscale in "${taxRateName}"`; + } + const updatedValue = value as string | boolean; + if (isFirst) { + return `imposta ${translations.common[key].toLowerCase()} su "${updatedValue}"`; + } + return `${translations.common[key].toLowerCase()} a "${updatedValue}"`; + }); + return `${formatList(fragments)} tramite regole dello spazio di lavoro`; + }, }, transactionMerge: { listPage: { diff --git a/src/languages/ja.ts b/src/languages/ja.ts index 799872b3e035..ce78c3efd6b0 100644 --- a/src/languages/ja.ts +++ b/src/languages/ja.ts @@ -17,6 +17,8 @@ import dedent from '@libs/StringUtils/dedent'; import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; +import {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; +import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { ChangeFieldParams, @@ -1482,6 +1484,32 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: '距離レートのエラーを修正して、もう一度お試しください。', AskToExplain: `. 説明する ✨`, + policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { + const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); + const fragments = entries.map(([key, value], i) => { + const isFirst = i === 0; + if (key === 'reimbursable') { + return value ? '経費を「立替精算対象」にマークしました' : '経費を「非精算」としてマークしました'; + } + if (key === 'billable') { + return value ? '経費を「請求可能」とマークしました' : '経費を「請求対象外」としてマークしました'; + } + if (key === 'tax') { + const taxEntry = value as PolicyRulesModifiedFields['tax']; + const taxRateName = taxEntry?.field_id_TAX.name ?? ''; + if (isFirst) { + return `税率を「${taxRateName}」に設定`; + } + return `税率を「${taxRateName}」に`; + } + const updatedValue = value as string | boolean; + if (isFirst) { + return `${translations.common[key].toLowerCase()} を「${updatedValue}」に設定`; + } + return `${translations.common[key].toLowerCase()} を「${updatedValue}」に`; + }); + return `${formatList(fragments)}(ワークスペースルール経由)`; + }, }, transactionMerge: { listPage: { diff --git a/src/languages/nl.ts b/src/languages/nl.ts index d86ae80b8bd5..3623ef427af9 100644 --- a/src/languages/nl.ts +++ b/src/languages/nl.ts @@ -17,6 +17,8 @@ import dedent from '@libs/StringUtils/dedent'; import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; +import {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; +import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { ChangeFieldParams, @@ -1483,6 +1485,32 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Los het foutieve kilometertarief op en probeer het opnieuw.', AskToExplain: `. Uitleggen ✨`, + policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { + const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); + const fragments = entries.map(([key, value], i) => { + const isFirst = i === 0; + if (key === 'reimbursable') { + return value ? 'heeft de uitgave als „vergoedbaar” gemarkeerd' : 'markeerde de uitgave als ‘niet-terugbetaalbaar’'; + } + if (key === 'billable') { + return value ? 'heeft de uitgave gemarkeerd als ‘factureerbaar’' : 'heeft de uitgave als ‘niet-declarabel’ gemarkeerd'; + } + if (key === 'tax') { + const taxEntry = value as PolicyRulesModifiedFields['tax']; + const taxRateName = taxEntry?.field_id_TAX.name ?? ''; + if (isFirst) { + return `stel het belastingtarief in op "${taxRateName}"`; + } + return `belastingtarief naar "${taxRateName}"`; + } + const updatedValue = value as string | boolean; + if (isFirst) { + return `stel de ${translations.common[key].toLowerCase()} in op "${updatedValue}"`; + } + return `${translations.common[key].toLowerCase()} naar "${updatedValue}"`; + }); + return `${formatList(fragments)} via werkruimteregels`; + }, }, transactionMerge: { listPage: { diff --git a/src/languages/pl.ts b/src/languages/pl.ts index ad343fba20a7..2158f487d648 100644 --- a/src/languages/pl.ts +++ b/src/languages/pl.ts @@ -17,6 +17,8 @@ import dedent from '@libs/StringUtils/dedent'; import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; +import {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; +import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { ChangeFieldParams, @@ -1482,6 +1484,32 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Napraw błąd stawki za dystans i spróbuj ponownie.', AskToExplain: `. Wyjaśnij ✨`, + policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { + const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); + const fragments = entries.map(([key, value], i) => { + const isFirst = i === 0; + if (key === 'reimbursable') { + return value ? 'oznaczył wydatek jako „podlegający zwrotowi”' : 'oznaczył wydatek jako „niepodlegający zwrotowi”'; + } + if (key === 'billable') { + return value ? 'oznaczył wydatek jako „refakturowalny”' : 'oznaczył wydatek jako „niepodlegający refakturowaniu”'; + } + if (key === 'tax') { + const taxEntry = value as PolicyRulesModifiedFields['tax']; + const taxRateName = taxEntry?.field_id_TAX.name ?? ''; + if (isFirst) { + return `ustaw stawkę podatku na „${taxRateName}”`; + } + return `stawka podatku na „${taxRateName}”`; + } + const updatedValue = value as string | boolean; + if (isFirst) { + return `ustaw ${translations.common[key].toLowerCase()} na „${updatedValue}”`; + } + return `${translations.common[key].toLowerCase()} na „${updatedValue}”`; + }); + return `${formatList(fragments)} przez zasady przestrzeni roboczej`; + }, }, transactionMerge: { listPage: { diff --git a/src/languages/pt-BR.ts b/src/languages/pt-BR.ts index 28391858cf31..5097a2b63243 100644 --- a/src/languages/pt-BR.ts +++ b/src/languages/pt-BR.ts @@ -17,6 +17,8 @@ import dedent from '@libs/StringUtils/dedent'; import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; +import {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; +import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { ChangeFieldParams, @@ -1480,6 +1482,32 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Corrija o erro na taxa de distância e tente novamente.', AskToExplain: `. Explicar ✨`, + policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { + const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); + const fragments = entries.map(([key, value], i) => { + const isFirst = i === 0; + if (key === 'reimbursable') { + return value ? 'marcou a despesa como "reembolsável"' : 'marcou a despesa como “não reembolsável”'; + } + if (key === 'billable') { + return value ? 'marcou a despesa como “faturável”' : 'marcou a despesa como "não faturável"'; + } + if (key === 'tax') { + const taxEntry = value as PolicyRulesModifiedFields['tax']; + const taxRateName = taxEntry?.field_id_TAX.name ?? ''; + if (isFirst) { + return `definir a taxa de imposto como "${taxRateName}"`; + } + return `alíquota de imposto para "${taxRateName}"`; + } + const updatedValue = value as string | boolean; + if (isFirst) { + return `defina o ${translations.common[key].toLowerCase()} como "${updatedValue}"`; + } + return `${translations.common[key].toLowerCase()} para "${updatedValue}"`; + }); + return `${formatList(fragments)} via regras do workspace`; + }, }, transactionMerge: { listPage: { diff --git a/src/languages/zh-hans.ts b/src/languages/zh-hans.ts index 68624fc409d0..d18cad801497 100644 --- a/src/languages/zh-hans.ts +++ b/src/languages/zh-hans.ts @@ -17,6 +17,8 @@ import dedent from '@libs/StringUtils/dedent'; import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; +import {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; +import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { ChangeFieldParams, @@ -1459,6 +1461,32 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: '修复里程费率错误后请重试。', AskToExplain: `. 解释 ✨`, + policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { + const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); + const fragments = entries.map(([key, value], i) => { + const isFirst = i === 0; + if (key === 'reimbursable') { + return value ? '将该报销单标记为“可报销”' : '将该报销单标记为“不可报销”'; + } + if (key === 'billable') { + return value ? '将该报销标记为“可向客户收费”' : '已将该报销标记为“不可计费”'; + } + if (key === 'tax') { + const taxEntry = value as PolicyRulesModifiedFields['tax']; + const taxRateName = taxEntry?.field_id_TAX.name ?? ''; + if (isFirst) { + return `将税率设置为“${taxRateName}”`; + } + return `税率为“${taxRateName}”`; + } + const updatedValue = value as string | boolean; + if (isFirst) { + return `将 ${translations.common[key].toLowerCase()} 设置为 “${updatedValue}”`; + } + return `${translations.common[key].toLowerCase()} 为 “${updatedValue}”`; + }); + return `${formatList(fragments)} 通过工作区规则`; + }, }, transactionMerge: { listPage: { diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 4df78d4fa146..c23c05bbc2b4 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -12,7 +12,7 @@ import {convertToDisplayString} from './CurrencyUtils'; import DateUtils from './DateUtils'; import {getEnvironmentURL} from './Environment/Environment'; // eslint-disable-next-line @typescript-eslint/no-deprecated -import {translateLocal} from './Localize'; +import {formatList, translateLocal} from './Localize'; import Log from './Log'; import Parser from './Parser'; import {getPersonalDetailByEmail} from './PersonalDetailsUtils'; @@ -469,6 +469,18 @@ function getForReportAction({ buildMessageFragmentForValue(translateLocal, oldAttendees, attendees, translateLocal('iou.attendees'), false, setFragments, removalFragments, changeFragments); } + const hasPolicyRulesModifiedFields = isReportActionOriginalMessageAnObject && 'policyRulesModifiedFields' in reportActionOriginalMessage && 'policyID' in reportActionOriginalMessage; + if (hasPolicyRulesModifiedFields) { + const rulePolicyID = reportActionOriginalMessage.policyID; + const policyRulesModifiedFields = reportActionOriginalMessage.policyRulesModifiedFields; + + if (policyRulesModifiedFields && rulePolicyID) { + const policyRulesRoute = `${environmentURL}/${ROUTES.WORKSPACE_RULES.getRoute(rulePolicyID)}`; + // eslint-disable-next-line @typescript-eslint/no-deprecated + return translateLocal('iou.policyRulesModifiedFields', policyRulesModifiedFields, policyRulesRoute, formatList); + } + } + const message = // eslint-disable-next-line @typescript-eslint/no-deprecated getMessageLine(translateLocal, `\n${translateLocal('iou.changed')}`, changeFragments) + @@ -713,10 +725,21 @@ function getForReportActionTemp({ buildMessageFragmentForValue(translate, oldAttendees, attendees, translate('iou.attendees'), false, setFragments, removalFragments, changeFragments); } + const hasPolicyRulesModifiedFields = isReportActionOriginalMessageAnObject && 'policyRulesModifiedFields' in reportActionOriginalMessage && 'policyID' in reportActionOriginalMessage; + if (hasPolicyRulesModifiedFields) { + const {policyRulesModifiedFields, policyID} = reportActionOriginalMessage; + + if (policyRulesModifiedFields && policyID) { + const policyRulesRoute = `${environmentURL}/${ROUTES.WORKSPACE_RULES.getRoute(policyID)}`; + return translate('iou.policyRulesModifiedFields', policyRulesModifiedFields, policyRulesRoute, formatList); + } + } + const message = getMessageLine(translate, `\n${translate('iou.changed')}`, changeFragments) + getMessageLine(translate, `\n${translate('iou.set')}`, setFragments) + getMessageLine(translate, `\n${translate('iou.removed')}`, removalFragments); + if (message === '') { return translate('iou.changedTheExpense'); } diff --git a/src/types/onyx/ExpenseRule.ts b/src/types/onyx/ExpenseRule.ts index 7880a17e988e..9d54945fac58 100644 --- a/src/types/onyx/ExpenseRule.ts +++ b/src/types/onyx/ExpenseRule.ts @@ -1,5 +1,5 @@ -/** Model of tax rate */ -type TaxRate = { +/** Model of tax rate on a personal rule */ +type PersonalRuleTaxRate = { /** The tax ID */ externalID: string; @@ -7,6 +7,18 @@ type TaxRate = { value: string; }; +/** Model of tax rate on a policy rule */ +type PolicyRuleTaxRate = { + /** The tax ID */ + externalID: string; + + /** The tax rate */ + value: string; + + /** The name of the tax rate */ + name: string; +}; + /** Model of expense rule */ type ExpenseRule = { /** Whether the transaction is set to be billable */ @@ -37,8 +49,8 @@ type ExpenseRule = { tag?: string; /** The tax rate set by the rule */ - tax?: Record; + tax?: Record; }; -export type {TaxRate}; +export type {PersonalRuleTaxRate, PolicyRuleTaxRate}; export default ExpenseRule; diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 912dbdd73757..38e14f12eb7d 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -1,6 +1,7 @@ import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; import type DeepValueOf from '@src/types/utils/DeepValueOf'; +import type {PolicyRuleTaxRate} from './ExpenseRule'; import type {Attendee} from './IOU'; import type {OldDotOriginalMessageMap} from './OldDotAction'; import type {AllConnectionName} from './Policy'; @@ -731,10 +732,44 @@ type OriginalMessageModifiedExpense = { /** Whether the updated description was generated by AI */ aiGenerated?: boolean; + /** The policy ID that the expense was modified in */ + policyID?: string; + + /** The fields that were modified by policy rules */ + policyRulesModifiedFields?: PolicyRulesModifiedFields; + /** The Concierge reasoning for the action */ reasoning?: string; }; +/** Policy rules modified fields */ +type PolicyRulesModifiedFields = { + /** The value that the merchant was changed to */ + merchant?: string; + + /** The value that the amount was changed to */ + category?: string; + + /** The value that the tag was changed to */ + tag?: string; + + /** The value that the description was changed to */ + description?: string; + + /** The value that the billable status was changed to */ + billable?: boolean; + + /** The value that the reimbursable status was changed to */ + reimbursable?: boolean; + + /** The value that the tax was changed to */ + tax?: { + /** The tax rate being used */ + // eslint-disable-next-line @typescript-eslint/naming-convention + field_id_TAX: PolicyRuleTaxRate; + }; +}; + /** Model of a `travel update` report action */ type OriginalMessageTravelUpdate = Reservation & UpdateOperationType; @@ -1236,6 +1271,7 @@ export type { PaymentMethodType, OriginalMessageSource, Decision, + PolicyRulesModifiedFields, OriginalMessageChangeLog, JoinWorkspaceResolution, OriginalMessageModifiedExpense, diff --git a/tests/unit/ModifiedExpenseMessageTest.ts b/tests/unit/ModifiedExpenseMessageTest.ts index 2ea0f4a43620..962e2cbe2592 100644 --- a/tests/unit/ModifiedExpenseMessageTest.ts +++ b/tests/unit/ModifiedExpenseMessageTest.ts @@ -1,3 +1,4 @@ +import {getEnvironmentURL} from '@libs/Environment/Environment'; import {getForReportAction, getMovedFromOrToReportMessage, getMovedReportID} from '@libs/ModifiedExpenseMessage'; // eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking import * as PolicyUtils from '@libs/PolicyUtils'; @@ -798,6 +799,120 @@ describe('ModifiedExpenseMessage', () => { }); }); + describe('when policy rules modify an expense', () => { + let environmentURL: string; + beforeAll(async () => { + environmentURL = await getEnvironmentURL(); + }); + + it('returns the correct text message with multiple overrides', () => { + const reportAction = { + ...createRandomReportAction(1), + actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, + originalMessage: { + policyID: '1234', + policyRulesModifiedFields: { + category: 'Travel', + merchant: "McDonald's", + billable: true, + reimbursable: true, + }, + } as OriginalMessageModifiedExpense, + }; + + const result = getForReportAction({reportAction, policyID: report.policyID}); + + const expectedResult = `set the category to "Travel", merchant to "McDonald's", marked the expense as "billable", and marked the expense as "reimbursable" via workspace rules`; + + expect(result).toEqual(expectedResult); + }); + + it('returns the correct text message with tax rate overrides', () => { + const reportAction = { + ...createRandomReportAction(1), + actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, + originalMessage: { + policyID: '1234', + policyRulesModifiedFields: { + tax: { + // eslint-disable-next-line @typescript-eslint/naming-convention + field_id_TAX: { + externalID: '', + name: 'New Tax Rate', + value: '10', + }, + }, + }, + } as OriginalMessageModifiedExpense, + }; + + const result = getForReportAction({reportAction, policyID: report.policyID}); + + const expectedResult = `set the tax rate to "New Tax Rate" via workspace rules`; + + expect(result).toEqual(expectedResult); + }); + + it('returns the correct text message with two overrides', () => { + const reportAction = { + ...createRandomReportAction(1), + actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, + originalMessage: { + policyID: '1234', + policyRulesModifiedFields: { + category: 'Travel', + merchant: "McDonald's", + }, + } as OriginalMessageModifiedExpense, + }; + + const result = getForReportAction({reportAction, policyID: report.policyID}); + + const expectedResult = `set the category to "Travel" and merchant to "McDonald's" via workspace rules`; + + expect(result).toEqual(expectedResult); + }); + + it('returns the correct text message with a single override', () => { + const reportAction = { + ...createRandomReportAction(1), + actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, + originalMessage: { + policyID: '1234', + policyRulesModifiedFields: { + billable: true, + }, + } as OriginalMessageModifiedExpense, + }; + + const result = getForReportAction({reportAction, policyID: report.policyID}); + + const expectedResult = `marked the expense as "billable" via workspace rules`; + + expect(result).toEqual(expectedResult); + }); + + it('returns the correct text message with boolean overrides', () => { + const reportAction = { + ...createRandomReportAction(1), + actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, + originalMessage: { + policyID: '1234', + policyRulesModifiedFields: { + reimbursable: true, + billable: true, + }, + } as OriginalMessageModifiedExpense, + }; + + const result = getForReportAction({reportAction, policyID: report.policyID}); + + const expectedResult = `marked the expense as "reimbursable" and marked the expense as "billable" via workspace rules`; + + expect(result).toEqual(expectedResult); + }); + }); + describe('when the category is changed without source (backward compatibility)', () => { const reportAction = { ...createRandomReportAction(1),