Skip to content

Commit

Permalink
Refactor series code generation logic for improved efficiency.
Browse files Browse the repository at this point in the history
Simplify series code handling by removing redundant functions and streamlining the removal process, enhancing code readability and maintenance.
  • Loading branch information
DmitryKatson committed Sep 17, 2024
1 parent 1c0d5a2 commit 7c98b5d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,35 +454,12 @@ codeunit 324 "No. Series Copilot Impl."
Json.GetStringPropertyValueByName('seriesCode', NoSeriesCode);

if NoSeriesCodes.Contains(NoSeriesCode) and (not IsExists) then begin
Json.ReplaceOrAddJPropertyInJObject('seriesCode', GenerateNewSeriesCodeValue(NoSeriesCodes, NoSeriesCode));
NoSeriesObj := Json.GetObjectAsText();
Json.ReplaceJObjectInCollection(i, NoSeriesObj);
Json.RemoveJObjectFromCollection(i);
exit;
end;
NoSeriesCodes.Add(NoSeriesCode);
end;

local procedure GenerateNewSeriesCodeValue(var NoSeriesCodes: List of [Text]; var NoSeriesCode: Text): Text
var
NewNoSeriesCode: Text;
begin
repeat
NewNoSeriesCode := CopyStr(NoSeriesCode, 1, 18) + '-' + RandomCharacter();
until not NoSeriesCodes.Contains(NewNoSeriesCode);

NoSeriesCode := NewNoSeriesCode;
exit(NewNoSeriesCode);
end;

local procedure RandomCharacter(): Char
begin
exit(RandIntInRange(33, 126)); // ASCII: ! (33) to ~ (126)
end;

local procedure RandIntInRange(MinInt: Integer; MaxInt: Integer): Integer
begin
exit(MinInt - 1 + Random(MaxInt - MinInt + 1));
end;

local procedure InsertGeneratedNoSeries(var GeneratedNoSeries: Record "No. Series Generation Detail"; NoSeriesObj: Text; GenerationNo: Integer)
var
Json: Codeunit Json;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ codeunit 336 "No. Series Cop. Tools Impl."

local procedure GetMatchLengthTreshold(): Decimal
begin
exit(4);
exit(2);
end;

local procedure RequiredNearness(): Decimal
Expand Down

0 comments on commit 7c98b5d

Please sign in to comment.