public void testReceivingBarcodes() { CswNbtMetaDataNodeType ChemicalNT = TestData.CswNbtResources.MetaData.getNodeType("Chemical"); CswNbtObjClassChemical ChemicalNode = TestData.CswNbtResources.Nodes.makeNodeFromNodeTypeId(ChemicalNT.NodeTypeId); CswNbtObjClassUnitOfMeasure GramNode = TestData.CswNbtResources.Nodes.GetNode(new CswPrimaryKey("nodes", 26745)); CswNbtMetaDataNodeType SizeNT = TestData.CswNbtResources.MetaData.getNodeType("Size"); CswNbtObjClassSize Size = TestData.CswNbtResources.Nodes.makeNodeFromNodeTypeId(SizeNT.NodeTypeId, OnAfterMakeNode : delegate(CswNbtNode NewNode) { CswNbtObjClassSize AsSize = NewNode; AsSize.Material.RelatedNodeId = ChemicalNode.NodeId; AsSize.UnitCount.Value = 5; AsSize.InitialQuantity.Quantity = 10; AsSize.InitialQuantity.UnitId = GramNode.NodeId; }, OverrideUniqueValidation: true); CswNbtActReceiving ReceivingAction = new CswNbtActReceiving(TestData.CswNbtResources, ChemicalNode.NodeId); CswNbtMetaDataNodeType ContainerNT = TestData.CswNbtResources.MetaData.getNodeType("Container"); CswNbtObjClassContainer InitialContainer = ReceivingAction.makeContainer(null); JObject ContainerAddProps = ReceivingAction.getContainerAddProps(InitialContainer); CswCommaDelimitedString Barcodes = new CswCommaDelimitedString(); Barcodes.Add("testbarcode1"); Barcodes.Add("testbarcode2"); int NumContainers = 2; CswNbtAmountsGridQuantity Quantity = new CswNbtAmountsGridQuantity() { NumContainers = NumContainers, Quantity = 10, SizeName = Size.NodeName, SizeNodeId = Size.NodeId, UnitNodeId = GramNode.NodeId, ContainerIds = new Collection <string>() { InitialContainer.NodeId.ToString() }, }; foreach (string Barcode in Barcodes) { Quantity.AddBarcode(Barcode); } CswNbtReceivingDefinition ReceiptDef = new CswNbtReceivingDefinition() { ContainerNodeId = InitialContainer.NodeId, ContainerNodeTypeId = ContainerNT.NodeTypeId, ContainerProps = ContainerAddProps, MaterialNodeId = ChemicalNode.NodeId, Quantities = new Collection <CswNbtAmountsGridQuantity>() { Quantity } }; CswNbtMetaDataNodeTypeProp BarcodeNTP = ContainerNT.getNodeTypePropByObjectClassProp(CswNbtObjClassContainer.PropertyName.Barcode); string Before = BarcodeNTP.Sequence.getCurrent(); ReceivingAction.receiveMaterial(ReceiptDef); string After = BarcodeNTP.Sequence.getCurrent(); Assert.AreEqual(Before, After, "Creating containers in Receiving with custom barcodes consumed barcode sequence values when it shouldn't have"); }
} // makeContainer() public JObject receiveMaterial(CswNbtReceivingDefinition ReceiptDefinition) { JObject Ret = new JObject(); CswNbtObjClassContainer InitialContainerNode = _CswNbtResources.Nodes[ReceiptDefinition.ContainerNodeId]; if (null != InitialContainerNode && ReceiptDefinition.Quantities.Count > 0) { //Generate the barcodes upfront and treat them as custom barcodes so all Containers in this Receipt Def have similar numbers CswNbtMetaDataNodeTypeProp BarcodeProp = (CswNbtMetaDataNodeTypeProp)InitialContainerNode.NodeType.getBarcodeProperty(); for (int i = 0; i < ReceiptDefinition.Quantities.Count; i++) { CswNbtAmountsGridQuantity quantity = ReceiptDefinition.Quantities[i]; while (quantity.getNumBarcodes() < quantity.NumContainers) { if (quantity.getNumBarcodes() == 0 && i == 0 && false == String.IsNullOrEmpty(InitialContainerNode.Barcode.Barcode)) //special case: the Initial Container node already has a barcode, so insert that one if a user didn't specify a custom barcode { quantity.AddBarcode(InitialContainerNode.Barcode.Barcode); } else { if (null != BarcodeProp.Sequence) { quantity.AddBarcode(BarcodeProp.Sequence.getNext()); } } } } CswNbtNode ReceiptLot = _makeReceiptLot(ReceiptDefinition.MaterialNodeId, ReceiptDefinition, InitialContainerNode.ExpirationDate.DateTimeValue); if (null == ReceiptDefinition.ReceiptLotNodeId) { ReceiptDefinition.ReceiptLotNodeId = ReceiptLot.NodeId; } ReceiptDefinition.Quantities[0].ContainerIds.Add(InitialContainerNode.NodeId.ToString()); int processed = 0; receiveContainers(ReceiptDefinition, ref processed, 1); //process only the first container (the initial one) commitSDSDocNode(ReceiptDefinition.MaterialNodeId, ReceiptDefinition.SDSNodeId, ReceiptDefinition.SDSProps); int TotalContainersToMake = ReceiptDefinition.CountNumberContainersToMake(); int Threshhold = CswConvert.ToInt32(_CswNbtResources.ConfigVbls.getConfigVariableValue("batchthreshold")); bool UseBatchOp = TotalContainersToMake >= Threshhold; Collection <CswPrimaryKey> ContainerIds = null; if (UseBatchOp) { //Containers will be created in a batch op CswNbtBatchOpReceiving ReceivingBatchOp = new CswNbtBatchOpReceiving(_CswNbtResources); ReceivingBatchOp.makeBatchOp(ReceiptDefinition); } else { //Create the containers now int nodesProcessed = 0; CswNbtReceivingDefinition ReceivedContainers = receiveContainers(ReceiptDefinition, ref nodesProcessed, TotalContainersToMake + 1); ContainerIds = new Collection <CswPrimaryKey>(); foreach (CswNbtAmountsGridQuantity Quantity in ReceivedContainers.Quantities) { foreach (string ContainerId in Quantity.ContainerIds) { ContainerIds.Add(CswConvert.ToPrimaryKey(ContainerId)); } } } CswNbtNode MaterialNode = _CswNbtResources.Nodes.GetNode(ReceiptDefinition.MaterialNodeId); Ret = getLandingPageData(_CswNbtResources, MaterialNode, UseBatchOp, ContainerIds); } return(Ret); }