Author: mor
Date: Tue Jan  5 11:50:19 2010
New Revision: 896010

URL: http://svn.apache.org/viewvc?rev=896010&view=rev
Log:
Example:
1. The currency of accounting/facility set to Indian Rupees, its INR
2) Warehouse manager receive a purchase order with an item with price 10 USD
3) In the receive screen, the system prompts for the unit price of 500 INR (the 
currency exchange rate between INR and USD is about 50 i.e 1 USD -> 50 INR)
4) The user doesn't change the value and after the item is received both the 
order item (unitPrice) and the supplier product (lastPrice) price are updated 
with the new unit price of 500 USD.

This is automatically happening with setUnitPriceAsLastPrice service.

With the fix the receive screen now display the original price and its 
currency, and the price in the facility currency (if different); if the former 
is edited, and Ajax event update the latter; the latter will be used as 
inventory item's unit cost; if the former is not updated, then no event will be 
triggered to change item price or supplier product price.

Bug reported by Jacopo Cappellato and fix provided by Akash Jain. Part of 
OFBIZ-3389


Added:
    ofbiz/trunk/applications/order/webapp/ordermgr/images/js/ConvertUom.js   
(with props)
Modified:
    
ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml
    ofbiz/trunk/applications/order/servicedef/secas.xml
    ofbiz/trunk/applications/order/servicedef/services.xml
    ofbiz/trunk/applications/product/config/ProductUiLabels.xml
    
ofbiz/trunk/applications/product/script/org/ofbiz/shipment/receipt/ShipmentReceiptServices.xml
    ofbiz/trunk/applications/product/servicedef/services_shipment.xml
    
ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/inventory/ReceiveInventory.groovy
    ofbiz/trunk/applications/product/webapp/facility/WEB-INF/controller.xml
    
ofbiz/trunk/applications/product/webapp/facility/inventory/receiveInventory.ftl
    ofbiz/trunk/applications/product/widget/facility/FacilityScreens.xml

Modified: 
ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml?rev=896010&r1=896009&r2=896010&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml 
(original)
+++ 
ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml 
Tue Jan  5 11:50:19 2010
@@ -1189,20 +1189,26 @@
                 </entity-and>
                 <iterate entry="supplierProduct" list="supplierProducts">
                     <now-timestamp field="nowTimestamp"/>
-                    <if>
-                        <condition>
-                            <if-compare-field field="parameters.unitCost" 
to-field="supplierProduct.lastPrice" operator="not-equals" type="BigDecimal"/>
-                        </condition>
-                        <then>
-                            <make-value value-field="newSupplierProduct" 
entity-name="SupplierProduct"/>
+                    <if-not-empty field="parameters.orderCurrencyUnitPrice">
+                        <if-compare-field 
field="parameters.orderCurrencyUnitPrice" operator="not-equals" 
to-field="supplierProduct.lastPrice" type="BigDecimal">
                             <clone-value value-field="supplierProduct" 
new-value-field="newSupplierProduct"/>
-                            <set from-field="nowTimestamp" 
field="newSupplierProduct.availableFromDate"/>
-                            <set from-field="parameters.unitCost" 
field="newSupplierProduct.lastPrice" type="BigDecimal"/>
+                            <set field="newSupplierProduct.availableFromDate" 
from-field="nowTimestamp"/>
+                            <set field="newSupplierProduct.lastPrice" 
from-field="parameters.orderCurrencyUnitPrice" type="BigDecimal"/>
                             <create-value value-field="newSupplierProduct"/>
-                            <set from-field="nowTimestamp" 
field="supplierProduct.availableThruDate"/>
+                            <set field="supplierProduct.availableThruDate" 
from-field="nowTimestamp"/>
                             <store-value value-field="supplierProduct"/>
-                        </then>
-                    </if>
+                        </if-compare-field>
+                    <else>
+                        <if-compare-field field="parameters.unitCost" 
operator="not-equals" to-field="supplierProduct.lastPrice" type="BigDecimal">
+                            <clone-value value-field="supplierProduct" 
new-value-field="newSupplierProduct"/>
+                            <set field="newSupplierProduct.availableFromDate" 
from-field="nowTimestamp"/>
+                            <set field="newSupplierProduct.lastPrice" 
from-field="parameters.unitCost" type="BigDecimal"/>
+                            <create-value value-field="newSupplierProduct"/>
+                            <set field="supplierProduct.availableThruDate" 
from-field="nowTimestamp"/>
+                            <store-value value-field="supplierProduct"/>
+                        </if-compare-field>
+                    </else>
+                    </if-not-empty>
                 </iterate>
             </then>
             <else>

