svn commit: r592455 - in /ofbiz/trunk/applications: order/src/org/ofbiz/order/shoppingcart/ product/data/ product/entitydef/ product/servicedef/ product/src/org/ofbiz/product/price/ product/webapp/catalog/product/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r592455 - in /ofbiz/trunk/applications: order/src/org/ofbiz/order/shoppingcart/ product/data/ product/entitydef/ product/servicedef/ product/src/org/ofbiz/product/price/ product/webapp/catalog/product/

jacopoc
Author: jacopoc
Date: Tue Nov  6 07:28:19 2007
New Revision: 592455

URL: http://svn.apache.org/viewvc?rev=592455&view=rev
Log:
Implemented support (first version) for the definition of custom services to calculate the unit price of a product.
Added new optional field to the calculateProductPrice service: amount (this is the amount specified for the products that require an amount during order entry).

Modified:
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
    ofbiz/trunk/applications/product/data/ProductTypeData.xml
    ofbiz/trunk/applications/product/entitydef/entitymodel.xml
    ofbiz/trunk/applications/product/servicedef/services_pricepromo.xml
    ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java
    ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java?rev=592455&r1=592454&r2=592455&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java Tue Nov  6 07:28:19 2007
@@ -1028,6 +1028,7 @@
                     priceContext.put("partyId", partyId);
                 }
                 priceContext.put("quantity", new Double(this.getQuantity()));
