[ofbiz-framework] branch trunk updated (390708f -> 1558f23)

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

[ofbiz-framework] branch trunk updated (390708f -> 1558f23)

nmalin
This is an automated email from the ASF dual-hosted git repository.

nmalin pushed a change to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git.


    from 390708f  Improved: increases tasks.checkstyleMain.maxErrors
     new 7968f62  Improved: Convert InventoryIssueServices.xml mini lang to groovy
     new b862632  Fixed: Convert InventoryIssueServices.xml mini lang to groovy (OFBIZ-11591)
     new 1558f23  Fixed: Remove unnecessary semi-column

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../inventory/InventoryIssueServices.groovy        | 233 +++++++++++++++++
 .../shipment/shipment/ShipmentServices.groovy      |  34 +--
 .../product/inventory/InventoryIssueServices.xml   | 279 ---------------------
 .../product/servicedef/services_facility.xml       |   8 +-
 .../ofbiz/service/engine/GroovyBaseScript.groovy   |   6 +-
 5 files changed, 257 insertions(+), 303 deletions(-)
 create mode 100644 applications/product/groovyScripts/product/inventory/InventoryIssueServices.groovy
 delete mode 100644 applications/product/minilang/product/inventory/InventoryIssueServices.xml

Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] 01/03: Improved: Convert InventoryIssueServices.xml mini lang to groovy

nmalin
This is an automated email from the ASF dual-hosted git repository.

nmalin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit 7968f62e51b9f710eec880c490cd4e3339f027b1
Author: Sebastian Berg <[hidden email]>
AuthorDate: Fri Apr 17 11:40:47 2020 +0200

    Improved: Convert InventoryIssueServices.xml mini lang to groovy
   
    (OFBIZ-11591)
---
 .../inventory/InventoryIssueServices.groovy        | 233 +++++++++++++++++
 .../product/inventory/InventoryIssueServices.xml   | 279 ---------------------
 .../product/servicedef/services_facility.xml       |   8 +-
 3 files changed, 237 insertions(+), 283 deletions(-)

