[OFBiz] SVN: r6967 - in trunk/applications/product: entitydef script/org/ofbiz/product/inventory servicedef
jacopo@svn.ofbiz.org
jacopo at svn.ofbiz.org
Fri Mar 10 11:29:39 CST 2006
Author: jacopo
Date: 2006-03-10 11:29:27 -0600 (Fri, 10 Mar 2006)
New Revision: 6967
Modified:
trunk/applications/product/entitydef/eecas.xml
trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml
trunk/applications/product/servicedef/services_facility.xml
Log:
Implemented new service (triggered by an eca rule every time an InventoryItem is created) that checks if the following fields are properly populated:
facilityId
ownerPartyId
unitCost
currencyUomId
if they are empty, the service tries to set default values for them; ifdefault values are not found, it returns an error message.
PS: at the moment the eca rule is commented so the service will not run by default; uncomment it if you want to make some tests.
Modified: trunk/applications/product/entitydef/eecas.xml
===================================================================
--- trunk/applications/product/entitydef/eecas.xml 2006-03-10 06:26:27 UTC (rev 6966)
+++ trunk/applications/product/entitydef/eecas.xml 2006-03-10 17:29:27 UTC (rev 6967)
@@ -25,7 +25,7 @@
xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/entity-eca.xsd">
<!-- Product Keyword Indexing ECAs -->
<eca entity="Product" operation="create-store" event="return">
- <condition field-name="autoCreateKeywords" operator="not-equals" value="N"/>
+ <condition field-name="autoCreateKeywords" operator="equals" value="Y"/>
<action service="indexProductKeywords" mode="sync" value-attr="productInstance"/>
</eca>
<eca entity="ProductAttribute" operation="create-store" event="return">
@@ -45,8 +45,11 @@
<action service="checkProductInventoryDiscontinuation" mode="async"/>
</eca>
<!-- Just in case an InventoryItem is ever created with ATP/QOH values, catch and handle that -->
+ <!-- Then verify that all the needed InventoryItem fields are properly populated, if not, fill it
+ with default values; if default values are not found, return an error. -->
<eca entity="InventoryItem" operation="create" event="return">
<action service="createInventoryItemCheckSetAtpQoh" mode="sync"/>
+ <!--<action service="inventoryItemCheckSetDefaultValues" mode="sync"/>-->
</eca>
<!-- The InventoryItemDetail entity should never be updated/stored or deleted/removed, but we'll catch those too anyway... -->
<eca entity="InventoryItemDetail" operation="create-store-remove" event="return">
Modified: trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml
===================================================================
--- trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml 2006-03-10 06:26:27 UTC (rev 6966)
+++ trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml 2006-03-10 17:29:27 UTC (rev 6967)
@@ -61,6 +61,83 @@
</then>
</if>
</simple-method>
+ <simple-method method-name="inventoryItemCheckSetDefaultValues" short-description="Check and, if empty, fills with default values ownerPartyId, currencyUomId, unitCost" login-required="false">
+ <entity-one entity-name="InventoryItem" value-name="inventoryItem"/>
+ <!-- if all the inventoryItem's fields are already filled, return with success -->
+ <if>
+ <condition>
+ <and>
+ <not><if-empty field-name="inventoryItem.facilityId"/></not>
+ <not><if-empty field-name="inventoryItem.ownerPartyId"/></not>
+ <not><if-empty field-name="inventoryItem.currencyUomId"/></not>
+ <not><if-empty field-name="inventoryItem.unitCost"/></not>
+ </and>
+ </condition>
+ <then>
+ <return/>
+ </then>
+ </if>
+ <if-empty field-name="inventoryItem.facilityId">
+ <add-error>
+ <fail-message message="Error: you cannot create inventory items with no facility id."/>
+ </add-error>
+ <check-errors/>
+ </if-empty>
+ <!-- if inventoryItem's ownerPartyId is empty, get the ownerPartyId from the facility -->
+ <if-empty field-name="inventoryItem.ownerPartyId">
+ <get-related-one value-name="inventoryItem" relation-name="Facility" to-value-name="facility"/>
+ <set field="inventoryItem.ownerPartyId" from-field="facility.ownerPartyId"/>
+ <!-- if inventoryItem's ownerPartyId is still empty, return an error message -->
+ <if-empty field-name="inventoryItem.ownerPartyId">
+ <add-error>
+ <fail-message message="Error: you cannot create inventory items with no ownerPartyId."/>
+ </add-error>
+ <check-errors/>
+ </if-empty>
+ </if-empty>
+ <!-- if inventoryItem's currencyUomId is empty, get the currencyUomId
+ from the party accounting preferences of the owner of the inventory item -->
+ <if-empty field-name="inventoryItem.currencyUomId">
+ <entity-one entity-name="PartyAcctgPreference" value-name="accPref">
+ <field-map field-name="partyId" env-name="inventoryItem.ownerPartyId"/>
+ </entity-one>
+ <set field="inventoryItem.currencyUomId" from-field="accPref.baseCurrencyUomId"/>
+ <!-- if inventoryItem's currencyUomId is still empty, return an error message -->
+ <if-empty field-name="inventoryItem.currencyUomId">
+ <add-error>
+ <fail-message message="Error: you cannot create inventory items with no currencyUomId."/>
+ </add-error>
+ <check-errors/>
+ </if-empty>
+ </if-empty>
+ <!-- if inventoryItem's unitCost is empty, get the product's standard
+ cost by calling the getProductCost service -->
+ <if-empty field-name="inventoryItem.unitCost">
+ <set from-field="inventoryItem.productId" field="inputMap.productId"/>
+ <set from-field="inventoryItem.currencyUomId" field="inputMap.currencyUomId"/>
+ <set value="EST_STD" field="inputMap.costComponentTypePrefix"/> <!-- TODO: create a new service getProductStdCost that calls getProductCost -->
+ <call-service service-name="getProductCost" in-map-name="inputMap">
+ <result-to-field result-name="productCost" field-name="inventoryItem.unitCost"/>
+ </call-service>
+ <!-- TODO: getProductCost returns 0 even if no std costs are found -->
+ <!-- if inventoryItem's unitCost is still empty, or negative return an error message -->
+ <!-- if you don't want inventory item with unitCost = 0, change the operator
+ attribute from "less" to "less-equals".
+ -->
+ <if-compare field-name="inventoryItem.unitCost" operator="less" value="0" type="Double">
+ <add-error>
+ <fail-message message="Error: you cannot create inventory items with a negative unitCost."/>
+ </add-error>
+ </if-compare>
+ <if-empty field-name="inventoryItem.unitCost">
+ <add-error>
+ <fail-message message="Error: you cannot create inventory items with no unitCost."/>
+ </add-error>
+ </if-empty>
+ <check-errors/>
+ </if-empty>
+ <store-value value-name="inventoryItem"/>
+ </simple-method>
<simple-method method-name="updateInventoryItem" short-description="Update an InventoryItem">
<check-permission permission="CATALOG" action="_UPDATE">
Modified: trunk/applications/product/servicedef/services_facility.xml
===================================================================
--- trunk/applications/product/servicedef/services_facility.xml 2006-03-10 06:26:27 UTC (rev 6966)
+++ trunk/applications/product/servicedef/services_facility.xml 2006-03-10 17:29:27 UTC (rev 6967)
@@ -38,7 +38,7 @@
</auto-attributes>
<override name="inventoryItemTypeId" optional="false"/>
<override name="productId" optional="false"/>
- <override name="unitCost" optional="false"/>
+ <override name="facilityId" optional="false"/>
</service>
<service name="createInventoryItemCheckSetAtpQoh" engine="simple"
location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="createInventoryItemCheckSetAtpQoh" auth="false">
@@ -63,6 +63,11 @@
<description>Check Product Inventory Discontinuation</description>
<attribute name="productId" mode="IN" optional="false" type="String"/>
</service>
+ <service name="inventoryItemCheckSetDefaultValues" default-entity-name="InventoryItem" engine="simple"
+ location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="inventoryItemCheckSetDefaultValues" auth="false">
+ <description>Check and, if empty, fills with default values ownerPartyId, currencyUomId, unitCost</description>
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ </service>
<service name="createInventoryItemDetail" default-entity-name="InventoryItemDetail" engine="simple"
location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="createInventoryItemDetail" auth="true">
More information about the Svn
mailing list