+                priceContext.put("amount", new Double(this.getSelectedAmount()));
                 priceContext.put("product", this.getProduct());
                 if (cart.getOrderType().equals("PURCHASE_ORDER")) {
                     Map priceResult = dispatcher.runSync("calculatePurchasePrice", priceContext);

Modified: ofbiz/trunk/applications/product/data/ProductTypeData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/data/ProductTypeData.xml?rev=592455&r1=592454&r2=592455&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/data/ProductTypeData.xml (original)
+++ ofbiz/trunk/applications/product/data/ProductTypeData.xml Tue Nov  6 07:28:19 2007
@@ -400,6 +400,8 @@
     <ProductPriceActionType description="Promo Amount Override" productPriceActionTypeId="PRICE_PFLAT"/>
     <ProductPriceActionType description="Wholesale Amount Override" productPriceActionTypeId="PRICE_WFLAT"/>
 
+    <CustomMethodType customMethodTypeId="PRICE_FORMULA" description="Formula for calculating the unit price of a product"/>
+
     <ProductStoreGroup productStoreGroupName="Not Applicable" description="Not Applicable" productStoreGroupId="_NA_" productStoreGroupTypeId="" primaryParentGroupId=""/>
 
     <ProductType description="Fixed Asset Usage" isPhysical="Y" isDigital="N" hasTable="N" parentTypeId="" productTypeId="ASSET_USAGE"/>

Modified: ofbiz/trunk/applications/product/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/entitydef/entitymodel.xml?rev=592455&r1=592454&r2=592455&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/product/entitydef/entitymodel.xml Tue Nov  6 07:28:19 2007
@@ -1725,6 +1725,7 @@
       <field name="thruDate" type="date-time"></field>
       <field name="price" type="currency-precise"></field>
       <field name="termUomId" type="id"><description>mainly used for recurring and usage prices to specify a time/freq measure, or a usage unit measure (bits, minutes, etc)</description></field>
+      <field name="customPriceCalcService" type="id"><description>used to specify an external service for the price calculation</description></field>
       <field name="createdDate" type="date-time"></field>
       <field name="createdByUserLogin" type="id-vlong"></field>
       <field name="lastModifiedDate" type="date-time"></field>
@@ -1752,6 +1753,9 @@
       </relation>
       <relation type="one" fk-name="PROD_PRICE_PSTG" rel-entity-name="ProductStoreGroup">
         <key-map field-name="productStoreGroupId"/>
+      </relation>
+      <relation type="one" fk-name="PROD_PRICE_CMET" rel-entity-name="CustomMethod">
+        <key-map field-name="customPriceCalcService" rel-field-name="customMethodId"/>
       </relation>
       <relation type="one" fk-name="PROD_PRICE_CBUL" title="CreatedBy" rel-entity-name="UserLogin">
         <key-map field-name="createdByUserLogin" rel-field-name="userLoginId"/>

Modified: ofbiz/trunk/applications/product/servicedef/services_pricepromo.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services_pricepromo.xml?rev=592455&r1=592454&r2=592455&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/servicedef/services_pricepromo.xml (original)
+++ ofbiz/trunk/applications/product/servicedef/services_pricepromo.xml Tue Nov  6 07:28:19 2007
@@ -36,6 +36,7 @@
         <attribute name="productStoreGroupId" type="String" mode="IN" optional="true"/>
         <attribute name="agreementId" type="String" mode="IN" optional="true"/>
         <attribute name="quantity" type="Double" mode="IN" optional="true"/>
+        <attribute name="amount" type="Double" mode="IN" optional="true"/>
         <attribute name="currencyUomId" type="String" mode="IN" optional="true"/>
         <attribute name="productPricePurposeId" type="String" mode="IN" optional="true"><!-- defaults to PURCHASE --></attribute>
         <attribute name="termUomId" type="String" mode="IN" optional="true"><!-- if specified ProductPrice records will be filtered by this, ensures for purposes like recurring prices that only the recurring term desired is taken into consideration --></attribute>

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java?rev=592455&r1=592454&r2=592455&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java Tue Nov  6 07:28:19 2007
@@ -195,7 +195,9 @@
         Double quantityDbl = (Double) context.get("quantity");
         if (quantityDbl == null) quantityDbl = new Double(1.0);
         double quantity = quantityDbl.doubleValue();
-        
+
+        Double amountDbl = (Double) context.get("amount");
+
         List productPriceEcList = FastList.newInstance();
         productPriceEcList.add(new EntityExpr("productId", EntityOperator.EQUALS, productId));
         // this funny statement is for backward compatibility purposes; the productPricePurposeId is a new pk field on the ProductPrice entity and in order databases may not be populated, until the pk is updated and such; this will ease the transition somewhat
@@ -480,9 +482,42 @@
 
         boolean validPriceFound = false;
         double defaultPrice = 0;
-        if (defaultPriceValue != null && defaultPriceValue.get("price") != null) {
-            defaultPrice = defaultPriceValue.getDouble("price").doubleValue();
-            validPriceFound = true;
+        List orderItemPriceInfos = FastList.newInstance();
+        List additionalAdjustments = FastList.newInstance();
+        if (defaultPriceValue != null) {
+            // If a price calc formula (service) is specified, then use it to get the unit price
+            if (UtilValidate.isNotEmpty(defaultPriceValue.getString("customPriceCalcService"))) {
+                GenericValue customMethod = null;
+                try {
+                    customMethod = defaultPriceValue.getRelatedOne("CustomMethod");
+                } catch(GenericEntityException gee) {
+                    Debug.logError(gee, "An error occurred while getting the customPriceCalcService", module);
+                }
+                if (UtilValidate.isNotEmpty(customMethod) && UtilValidate.isNotEmpty(customMethod.getString("customMethodName"))) {
+                    Map inMap = UtilMisc.toMap("userLogin", (GenericValue) context.get("userLogin"), "product", product);
+                    inMap.put("currencyUomId", currencyUomId);
+                    inMap.put("quantity", quantityDbl);
+                    inMap.put("amount", amountDbl);
+                    try {
+                        Map outMap = dispatcher.runSync(customMethod.getString("customMethodName"), inMap);
+                        if (!ServiceUtil.isError(outMap)) {
+                            Double calculatedDefaultPrice = (Double)outMap.get("price");
+                            orderItemPriceInfos = (List)outMap.get("orderItemPriceInfos");
+                            //additionalAdjustments = (List)outMap.get("additionalAdjustments");
+                            if (UtilValidate.isNotEmpty(calculatedDefaultPrice)) {
+                                defaultPrice = calculatedDefaultPrice.doubleValue();
+                                validPriceFound = true;
+                            }
+                        }
+                    } catch(GenericServiceException gse) {
+                        Debug.logError(gse, "An error occurred while running the customPriceCalcService [" + customMethod.getString("customMethodName") + "]", module);
+                    }
+                }
+            }
+            if (!validPriceFound && defaultPriceValue.get("price") != null) {
+                defaultPrice = defaultPriceValue.getDouble("price").doubleValue();
+                validPriceFound = true;
+            }
         }
 
         Double listPriceDbl = listPriceValue != null ? listPriceValue.getDouble("price") : null;
@@ -512,7 +547,7 @@
             result.put("specialPromoPrice", specialPromoPriceValue != null ? specialPromoPriceValue.getDouble("price") : null);
             result.put("validPriceFound", new Boolean(validPriceFound));
             result.put("isSale", Boolean.FALSE);
-            result.put("orderItemPriceInfos", FastList.newInstance());
+            result.put("orderItemPriceInfos", orderItemPriceInfos);
 
             Map errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore,
                     checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher);

Modified: ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml?rev=592455&r1=592454&r2=592455&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml Tue Nov  6 07:28:19 2007
@@ -247,6 +247,13 @@
                 </entity-options>
             </drop-down>
         </field>
+        <field name="customPriceCalcService">
+            <drop-down allow-empty="true">
+                <entity-options entity-name="CustomMethod" key-field-name="customMethodId" description="${description}">
+                    <entity-constraint name="customMethodTypeId" operator="equals" value="PRICE_FORMULA"/>
+                </entity-options>
+            </drop-down>
+        </field>
         <field name="submitButton" title="${uiLabelMap.CommonCreate}" widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
     <form name="UpdateProductPrice" type="list" target="updateProductPrice" title="" list-name="productPrices">
@@ -264,6 +271,13 @@
                     <entity-constraint name="uomTypeId" operator="not-equals" value="CURRENCY_MEASURE"/>
                     <entity-order-by field-name="typeDescription"/>
                     <entity-order-by field-name="uomId"/>
+                </entity-options>
+            </drop-down>
+        </field>
+        <field name="customPriceCalcService">
+            <drop-down allow-empty="true">
+                <entity-options entity-name="CustomMethod" key-field-name="customMethodId" description="${description}">
+                    <entity-constraint name="customMethodTypeId" operator="equals" value="PRICE_FORMULA"/>
                 </entity-options>
             </drop-down>
         </field>