Author: nmalin
Date: Tue Jul  3 21:58:32 2018
New Revision: 1835028

URL: http://svn.apache.org/viewvc?rev=1835028&view=rev
Log:
Improved: Resolve shipping address from Invoice
(OFBIZ-10249)
In some country (like european) you need to indicate on your sales invoice 
where you ship the finish good product related.
To help this case, I added a new worker function 
(InvoiceWorker.getShippingAddress) to found information from an invoice and 
improve the generic EditInvoice.groovy and the invoice ftl template to display 
it as example.
To homogenize postal address displaying with order I use the subscreen 
PartyScreens.xml#postalAddressPdfFormatter on the invoice ftl template

Modified:
    
ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/EditInvoice.groovy
    
ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceWorker.java
    
ofbiz/ofbiz-framework/trunk/applications/accounting/template/invoice/InvoiceReportContactMechs.fo.ftl
    
ofbiz/ofbiz-framework/trunk/applications/accounting/widget/AccountingPrintScreens.xml
    
ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/accounting-entitymodel.xml

Modified: 
ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/EditInvoice.groovy
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/EditInvoice.groovy?rev=1835028&r1=1835027&r2=1835028&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/EditInvoice.groovy
 (original)
+++ 
ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/EditInvoice.groovy
 Tue Jul  3 21:58:32 2018
