ofbiz-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iwolf <ingo.wolfm...@wolfix.at>
Subject Re: Multiple invoice templates
Date Wed, 08 Oct 2014 15:37:02 GMT
For anyone who is interested, here is my solutions:

/applications/accounting/widget/AccountingPrintScreens.xml add:

<screen name="InvoicePDF">
   <section>
   <actions>	
     <script
location="component://accounting/webapp/accounting/WEB-INF/actions/invoice/InvoiceTemplate.groovy"/>
   </actions>		
   <widgets>				
       <include-screen name="${template}" location="${templatepath}"/>
   </widgets>
   </section>		
</screen>

Then rename the existing <screen name="InvoicePDF"> to <screen
name="InvoicePDF_default">

Add the following script
accounting/webapp/accounting/WEB-INF/actions/invoice/InvoiceTemplate.groovy

##START
import org.ofbiz.accounting.invoice.*;

invoiceId = parameters.get("invoiceId");
templatepath = "component://accounting/widget/AccountingPrintScreens.xml"
template = "InvoicePDF_default";

if (invoiceId) {
    invoice = delegator.findOne("Invoice", [invoiceId : invoiceId], false);

	billingParty = InvoiceWorker.getBillToParty(invoice);
    sendingParty = InvoiceWorker.getSendFromParty(invoice);
	
	if (billingParty) {
		partyId = billingParty.partyId;
		
				// get the template	
		partyContents = delegator.findByAndCache("PartyContent", [partyId :
partyId]) 
		templateattr = delegator.findByAnd("PartyAttribute", [partyId : partyId,
attrName :"invoiceTemplate"], null, false);
	}
	if (templateattr.size()==0){
		partyId = sendingParty.partyId;
		partyContents = delegator.findByAndCache("PartyContent", [partyId :
partyId]) 
		templateattr = delegator.findByAnd("PartyAttribute", [partyId : partyId,
attrName :"invoiceTemplate"], null, false);
	}
	
	if(templateattr.size()>0){
		tmp_template = templateattr[0].get("attrValue").split("#");
		templatepath = tmp_template[0]
		template = tmp_template[1]
	}
	context.templatepath = templatepath
	context.template = template
}
###END

I use the partyAttributes pointing to the screen definition. For example:

attribute Name = invoiceTemplate
attribute Value =
component://accounting/widget/AccountingPrintScreens.xml#InvoicePDF_default 

If no template is defined it falls back to the default default screen
definition.

Again thanks to Nicolas for pointing me here!



--
View this message in context: http://ofbiz.135035.n4.nabble.com/Multiple-invoice-templates-tp4654897p4656631.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Mime
View raw message