diff --git a/applications/product/groovyScripts/product/inventory/InventoryIssueServices.groovy b/applications/product/groovyScripts/product/inventory/InventoryIssueServices.groovy
new file mode 100644
index 0000000..a1b6f09
--- /dev/null
+++ b/applications/product/groovyScripts/product/inventory/InventoryIssueServices.groovy
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.ofbiz.entity.GenericValue
+
+
+/**
+ * Issues the Inventory for an Order that was Immediately Fulfilled
+ * @return
+ */
+def issueImmediatelyFulfilledOrder() {
+    GenericValue orderHeader = from("OrderHeader").where(parameters).queryOne()
+
+    if (orderHeader) {
+        GenericValue productStore = from("ProductStore").where(productStoreId: orderHeader.productStoreId).queryOne()
+
+        if (orderHeader.needsInventoryIssuance == "Y") {
+            List orderItemList = orderHeader.getRelated("OrderItem")
+            /*
+             * before issuing inventory, check to see if there is inventory information in this database
+             * if inventory info is not available for all of the products, then don't do the issuance,
+             * ie there has to be at least SOME inventory info in the database to facilitate inventory-less cases
+             */
+            long iiCount = from("InventoryItem").where(facilityId: orderHeader.originFacilityId).queryCount()
+
+            // now go through each order item and call a service to issue the inventory
+            if (iiCount > 0l) {
+                for (GenericValue orderItem : orderItemList) {
+                    if (orderItem.productId) {
+                        Map callSvcMap = orderItem.getAllFields()
+                        callSvcMap.orderHeader = orderHeader
+                        callSvcMap.orderItem = orderItem
+                        callSvcMap.productStore = productStore
+                        run service: "issueImmediatelyFulfilledOrderItem", with: callSvcMap
+                    }
+                }
+                // now that the issuance is done, set the needsInventoryIssuance=N
+                orderHeader.needsInventoryIssuance = "N"
+                orderHeader.store()
+                logInfo("Issued inventory for orderId ${orderHeader.orderId}.")
+            } else {
+                logInfo("Not issuing inventory for orderId ${orderHeader.orderId}," +
+                        " no inventory information available.")
+            }
+        }
+    }
+    return success()
+}
+
+/**
+ * Issues the Inventory for an Order Item that was Immediately Fulfilled
+ * @return
+ */
+def issueImmediatelyFulfilledOrderItem() {
+    GenericValue lastNonSerInventoryItem
+    GenericValue orderItem = parameters.orderItem ?:
+            from("OrderItem").where(parameters).queryOne()
+
+    // kind of like the inventory reservation routine (with a few variations...), find InventoryItems to issue from,
+    // but instead of doing the reservation just create an issuance and an inventory item detail for the change
+    if (orderItem.productId) {
+        // NOTE: the inventory will be issued from the OrderHeader.originFacilityId
+        GenericValue orderHeader = parameters.orderHeader ?:
+                from("OrderHeader").where(parameters).queryOne()
+
+        // get the ProductStore to fund the reserveOrderEnumId
+        GenericValue productStore = parameters.productStore ?:
+                from("ProductStore").where(productStoreId: orderHeader.productStoreId).queryOne()
+
+        // before we do the find, put together the orderBy list based on which reserveOrderEnumId is specified
+        String orderBy = "+datetimeReceived"
+        switch (productStore.reserveOrderEnumId) {
+            case "INVRO_FIFO_EXP":
+                orderBy = "+expireDate"
+                break
+            case "INVRO_LIFO_EXP":
+                orderBy = "-expireDate"
+                break
+            case "INVRO_LIFO_REC":
+                orderBy = "-datetimeReceived"
+                break
+            default:
+                break
+        }
+        Map lookupFieldMap = [productId: orderItem.productId,
+                              facilityId: orderHeader.originFacilityId]
+        from("InventoryItem")
+                .where(lookupFieldMap)
+                .orderBy(orderBy)
+                .queryList()
+                .each { inventoryItem ->
+                    // this is a little trick to get the InventoryItem value object without doing a query, possible
+                    // since all fields on InventoryItem are also on InventoryItemAndLocation with the same names
+                    GenericValue tmpLastNonSerInventoryItem = issueImmediateForInventoryItemInline(inventoryItem)
+                    if (tmpLastNonSerInventoryItem) {
+                        lastNonSerInventoryItem = tmpLastNonSerInventoryItem
+                    }
+                }
+
+        parameters.quantityNotIssued = orderItem.quantity
+        // if quantityNotIssued is not 0, then pull it from the last non-serialized inventory item found,
+        // in the quantityNotIssued field
+        if (parameters.quantityNotIssued != (BigDecimal) 0) {
+            BigDecimal availableToPromiseDiff = - parameters.quantityNotIssued
+            BigDecimal quantityOnHandDiff = - parameters.quantityNotIssued
+            if (lastNonSerInventoryItem) {
+                // create ItemIssuance record
+                Map serviceResult = run service: "createItemIssuance",
+                        with: [orderId: parameters.orderId,
+                               orderItemSeqId: parameters.orderItemSeqId,
+                               inventoryItemId: lastNonSerInventoryItem.inventoryItemId,
+                               quantity: parameters.quantityNotIssued]
+                String itemIssuanceId = serviceResult.itemIssuanceId
+
+                // subtract from quantityNotIssued from the availableToPromise and quantityOnHand of existing inventory item
+                // instead of updating InventoryItem, add an InventoryItemDetail
+                run service: "createInventoryItemDetail",
+                        with: [inventoryItemId: lastNonSerInventoryItem.inventoryItemId,
+                               orderId: parameters.orderId,
+                               orderItemSeqId: parameters.orderItemSeqId,
+                               itemIssuanceId: itemIssuanceId,
+                               availableToPromiseDiff: availableToPromiseDiff.setScale(6),
+                               quantityOnHandDiff: quantityOnHandDiff.setScale(6)]
+            } else {
+                // no non-ser inv item, create a non-ser InventoryItem with availableToPromise = -quantityNotIssued
+                Map serviceResult = run service: "createInventoryItem",
+                        with: [productId: orderItem.productId,
+                               facilityId: orderHeader.originFacilityId,
+                               inventoryItemTypeId: "NON_SERIAL_INV_ITEM"]
+                String newInventoryItemId = serviceResult.inventoryItemId
+
+                // create ItemIssuance record
+                serviceResult = run service: "createItemIssuance",
+                        with: [inventoryItemId: newInventoryItemId,
+                               orderId: parameters.orderId,
+                               orderItemSeqId: parameters.orderItemSeqId,
+                               quantity: parameters.quantityNotIssued]
+                String itemIssuanceId = serviceResult.itemIssuanceId
+
+                // also create a detail record with the quantities
+                run service: "createInventoryItemDetail",
+                        with: [inventoryItemId: newInventoryItemId,
+                               orderId: parameters.orderId,
+                               orderItemSeqId: parameters.orderItemSeqId,
+                               itemIssuanceId: itemIssuanceId,
+                               availableToPromiseDiff: availableToPromiseDiff.setScale(6),
+                               quantityOnHandDiff: quantityOnHandDiff.setScale(6)]
+            }
+            parameters.quantityNotIssued = 0
+        }
+    }
+    return success()
+}
+
+/**
+ * Does a issuance for one InventoryItem, meant to be called in-line
+ * @return
+ */
+def issueImmediateForInventoryItemInline(GenericValue inventoryItem) {
+    GenericValue lastNonSerInventoryItem
+    // only do something with this inventoryItem if there is more inventory to issue
+    if (parameters.quantityNotIssued > (BigDecimal) 0) {
+        if ("SERIALIZED_INV_ITEM" == inventoryItem.inventoryItemTypeId) {
+            if ("INV_AVAILABLE" == inventoryItem.statusId) {
+                // change status on inventoryItem
+                inventoryItem.statusId = "INV_DELIVERED"
+                run service: "updateInventoryItem", with: inventoryItem.getAllFields()
+
+                // create ItemIssuance record
+                run service: "createItemIssuance", with: [orderId: parameters.orderId,
+                                                          orderItemSeqId: parameters.orderItemSeqId,
+                                                          inventoryItemId: inventoryItem.inventoryItemId,
+                                                          quantity: (BigDecimal) 1]
+
+                parameters.quantityNotIssued -= (BigDecimal) 1
+            }
+        }
+        if (inventoryItem.inventoryItemTypeId == "NON_SERIAL_INV_ITEM") {
+            // reduce atp on inventoryItem if availableToPromise greater than 0,
+            // if not the code at the end of this method will handle it
+            if ((!inventoryItem.statusId || inventoryItem.statusId == "INV_AVAILABLE") &&
+                    inventoryItem.availableToPromiseTotal &&
+                    inventoryItem.availableToPromiseTotal > (BigDecimal) 0) {
+                parameters.deductAmount = parameters.quantityNotIssued > inventoryItem.availableToPromiseTotal ?
+                        inventoryItem.availableToPromiseTotal :
+                        parameters.quantityNotIssued
+
+                // create ItemIssuance record
+                Map serviceResult = run service: "createItemIssuance",
+                        with: [orderId: parameters.orderId,
+                               orderitemSeqId: parameters.orderItemSeqId,
+                               inventoryItemId: inventoryItem.inventoryItemId,
+                               quantity: parameters.deductAmount]
+                String itemIssuanceId = serviceResult.itemIssuanceId
+
+                // instead of updating InventoryItem, add an InventoryItemDetail
+                // update availableToPromiseDiff AND quantityOnHandDiff since this is an issuance
+                BigDecimal availableToPromiseDiff = - parameters.deductAmount
+                BigDecimal quantityOnHandDiff = - parameters.deductAmount
+                run service: "createInventoryItemDetail",
+                        with: [inventoryItemId: inventoryItem.inventoryItemId,
+                               orderId: parameters.orderId,
+                               orderItemSeqId: parameters.orderItemSeqId,
+                               itemIssuanceId: itemIssuanceId,
+                               availableToPromiseDiff: availableToPromiseDiff.setScale(6),
+                               quantityOnHandDiff: quantityOnHandDiff.setScale(6)]
+
+                parameters.quantityNotIssued -= parameters.deductAmount
+
+                // keep track of the last non-serialized inventory item for use if inventory is not sufficient for amount already issued
+                // use env variable named lastNonSerInventoryItem
+                lastNonSerInventoryItem = inventoryItem
+            }
+        }
+    }
+    return lastNonSerInventoryItem
+}
diff --git a/applications/product/minilang/product/inventory/InventoryIssueServices.xml b/applications/product/minilang/product/inventory/InventoryIssueServices.xml
deleted file mode 100644
index c7e2ca6..0000000
--- a/applications/product/minilang/product/inventory/InventoryIssueServices.xml
+++ /dev/null
@@ -1,279 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied.  See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-
-<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-        xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd">
-    <simple-method method-name="issueImmediatelyFulfilledOrder" short-description="Issues the Inventory for an Order that was Immediately Fulfilled" login-required="false">
-        <entity-one entity-name="OrderHeader" value-field="orderHeader"/>
-
-        <entity-one entity-name="ProductStore" value-field="productStore">
-            <field-map field-name="productStoreId" from-field="orderHeader.productStoreId"/>
-        </entity-one>
-
-        <if-not-empty field="orderHeader">
-            <if-compare field="orderHeader.needsInventoryIssuance" operator="equals" value="Y">
-                <get-related list="orderItemList" relation-name="OrderItem" value-field="orderHeader"/>
-
-                <!-- before issuing inventory, check to see if there is inventory information in this database -->
-                <!-- if inventory info is not available for all of the products, then don't do the issuance,
-                 ie there has to be at least SOME inventory info in the database to facilitate inventory-less cases -->
-                <entity-count entity-name="InventoryItem" count-field="iiCount">
-                    <condition-expr field-name="facilityId" operator="equals" from-field="orderHeader.originFacilityId"/>
-                </entity-count>
-
-                <!-- now go through each order item and call a service to issue the inventory -->
-                <if-compare field="iiCount" operator="greater" value="0" type="BigDecimal">
-                    <iterate list="orderItemList" entry="orderItem">
-                        <if-not-empty field="orderItem.productId">
-                            <clear-field field="callSvcMap"/>
-                            <set-service-fields service-name="issueImmediatelyFulfilledOrderItem" map="orderItem" to-map="callSvcMap"/>
-                            <set field="callSvcMap.orderHeader" from-field="orderHeader"/>
-                            <set field="callSvcMap.orderItem" from-field="orderItem"/>
-                            <set field="callSvcMap.productStore" from-field="productStore"/>
-                            <call-service service-name="issueImmediatelyFulfilledOrderItem" in-map-name="callSvcMap"/>
-                        </if-not-empty>
-                    </iterate>
-                    <!-- now that the issuance is done, set the needsInventoryIssuance=N -->
-                    <set field="orderHeader.needsInventoryIssuance" value="N"/>
-                    <store-value value-field="orderHeader"/>
-                    <log level="info" message="Issued inventory for orderId ${orderHeader.orderId}."/>
-                <else>
-                    <log level="info" message="Not issuing inventory for orderId ${orderHeader.orderId}, no inventory information available."/>
-                </else>
-                </if-compare>
-            </if-compare>
-        </if-not-empty>
-    </simple-method>
-    <simple-method method-name="issueImmediatelyFulfilledOrderItem" short-description="Issues the Inventory for an Order Item that was Immediately Fulfilled" login-required="false">
-        <if-empty field="parameters.orderItem">
-            <entity-one entity-name="OrderItem" value-field="orderItem"/>
-        <else>
-            <set field="orderItem" from-field="parameters.orderItem"/>
-        </else>
-        </if-empty>
-
-        <!-- kind of like the inventory reservation routine (with a few variations...), find InventoryItems to issue from, but instead of doing the reservation just create an issuance and an inventory item detail for the change -->
-        <if-not-empty field="orderItem.productId">
-            <now-timestamp field="nowTimestamp"/>
-
-            <!-- NOTE: the inventory will be issued from the OrderHeader.originFacilityId -->
-            <if-empty field="parameters.orderHeader">
-                <entity-one entity-name="OrderHeader" value-field="orderHeader"/>
-            <else>
-                <set field="orderHeader" from-field="parameters.orderHeader"/>
-            </else>
-            </if-empty>
-
-            <!-- get the ProductStore to fund the reserveOrderEnumId -->
-            <if-empty field="parameters.productStore">
-                <entity-one entity-name="ProductStore" value-field="productStore">
-                    <field-map field-name="productStoreId" from-field="orderHeader.productStoreId"/>
-                </entity-one>
-            <else>
-                <set field="productStore" from-field="parameters.productStore"/>
-            </else>
-            </if-empty>
-
-            <!-- before we do the find, put together the orderBy list based on which reserveOrderEnumId is specified -->
-            <if-compare value="INVRO_FIFO_EXP" operator="equals" field="productStore.reserveOrderEnumId">
-                <set field="orderByString" value="+expireDate"/>
-            <else>
-                <if-compare value="INVRO_LIFO_EXP" operator="equals" field="productStore.reserveOrderEnumId">
-                    <set field="orderByString" value="-expireDate"/>
-                <else>
-                    <if-compare value="INVRO_LIFO_REC" operator="equals" field="productStore.reserveOrderEnumId">
-                        <set field="orderByString" value="-datetimeReceived"/>
-                    <else>
-                        <!-- the default reserveOrderEnumId is INVRO_FIFO_REC, ie FIFO based on date received -->
-                        <set field="orderByString" value="+datetimeReceived"/>
-                    </else>
-                    </if-compare>
-                </else>
-                </if-compare>
-            </else>
-            </if-compare>
-            <field-to-list field="orderByString" list="orderByList"/>
-            <set field="lookupFieldMap.productId" from-field="orderItem.productId"/>
-            <set field="lookupFieldMap.facilityId" from-field="orderHeader.originFacilityId"/>
-            <find-by-and entity-name="InventoryItem" map="lookupFieldMap" list="inventoryItemList" order-by-list="orderByList"/>
-
-            <set field="parameters.quantityNotIssued" from-field="orderItem.quantity"/>
-
-            <iterate list="inventoryItemList" entry="inventoryItem">
-                <!-- this is a little trick to get the InventoryItem value object without doing a query, possible since all fields on InventoryItem are also on InventoryItemAndLocation with the same names -->
-                <call-simple-method method-name="issueImmediateForInventoryItemInline"/>
-            </iterate>
-
-            <!-- if quantityNotIssued is not 0, then pull it from the last non-serialized inventory item found, in the quantityNotIssued field -->
-            <if-compare field="parameters.quantityNotIssued" operator="not-equals" value="0" type="BigDecimal">
-                <if-not-empty field="lastNonSerInventoryItem">
-                    <!-- create ItemIssuance record -->
-                    <set field="issuanceCreateMap.orderId" from-field="parameters.orderId"/>
-                    <set field="issuanceCreateMap.orderItemSeqId" from-field="parameters.orderItemSeqId"/>
-                    <set field="issuanceCreateMap.inventoryItemId" from-field="lastNonSerInventoryItem.inventoryItemId"/>
-                    <set field="issuanceCreateMap.quantity" from-field="parameters.quantityNotIssued"/>
-                    <call-service service-name="createItemIssuance" in-map-name="issuanceCreateMap">
-                        <result-to-field result-name="itemIssuanceId"/>
-                    </call-service>
-
-                    <!-- subtract from quantityNotIssued from the availableToPromise and quantityOnHand of existing inventory item -->
-                    <!-- instead of updating InventoryItem, add an InventoryItemDetail -->
-                    <set field="createDetailMap.inventoryItemId" from-field="lastNonSerInventoryItem.inventoryItemId"/>
-                    <set field="createDetailMap.orderId" from-field="parameters.orderId"/>
-                    <set field="createDetailMap.orderItemSeqId" from-field="parameters.orderItemSeqId"/>
-                    <set field="createDetailMap.itemIssuanceId" from-field="itemIssuanceId"/>
-                    <calculate field="createDetailMap.availableToPromiseDiff" decimal-scale="6">
-                        <calcop operator="negative" field="parameters.quantityNotIssued"/>
-                    </calculate>
-                    <calculate field="createDetailMap.quantityOnHandDiff" decimal-scale="6">
-                        <calcop operator="negative" field="parameters.quantityNotIssued"/>
-                    </calculate>
-                    <call-service service-name="createInventoryItemDetail" in-map-name="createDetailMap"/>
-
-                    <clear-field field="createDetailMap"/>
-                    <clear-field field="itemIssuanceId"/>
-                <else>
-                    <!-- no non-ser inv item, create a non-ser InventoryItem with availableToPromise = -quantityNotIssued -->
-                    <clear-field field="createInvItemInMap"/>
-                    <clear-field field="createInvItemOutMap"/>
-                    <set field="createInvItemInMap.productId" from-field="orderItem.productId"/>
-                    <set field="createInvItemInMap.facilityId" from-field="orderHeader.originFacilityId"/>
-                    <set field="createInvItemInMap.inventoryItemTypeId" value="NON_SERIAL_INV_ITEM"/>
-                    <call-service service-name="createInventoryItem" in-map-name="createInvItemInMap">
-                        <result-to-field result-name="inventoryItemId" field="createInvItemOutMap.inventoryItemId"/>
-                    </call-service>
-
-                    <!-- create ItemIssuance record -->
-                    <set field="issuanceCreateMap.orderId" from-field="parameters.orderId"/>
-                    <set field="issuanceCreateMap.orderItemSeqId" from-field="parameters.orderItemSeqId"/>
-                    <set field="issuanceCreateMap.inventoryItemId" from-field="createInvItemOutMap.inventoryItemId"/>
-                    <set field="issuanceCreateMap.quantity" from-field="parameters.quantityNotIssued"/>
-                    <call-service service-name="createItemIssuance" in-map-name="issuanceCreateMap">
-                        <result-to-field result-name="itemIssuanceId"/>
-                    </call-service>
-
-                    <!-- also create a detail record with the quantities -->
-                    <set field="createDetailMap.inventoryItemId" from-field="createInvItemOutMap.inventoryItemId"/>
-                    <set field="createDetailMap.orderId" from-field="parameters.orderId"/>
-                    <set field="createDetailMap.orderItemSeqId" from-field="parameters.orderItemSeqId"/>
-                    <set field="createDetailMap.itemIssuanceId" from-field="itemIssuanceId"/>
-                    <calculate field="createDetailMap.availableToPromiseDiff" decimal-scale="6">
-                        <calcop operator="negative" field="parameters.quantityNotIssued"/>
-                    </calculate>
-                    <calculate field="createDetailMap.quantityOnHandDiff" decimal-scale="6">
-                        <calcop operator="negative" field="parameters.quantityNotIssued"/>
-                    </calculate>
-                    <call-service service-name="createInventoryItemDetail" in-map-name="createDetailMap"/>
-
-                    <clear-field field="createDetailMap"/>
-                    <clear-field field="itemIssuanceId"/>
-                </else>
-                </if-not-empty>
-
-                <calculate field="parameters.quantityNotIssued" ><number value="0"/></calculate>
-            </if-compare>
-        </if-not-empty>
-    </simple-method>
-    <simple-method method-name="issueImmediateForInventoryItemInline" short-description="Does a issuance for one InventoryItem, meant to be called in-line">
-        <!-- only do something with this inventoryItem if there is more inventory to issue -->
-        <if-compare field="parameters.quantityNotIssued" operator="greater" value="0" type="BigDecimal">
-            <if-compare value="SERIALIZED_INV_ITEM" operator="equals" field="inventoryItem.inventoryItemTypeId">
-                <if-compare value="INV_AVAILABLE" operator="equals" field="inventoryItem.statusId">
-                    <!-- change status on inventoryItem -->
-                    <set field="inventoryItem.statusId" value="INV_DELIVERED"/>
-                    <set-service-fields service-name="updateInventoryItem"  map="inventoryItem" to-map="inventoryItemMap"/>
-                    <call-service service-name="updateInventoryItem" in-map-name="inventoryItemMap"/>
-
-                    <!-- create ItemIssuance record -->
-                    <set field="issuanceCreateMap.orderId" from-field="parameters.orderId"/>
-                    <set field="issuanceCreateMap.orderItemSeqId" from-field="parameters.orderItemSeqId"/>
-                    <set field="issuanceCreateMap.inventoryItemId" from-field="inventoryItem.inventoryItemId"/>
-                    <calculate field="issuanceCreateMap.quantity" ><number value="1"/></calculate>
-                    <call-service service-name="createItemIssuance" in-map-name="issuanceCreateMap"/>
-                    <clear-field field="issuanceCreateMap"/>
-
-                    <calculate field="parameters.quantityNotIssued">
-                        <calcop operator="subtract" field="parameters.quantityNotIssued"><number value="1.0"/></calcop>
-                    </calculate>
-                </if-compare>
-            </if-compare>
-            <if-compare field="inventoryItem.inventoryItemTypeId" operator="equals" value="NON_SERIAL_INV_ITEM">
-                <!-- reduce atp on inventoryItem if availableToPromise greater than 0, if not the code at the end of this method will handle it -->
-                <if>
-                    <condition>
-                        <and>
-                            <or>
-                                <if-empty field="inventoryItem.statusId"/>
-                                <if-compare field="inventoryItem.statusId" operator="equals" value="INV_AVAILABLE"/>
-                            </or>
-                            <not><if-empty field="inventoryItem.availableToPromiseTotal"/></not>
-                            <if-compare field="inventoryItem.availableToPromiseTotal" operator="greater" value="0" type="BigDecimal"/>
-                        </and>
-                    </condition>
-                    <then>
-                        <if-compare-field field="parameters.quantityNotIssued" to-field="inventoryItem.availableToPromiseTotal" operator="greater" type="BigDecimal">
-                            <set field="parameters.deductAmount" from-field="inventoryItem.availableToPromiseTotal"/>
-                        <else>
-                            <set field="parameters.deductAmount" from-field="parameters.quantityNotIssued"/>
-                        </else>
-                        </if-compare-field>
-
-                        <!-- create ItemIssuance record -->
-                        <set field="issuanceCreateMap.orderId" from-field="parameters.orderId"/>
-                        <set field="issuanceCreateMap.orderItemSeqId" from-field="parameters.orderItemSeqId"/>
-                        <set field="issuanceCreateMap.inventoryItemId" from-field="inventoryItem.inventoryItemId"/>
-                        <set field="issuanceCreateMap.quantity" from-field="parameters.deductAmount"/>
-                        <call-service service-name="createItemIssuance" in-map-name="issuanceCreateMap">
-                            <result-to-field result-name="itemIssuanceId"/>
-                        </call-service>
-
-                        <!-- instead of updating InventoryItem, add an InventoryItemDetail -->
-                        <set field="createDetailMap.inventoryItemId" from-field="inventoryItem.inventoryItemId"/>
-                        <set field="createDetailMap.orderId" from-field="parameters.orderId"/>
-                        <set field="createDetailMap.orderItemSeqId" from-field="parameters.orderItemSeqId"/>
-                        <set field="createDetailMap.itemIssuanceId" from-field="itemIssuanceId"/>
-                        <!-- update availableToPromiseDiff AND quantityOnHandDiff since this is an issuance -->
-                        <calculate field="createDetailMap.availableToPromiseDiff" decimal-scale="6">
-                            <calcop operator="negative" field="parameters.deductAmount"/>
-                        </calculate>
-                        <calculate field="createDetailMap.quantityOnHandDiff" decimal-scale="6">
-                            <calcop operator="negative" field="parameters.deductAmount"/>
-                        </calculate>
-                        <call-service service-name="createInventoryItemDetail" in-map-name="createDetailMap"/>
-                        <clear-field field="createDetailMap"/>
-
-                        <calculate field="parameters.quantityNotIssued" >
-                            <calcop operator="subtract" field="parameters.quantityNotIssued">
-                                <calcop operator="get" field="parameters.deductAmount"/>
-                            </calcop>
-                        </calculate>
-
-                        <clear-field field="issuanceCreateMap"/>
-                        <clear-field field="itemIssuanceId"/>
-
-                        <!-- keep track of the last non-serialized inventory item for use if inventory is not sufficient for amount already issued -->
-                        <!-- use env variable named lastNonSerInventoryItem -->
-                        <set field="lastNonSerInventoryItem" from-field="inventoryItem"/>
-                    </then>
-                </if>
-            </if-compare>
-        </if-compare>
-    </simple-method>
-</simple-methods>
diff --git a/applications/product/servicedef/services_facility.xml b/applications/product/servicedef/services_facility.xml
index 08a61b2..a534f9c 100644
--- a/applications/product/servicedef/services_facility.xml
+++ b/applications/product/servicedef/services_facility.xml
@@ -811,8 +811,8 @@ under the License.
         <attribute name="statusId" type="String" mode="IN" optional="true"/>
     </service>
 
