Record Inventory Effects Under the Warehouse's Analysis Set
This Groovy script makes the inventory effect of a document follow the warehouse's analysis set rather than the document's. Just before the document sends its inventory transaction request for processing, the script gives every line of that request the analysis set of the line's warehouse.
Recommended pattern
This script is not tied to any customer's setup. It has no parameters: attach it and it works.
| Class name | EASetInvRequestAnalysisSetFromWarehouse |
| Script | EASetInvRequestAnalysisSetFromWarehouse.groovy |
| Runs on | Any document with an inventory effect. Target action PreSendRequest. |
| Uses | No parameters. Leave Parameter 1 empty. |
| Shipped as | Source to paste. It is not built into the system. |
When to use it
Some companies use the analysis set to stand for a site or a business line, and give each warehouse the analysis set it belongs to on the Warehouse screen. Stock reports filtered by analysis set then only add up correctly if every movement in that warehouse carries the warehouse's analysis set. Users, however, often save stock issues and similar documents under their own login analysis set, which is usually different.
With this script on the flow, the document is saved as the user entered it, but its quantity transactions are recorded under the warehouse's analysis set. Nobody has to remember to change the dimension by hand.
How it works
- It waits for the inventory request. A saved document is processed in the background through business requests. PreSendRequest flows run once for each request the document sends, just before it is sent. The script acts only on the inventory transaction request and leaves every other request, such as the accounting one, untouched.
- It goes through the request lines. Each request line that has a warehouse is given that warehouse's analysis set, as set on the Warehouse screen. Lines without a warehouse are skipped.
- The document itself does not change. Only the request is changed. The document's lines keep the analysis set the user saved them with, and the quantity transactions created when the request is processed carry the warehouse's.
A warehouse with no analysis set
The script copies whatever the warehouse holds. If a warehouse's analysis set is empty, its request lines lose their analysis set too.
Setting it up
- On Inventory → Master Files → Warehouse, give each warehouse the analysis set its movements should carry.
- Open Administration → Display Customization → Entity Flow and create a flow whose target type is the document to cover (for example Stock Issue). Add one flow per document type, or use an entity type list.
- In the Details grid, add a line with Target Action set to PreSendRequest, and paste the whole script into its Groovy Script column. Leave Class Name empty: it is filled in when you save.
- Leave all parameters empty, and save the flow.
The flow affects documents saved from now on. A document that was already processed keeps its old quantity transactions until its inventory request is regenerated.
Example
Warehouse W-NORTH has the analysis set NORTH. A user whose login analysis set is PUBLIC saves a stock issue from W-NORTH. The issue's line still shows PUBLIC, but the quantity transaction for that line is recorded under NORTH, the same analysis set as every other movement in that warehouse.
The script
package com.namasoft.modules.supplychain.domain.utils.plugnplay.groovy
import com.namasoft.infra.domainbase.datafields.LongTextDF
import com.namasoft.infra.domainbase.entity.base.EntityAction
import com.namasoft.infra.domainbase.util.Result
import com.namasoft.modules.basic.domain.requests.InvTransReqLine
import com.namasoft.modules.basic.domain.requests.inv.InvTransReq
import com.namasoft.modules.supplychain.domain.entities.BasicSCDocument
import com.namasoft.modules.supplychain.domain.entities.Warehouse
class EASetInvRequestAnalysisSetFromWarehouse implements EntityAction<BasicSCDocument> {
@Override
Result doAction(BasicSCDocument object, LongTextDF... parameters) {
Result result = Result.createAccumulatingResult();
if (!(object.fetchCurrentlySendingRequest() instanceof InvTransReq))
return result;
InvTransReq req = object.fetchCurrentlySendingRequest();
for (final InvTransReqLine l in req.getList().getLines()) {
if (l.getSpecificDimensions() == null)
continue;
if (l.getSpecificDimensions().getWarehouse() == null)
continue;
Warehouse w = l.getSpecificDimensions().getWarehouse().toReal();
l.getGenericDimensions().setAnalysisSet(w.getAnalysisSet());
}
return result;
}
@Override
String describe() {
return "Use it on PreSendRequest. When the document sends its inventory transaction request, every request line that has a " +
"warehouse takes the analysis set of that warehouse, so the inventory effect is recorded under the warehouse's analysis set. " +
"The document's own lines are not changed, and other requests (such as the accounting request) are left alone. " +
"Parameter 1 is not used.";
}
@Override
List<String> columnNames() {
return Arrays.asList("Not used - leave empty");
}
}Related
- EAGroovyAction: how Groovy scripts are attached to entity flows.
- Business Requests: how a saved document's effects are processed in the background.