Modified: ofbiz/trunk/applications/order/servicedef/secas.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/secas.xml?rev=896010&r1=896009&r2=896010&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/secas.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/secas.xml Tue Jan  5 11:50:19 2010
@@ -32,27 +32,25 @@
     <eca service="storeOrder" event="return">
         <action service="balanceOrderItemsWithNegativeReservations" 
mode="sync"/>
     </eca>
-    <!--
+
     <eca service="storeOrder" event="return">
         <condition field-name="orderTypeId" operator="equals" 
value="PURCHASE_ORDER"/>
         <action service="setUnitPriceAsLastPrice" mode="sync"/>
     </eca>
-    -->
+
     <eca service="storeOrder" event="return">
         <action service="setOrderReservationPriority" mode="sync"/>
     </eca>
-    <!--
+
     <eca service="updateOrderItems" event="commit">
         <condition field-name="orderTypeId" operator="equals" 
value="PURCHASE_ORDER"/>
         <action service="setUnitPriceAsLastPrice" mode="sync"/>
     </eca>
-    -->
+
     <eca service="receiveInventoryProduct" event="commit">
         <condition field-name="facilityId" operator="is-not-empty"/>
         <action service="addProductsBackToCategory" mode="sync"/>
-        <!--
         <action service="setUnitPriceAsLastPrice" mode="sync"/>
-        -->
     </eca>
     <eca service="receiveInventoryProduct" event="commit">
         <condition field-name="facilityId" operator="is-not-empty"/>

Modified: ofbiz/trunk/applications/order/servicedef/services.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?rev=896010&r1=896009&r2=896010&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services.xml Tue Jan  5 11:50:19 
2010
@@ -971,6 +971,7 @@
         <attribute name="unitCost" mode="IN" type="String" optional="true"/>
         <attribute name="itemPriceMap" type="Map" mode="IN" 
string-map-prefix="ipm_" optional="true"/>
         <attribute name="overridePriceMap" type="Map" mode="IN" 
string-map-prefix="opm_" optional="true"/>
+        <attribute name="orderCurrencyUnitPrice" type="String" mode="IN" 
optional="true"/>
    </service>
 
     <service name="cancelAllBackOrders" engine="simple"

Added: ofbiz/trunk/applications/order/webapp/ordermgr/images/js/ConvertUom.js
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/images/js/ConvertUom.js?rev=896010&view=auto
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/images/js/ConvertUom.js 
(added)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/images/js/ConvertUom.js Tue 
Jan  5 11:50:19 2010
@@ -0,0 +1,15 @@
+function getConvertedPrice(element, uomId, uomIdTo, rowCount, 
orderCurrencyUnitPrice, unitCost) {
+    var request = $F('getConvertedPrice');
+    new Ajax.Request(request, {
+        asynchronous: false,
+        onSuccess: function(transport) {
+            var data = transport.responseText.evalJSON(true);
+            if (data.convertedValue && confirm($('alertMessage').value)) {
+                $('unitCost_'+rowCount).value = data.convertedValue;
+            } else {
+                $('orderCurrencyUnitPrice_'+rowCount).value = 
orderCurrencyUnitPrice;
+                $('unitCost_'+rowCount).value = unitCost;
+            }
+        }, parameters: { uomId : uomId, uomIdTo : uomIdTo, originalValue : 
element.value }
+    });
+}
\ No newline at end of file

Propchange: 
ofbiz/trunk/applications/order/webapp/ordermgr/images/js/ConvertUom.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ofbiz/trunk/applications/order/webapp/ordermgr/images/js/ConvertUom.js
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: 
ofbiz/trunk/applications/order/webapp/ordermgr/images/js/ConvertUom.js
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/trunk/applications/product/config/ProductUiLabels.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/config/ProductUiLabels.xml?rev=896010&r1=896009&r2=896010&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/config/ProductUiLabels.xml (original)
+++ ofbiz/trunk/applications/product/config/ProductUiLabels.xml Tue Jan  5 
11:50:19 2010
@@ -8652,6 +8652,9 @@
         </value>
         <value 
