From b50fa8e6c62d24e0ac9401c5e6a40ae1fd07e114 Mon Sep 17 00:00:00 2001 From: Jonathan Neugebauer Date: Wed, 16 Dec 2020 20:42:59 +0100 Subject: [PATCH] Update AL code generator to respect modularity --- .../mdal/extensions/DocumentExtensions.xtend | 10 +- .../extensions/DocumentHeaderExtensions.xtend | 52 +++---- .../mdal/extensions/MasterExtensions.xtend | 54 ++++--- .../mdal/extensions/SolutionExtensions.xtend | 138 ++++++++++-------- 4 files changed, 141 insertions(+), 113 deletions(-) diff --git a/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/DocumentExtensions.xtend b/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/DocumentExtensions.xtend index c283300..339b52a 100644 --- a/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/DocumentExtensions.xtend +++ b/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/DocumentExtensions.xtend @@ -145,10 +145,12 @@ class DocumentExtensions { document.line.doGenerate // Codeunits - document.saveCodeunit(document.codeunitNamePost, document.doGenerateCodeunitPost) - document.saveCodeunit(document.codeunitNamePostYesNo, document.doGenerateCodeunitPostYesNo) - document.saveCodeunit(document.codeunitNameJnlCheckLine, document.doGenerateCodeunitJnlCheckLine) - document.saveCodeunit(document.codeunitNameJnlPostLine, document.doGenerateCodeunitJnlPostLine) + if (document.solution.ledgerEntry !== null) { + document.saveCodeunit(document.codeunitNamePost, document.doGenerateCodeunitPost) + document.saveCodeunit(document.codeunitNamePostYesNo, document.doGenerateCodeunitPostYesNo) + document.saveCodeunit(document.codeunitNameJnlCheckLine, document.doGenerateCodeunitJnlCheckLine) + document.saveCodeunit(document.codeunitNameJnlPostLine, document.doGenerateCodeunitJnlPostLine) + } } static def doGenerateStatusEnum(Document document) ''' diff --git a/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/DocumentHeaderExtensions.xtend b/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/DocumentHeaderExtensions.xtend index 617ebf0..fa0f516 100644 --- a/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/DocumentHeaderExtensions.xtend +++ b/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/DocumentHeaderExtensions.xtend @@ -1295,31 +1295,33 @@ class DocumentHeaderExtensions { ToolTip = 'View or add comments for the record.'; } } - group("P&osting") - { - Caption = 'P&osting'; - Image = Post; - action(Post) - { - ApplicationArea = All; - Caption = 'P&ost'; - Ellipsis = true; - Image = PostOrder; - Promoted = true; - PromotedCategory = Category7; - PromotedIsBig = true; - ShortCutKey = 'F9'; - ToolTip = 'Finalize the document or journal by posting the amounts and quantities to the related accounts in your company books.'; - - trigger OnAction() - var - «document.codeunitVariableNamePostYesNo»: Codeunit «document.codeunitNamePostYesNo.saveQuote»; - begin - «document.codeunitVariableNamePostYesNo».Run(Rec); - CurrPage.Update(false); - end; - } - } + «IF document.solution.ledgerEntry !== null» + group("P&osting") + { + Caption = 'P&osting'; + Image = Post; + action(Post) + { + ApplicationArea = All; + Caption = 'P&ost'; + Ellipsis = true; + Image = PostOrder; + Promoted = true; + PromotedCategory = Category7; + PromotedIsBig = true; + ShortCutKey = 'F9'; + ToolTip = 'Finalize the document or journal by posting the amounts and quantities to the related accounts in your company books.'; + + trigger OnAction() + var + «document.codeunitVariableNamePostYesNo»: Codeunit «document.codeunitNamePostYesNo.saveQuote»; + begin + «document.codeunitVariableNamePostYesNo».Run(Rec); + CurrPage.Update(false); + end; + } + } + «ENDIF» } } } diff --git a/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/MasterExtensions.xtend b/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/MasterExtensions.xtend index 0991b8f..42365ba 100644 --- a/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/MasterExtensions.xtend +++ b/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/MasterExtensions.xtend @@ -139,12 +139,14 @@ class MasterExtensions { CommentLine.SetRange("No.", "No."); CommentLine.DeleteAll(); - «document.header.tableVariableName».SetCurrentKey("«master.cleanedName» No."); - «document.header.tableVariableName».SetRange("«master.cleanedName» No.", "No."); - IF NOT «document.header.tableVariableName».IsEmpty THEN - Error( - ExistingDocumentsErr, - TableCaption, "No.", «document.header.tableVariableName».TableCaption); + «IF document !== null» + «document.header.tableVariableName».SetCurrentKey("«master.cleanedName» No."); + «document.header.tableVariableName».SetRange("«master.cleanedName» No.", "No."); + IF NOT «document.header.tableVariableName».IsEmpty THEN + Error( + ExistingDocumentsErr, + TableCaption, "No.", «document.header.tableVariableName».TableCaption); + «ENDIF» end; trigger OnRename() @@ -158,8 +160,10 @@ class MasterExtensions { NoSeriesMgt: Codeunit NoSeriesManagement; CommentLine: Record "Comment Line"; «master.tableVariableName»: Record "«master.tableName»"; - «document.header.tableVariableName»: Record "«document.header.tableName»"; - ExistingDocumentsErr: Label 'You cannot delete %1 %2 because there is at least one outstanding %3 for this «master.name».'; + «IF document !== null» + «document.header.tableVariableName»: Record "«document.header.tableName»"; + ExistingDocumentsErr: Label 'You cannot delete %1 %2 because there is at least one outstanding %3 for this «master.name».'; + «ENDIF» «IF master.hasTemplateOfType(TemplateDimensions)» DimMgt: Codeunit DimensionManagement; «ENDIF» @@ -379,22 +383,24 @@ class MasterExtensions { } } } - area(creation) - { - action(New«document.cleanedName») - { - AccessByPermission = tabledata «document.header.tableName.saveQuote» = RIM; - ApplicationArea = All; - Caption = '«document.name»'; - Image = NewDocument; - Promoted = true; - PromotedCategory = Category4; - RunObject = Page «document.documentPageName.saveQuote»; - RunPageLink = "«master.name» No." = field("No."); - RunPageMode = Create; - Visible = NOT IsOfficeAddin; - } - } + «IF document !== null» + area(creation) + { + action(New«document.cleanedName») + { + AccessByPermission = tabledata «document.header.tableName.saveQuote» = RIM; + ApplicationArea = All; + Caption = '«document.name»'; + Image = NewDocument; + Promoted = true; + PromotedCategory = Category4; + RunObject = Page «document.documentPageName.saveQuote»; + RunPageLink = "«master.name» No." = field("No."); + RunPageMode = Create; + Visible = NOT IsOfficeAddin; + } + } + «ENDIF» } var diff --git a/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/SolutionExtensions.xtend b/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/SolutionExtensions.xtend index e8a31b4..4229e20 100644 --- a/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/SolutionExtensions.xtend +++ b/de.joneug.mdal/src/main/java/de/joneug/mdal/extensions/SolutionExtensions.xtend @@ -35,37 +35,45 @@ class SolutionExtensions { static def doGenerate(Solution solution) { solution.logInfo("Generating solution '" + solution.name + "'") - // Setup - solution.logInfo("Generating setup files") - solution.doGenerateSetup + if (solution.master !== null || solution.document !== null) { + // Setup + solution.logInfo("Generating setup files") + solution.doGenerateSetup + } // Comments solution.logInfo("Generating comment files") solution.doGenerateCommentObjects - // Source Code Setup - solution.logInfo("Generating source code setup files") - solution.doGenerateSourceCodeSetupObjects - - // Master - solution.logInfo("Generating master files") - solution.master.doGenerate + if (solution.master !== null) { + // Master + solution.logInfo("Generating master files") + solution.master.doGenerate + } // Supplementals solution.logInfo("Generating supplemental files") solution.supplementals.forEach[it.doGenerate] - // Document - solution.logInfo("Generating document files") - solution.document.doGenerate - - // Ledger Entry - solution.logInfo("Generating ledger entry files") - solution.ledgerEntry.doGenerate - - // Navigate Extensions - solution.logInfo("Generating navigate files") - solution.doGenerateNavigateExtensionObjects + if (solution.document !== null) { + // Document + solution.logInfo("Generating document files") + solution.document.doGenerate + + // Ledger Entry + if (solution.ledgerEntry !== null) { + solution.logInfo("Generating ledger entry files") + solution.ledgerEntry.doGenerate + } + + // Source Code Setup + solution.logInfo("Generating source code setup files") + solution.doGenerateSourceCodeSetupObjects + + // Navigate Extensions + solution.logInfo("Generating navigate files") + solution.doGenerateNavigateExtensionObjects + } } /* @@ -111,22 +119,24 @@ class SolutionExtensions { Caption = '«solution.master.cleanedName» Nos.'; TableRelation = "No. Series"; } - field(3; "«solution.document.shortName» Nos."; Code[20]) - { - Caption = '«solution.document.shortName» Nos.'; - TableRelation = "No. Series"; - } - field(4; "«solution.document.shortNamePosted» Nos."; Code[20]) - { - Caption = '«solution.document.shortNamePosted» Nos.'; - TableRelation = "No. Series"; - } - field(10; "Copy Comments"; Boolean) - { - AccessByPermission = TableData «solution.document.header.tableNamePosted.saveQuote» = R; - Caption = 'Copy Comments To Posted Reg.'; - InitValue = true; - } + «IF solution.document !== null» + field(3; "«solution.document.shortName» Nos."; Code[20]) + { + Caption = '«solution.document.shortName» Nos.'; + TableRelation = "No. Series"; + } + field(4; "«solution.document.shortNamePosted» Nos."; Code[20]) + { + Caption = '«solution.document.shortNamePosted» Nos.'; + TableRelation = "No. Series"; + } + field(10; "Copy Comments"; Boolean) + { + AccessByPermission = TableData «solution.document.header.tableNamePosted.saveQuote» = R; + Caption = 'Copy Comments To Posted Reg.'; + InitValue = true; + } + «ENDIF» } keys @@ -165,15 +175,17 @@ class SolutionExtensions { { area(content) { - group(General) - { - Caption = 'General'; - - field("Copy Comments"; "Copy Comments") - { - ApplicationArea = All; - } - } + «IF solution.document !== null» + group(General) + { + Caption = 'General'; + + field("Copy Comments"; "Copy Comments") + { + ApplicationArea = All; + } + } + «ENDIF» group("Number Series") { Caption = 'Number Series'; @@ -182,14 +194,16 @@ class SolutionExtensions { { ApplicationArea = All; } - field("«solution.document.shortName» Nos."; "«solution.document.shortName» Nos.") - { - ApplicationArea = All; - } - field("«solution.document.shortNamePosted» Nos."; "«solution.document.shortNamePosted» Nos.") - { - ApplicationArea = All; - } + «IF solution.document !== null» + field("«solution.document.shortName» Nos."; "«solution.document.shortName» Nos.") + { + ApplicationArea = All; + } + field("«solution.document.shortNamePosted» Nos."; "«solution.document.shortNamePosted» Nos.") + { + ApplicationArea = All; + } + «ENDIF» } } } @@ -214,12 +228,16 @@ class SolutionExtensions { */ static def void doGenerateCommentObjects(Solution solution) { - solution.saveEnumExt(solution.commentLineTableNameEnumExtName, solution.doGenerateCommentLineTableNameEnumExt) - solution.saveEnum(solution.commentDocumentTypeEnumName, solution.doGenerateCommentDocumentTypeEnum) - solution.saveTableExt(solution.commentLineTableExtName, solution.doGenerateCommentLineTableExtName) - solution.saveTable(solution.commentLineTableName, solution.doGenerateCommentLineTable) - solution.savePage(solution.commentListPageName, solution.doGenerateCommentListPage) - solution.savePage(solution.commentSheetPageName, solution.doGenerateCommentSheetPage) + if (solution.master !== null) { + solution.saveEnumExt(solution.commentLineTableNameEnumExtName, solution.doGenerateCommentLineTableNameEnumExt) + solution.saveTableExt(solution.commentLineTableExtName, solution.doGenerateCommentLineTableExtName) + } + if (solution.document !== null) { + solution.saveEnum(solution.commentDocumentTypeEnumName, solution.doGenerateCommentDocumentTypeEnum) + solution.saveTable(solution.commentLineTableName, solution.doGenerateCommentLineTable) + solution.savePage(solution.commentListPageName, solution.doGenerateCommentListPage) + solution.savePage(solution.commentSheetPageName, solution.doGenerateCommentSheetPage) + } } static def getCommentLineTableNameEnumExtName(Solution solution) {