-    <service name="issueImmediatelyFulfilledOrder" engine="simple"
-                location="component://product/minilang/product/inventory/InventoryIssueServices.xml" invoke="issueImmediatelyFulfilledOrder" auth="false">
+    <service name="issueImmediatelyFulfilledOrder" engine="groovy"
+                location="component://product/groovyScripts/product/inventory/InventoryIssueServices.groovy" invoke="issueImmediatelyFulfilledOrder" auth="false">
         <description>
             Issues the Inventory for an Order that was Immediately Fulfilled.
             Note that this skips the normal inventory reservation process, and the shipment process (no shipment is created).
@@ -823,8 +823,8 @@ under the License.
         </type-validate>
         </attribute>
     </service>
-    <service name="issueImmediatelyFulfilledOrderItem" engine="simple"
-                location="component://product/minilang/product/inventory/InventoryIssueServices.xml" invoke="issueImmediatelyFulfilledOrderItem" auth="false">
+    <service name="issueImmediatelyFulfilledOrderItem" engine="groovy"
+                location="component://product/groovyScripts/product/inventory/InventoryIssueServices.groovy" invoke="issueImmediatelyFulfilledOrderItem" auth="false">
         <description>
             Issues the Inventory for an Order Item that was Immediately Fulfilled for more info see the issueImmediatelyFulfilledOrder service.
         </description>

Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] 02/03: Fixed: Convert InventoryIssueServices.xml mini lang to groovy (OFBIZ-11591)