xml:lang="zh">只有重新创建产品目录,才能修改。</value>
     </property>
+    <property key="ProductChangePerUnitPrice">
+        <value xml:lang="en">If you change Per Unit Price then it will also 
get update in Supplier product last price and order item price, would you like 
to continue.</value>
+    </property>
     <property key="ProductChannel">
         <value xml:lang="de">Verkaufskanal</value>
         <value xml:lang="en">Channel</value>
@@ -15520,6 +15523,12 @@
         <value xml:lang="th">ราคาต่อหน่วย</value>
         <value xml:lang="zh">每单价</value>
     </property>
+    <property key="ProductPerUnitPriceFacility">
+        <value xml:lang="en">Per Unit Price (Facility)</value>
+    </property>
+    <property key="ProductPerUnitPriceOrder">
+        <value xml:lang="en">Per Unit Price (Order)</value>
+    </property>
     <property key="ProductPercent">
         <value xml:lang="de">Prozent</value>
         <value xml:lang="en">percent</value>

Modified: 
ofbiz/trunk/applications/product/script/org/ofbiz/shipment/receipt/ShipmentReceiptServices.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/script/org/ofbiz/shipment/receipt/ShipmentReceiptServices.xml?rev=896010&r1=896009&r2=896010&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/product/script/org/ofbiz/shipment/receipt/ShipmentReceiptServices.xml
 (original)
+++ 
ofbiz/trunk/applications/product/script/org/ofbiz/shipment/receipt/ShipmentReceiptServices.xml
 Tue Jan  5 11:50:19 2010
@@ -415,21 +415,18 @@
 
     <simple-method method-name="updateIssuanceShipmentAndPoOnReceiveInventory" 
short-description="Update issuance, shipment and order items if quantity 
received is higher than quantity on purchase order">
         <entity-one value-field="orderItem" entity-name="OrderItem"/>
-        <!-- TODO: this is disabled because it doesn't consider different 
currencies between orders and inventory
-        <set field="unitCost" from-field="parameters.unitCost" 
type="BigDecimal"/>
-        <if>
-            <condition>
-                <and>
-                    <not><if-empty field="unitCost"/></not>
-                    <if-compare-field field="unitCost" operator="not-equals" 
to-field="orderItem.unitPrice" type="BigDecimal"/>
-                </and>
-            </condition>
-            <then>
-                <set field="orderItem.unitPrice" from-field="unitCost"/>
+        <if-not-empty field="parameters.orderCurrencyUnitPrice">
+            <if-compare-field field="parameters.orderCurrencyUnitPrice" 
operator="not-equals" to-field="orderItem.unitPrice" type="BigDecimal">
+                <set field="orderItem.unitPrice" 
from-field="parameters.orderCurrencyUnitPrice" type="BigDecimal"/>
                 <store-value value-field="orderItem"/>
-            </then>
-        </if>
-        -->
+            </if-compare-field>
+        <else>
+            <if-compare-field field="parameters.unitCost" 
operator="not-equals" to-field="orderItem.unitPrice" type="BigDecimal">
+                <set field="orderItem.unitPrice" 
from-field="parameters.unitCost" type="BigDecimal"/>
+                <store-value value-field="orderItem"/>
+            </if-compare-field>
+        </else>
+        </if-not-empty>
         <call-simple-method method-name="getReceivedQuantityForOrderItem"/>
         <if-compare-field field="orderItem.quantity" operator="less" 
to-field="receivedQuantity" type="BigDecimal">
             <set field="orderItem.quantity" from-field="receivedQuantity"/>

Modified: ofbiz/trunk/applications/product/servicedef/services_shipment.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services_shipment.xml?rev=896010&r1=896009&r2=896010&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/servicedef/services_shipment.xml (original)
+++ ofbiz/trunk/applications/product/servicedef/services_shipment.xml Tue Jan  
5 11:50:19 2010
@@ -701,6 +701,7 @@
         <attribute name="priorityOrderItemSeqId" type="String" mode="IN" 
optional="true"/>
         <attribute name="currentInventoryItemId" type="String" mode="IN" 
optional="true"><!-- allow this to be passed in to update an existing 
InventoryItem, and all else is the same; if not passed in a new one will be 
created --></attribute>
         <attribute name="inventoryItemId" type="String" mode="OUT" 
