Hello together,
The "ThrowWrongAmountError" function of sales line shows the error
Text049: Label 'cannot be %1.';
FieldError("Prepmt. Line Amount", StrSubstNo(Text049, "Prepmt. Amt. Inv."));
Called in procedure CheckPrepmtAmounts()
if expression (("Prepmt. Line Amount" + Currency."Amount Rounding Precision") < "Prepmt. Amt. Inv.")
Please adjust this message so that it represents the condition.
Idea:
'The prepayment line amount (including rounding tolerance of %1) cannot be less than the amount already invoiced (%2). \Minimum required prepayment line amount: %3';
codeunit 50146 "Fix Sales Prepayment Event Handler"
{
///
/// Handles the OnBeforeThrowWrongAmountError event from the Sales Line table.
/// Adjusts the prepayment amount error message to account for currency rounding precision.
///
[EventSubscriber(ObjectType::Table, Database::"Sales Line", OnBeforeThrowWrongAmountError, '', false, false)]
local procedure OnBeforeThrowWrongAmountError(var SalesLine : Record "Sales Line"; var IsHandled: Boolean)
var
Currency: Record Currency;
PrepaymentLineAmountError: Label 'The prepayment line amount (including rounding tolerance of %1) cannot be less than the amount already invoiced (%2). \Minimum required prepayment line amount: %3';
CurrencyAmountRoundingPrecision: Decimal;
ErrorMessage: Text;
begin
IsHandled := true;
// Get the currency rounding precision
if SalesLine."Currency Code" <> '' then begin
Currency.Get(SalesLine."Currency Code");
CurrencyAmountRoundingPrecision := Currency."Amount Rounding Precision";
end else begin
Currency.InitRoundingPrecision();
CurrencyAmountRoundingPrecision := Currency."Amount Rounding Precision";
end;
// Build meaningful error message describing the condition
ErrorMessage := StrSubstNo(
PrepaymentLineAmountError,
CurrencyAmountRoundingPrecision,
SalesLine."Prepmt. Amt. Inv.",
SalesLine."Prepmt. Amt. Inv." - CurrencyAmountRoundingPrecision
);
// Throw the error with the meaningful message
SalesLine.FieldError("Prepmt. Line Amount", ErrorMessage);
end;
}