nmalin
In reply to this post by nmalin
This is an automated email from the ASF dual-hosted git repository.

nmalin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit b862632a9496b9d0c64ec2f5a3f410e178709bf0
Author: Nicolas Malin <[hidden email]>
AuthorDate: Fri May 29 16:27:43 2020 +0200

    Fixed: Convert InventoryIssueServices.xml mini lang to groovy
    (OFBIZ-11591)
   
    Side effect: Inventory Issuance use generic shipment service to control the authorization
    but without a shipment, checkCanChangeShipmentStatusGeneral failed with NPE.
   
    I complete the function to escape if a shipment isn't present and only valid with facility permission
---
 .../shipment/shipment/ShipmentServices.groovy      | 34 ++++++++++++----------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/applications/product/groovyScripts/shipment/shipment/ShipmentServices.groovy b/applications/product/groovyScripts/shipment/shipment/ShipmentServices.groovy
index 1940f59..c51ffe6 100644
--- a/applications/product/groovyScripts/shipment/shipment/ShipmentServices.groovy
+++ b/applications/product/groovyScripts/shipment/shipment/ShipmentServices.groovy
@@ -746,22 +746,24 @@ def checkCanChangeShipmentStatusGeneral(Map inputParameters) {
     }
     Boolean hasPermission = serviceResult.hasPermission
     GenericValue testShipment = from("Shipment").where(inputParameters).cache().queryOne()