optional="true"></attribute>
+        <attribute name="orderCurrencyUnitPrice" type="String" mode="IN" 
optional="true"/>
         <override name="quantityAccepted" optional="false"/>
         <override name="quantityRejected" optional="false"/>
         <override name="inventoryItemTypeId" optional="false"/>
@@ -890,5 +891,6 @@
         <attribute name="shipmentId" type="String" mode="IN" optional="true"/>
         <attribute name="shipmentItemSeqId" type="String" mode="IN" 
optional="true"/>
         <attribute name="unitCost" type="String" mode="IN" optional="true"/>
+        <attribute name="orderCurrencyUnitPrice" type="String" mode="IN" 
optional="true"/>
     </service>
 </services>

Modified: 
ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/inventory/ReceiveInventory.groovy
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/inventory/ReceiveInventory.groovy?rev=896010&r1=896009&r2=896010&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/inventory/ReceiveInventory.groovy
 (original)
+++ 
ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/inventory/ReceiveInventory.groovy
 Tue Jan  5 11:50:19 2010
@@ -130,12 +130,14 @@
     }
 }
 // convert the unit prices to that of the facility owner's currency
+orderCurrencyUnitPriceMap = [:];
 if (purchaseOrder && facility) {
     if (ownerAcctgPref) {
         ownerCurrencyUomId = ownerAcctgPref.baseCurrencyUomId;
         orderCurrencyUomId = purchaseOrder.currencyUom;
         if (!orderCurrencyUomId.equals(ownerCurrencyUomId)) {
             purchaseOrderItems.each { item ->
+            orderCurrencyUnitPriceMap.(item.orderItemSeqId) = item.unitPrice;
                 serviceResults = dispatcher.runSync("convertUom",
                         [uomId : orderCurrencyUomId, uomIdTo : 
ownerCurrencyUomId, originalValue : item.unitPrice]);
                 if (ServiceUtil.isError(serviceResults)) {
@@ -152,10 +154,13 @@
 
         // put the pref currency in the map for display and form use
         context.currencyUomId = ownerCurrencyUomId;
+        context.orderCurrencyUomId = orderCurrencyUomId;
     } else {
         request.setAttribute("_ERROR_MESSAGE_", "Either no owner party was set 
for this facility, or no accounting preferences were set for this owner 
party.");
     }
 }
+context.orderCurrencyUnitPriceMap = orderCurrencyUnitPriceMap;
+
 receivedQuantities = [:];
 salesOrderItems = [:];
 if (purchaseOrderItems) {

Modified: 
ofbiz/trunk/applications/product/webapp/facility/WEB-INF/controller.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/facility/WEB-INF/controller.xml?rev=896010&r1=896009&r2=896010&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/facility/WEB-INF/controller.xml 
(original)
+++ ofbiz/trunk/applications/product/webapp/facility/WEB-INF/controller.xml Tue 
Jan  5 11:50:19 2010
@@ -1310,7 +1310,12 @@
         <response name="success" type="view" 
value="EditShipmentGatewayConfigType"/>
         <response name="error" type="view" 
value="EditShipmentGatewayConfigType"/>
     </request-map>
-    
+    <request-map uri="getConvertedPrice">
+        <security https="true" auth="true"/>
+        <event type="service" invoke="convertUom"/>
+        <response name="success" type="request" value="json"/>
+        <response name="error" type="request" value="json"/>
+    </request-map>
     <!-- ================ Lookup Requests ================= -->
     <request-map uri="LookupOrderHeaderAndShipInfo"><security https="true" 
auth="true"/><response name="success" type="view" 
value="LookupOrderHeaderAndShipInfo"/></request-map>
     <request-map uri="LookupPurchaseOrderHeaderAndShipInfo"><security 
https="true" auth="true"/><response name="success" type="view" 
value="LookupPurchaseOrderHeaderAndShipInfo"/></request-map>

Modified: 
ofbiz/trunk/applications/product/webapp/facility/inventory/receiveInventory.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/facility/inventory/receiveInventory.ftl?rev=896010&r1=896009&r2=896010&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/product/webapp/facility/inventory/receiveInventory.ftl 
(original)
+++ 
ofbiz/trunk/applications/product/webapp/facility/inventory/receiveInventory.ftl 
Tue Jan  5 11:50:19 2010
@@ -299,6 +299,8 @@
 
         <#-- Multi-Item PO Receiving -->
         <#elseif requestParameters.initialSelected?exists && 
purchaseOrder?has_content>
+          <input type="hidden" id="getConvertedPrice" value="<@ofbizUrl 
secure="${request.isSecure()?string}">getConvertedPrice"</@ofbizUrl> />
+          <input type="hidden" id="alertMessage" 
value="${uiLabelMap.ProductChangePerUnitPrice}" />
           <form method="post" 
action="<@ofbizUrl>receiveInventoryProduct</@ofbizUrl>" name="selectAllForm">
             <#-- general request fields -->
             <input type="hidden" name="facilityId" 
value="${requestParameters.facilityId?if_exists}"/>
@@ -433,12 +435,27 @@
                           <td>&nbsp;</td>
                           <td 
align="right">${uiLabelMap.ProductFacilityOwner}:</td>
                           <td align="right"><input type="text" 
name="ownerPartyId_o_${rowCount}" size="20" maxlength="20" 
value="${facility.ownerPartyId}"/></td>
-                          <td align="right">${uiLabelMap.ProductPerUnitPrice} 
:</td>
-                          <td align="right">
-                            <input type="hidden" 
name="currencyUomId_o_${rowCount}" value="${currencyUomId?if_exists}"/>
-                            <input type="text" name="unitCost_o_${rowCount}" 
value="${itemCost}" size="6" maxlength="20"/>
-                            ${currencyUomId?if_exists}
-                          </td>
+                          <#if currencyUomId != orderCurrencyUomId>
+                            <td>${uiLabelMap.ProductPerUnitPriceOrder}:</td>
+                            <td>
+                              <input type="hidden" 
name="orderCurrencyUomId_o_${rowCount}" value="${orderCurrencyUomId?if_exists}" 
/>
+                              <input type="text" 
id="orderCurrencyUnitPrice_${rowCount}" 
name="orderCurrencyUnitPrice_o_${rowCount}" 
value="${orderCurrencyUnitPriceMap[orderItem.orderItemSeqId]}" 
onchange="javascript:getConvertedPrice(orderCurrencyUnitPrice_${rowCount}, 
'${orderCurrencyUomId}', '${currencyUomId}', '${rowCount}', 
'${orderCurrencyUnitPriceMap[orderItem.orderItemSeqId]}', '${itemCost}');" 
size="6" maxlength="20" />
+                              ${orderCurrencyUomId?if_exists}
+                            </td>
+                            <td>${uiLabelMap.ProductPerUnitPriceFacility}:</td>
+                            <td>
+                              <input type="hidden" 
name="currencyUomId_o_${rowCount}" value="${currencyUomId?if_exists}" />
+                              <input type="text" id="unitCost_${rowCount}" 
name="unitCost_o_${rowCount}" value="${itemCost}" readonly size="6" 
maxlength="20" />
+                              ${currencyUomId?if_exists}
+                            </td>
+                          <#else>
+                            <td>${uiLabelMap.ProductPerUnitPrice}:</td>
+                            <td align="right">
+                              <input type="hidden" 
name="currencyUomId_o_${rowCount}" value="${currencyUomId?if_exists}" />
+                              <input type="text" name="unitCost_o_${rowCount}" 
value="${itemCost}" size="6" maxlength="20" />
+                              ${currencyUomId?if_exists}
+                            </td>
+                          </#if>
                         </tr>
                       </table>
                     </td>

Modified: ofbiz/trunk/applications/product/widget/facility/FacilityScreens.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/widget/facility/FacilityScreens.xml?rev=896010&r1=896009&r2=896010&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/widget/facility/FacilityScreens.xml 
(original)
+++ ofbiz/trunk/applications/product/widget/facility/FacilityScreens.xml Tue 
Jan  5 11:50:19 2010
@@ -1065,6 +1065,7 @@
                 <entity-one entity-name="Facility" value-field="facility"/>
                 <property-map resource="ProductUiLabels" 
map-name="uiLabelMap"/>
                 <set field="title" 
value="${uiLabelMap.ProductReceiveInventory}"/>
+                <set field="layoutSettings.javaScripts[+0]" 
value="/ordermgr/images/js/ConvertUom.js" global="true"/>
             </actions>
             <widgets>
                 <decorator-screen name="CommonFacilityDecorator" 
location="${parameters.commonFacilityDecoratorLocation}">


Reply via email to