@@ -49,6 +49,8 @@ if (invoice) {
     context.billToParty = billToParty
     sendingParty = InvoiceWorker.getSendFromParty(invoice)
     context.sendingParty = sendingParty
+    shippingAddress = InvoiceWorker.getShippingAddress(invoice)
+    context.shippingAddress = shippingAddress
 
     if (currency && !invoice.getString("currencyUomId").equals(currency)) {
         conversionRate = 
InvoiceWorker.getInvoiceCurrencyConversionRate(invoice)

Modified: 
ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceWorker.java
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceWorker.java?rev=1835028&r1=1835027&r2=1835028&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceWorker.java
 (original)
+++ 
ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceWorker.java
 Tue Jul  3 21:58:32 2018
@@ -316,6 +316,31 @@ public final class InvoiceWorker {
     }
 
     /**
+      * Method to obtain the shipping address from an invoice
+      * first resolve from InvoiceContactMech and if not found try from 
Shipment if present
+      * @param invoice GenericValue object of the Invoice
+      * @return GenericValue object of the PostalAddress
+      */
+    public static GenericValue getShippingAddress(GenericValue invoice) {
+        GenericValue postalAddress = getInvoiceAddressByType(invoice, 
"SHIPPING_LOCATION", false);
+        Delegator delegator = invoice.getDelegator();
+        if (postalAddress == null) {
+            try {
+                GenericValue shipmentView = 
EntityQuery.use(delegator).from("InvoiceItemAndShipmentView")
+                        .where("invoiceId", 
invoice.get("invoiceId")).queryFirst();
+                if (shipmentView != null) {
+                    GenericValue shipment = 
EntityQuery.use(delegator).from("Shipment")
+                        .where("shipmentId", 
shipmentView.get("shipmentId")).queryOne();
+                    postalAddress = 
shipment.getRelatedOne("DestinationPostalAddress");
+                }
+            } catch (GenericEntityException e) {
+                Debug.logError("Touble getting ContactMech entity from OISG", 
module);
+            }
+        }
+        return postalAddress;
+    }
+
+    /**
       * Method to obtain the billing address for an invoice
       * @param invoice GenericValue object of the Invoice
       * @return GenericValue object of the PostalAddress

Modified: 
ofbiz/ofbiz-framework/trunk/applications/accounting/template/invoice/InvoiceReportContactMechs.fo.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/template/invoice/InvoiceReportContactMechs.fo.ftl?rev=1835028&r1=1835027&r2=1835028&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/trunk/applications/accounting/template/invoice/InvoiceReportContactMechs.fo.ftl
 (original)
+++ 
ofbiz/ofbiz-framework/trunk/applications/accounting/template/invoice/InvoiceReportContactMechs.fo.ftl
 Tue Jul  3 21:58:32 2018
@@ -19,26 +19,24 @@ under the License.
 <#escape x as x?xml>
 <fo:table table-layout="fixed" width="100%" space-after="0.3in">
    <fo:table-column column-width="3.5in"/>
+   <fo:table-column column-width="3.5in"/>
     <fo:table-body>
       <fo:table-row >
         <fo:table-cell>
           <fo:block>_______________________________</fo:block>
       </fo:table-cell>
+        <fo:table-cell>
+          <fo:block>_______________________________</fo:block>
+      </fo:table-cell>
     </fo:table-row>
       <fo:table-row >
         <fo:table-cell>
           <fo:block>${uiLabelMap.CommonTo}: </fo:block>
-            <#if billingAddress?has_content>
+            <#if billingAddress??>
                 <#assign billToPartyNameResult = 
dispatcher.runSync("getPartyNameForDate", 
Static["org.apache.ofbiz.base.util.UtilMisc"].toMap("partyId", 
billToParty.partyId, "compareDate", invoice.invoiceDate, "userLogin", 
userLogin))/>
                 
<fo:block>${billToPartyNameResult.fullName?default(billingAddress.toName)?default("Billing
 Name Not Found")}</fo:block>
-                <#if billingAddress.attnName??>
-                    <fo:block>${billingAddress.attnName}</fo:block>
-                </#if>
-                    <fo:block>${billingAddress.address1!}</fo:block>
-                <#if billingAddress.address2??>
-                    <fo:block>${billingAddress.address2}</fo:block>
-                </#if>
-                <fo:block>${billingAddress.city!} 
${billingAddress.stateProvinceGeoId!} ${billingAddress.postalCode!}</fo:block>
+                ${setContextField("postalAddress", billingAddress)}
+                
${screens.render("component://party/widget/partymgr/PartyScreens.xml#postalAddressPdfFormatter")}
                 <#if billToPartyTaxId?has_content>
                     <fo:block>${uiLabelMap.PartyTaxId}: 
${billToPartyTaxId}</fo:block>
                 </#if>
@@ -46,6 +44,16 @@ under the License.
                 
<fo:block>${uiLabelMap.AccountingNoGenBilAddressFound}${billToParty.partyId}</fo:block>
             </#if>
        </fo:table-cell>
+        <fo:table-cell>
+            <#if shippingAddress??>
+                <fo:block>${uiLabelMap.OrderShipTo}: </fo:block>
+                ${setContextField("postalAddress", shippingAddress)}
+                
${screens.render("component://party/widget/partymgr/PartyScreens.xml#postalAddressPdfFormatter")}
+            <#else>
+                <fo:block/>
+            </#if>
+       </fo:table-cell>
+
     </fo:table-row>
   </fo:table-body>
 </fo:table>

Modified: 
ofbiz/ofbiz-framework/trunk/applications/accounting/widget/AccountingPrintScreens.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/widget/AccountingPrintScreens.xml?rev=1835028&r1=1835027&r2=1835028&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/trunk/applications/accounting/widget/AccountingPrintScreens.xml
 (original)
+++ 
ofbiz/ofbiz-framework/trunk/applications/accounting/widget/AccountingPrintScreens.xml
 Tue Jul  3 21:58:32 2018
@@ -30,6 +30,7 @@ under the License.
                 <property-map resource="AccountingUiLabels" 
map-name="uiLabelMap" global="true"/>
                 <property-map resource="ProductUiLabels" map-name="uiLabelMap" 
global="true"/>
                 <property-map resource="PartyUiLabels" map-name="uiLabelMap" 
global="true"/>
+                <property-map resource="OrderUiLabels" map-name="uiLabelMap" 
global="true"/>
                 <property-map resource="CommonUiLabels" map-name="uiLabelMap" 
global="true"/>
                 <set field="titleProperty" value="AccountingInvoice"/>
                 <script 
location="component://accounting/groovyScripts/invoice/EditInvoice.groovy"/>

Modified: 
ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/accounting-entitymodel.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/accounting-entitymodel.xml?rev=1835028&r1=1835027&r2=1835028&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/accounting-entitymodel.xml
 (original)
+++ 
ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/accounting-entitymodel.xml
 Tue Jul  3 21:58:32 2018
@@ -1707,6 +1707,24 @@ under the License.
             <key-map field-name="invoiceItemSeqId"/>
         </view-link>
     </view-entity>
+    <view-entity entity-name="InvoiceItemAndShipmentView" 
package-name="org.apache.ofbiz.accounting.invoice">
+        <member-entity entity-alias="INVITM" entity-name="InvoiceItem"/>
+        <member-entity entity-alias="ORDBIL" entity-name="OrderItemBilling"/>
+        <member-entity entity-alias="ITMISS" entity-name="ItemIssuance"/>
+        <member-entity entity-alias="SHIP" entity-name="Shipment"/>
+        <alias-all entity-alias="INVITM"/>
+        <alias-all entity-alias="SHIP"/>
+        <view-link entity-alias="INVITM" rel-entity-alias="ORDBIL">
+            <key-map field-name="invoiceId"/>
+            <key-map field-name="invoiceItemSeqId"/>
+        </view-link>
+        <view-link entity-alias="ORDBIL" rel-entity-alias="ITMISS">
+            <key-map field-name="itemIssuanceId"/>
+        </view-link>
+        <view-link entity-alias="ITMISS" rel-entity-alias="SHIP">
+            <key-map field-name="shipmentId"/>
+        </view-link>
+    </view-entity>
 
     <view-entity entity-name="InvoiceContentAndInfo"
             package-name="org.apache.ofbiz.accounting.invoice"


Reply via email to