Skip to content

[No QA] Add violation for custom rules #56553

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

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4998,6 +4998,7 @@ const CONST = {
PER_DAY_LIMIT: 'perDayLimit',
RECEIPT_NOT_SMART_SCANNED: 'receiptNotSmartScanned',
RECEIPT_REQUIRED: 'receiptRequired',
CUSTOM_RULES: 'customRules',
RTER: 'rter',
SMARTSCAN_FAILED: 'smartscanFailed',
SOME_TAG_LEVELS_REQUIRED: 'someTagLevelsRequired',
Expand Down
5 changes: 4 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type MoneyRequestViewProps = {

const receiptImageViolationNames: OnyxTypes.ViolationName[] = [
CONST.VIOLATIONS.RECEIPT_REQUIRED,
CONST.VIOLATIONS.CUSTOM_RULES,
CONST.VIOLATIONS.RECEIPT_NOT_SMART_SCANNED,
CONST.VIOLATIONS.CASH_EXPENSE_WITH_NO_RECEIPT,
CONST.VIOLATIONS.SMARTSCAN_FAILED,
Expand Down Expand Up @@ -407,10 +408,12 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
}, [transactionViolations, translate]);

const receiptRequiredViolation = transactionViolations?.some((violation) => violation.name === CONST.VIOLATIONS.RECEIPT_REQUIRED);
const customRulesViolation = transactionViolations?.some((violation) => violation.name === CONST.VIOLATIONS.CUSTOM_RULES);

// Whether to show receipt audit result (e.g.`Verified`, `Issue Found`) and messages (e.g. `Receipt not verified. Please confirm accuracy.`)
// `!!(receiptViolations.length || didReceiptScanSucceed)` is for not showing `Verified` when `receiptViolations` is empty and `didReceiptScanSucceed` is false.
const shouldShowAuditMessage = !isReceiptBeingScanned && (hasReceipt || receiptRequiredViolation) && !!(receiptViolations.length || didReceiptScanSucceed) && isPaidGroupPolicy(report);
const shouldShowAuditMessage =
!isReceiptBeingScanned && (hasReceipt || !!receiptRequiredViolation || !!customRulesViolation) && !!(receiptViolations.length || didReceiptScanSucceed) && isPaidGroupPolicy(report);
const shouldShowReceiptAudit = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt);

const errors = {
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useViolations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const violationFields: Record<ViolationName, ViolationField> = {
perDayLimit: 'amount',
receiptNotSmartScanned: 'receipt',
receiptRequired: 'receipt',
customRules: 'receipt',
rter: 'merchant',
smartscanFailed: 'receipt',
someTagLevelsRequired: 'tag',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ import type {
ViolationsAutoReportedRejectedExpenseParams,
ViolationsCashExpenseWithNoReceiptParams,
ViolationsConversionSurchargeParams,
ViolationsCustomRulesParams,
ViolationsInvoiceMarkupParams,
ViolationsMaxAgeParams,
ViolationsMissingTagParams,
Expand Down Expand Up @@ -5343,6 +5344,7 @@ const translations = {
}
return message;
},
customRules: ({message}: ViolationsCustomRulesParams) => message,
reviewRequired: 'Review required',
rter: ({brokenBankConnection, email, isAdmin, isTransactionOlderThan7Days, member, rterType}: ViolationsRterParams) => {
if (rterType === CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION_530 || rterType === CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION) {
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ import type {
ViolationsAutoReportedRejectedExpenseParams,
ViolationsCashExpenseWithNoReceiptParams,
ViolationsConversionSurchargeParams,
ViolationsCustomRulesParams,
ViolationsInvoiceMarkupParams,
ViolationsMaxAgeParams,
ViolationsMissingTagParams,
Expand Down Expand Up @@ -5856,6 +5857,7 @@ const translations = {
}
return message;
},
customRules: ({message}: ViolationsCustomRulesParams) => message,
reviewRequired: 'Revisión requerida',
rter: ({brokenBankConnection, isAdmin, email, isTransactionOlderThan7Days, member, rterType}: ViolationsRterParams) => {
if (rterType === CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION_530 || rterType === CONST.RTER_VIOLATION_TYPES.BROKEN_CARD_CONNECTION) {
Expand Down
3 changes: 3 additions & 0 deletions src/languages/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ type ViolationsPerDayLimitParams = {formattedLimit: string};

type ViolationsReceiptRequiredParams = {formattedLimit?: string; category?: string};

type ViolationsCustomRulesParams = {message: string};

type ViolationsRterParams = {
brokenBankConnection: boolean;
isAdmin: boolean;
Expand Down Expand Up @@ -774,6 +776,7 @@ export type {
ViolationsOverLimitParams,
ViolationsPerDayLimitParams,
ViolationsReceiptRequiredParams,
ViolationsCustomRulesParams,
ViolationsRterParams,
ViolationsTagOutOfPolicyParams,
ViolationsTaxOutOfPolicyParams,
Expand Down
1 change: 1 addition & 0 deletions src/libs/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,7 @@ function validateTransactionViolationDraftProperty(key: keyof TransactionViolati
duplicates: 'array',
rterType: CONST.RTER_VIOLATION_TYPES,
tooltip: 'string',
message: 'string',
});
case 'showInReview':
return validateBoolean(value);
Expand Down
3 changes: 3 additions & 0 deletions src/libs/Violations/ViolationsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ const ViolationsUtils = {
taxName,
type,
rterType,
message = '',
} = violation.data ?? {};

switch (violation.name) {
Expand Down Expand Up @@ -310,6 +311,8 @@ const ViolationsUtils = {
return translate('violations.receiptNotSmartScanned');
case 'receiptRequired':
return translate('violations.receiptRequired', {formattedLimit, category});
case 'customRules':
return translate('violations.customRules', {message});
case 'rter':
return translate('violations.rter', {
brokenBankConnection,
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/TransactionViolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ type TransactionViolationData = {
/** Type of the RTER violation */
rterType?: ValueOf<typeof CONST.RTER_VIOLATION_TYPES>;

/** A generic message to display to the user */
message?: string;

/** Message to display to the user */
tooltip?: string;
};
Expand Down
Loading