This is an automated email from the ASF dual-hosted git repository. nmalin pushed a commit to branch release22.01 in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/release22.01 by this push: new 0af153a750 Implemented: Configure invoice, quote and order templates for an organizational party (OFBIZ-10215) (OFBIZ-10216) (OFBIZ-10217) 0af153a750 is described below commit 0af153a75046b3c307e5c6fe6f2361d3d1de8e4b Author: Nicolas Malin <nicolas.ma...@nereide.fr> AuthorDate: Wed May 25 13:58:34 2022 +0200 Implemented: Configure invoice, quote and order templates for an organizational party (OFBIZ-10215) (OFBIZ-10216) (OFBIZ-10217) Add the possibility to print invoice, quote and order as pdf from the organizational party configuration. With this you can define your own xslfo template connected to a custom screen and configure it for each organization through PartyPrefDocTypeTpl Thanks to Ingo Wolfmayr for patch submission --- .../accounting/widget/AccountingPrintScreens.xml | 13 ++++ .../groovyScripts/template/DocTypeTemplate.groovy | 70 ++++++++++++++++++++++ .../datamodel/data/demo/AccountingDemoData.xml | 4 ++ applications/datamodel/data/demo/OrderDemoData.xml | 10 ++++ .../order/widget/ordermgr/OrderPrintScreens.xml | 13 ++++ .../order/widget/ordermgr/QuoteScreens.xml | 16 ++++- 6 files changed, 125 insertions(+), 1 deletion(-) diff --git a/applications/accounting/widget/AccountingPrintScreens.xml b/applications/accounting/widget/AccountingPrintScreens.xml index 27bf329d74..763585972c 100644 --- a/applications/accounting/widget/AccountingPrintScreens.xml +++ b/applications/accounting/widget/AccountingPrintScreens.xml @@ -25,6 +25,19 @@ under the License. <!-- generate a PDF for the invoice. Sharing the same script file as the HTML page for viewing invoice --> <screen name="InvoicePDF"> + <section> + <actions> + <set field="defaultTemplateLocation" value="component://accounting/widget/AccountingPrintScreens.xml"/> + <set field="defaultTemplateName" value="DefaultInvoicePDF"/> + <script location="component://commonext/groovyScripts/template/DocTypeTemplate.groovy"/> + </actions> + <widgets> + <include-screen name="${templateName}" location="${templateLocation}"/> + </widgets> + </section> + </screen> + + <screen name="DefaultInvoicePDF"> <section> <actions> <property-map resource="AccountingUiLabels" map-name="uiLabelMap" global="true"/> diff --git a/applications/commonext/groovyScripts/template/DocTypeTemplate.groovy b/applications/commonext/groovyScripts/template/DocTypeTemplate.groovy new file mode 100644 index 0000000000..1c5986392d --- /dev/null +++ b/applications/commonext/groovyScripts/template/DocTypeTemplate.groovy @@ -0,0 +1,70 @@ +package org.apache.ofbiz.common.template +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.ofbiz.entity.GenericValue +import org.apache.ofbiz.entity.model.ModelUtil + +def getFieldTypeName(String entityName) { + return ModelUtil.lowerFirstChar(entityName) + 'Id' +} + +/** + * For a entityTypeName and a value return the matching templating document screen + * If no value found, do a recursive search on parentType + */ +def getCustomScreenTemplate(String entityTypeName, String fieldTypeValue) { + if (! fieldTypeValue) { + return null + } + GenericValue tplCustScreen = from("PartyPrefDocTypeTplAndCustomScreen") + .where(getFieldTypeName(entityTypeName), fieldTypeValue) + .cache() + .queryFirst() + if (tplCustScreen) { + return tplCustScreen + } + // No template found for this type, try if the parent had + String parentTypeValue = from(entityTypeName).where().cache().queryFirst().parentTypeId + return getCustomScreenTemplate(entityTypeName, parentTypeValue) +} + +// first resolve the document reference passed on the context +String entityName = "" +String entityTypeName = "" +if (parameters.orderId) { + entityName = "OrderHeader" + entityTypeName = "OrderType" +} else if (parameters.invoiceId) { + entityName ="Invoice" +} else if (parameters.quoteId) { + entityName = "Quote" +} + +// second ask for this entity the custom screen to use +GenericValue tplCustScreen +if (entityName) { + entityTypeName = entityTypeName ?: entityName + 'Type' + GenericValue entityValue = from(entityName).where(parameters).queryOne() + if (entityValue) { + tplCustScreen = getCustomScreenTemplate(entityTypeName, entityValue[getFieldTypeName(entityTypeName)]) + } +} +context.templateLocation = tplCustScreen ? tplCustScreen.customScreenLocation : context.defaultTemplateLocation +context.templateName = tplCustScreen ? tplCustScreen.customScreenName : context.defaultTemplateName diff --git a/applications/datamodel/data/demo/AccountingDemoData.xml b/applications/datamodel/data/demo/AccountingDemoData.xml index 1909d92cf4..7ef3ec5add 100644 --- a/applications/datamodel/data/demo/AccountingDemoData.xml +++ b/applications/datamodel/data/demo/AccountingDemoData.xml @@ -1609,5 +1609,9 @@ under the License. <InventoryItem facilityId="WebStoreWarehouse" locationSeqId="TLTLTLUL01" datetimeReceived="2008-08-01 08:00:00.000" inventoryItemId="9030" inventoryItemTypeId="NON_SERIAL_INV_ITEM" productId="MAT_B_COST" ownerPartyId="Company" currencyUomId="USD" unitCost="7.0"/> <InventoryItemDetail inventoryItemId="9030" inventoryItemDetailSeqId="0001" effectiveDate="2001-05-13 12:00:00.0" availableToPromiseDiff="20" quantityOnHandDiff="20" accountingQuantityDiff="20"/> + + <!-- defaut template screen use for Company --> + <CustomScreen customScreenId="DEFAULT_INV_TPL" customScreenTypeId="CST_INVOICE_TPL" customScreenName="DefaultInvoicePDF" customScreenLocation="component://accounting/widget/AccountingPrintScreens.xml"/> + <PartyPrefDocTypeTpl partyPrefDocTypeTplId="InvTplInvoice" partyId="Company" fromDate="2001-05-13 00:00:00" invoiceTypeId="INVOICE" customScreenId="DEFAULT_INV_TPL"/> </entity-engine-xml> diff --git a/applications/datamodel/data/demo/OrderDemoData.xml b/applications/datamodel/data/demo/OrderDemoData.xml index e0785c2f0e..1cbe72d2a4 100644 --- a/applications/datamodel/data/demo/OrderDemoData.xml +++ b/applications/datamodel/data/demo/OrderDemoData.xml @@ -2600,5 +2600,15 @@ under the License. <AgreementTerm agreementId="AGR_SALES" agreementItemSeqId="00001" agreementTermId="9000" description="Sales test agreement" termDays="30" termTypeId="FIN_PAYMENT_FIXDAY"/> <!-- An AgreementProductAppls aris related to an AgreementItem. AgreementProductAppls are optional. If a product id and a price are specified the price will override the ProductPrice if the agreement is selected in the order --> <AgreementProductAppl agreementId="AGR_SALES" agreementItemSeqId="00001" price="10.000" productId="GZ-1000"/> + + <CustomScreen customScreenId="DEFAULT_ORD_TPL" customScreenTypeId="CST_ORDER_TPL" customScreenName="DefaultOrderPDF" customScreenLocation="component://order/widget/ordermgr/OrderPrintScreens.xml"/> + <PartyPrefDocTypeTpl partyPrefDocTypeTplId="OrdTplSales" partyId="Company" fromDate="2001-05-13 00:00:00" orderTypeId="SALES_ORDER" customScreenId="DEFAULT_ORD_TPL"/> + <PartyPrefDocTypeTpl partyPrefDocTypeTplId="OrdTplPurchase" partyId="Company" fromDate="2001-05-13 00:00:00" orderTypeId="PURCHASE_ORDER" customScreenId="DEFAULT_ORD_TPL"/> + + <CustomScreen customScreenId="DEFAULT_QUOTE_TPL" customScreenTypeId="CST_QUOTE_TPL" customScreenName="DefaultQuotePDF" customScreenLocation="component://order/widget/ordermgr/QuoteScreens.xml"/> + <PartyPrefDocTypeTpl partyPrefDocTypeTplId="QuoTplOther" partyId="Company" fromDate="2001-05-13 00:00:00" quoteTypeId="OTHER_QUOTE" customScreenId="DEFAULT_QUOTE_TPL"/> + <PartyPrefDocTypeTpl partyPrefDocTypeTplId="QuoTplProposal" partyId="Company" fromDate="2001-05-13 00:00:00" quoteTypeId="PROPOSAL" customScreenId="DEFAULT_QUOTE_TPL"/> + <PartyPrefDocTypeTpl partyPrefDocTypeTplId="QuoTplProduct" partyId="Company" fromDate="2001-05-13 00:00:00" quoteTypeId="PRODUCT_QUOTE" customScreenId="DEFAULT_QUOTE_TPL"/> + <PartyPrefDocTypeTpl partyPrefDocTypeTplId="QuoTplPurchase" partyId="Company" fromDate="2001-05-13 00:00:00" quoteTypeId="PURCHASE_QUOTE" customScreenId="DEFAULT_QUOTE_TPL"/> </entity-engine-xml> diff --git a/applications/order/widget/ordermgr/OrderPrintScreens.xml b/applications/order/widget/ordermgr/OrderPrintScreens.xml index 079c8126dd..0ed42615bf 100644 --- a/applications/order/widget/ordermgr/OrderPrintScreens.xml +++ b/applications/order/widget/ordermgr/OrderPrintScreens.xml @@ -25,6 +25,19 @@ under the License. <!-- generate a PDF for the order, sharing the same groovy file as the HTML page for viewing the order --> <screen name="OrderPDF"> + <section> + <actions> + <set field="defaultTemplateLocation" value="component://order/widget/ordermgr/OrderPrintScreens.xml"/> + <set field="defaultTemplateName" value="DefaultOrderPDF"/> + <script location="component://commonext/groovyScripts/template/DocTypeTemplate.groovy"/> + </actions> + <widgets> + <include-screen name="${templateName}" location="${templateLocation}"/> + </widgets> + </section> + </screen> + + <screen name="DefaultOrderPDF"> <section> <actions> <set field="titleProperty" value="OrderOrder" /> diff --git a/applications/order/widget/ordermgr/QuoteScreens.xml b/applications/order/widget/ordermgr/QuoteScreens.xml index 33eddc67c8..c0c23e6d40 100644 --- a/applications/order/widget/ordermgr/QuoteScreens.xml +++ b/applications/order/widget/ordermgr/QuoteScreens.xml @@ -160,8 +160,22 @@ under the License. </widgets> </section> </screen> - + + <!-- generate a PDF for the quote --> <screen name="QuoteReport"> + <section> + <actions> + <set field="defaultTemplateLocation" value="component://order/widget/ordermgr/QuoteScreens.xml"/> + <set field="defaultTemplateName" value="DefaultQuotePDF"/> + <script location="component://commonext/groovyScripts/template/DocTypeTemplate.groovy"/> + </actions> + <widgets> + <include-screen name="${templateName}" location="${templateLocation}"/> + </widgets> + </section> + </screen> + + <screen name="DefaultQuotePDF"> <section> <actions> <set field="titleProperty" value="OrderOrderQuoteReport"/>