-
-    boolean badMoveToPacked = testShipment.statusId == "SHIPMENT_PACKED" && fromStatusId == "SHIPMENT_PACKED"
-    boolean badMoveToShipped = testShipment.statusId == "SHIPMENT_SHIPPED" &&
-            ["SHIPMENT_PACKED", "SHIPMENT_SHIPPED"].contains(fromStatusId)
-    boolean badMoveToDelivered = testShipment.statusId == "SHIPMENT_DELIVERED" &&
-            ["SHIPMENT_PACKED", "SHIPMENT_SHIPPED", "SHIPMENT_DELIVERED"].contains(fromStatusId)
-
-    if (badMoveToPacked || badMoveToShipped || badMoveToDelivered
-            || testShipment.statusId == "SHIPMENT_CANCELLED") {
-        GenericValue testShipmentStatus = testShipment.getRelatedOne("StatusItem", true)
-        Map testShipmentMap = [testShipment: testShipment,
-                               testShipmentStatus: testShipmentStatus]
-        String failMessage = UtilProperties.getMessage("ProductErrorUiLabels",
-                "ShipmentCanChangeStatusPermissionError", testShipmentMap, locale)
-        hasPermission = false
-        result.failMessage = failMessage
+    if (testShipment) {
+
+        boolean badMoveToPacked = testShipment.statusId == "SHIPMENT_PACKED" && fromStatusId == "SHIPMENT_PACKED"
+        boolean badMoveToShipped = testShipment.statusId == "SHIPMENT_SHIPPED" &&
+                ["SHIPMENT_PACKED", "SHIPMENT_SHIPPED"].contains(fromStatusId)
+        boolean badMoveToDelivered = testShipment.statusId == "SHIPMENT_DELIVERED" &&
+                ["SHIPMENT_PACKED", "SHIPMENT_SHIPPED", "SHIPMENT_DELIVERED"].contains(fromStatusId)
+
+        if (badMoveToPacked || badMoveToShipped || badMoveToDelivered
+                || testShipment.statusId == "SHIPMENT_CANCELLED") {
+            GenericValue testShipmentStatus = testShipment.getRelatedOne("StatusItem", true)
+            Map testShipmentMap = [testShipment      : testShipment,
+                                   testShipmentStatus: testShipmentStatus]
+            String failMessage = UtilProperties.getMessage("ProductErrorUiLabels",
+                    "ShipmentCanChangeStatusPermissionError", testShipmentMap, locale)
+            hasPermission = false
+            result.failMessage = failMessage
+        }
     }
     result.hasPermission = hasPermission
     return result

Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] 03/03: Fixed: Remove unnecessary semi-column

