public void BaseQuickReceive(PurchaseOrderItemQuickReceive method) { var session = this.Session(); var order = this.PurchaseOrderWherePurchaseOrderItem; if (this.ExistPart) { var shipment = new PurchaseShipmentBuilder(session) .WithShipmentMethod(new ShipmentMethods(session).Ground) .WithShipToParty(order.OrderedBy) .WithShipFromParty(order.TakenViaSupplier) .WithShipToFacility(order.StoredInFacility) .Build(); var shipmentItem = new ShipmentItemBuilder(session) .WithPart(this.Part) .WithStoredInFacility(this.StoredInFacility) .WithQuantity(this.QuantityOrdered) .WithUnitPurchasePrice(this.UnitPrice) .WithContentsDescription($"{this.QuantityOrdered} * {this.Part.Name}") .Build(); shipment.AddShipmentItem(shipmentItem); new OrderShipmentBuilder(session) .WithOrderItem(this) .WithShipmentItem(shipmentItem) .WithQuantity(this.QuantityOrdered) .Build(); if (this.Part.InventoryItemKind.IsSerialised) { var serialisedItem = this.SerialisedItem; if (!this.ExistSerialisedItem) { serialisedItem = new SerialisedItemBuilder(session) .WithSerialNumber(this.SerialNumber) .Build(); this.Part.AddSerialisedItem(serialisedItem); } shipmentItem.SerialisedItem = serialisedItem; } if (shipment.ShipToParty is InternalOrganisation internalOrganisation) { if (internalOrganisation.IsAutomaticallyReceived) { shipment.Receive(); } } } else { this.QuantityReceived = 1; } }
public void GivenOrderItem_WhenObjectStateIsPartiallyReceived_ThenItemMayNotBeCancelledOrRejectedOrDeleted() { var administrator = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build(); var administrators = new UserGroups(this.Session).Administrators; administrators.AddMember(administrator); this.Session.Derive(); this.Session.Commit(); this.InstantiateObjects(this.Session); User user = this.Administrator; this.Session.SetUser(user); var item = new PurchaseOrderItemBuilder(this.Session) .WithPart(this.finishedGood) .WithQuantityOrdered(20) .WithAssignedUnitPrice(5) .Build(); this.order.AddPurchaseOrderItem(item); this.order.SetReadyForProcessing(); this.Session.Derive(); var shipment = new PurchaseShipmentBuilder(this.Session).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).WithShipFromParty(this.order.TakenViaSupplier).Build(); this.Session.Derive(); var shipmentItem = new ShipmentItemBuilder(this.Session).WithPart(this.finishedGood).WithQuantity(10).WithUnitPurchasePrice(1).Build(); shipment.AddShipmentItem(shipmentItem); this.Session.Derive(); new ShipmentReceiptBuilder(this.Session) .WithQuantityAccepted(3) .WithShipmentItem(shipmentItem) .WithOrderItem(item) .WithFacility(shipmentItem.StoredInFacility) .Build(); this.Session.Derive(); var acl = new AccessControlLists(this.Session.GetUser())[item]; Assert.Equal(new PurchaseOrderItemShipmentStates(this.Session).PartiallyReceived, item.PurchaseOrderItemShipmentState); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel)); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject)); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Delete)); }
public void GivenOrderItem_WhenObjectStateIsCompleted_ThenItemMayNotBeCancelledOrRejectedOrDeleted() { var administrator = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build(); var administrators = new UserGroups(this.Session).Administrators; administrators.AddMember(administrator); this.Session.Derive(); this.Session.Commit(); this.InstantiateObjects(this.Session); this.SetIdentity("admin"); var item = new PurchaseOrderItemBuilder(this.Session) .WithPart(this.finishedGood) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); this.order.AddPurchaseOrderItem(item); this.order.Confirm(); this.Session.Derive(); var shipment = new PurchaseShipmentBuilder(this.Session).WithShipFromParty(this.supplier).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).Build(); var shipmentItem = new ShipmentItemBuilder(this.Session).WithPart(this.finishedGood).Build(); shipment.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.Session) .WithQuantityAccepted(3) .WithShipmentItem(shipmentItem) .WithOrderItem(item) .Build(); this.Session.Derive(); shipment.AppsComplete(); this.Session.Derive(); Assert.Equal(new PurchaseOrderItemStates(this.Session).Completed, item.PurchaseOrderItemState); var acl = new AccessControlList(item, this.Session.GetUser()); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel)); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject)); Assert.False(acl.CanExecute(M.PurchaseOrderItem.Delete)); }
public void GivenShipmentReceiptForPartWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility() { var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build(); new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build(); var part = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); var order = new PurchaseOrderBuilder(this.Session) .WithTakenViaSupplier(supplier) .WithVatRegime(new VatRegimes(this.Session).Export) .Build(); var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(1).Build(); order.AddPurchaseOrderItem(item1); this.Session.Derive(); order.Confirm(); this.Session.Derive(); this.Session.Commit(); var shipment = new PurchaseShipmentBuilder(this.Session).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.Session).WithPart(part).Build(); shipment.AddShipmentItem(shipmentItem); var receipt = new ShipmentReceiptBuilder(this.Session) .WithQuantityAccepted(1M) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); shipment.AppsComplete(); this.Session.Derive(); this.Session.Commit(); Assert.Equal(new Facilities(this.Session).FindBy(M.Facility.FacilityType, new FacilityTypes(this.Session).Warehouse), receipt.InventoryItem.Facility); Assert.Equal(part.InventoryItemsWherePart[0], receipt.InventoryItem); this.Session.Rollback(); }
public void GivenShipmentReceiptForGoodWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build(); var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(1).Build(); order.AddPurchaseOrderItem(item1); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); order.Confirm(); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build(); shipment.AddShipmentItem(shipmentItem); var receipt = new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(1M) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); shipment.AppsComplete(); Assert.AreEqual(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"), receipt.InventoryItem.Facility); Assert.AreEqual(good.InventoryItemsWhereGood[0], receipt.InventoryItem); this.DatabaseSession.Rollback(); }
public void GivenShipmentReceiptWhenDerivingThenOrderItemQuantityReceivedIsUpdated() { var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build(); new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build(); var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1"); var order = new PurchaseOrderBuilder(this.Session).WithTakenViaSupplier(supplier).Build(); var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(good1.Part).WithQuantityOrdered(10).Build(); order.AddPurchaseOrderItem(item1); this.Session.Derive(); this.Session.Commit(); order.Confirm(); var shipment = new PurchaseShipmentBuilder(this.Session).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.Session).WithGood(good1).Build(); shipment.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.Session) .WithQuantityAccepted(10) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); shipment.AppsComplete(); this.Session.Derive(); this.Session.Commit(); Assert.Equal(10, item1.QuantityReceived); this.Session.Rollback(); }
public void GivenShipmentReceiptWhenValidatingThenRequiredRelationsMustExist() { var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build(); new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build(); var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1"); new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).PhysicalCount).WithPart(good1.Part).Build(); this.Session.Derive(); this.Session.Commit(); var inventoryItem = good1.Part.InventoryItemsWherePart.First; var builder = new ShipmentReceiptBuilder(this.Session); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithInventoryItem(inventoryItem); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); var shipment = new PurchaseShipmentBuilder(this.Session).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.Session).WithGood(good1).Build(); shipment.AddShipmentItem(shipmentItem); builder.WithShipmentItem(shipmentItem); builder.Build(); Assert.False(this.Session.Derive(false).HasErrors); }
public void GivenPurchaseShipmentItemForNonSerialisedNotFromPurchaseOrder_WhenDerived_ThenUnitPurchasePriceIsRequired() { var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1"); User user = this.Administrator; this.Session.SetUser(user); var shipment = new PurchaseShipmentBuilder(this.Session) .WithShipmentMethod(new ShipmentMethods(this.Session).Ground) .WithShipFromParty(this.InternalOrganisation.ActiveSuppliers.First) .Build(); var shipmentItem = new ShipmentItemBuilder(this.Session).WithPart(good1.Part).WithQuantity(1).Build(); shipment.AddShipmentItem(shipmentItem); var validation = this.Session.Derive(false); Assert.True(validation.HasErrors); Assert.Single(validation.Errors); Assert.Contains(MetaShipmentItem.Instance.UnitPurchasePrice, validation.Errors.First().RoleTypes); }
public void GivenShipmentReceiptForPartWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var part = new RawMaterialBuilder(this.DatabaseSession) .WithName("RawMaterial") .Build(); var order = new PurchaseOrderBuilder(this.DatabaseSession) .WithTakenViaSupplier(supplier) .WithVatRegime(new VatRegimes(this.DatabaseSession).Export) .Build(); var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(1).Build(); order.AddPurchaseOrderItem(item1); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build(); shipment.AddShipmentItem(shipmentItem); var receipt = new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(1M) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); shipment.AppsComplete(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Assert.AreEqual(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"), receipt.InventoryItem.Facility); Assert.AreEqual(part.InventoryItemsWherePart[0], receipt.InventoryItem); this.DatabaseSession.Rollback(); }
public void GivenOrderItem_WhenObjectStateIsPartiallyReceived_ThenProductChangeIsNotAllowed() { var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build(); var administrators = new UserGroups(this.DatabaseSession).Administrators; administrators.AddMember(administrator); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); this.InstantiateObjects(this.DatabaseSession); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate,21)) .Build(); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]); var item = new PurchaseOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); this.order.AddPurchaseOrderItem(item); this.order.Confirm(); this.DatabaseSession.Derive(true); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(this.supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build(); shipment.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(1) .WithShipmentItem(shipmentItem) .WithOrderItem(item) .Build(); shipment.AppsComplete(); this.DatabaseSession.Derive(true); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).PartiallyReceived, item.CurrentObjectState); var acl = new AccessControlList(item, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsFalse(acl.CanWrite(PurchaseOrderItems.Meta.Product)); }
public void GivenShipmentReceiptWhenValidatingThenRequiredRelationsMustExist() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Order).Build()); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var builder = new ShipmentReceiptBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithInventoryItem(inventoryItem); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build(); shipment.AddShipmentItem(shipmentItem); builder.WithShipmentItem(shipmentItem); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenNonSerialisedNonUnifiedPart_WhenPurchased_ThenAverageCostIsCalculated() { this.InternalOrganisation.IsAutomaticallyReceived = true; var secondFacility = new FacilityBuilder(this.Session) .WithFacilityType(new FacilityTypes(this.Session).Warehouse) .WithName("second facility") .WithOwner(this.InternalOrganisation) .Build(); var supplier = this.InternalOrganisation.ActiveSuppliers.First; var customer = this.InternalOrganisation.ActiveCustomers.First; var part = new NonUnifiedPartBuilder(this.Session).WithNonSerialisedDefaults(this.InternalOrganisation).Build(); var good = new NonUnifiedGoodBuilder(this.Session) .WithName(part.Name) .WithPart(part) .WithVatRate(new VatRates(this.Session).Zero) .Build(); this.Session.Derive(); var purchaseOrder1 = new PurchaseOrderBuilder(this.Session) .WithTakenViaSupplier(supplier) .WithDeliveryDate(this.Session.Now()) .Build(); this.Session.Derive(); // Beginning inventory: 150 items at 8 euro received in 2 facilities var purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(100).WithAssignedUnitPrice(8M).Build(); purchaseOrder1.AddPurchaseOrderItem(purchaseItem); this.Session.Derive(); purchaseOrder1.SetReadyForProcessing(); this.Session.Derive(); purchaseOrder1.Send(); this.Session.Derive(); purchaseItem.QuickReceive(); this.Session.Derive(); var purchaseOrder2 = new PurchaseOrderBuilder(this.Session) .WithTakenViaSupplier(supplier) .WithFacility(secondFacility) .WithDeliveryDate(this.Session.Now()) .Build(); this.Session.Derive(); // Beginning inventory: 150 items at 8 euro purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(50).WithAssignedUnitPrice(8M).Build(); purchaseOrder2.AddPurchaseOrderItem(purchaseItem); this.Session.Derive(); purchaseOrder2.SetReadyForProcessing(); this.Session.Derive(); purchaseOrder2.Send(); this.Session.Derive(); purchaseItem.QuickReceive(); this.Session.Derive(); Assert.Equal(150, part.QuantityOnHand); Assert.Equal(8, part.PartWeightedAverage.AverageCost); purchaseOrder1.Revise(); this.Session.Derive(); // Purchase: 75 items at 8.1 euro purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(75).WithAssignedUnitPrice(8.1M).Build(); purchaseOrder1.AddPurchaseOrderItem(purchaseItem); this.Session.Derive(); purchaseOrder1.SetReadyForProcessing(); this.Session.Derive(); purchaseOrder1.Send(); this.Session.Derive(); purchaseItem.QuickReceive(); this.Session.Derive(); Assert.Equal(225, part.QuantityOnHand); Assert.Equal(8.03M, part.PartWeightedAverage.AverageCost); var salesOrder = new SalesOrderBuilder(this.Session) .WithTakenBy(this.InternalOrganisation) .WithShipToCustomer(customer) .Build(); this.Session.Derive(); // Sell 50 items for 20 euro var salesItem1 = new SalesOrderItemBuilder(this.Session).WithProduct(good).WithQuantityOrdered(50).WithAssignedUnitPrice(20M).Build(); salesOrder.AddSalesOrderItem(salesItem1); this.Session.Derive(); salesOrder.SetReadyForPosting(); this.Session.Derive(); salesOrder.Post(); this.Session.Derive(); salesOrder.Accept(); this.Session.Derive(); salesOrder.Ship(); this.Session.Derive(); var customerShipment = salesItem1.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem as CustomerShipment; customerShipment.Pick(); this.Session.Derive(); customer.PickListsWhereShipToParty.First(v => v.PickListState.Equals(new PickListStates(this.Session).Created)).SetPicked(); var package = new ShipmentPackageBuilder(this.Session).Build(); customerShipment.AddShipmentPackage(package); foreach (ShipmentItem shipmentItem in customerShipment.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.Session).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build()); } this.Session.Derive(); customerShipment.Ship(); this.Session.Derive(); Assert.Equal(175, part.QuantityOnHand); Assert.Equal(8.03M, part.PartWeightedAverage.AverageCost); Assert.Equal(401.5M, salesItem1.CostOfGoodsSold); // Again Sell 50 items for 20 euro salesOrder.Revise(); this.Session.Derive(); var salesItem2 = new SalesOrderItemBuilder(this.Session).WithProduct(good).WithQuantityOrdered(50).WithAssignedUnitPrice(20M).Build(); salesOrder.AddSalesOrderItem(salesItem2); this.Session.Derive(); salesOrder.SetReadyForPosting(); this.Session.Derive(); salesOrder.Post(); this.Session.Derive(); salesOrder.Accept(); this.Session.Derive(); salesOrder.Ship(); this.Session.Derive(); var customerShipment2 = salesItem2.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem as CustomerShipment; customerShipment2.Pick(); this.Session.Derive(); customer.PickListsWhereShipToParty.First(v => v.PickListState.Equals(new PickListStates(this.Session).Created)).SetPicked(); var package2 = new ShipmentPackageBuilder(this.Session).Build(); customerShipment2.AddShipmentPackage(package2); foreach (ShipmentItem shipmentItem in customerShipment2.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.Session).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build()); } this.Session.Derive(); customerShipment2.Ship(); this.Session.Derive(); Assert.Equal(125, part.QuantityOnHand); Assert.Equal(8.03M, part.PartWeightedAverage.AverageCost); Assert.Equal(401.5M, salesItem1.CostOfGoodsSold); // Purchase: 50 items at 8.25 euro purchaseOrder1.Revise(); this.Session.Derive(); purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(50).WithAssignedUnitPrice(8.25M).Build(); purchaseOrder1.AddPurchaseOrderItem(purchaseItem); this.Session.Derive(); purchaseOrder1.SetReadyForProcessing(); this.Session.Derive(); purchaseOrder1.Send(); this.Session.Derive(); purchaseItem.QuickReceive(); this.Session.Derive(); Assert.Equal(175, part.QuantityOnHand); Assert.Equal(8.09M, part.PartWeightedAverage.AverageCost); // Use 65 items in a workorder var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(this.InternalOrganisation).Build(); this.Session.Derive(true); var inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workEffort) .WithInventoryItem(part.InventoryItemsWherePart.First) .WithQuantity(65) .Build(); this.Session.Derive(true); Assert.Equal(110, part.QuantityOnHand); Assert.Equal(8.09M, part.PartWeightedAverage.AverageCost); Assert.Equal(525.85M, inventoryAssignment.CostOfGoodsSold); // Cancel workeffort inventory assignment inventoryAssignment.Delete(); this.Session.Derive(true); Assert.Equal(175, part.QuantityOnHand); Assert.Equal(8.09M, part.PartWeightedAverage.AverageCost); // Use 35 items in a workorder inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workEffort) .WithInventoryItem(part.InventoryItemsWherePart.First) .WithQuantity(35) .Build(); this.Session.Derive(true); this.Session.Derive(true); Assert.Equal(140, part.QuantityOnHand); Assert.Equal(8.09M, part.PartWeightedAverage.AverageCost); Assert.Equal(283.15M, inventoryAssignment.CostOfGoodsSold); // Use 30 items in a workorder form second facility inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workEffort) .WithInventoryItem(part.InventoryItemsWherePart.First(v => v.Facility.Equals(secondFacility))) .WithQuantity(30) .Build(); this.Session.Derive(true); Assert.Equal(110, part.QuantityOnHand); Assert.Equal(8.09M, part.PartWeightedAverage.AverageCost); Assert.Equal(242.7M, inventoryAssignment.CostOfGoodsSold); // Purchase: 90 items at 8.35 euro var purchaseOrder3 = new PurchaseOrderBuilder(this.Session) .WithTakenViaSupplier(supplier) .WithDeliveryDate(this.Session.Now()) .Build(); this.Session.Derive(); purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(90).WithAssignedUnitPrice(8.35M).Build(); purchaseOrder3.AddPurchaseOrderItem(purchaseItem); this.Session.Derive(); purchaseOrder3.SetReadyForProcessing(); this.Session.Derive(); purchaseOrder3.Send(); this.Session.Derive(); purchaseOrder3.QuickReceive(); this.Session.Derive(); // Purchase: 50 items at 8.45 euro var purchaseOrder4 = new PurchaseOrderBuilder(this.Session) .WithTakenViaSupplier(supplier) .WithDeliveryDate(this.Session.Now()) .Build(); this.Session.Derive(); purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(50).WithAssignedUnitPrice(8.45M).Build(); purchaseOrder4.AddPurchaseOrderItem(purchaseItem); this.Session.Derive(); purchaseOrder4.SetReadyForProcessing(); this.Session.Derive(); purchaseOrder4.Send(); this.Session.Derive(); purchaseOrder4.QuickReceive(); this.Session.Derive(); Assert.Equal(250, part.QuantityOnHand); Assert.Equal(8.26M, part.PartWeightedAverage.AverageCost); // Ship 10 items to customer (without sales order) var outgoingShipment = new CustomerShipmentBuilder(this.Session) .WithShipToParty(customer) .WithShipToAddress(customer.ShippingAddress) .WithShipmentMethod(new ShipmentMethods(this.Session).Ground) .Build(); this.Session.Derive(true); var outgoingItem = new ShipmentItemBuilder(this.Session).WithGood(good).WithQuantity(10).Build(); outgoingShipment.AddShipmentItem(outgoingItem); this.Session.Derive(true); outgoingShipment.Pick(); this.Session.Derive(); customer.PickListsWhereShipToParty.First(v => v.PickListState.Equals(new PickListStates(this.Session).Created)).SetPicked(); package = new ShipmentPackageBuilder(this.Session).Build(); customerShipment2.AddShipmentPackage(package); foreach (ShipmentItem shipmentItem in outgoingShipment.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.Session).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build()); } this.Session.Derive(); outgoingShipment.Ship(); this.Session.Derive(); Assert.Equal(240, part.QuantityOnHand); Assert.Equal(8.26M, part.PartWeightedAverage.AverageCost); // Receive 10 items at 8.55 from supplier (without purchase order) var incomingShipment = new PurchaseShipmentBuilder(this.Session) .WithShipmentMethod(new ShipmentMethods(this.Session).Ground) .WithShipFromParty(supplier) .Build(); this.Session.Derive(); var incomingItem = new ShipmentItemBuilder(this.Session).WithPart(part).WithQuantity(10).WithUnitPurchasePrice(8.55M).Build(); incomingShipment.AddShipmentItem(incomingItem); this.Session.Derive(); incomingShipment.Receive(); this.Session.Derive(); Assert.Equal(250, part.QuantityOnHand); Assert.Equal(8.27M, part.PartWeightedAverage.AverageCost); // Receive 100 items at 7.9 from supplier (without purchase order) incomingShipment = new PurchaseShipmentBuilder(this.Session) .WithShipmentMethod(new ShipmentMethods(this.Session).Ground) .WithShipFromParty(supplier) .Build(); this.Session.Derive(); incomingItem = new ShipmentItemBuilder(this.Session).WithPart(part).WithQuantity(100).WithUnitPurchasePrice(7.9M).Build(); incomingShipment.AddShipmentItem(incomingItem); this.Session.Derive(); incomingShipment.Receive(); this.Session.Derive(); Assert.Equal(350, part.QuantityOnHand); Assert.Equal(8.17M, part.PartWeightedAverage.AverageCost); // Ship all items to customer (without sales order) outgoingShipment = new CustomerShipmentBuilder(this.Session) .WithShipToParty(customer) .WithShipFromFacility(part.DefaultFacility) .WithShipToAddress(customer.ShippingAddress) .WithShipmentMethod(new ShipmentMethods(this.Session).Ground) .Build(); this.Session.Derive(true); outgoingItem = new ShipmentItemBuilder(this.Session).WithGood(good).WithQuantity(330).Build(); outgoingShipment.AddShipmentItem(outgoingItem); this.Session.Derive(true); outgoingShipment.Pick(); this.Session.Derive(); customer.PickListsWhereShipToParty.First(v => v.PickListState.Equals(new PickListStates(this.Session).Created)).SetPicked(); package = new ShipmentPackageBuilder(this.Session).Build(); customerShipment2.AddShipmentPackage(package); foreach (ShipmentItem shipmentItem in outgoingShipment.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.Session).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build()); } this.Session.Derive(); outgoingShipment.Ship(); this.Session.Derive(); // Ship all items to customer (without sales order) outgoingShipment = new CustomerShipmentBuilder(this.Session) .WithShipToParty(customer) .WithShipFromFacility(secondFacility) .WithShipToAddress(customer.ShippingAddress) .WithShipmentMethod(new ShipmentMethods(this.Session).Ground) .Build(); this.Session.Derive(true); outgoingItem = new ShipmentItemBuilder(this.Session).WithGood(good).WithQuantity(20).Build(); outgoingShipment.AddShipmentItem(outgoingItem); this.Session.Derive(true); outgoingShipment.Pick(); this.Session.Derive(); customer.PickListsWhereShipToParty.First(v => v.PickListState.Equals(new PickListStates(this.Session).Created)).SetPicked(); package = new ShipmentPackageBuilder(this.Session).Build(); customerShipment2.AddShipmentPackage(package); foreach (ShipmentItem shipmentItem in outgoingShipment.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.Session).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build()); } this.Session.Derive(); outgoingShipment.Ship(); this.Session.Derive(); Assert.Equal(0, part.QuantityOnHand); Assert.Equal(8.17M, part.PartWeightedAverage.AverageCost); purchaseOrder1.Revise(); this.Session.Derive(); // Purchase 150 items at 8 euro purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(150).WithAssignedUnitPrice(8M).Build(); purchaseOrder1.AddPurchaseOrderItem(purchaseItem); this.Session.Derive(); purchaseOrder1.SetReadyForProcessing(); this.Session.Derive(); purchaseOrder1.Send(); this.Session.Derive(); purchaseItem.QuickReceive(); this.Session.Derive(); Assert.Equal(150, part.QuantityOnHand); Assert.Equal(8, part.PartWeightedAverage.AverageCost); }
public void GivenShipmentReceiptWhenDerivingThenInventoryItemQuantityOnHandIsUpdated() { var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(20).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var order1 = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithDeliveryDate(DateTime.UtcNow) .Build(); var salesItem = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item1").WithProduct(good).WithQuantityOrdered(30).WithActualUnitPrice(15).Build(); order1.AddSalesOrderItem(salesItem); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); order1.Confirm(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var sessionInventoryItem = (NonSerializedInventoryItem)this.DatabaseSession.Instantiate(inventoryItem); var sessionSalesItem = (SalesOrderItem)this.DatabaseSession.Instantiate(salesItem); var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); Assert.AreEqual(20, sessionSalesItem.QuantityPendingShipment); Assert.AreEqual(30, sessionSalesItem.QuantityReserved); Assert.AreEqual(10, sessionSalesItem.QuantityShortFalled); var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build(); var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(10).Build(); order.AddPurchaseOrderItem(item1); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); order.Confirm(); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build(); shipment.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(10) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); shipment.AppsComplete(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Assert.AreEqual(30, sessionInventoryItem.QuantityOnHand); Assert.AreEqual(30, sessionSalesItem.QuantityPendingShipment); Assert.AreEqual(30, sessionSalesItem.QuantityReserved); Assert.AreEqual(0, sessionSalesItem.QuantityShortFalled); }
public void GivenShipmentReceiptWhenDerivingThenOrderItemQuantityReceivedIsUpdated() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build(); var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(10).Build(); order.AddPurchaseOrderItem(item1); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); order.Confirm(); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build(); shipment.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(10) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); shipment.AppsComplete(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Assert.AreEqual(10, item1.QuantityReceived); this.DatabaseSession.Rollback(); }
public void BaseQuickReceive(PurchaseOrderQuickReceive method) { var session = this.Session(); if (this.ValidOrderItems.Any(v => ((PurchaseOrderItem)v).IsReceivable)) { var shipment = new PurchaseShipmentBuilder(session) .WithShipmentMethod(new ShipmentMethods(session).Ground) .WithShipToParty(this.OrderedBy) .WithShipToAddress(this.DerivedShipToAddress) .WithShipFromParty(this.TakenViaSupplier) .WithShipToFacility(this.StoredInFacility) .Build(); foreach (PurchaseOrderItem orderItem in this.ValidOrderItems) { ShipmentItem shipmentItem = null; if (orderItem.PurchaseOrderItemShipmentState.IsNotReceived && orderItem.ExistPart) { shipmentItem = new ShipmentItemBuilder(session) .WithPart(orderItem.Part) .WithStoredInFacility(orderItem.StoredInFacility) .WithQuantity(orderItem.QuantityOrdered) .WithUnitPurchasePrice(orderItem.UnitPrice) .WithContentsDescription($"{orderItem.QuantityOrdered} * {orderItem.Part.Name}") .Build(); shipment.AddShipmentItem(shipmentItem); new OrderShipmentBuilder(session) .WithOrderItem(orderItem) .WithShipmentItem(shipmentItem) .WithQuantity(orderItem.QuantityOrdered) .Build(); if (orderItem.Part.InventoryItemKind.IsSerialised) { var serialisedItem = orderItem.SerialisedItem; if (!orderItem.ExistSerialisedItem) { serialisedItem = new SerialisedItemBuilder(session) .WithSerialNumber(orderItem.SerialNumber) .Build(); orderItem.Part.AddSerialisedItem(serialisedItem); } shipmentItem.SerialisedItem = serialisedItem; serialisedItem.AcquiredDate = orderItem.PurchaseOrderWherePurchaseOrderItem.OrderDate; if (serialisedItem.ExistAcquiredDate && serialisedItem.ExistAcquisitionYear) { serialisedItem.RemoveAcquisitionYear(); } if (this.OrderedBy.SerialisedItemSoldOns.Contains(new SerialisedItemSoldOns(this.Session()).PurchaseshipmentReceive)) { serialisedItem.Buyer = this.OrderedBy; serialisedItem.OwnedBy = this.OrderedBy; serialisedItem.Ownership = new Ownerships(this.Session()).Own; } } } } if (shipment.ShipToParty is InternalOrganisation internalOrganisation) { if (internalOrganisation.IsAutomaticallyReceived) { shipment.Receive(); } } } }
public void GivenPurchaseOrder_WhenShipmentIsReceived_ThenCurrenShipmentStatusIsUpdated() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var part = new RawMaterialBuilder(this.DatabaseSession).WithName("RawMaterial").Build(); var order = new PurchaseOrderBuilder(this.DatabaseSession) .WithTakenViaSupplier(supplier) .WithBillToPurchaser(internalOrganisation) .WithVatRegime(new VatRegimes(this.DatabaseSession).Exempt) .Build(); var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(1).Build(); var item2 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(2).Build(); var item3 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(3).Build(); order.AddPurchaseOrderItem(item1); order.AddPurchaseOrderItem(item2); order.AddPurchaseOrderItem(item3); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); var shipment1 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build(); shipment1.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(1) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); shipment1.AppsComplete(); this.DatabaseSession.Derive(true); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Received, item1.CurrentShipmentStatus.PurchaseOrderItemObjectState); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).PartiallyReceived, order.CurrentShipmentStatus.PurchaseOrderObjectState); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentOrderStatus.PurchaseOrderObjectState); var shipment2 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build(); shipment2.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(2) .WithShipmentItem(shipmentItem) .WithOrderItem(item2) .Build(); shipment2.AppsComplete(); this.DatabaseSession.Derive(true); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Received, item2.CurrentShipmentStatus.PurchaseOrderItemObjectState); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).PartiallyReceived, order.CurrentShipmentStatus.PurchaseOrderObjectState); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentOrderStatus.PurchaseOrderObjectState); var shipment3 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build(); shipment3.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(3) .WithShipmentItem(shipmentItem) .WithOrderItem(item3) .Build(); shipment3.AppsComplete(); this.DatabaseSession.Derive(true); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Received, item3.CurrentShipmentStatus.PurchaseOrderItemObjectState); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).Received, order.CurrentShipmentStatus.PurchaseOrderObjectState); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).Completed, order.CurrentOrderStatus.PurchaseOrderObjectState); }
public void BaseQuickReceive(PurchaseOrderItemQuickReceive method) { var session = this.Session(); var order = this.PurchaseOrderWherePurchaseOrderItem; if (this.ExistPart) { var shipment = new PurchaseShipmentBuilder(session) .WithShipmentMethod(new ShipmentMethods(session).Ground) .WithShipToParty(order.OrderedBy) .WithShipFromParty(order.TakenViaSupplier) .WithShipToFacility(order.Facility) .Build(); var shipmentItem = new ShipmentItemBuilder(session) .WithPart(this.Part) .WithQuantity(this.QuantityOrdered) .WithUnitPurchasePrice(this.UnitPrice) .WithContentsDescription($"{this.QuantityOrdered} * {this.Part.Name}") .Build(); shipment.AddShipmentItem(shipmentItem); new OrderShipmentBuilder(session) .WithOrderItem(this) .WithShipmentItem(shipmentItem) .WithQuantity(this.QuantityOrdered) .Build(); new ShipmentReceiptBuilder(session) .WithQuantityAccepted(this.QuantityOrdered) .WithShipmentItem(shipmentItem) .WithOrderItem(this) .Build(); if (this.Part.InventoryItemKind.Serialised) { var serialisedItem = this.SerialisedItem; if (!this.ExistSerialisedItem) { serialisedItem = new SerialisedItemBuilder(session) .WithSerialNumber(this.SerialNumber) .Build(); this.Part.AddSerialisedItem(serialisedItem); } shipmentItem.SerialisedItem = serialisedItem; // HACK: DerivedRoles (WIP) var serialisedItemDeriveRoles = (SerialisedItemDerivedRoles)serialisedItem; serialisedItemDeriveRoles.PurchaseOrder = order; serialisedItemDeriveRoles.SuppliedBy = order.TakenViaSupplier; serialisedItem.RemoveAssignedPurchasePrice(); serialisedItemDeriveRoles.PurchasePrice = this.TotalExVat; serialisedItem.OwnedBy = order.OrderedBy; serialisedItem.Buyer = order.OrderedBy; serialisedItem.SerialisedItemAvailability = new SerialisedItemAvailabilities(this.Session()).Available; var inventoryItem = serialisedItem.SerialisedInventoryItemsWhereSerialisedItem .FirstOrDefault(v => v.SerialisedItem.Equals(serialisedItem) && v.Facility.Equals(order.Facility)); if (inventoryItem == null) { new SerialisedInventoryItemBuilder(this.Session()) .WithSerialisedItem(serialisedItem) .WithSerialisedInventoryItemState(new SerialisedInventoryItemStates(this.Session()).Good) .WithPart(this.Part) .WithUnitOfMeasure(new UnitsOfMeasure(this.Session()).Piece) .WithFacility(order.Facility) .Build(); } } if (shipment.ShipToParty is InternalOrganisation internalOrganisation) { if (internalOrganisation.IsAutomaticallyReceived) { shipment.Receive(); } } } else { this.QuantityReceived = 1; } }
public void GivenShipmentReceiptWhenDerivingThenInventoryItemQuantityOnHandIsUpdated() { var store = this.Session.Extent <Store>().First; store.IsImmediatelyPicked = false; var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.Session).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.Session) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.Session).ShippingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.Session).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); new CustomerRelationshipBuilder(this.Session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).Build(); var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1"); new InventoryItemTransactionBuilder(this.Session).WithQuantity(20).WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good1.Part).Build(); this.Session.Derive(); var inventoryItem = good1.Part.InventoryItemsWherePart.First; var order1 = new SalesOrderBuilder(this.Session) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithDeliveryDate(DateTime.UtcNow) .Build(); var salesItem = new SalesOrderItemBuilder(this.Session).WithDescription("item1").WithProduct(good1).WithQuantityOrdered(30).WithActualUnitPrice(15).Build(); order1.AddSalesOrderItem(salesItem); this.Session.Derive(); this.Session.Commit(); order1.Confirm(); this.Session.Derive(); this.Session.Commit(); var sessionInventoryItem = (NonSerialisedInventoryItem)this.Session.Instantiate(inventoryItem); var sessionSalesItem = (SalesOrderItem)this.Session.Instantiate(salesItem); var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build(); new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build(); Assert.Equal(20, sessionSalesItem.QuantityPendingShipment); Assert.Equal(30, sessionSalesItem.QuantityReserved); Assert.Equal(10, sessionSalesItem.QuantityShortFalled); var order = new PurchaseOrderBuilder(this.Session).WithTakenViaSupplier(supplier).Build(); var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(good1.Part).WithQuantityOrdered(10).Build(); order.AddPurchaseOrderItem(item1); this.Session.Derive(); this.Session.Commit(); order.Confirm(); var shipment = new PurchaseShipmentBuilder(this.Session).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.Session).WithGood(good1).Build(); shipment.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.Session) .WithQuantityAccepted(10) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); this.Session.Derive(); this.Session.Commit(); shipment.AppsComplete(); this.Session.Derive(); this.Session.Commit(); Assert.Equal(30, sessionInventoryItem.QuantityOnHand); Assert.Equal(30, sessionSalesItem.QuantityPendingShipment); Assert.Equal(30, sessionSalesItem.QuantityReserved); Assert.Equal(0, sessionSalesItem.QuantityShortFalled); }
public void BaseQuickReceive(PurchaseOrderQuickReceive method) { var session = this.Session(); if (this.ValidOrderItems.Any(v => ((PurchaseOrderItem)v).ExistPart)) { var shipment = new PurchaseShipmentBuilder(session) .WithShipmentMethod(new ShipmentMethods(session).Ground) .WithShipToParty(this.OrderedBy) .WithShipToAddress(this.ShipToAddress) .WithShipFromParty(this.TakenViaSupplier) .WithShipToFacility(this.Facility) .Build(); foreach (PurchaseOrderItem orderItem in this.ValidOrderItems) { ShipmentItem shipmentItem = null; if (orderItem.PurchaseOrderItemShipmentState.IsNotReceived && orderItem.ExistPart) { shipmentItem = new ShipmentItemBuilder(session) .WithPart(orderItem.Part) .WithQuantity(orderItem.QuantityOrdered) .WithUnitPurchasePrice(orderItem.UnitPrice) .WithContentsDescription($"{orderItem.QuantityOrdered} * {orderItem.Part.Name}") .Build(); shipment.AddShipmentItem(shipmentItem); new OrderShipmentBuilder(session) .WithOrderItem(orderItem) .WithShipmentItem(shipmentItem) .WithQuantity(orderItem.QuantityOrdered) .Build(); new ShipmentReceiptBuilder(session) .WithQuantityAccepted(orderItem.QuantityOrdered) .WithShipmentItem(shipmentItem) .WithOrderItem(orderItem) .Build(); if (orderItem.Part.InventoryItemKind.Serialised) { var serialisedItem = orderItem.SerialisedItem; if (!orderItem.ExistSerialisedItem) { serialisedItem = new SerialisedItemBuilder(session) .WithSerialNumber(orderItem.SerialNumber) .Build(); orderItem.Part.AddSerialisedItem(serialisedItem); } shipmentItem.SerialisedItem = serialisedItem; // HACK: DerivedRoles (WIP) var serialisedItemDeriveRoles = (SerialisedItemDerivedRoles)serialisedItem; serialisedItemDeriveRoles.PurchaseOrder = this; serialisedItemDeriveRoles.SuppliedBy = this.TakenViaSupplier; serialisedItem.RemoveAssignedPurchasePrice(); serialisedItemDeriveRoles.PurchasePrice = orderItem.TotalExVat; serialisedItem.AcquiredDate = orderItem.PurchaseOrderWherePurchaseOrderItem.OrderDate; if (serialisedItem.ExistAcquiredDate && serialisedItem.ExistAcquisitionYear) { serialisedItem.RemoveAcquisitionYear(); } serialisedItem.OwnedBy = this.OrderedBy; serialisedItem.Buyer = this.OrderedBy; serialisedItem.Ownership = new Ownerships(this.Session()).Own; serialisedItem.SerialisedItemAvailability = new SerialisedItemAvailabilities(this.Session()).Available; var inventoryItem = serialisedItem.SerialisedInventoryItemsWhereSerialisedItem .FirstOrDefault(v => v.SerialisedItem.Equals(serialisedItem) && v.Facility.Equals(this.Facility)); if (inventoryItem == null) { new SerialisedInventoryItemBuilder(this.Session()) .WithSerialisedItem(serialisedItem) .WithSerialisedInventoryItemState(new SerialisedInventoryItemStates(this.Session()).Good) .WithPart(orderItem.Part) .WithUnitOfMeasure(new UnitsOfMeasure(this.Session()).Piece) .WithFacility(this.Facility) .Build(); } } } } if (shipment.ShipToParty is InternalOrganisation internalOrganisation) { if (internalOrganisation.IsAutomaticallyReceived) { shipment.Receive(); } } } foreach (PurchaseOrderItem orderItem in this.ValidOrderItems.Where(v => !((PurchaseOrderItem)v).ExistPart)) { var orderItemDerivedRoles = (PurchaseOrderItemDerivedRoles)orderItem; orderItemDerivedRoles.QuantityReceived = 1; } }