nmalin
In reply to this post by nmalin
This is an automated email from the ASF dual-hosted git repository.

nmalin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit 1558f232c27ae289af06253b6ae3262379f5f98d
Author: Nicolas Malin <[hidden email]>
AuthorDate: Fri May 29 16:29:32 2020 +0200

    Fixed: Remove unnecessary semi-column
---
 .../groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy  | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy b/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
index 9e5dc3d..e508a17 100644
--- a/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
+++ b/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
@@ -18,8 +18,6 @@
  *******************************************************************************/
 package org.apache.ofbiz.service.engine
 
-import java.util.Map
-
 import org.apache.ofbiz.base.util.Debug
 import org.apache.ofbiz.entity.util.EntityQuery
 import org.apache.ofbiz.service.DispatchContext
@@ -33,8 +31,8 @@ abstract class GroovyBaseScript extends Script {
     public static final String module = GroovyBaseScript.class.getName()
 
     Map runService(String serviceName, Map inputMap) throws ExecutionServiceException {
-        LocalDispatcher dispatcher = binding.getVariable('dispatcher');
-        DispatchContext dctx = dispatcher.getDispatchContext();
+        LocalDispatcher dispatcher = binding.getVariable('dispatcher')
+        DispatchContext dctx = dispatcher.getDispatchContext()
         if (!inputMap.userLogin) {
             inputMap.userLogin = this.binding.getVariable('parameters').userLogin
         }