public void GivenFinishedGoodWithSerializedInventory_WhenDeriving_ThenQuantityOnHandUpdated() { // Arrange var available = new SerialisedInventoryItemStates(this.Session).Available; var warehouse = new Facilities(this.Session).FindBy(M.Facility.FacilityType, new FacilityTypes(this.Session).Warehouse); var kinds = new InventoryItemKinds(this.Session); var unitsOfMeasure = new UnitsOfMeasure(this.Session); var unknown = new InventoryTransactionReasons(this.Session).Unknown; var vatRate21 = new VatRateBuilder(this.Session).WithRate(21).Build(); var category = new ProductCategoryBuilder(this.Session).WithName("category").Build(); var serialPart = CreatePart("FG1", kinds.Serialised); var serialItem1 = new SerialisedItemBuilder(this.Session).WithSerialNumber("1").Build(); var serialItem2 = new SerialisedItemBuilder(this.Session).WithSerialNumber("2").Build(); var serialItem3 = new SerialisedItemBuilder(this.Session).WithSerialNumber("3").Build(); serialPart.AddSerialisedItem(serialItem1); serialPart.AddSerialisedItem(serialItem2); serialPart.AddSerialisedItem(serialItem3); var good = CreateGood("10101", vatRate21, "good1", unitsOfMeasure.Piece, category, serialPart); // Act this.Session.Derive(true); CreateInventoryTransaction(1, unknown, serialPart, serialItem1); CreateInventoryTransaction(1, unknown, serialPart, serialItem2); CreateInventoryTransaction(1, unknown, serialPart, serialItem3); this.Session.Derive(true); // Assert Assert.Equal(3, serialPart.QuantityOnHand); }
public void GivenSerializedInventoryItems_WhenVarianceContainsInvalidQuantity_ThenDerivationExceptionRaised() { // Arrange var kinds = new InventoryItemKinds(this.Session); var unitsOfMeasure = new UnitsOfMeasure(this.Session); var unknown = new InventoryTransactionReasons(this.Session).Unknown; var vatRegime = new VatRegimes(this.Session).BelgiumStandard; var category = new ProductCategoryBuilder(this.Session).WithName("category").Build(); var finishedGood = this.CreatePart("FG1", kinds.Serialised); var good = this.CreateGood("10101", vatRegime, "good1", unitsOfMeasure.Piece, category, finishedGood); var serialItem = new SerialisedItemBuilder(this.Session).WithSerialNumber("1").Build(); var variance = this.CreateInventoryTransaction(10, unknown, finishedGood, serialItem); // Act var derivation = this.Session.Derive(false); // Assert Assert.True(derivation.HasErrors); Assert.Contains(M.InventoryItemTransaction.Quantity, derivation.Errors.SelectMany(e => e.RoleTypes)); // Re-Arrange variance.Quantity = -10; // Act derivation = this.Session.Derive(false); // Assert Assert.True(derivation.HasErrors); Assert.Contains(M.InventoryItemTransaction.Quantity, derivation.Errors.SelectMany(e => e.RoleTypes)); }
public void GivenInventoryItem_WhenPositiveVariance_ThenQuantityOnHandIsRaised() { var nonSerialized = new InventoryItemKinds(this.Session).NonSerialised; var unknown = new InventoryTransactionReasons(this.Session).Unknown; var vatRate21 = new VatRateBuilder(this.Session).WithRate(21).Build(); var piece = new UnitsOfMeasure(this.Session).Piece; var category = this.Session.Extent <ProductCategory>().First; var finishedGood = this.CreatePart("FG1", nonSerialized); this.Session.Derive(true); this.Session.Commit(); var inventoryItem = (NonSerialisedInventoryItem)finishedGood.InventoryItemsWherePart.First(); Assert.Equal(0, finishedGood.QuantityOnHand); Assert.Equal(0, inventoryItem.QuantityOnHand); var transaction = this.CreateInventoryTransaction(10, unknown, finishedGood); this.Session.Derive(true); Assert.Equal(10, finishedGood.QuantityOnHand); Assert.Equal(10, inventoryItem.QuantityOnHand); }
protected override void BaseSetup(Setup setup) { var reasons = new InventoryTransactionReasons(this.Session); var merge = this.Cache.Merger().Action(); merge(CreatedId, v => v.Name = "Created"); merge(InProgressId, v => v.Name = "In Progress"); merge(CompletedId, v => v.Name = "Completed"); merge(FinishedId, v => v.Name = "Finished"); merge(CancelledId, v => v.Name = "Cancelled"); // The created state is the initial and re-opened state (Cancel Consumption for Re-Open) //this.Created.AddInventoryTransactionReasonsToCreate(reasons.Reservation); //this.Created.AddInventoryTransactionReasonsToCancel(reasons.Consumption); this.Created.AddInventoryTransactionReasonsToCreate(reasons.Consumption); // The inprogress state is the initial and re-opened state (Cancel Consumption for Re-Open) this.InProgress.AddInventoryTransactionReasonsToCreate(reasons.Consumption); // The Delivered state should create a Consumption (which Decreases the Reservation) //this.Completed.AddInventoryTransactionReasonsToCreate(reasons.Reservation); this.Completed.AddInventoryTransactionReasonsToCreate(reasons.Consumption); // The Cancelled state should cancel any existing Consumption and Reservation //this.Cancelled.AddInventoryTransactionReasonsToCancel(reasons.Reservation); this.Cancelled.AddInventoryTransactionReasonsToCancel(reasons.Consumption); }
protected override void BaseSetup(Setup setup) { var reasons = new InventoryTransactionReasons(this.Session); var merge = this.Cache.Merger().Action(); merge(ProvisionalId, v => { v.Name = "Provisional"; }); merge(CancelledId, v => { v.Name = "Cancelled"; v.AddInventoryTransactionReasonsToCancel(reasons.Reservation); }); merge(CompletedId, v => { v.Name = "Completed"; }); merge(RejectedId, v => { v.Name = "Rejected"; v.AddInventoryTransactionReasonsToCancel(reasons.Reservation); }); merge(OnHoldId, v => { v.Name = "On Hold"; }); merge(InProcessId, v => { v.Name = "In Process"; v.AddInventoryTransactionReasonsToCreate(reasons.Reservation); }); merge(FinishedId, v => { v.Name = "Finished"; }); merge(ReadyForPostingId, v => { v.Name = "Ready For Posting"; }); merge(RequestsApprovalId, v => { v.Name = "Requests Approval"; }); merge(AwaitingAcceptanceId, v => { v.Name = "Awaiting customer acceptance"; }); }
public void GivenWorkEffort_WhenAddingInventoryAssignment_ThenInventoryConsumptionCreated() { // Arrange var customer = new OrganisationBuilder(this.Session).WithName("Org1").Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var reasons = new InventoryTransactionReasons(this.Session); var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build(); var part = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); this.Session.Derive(true); new InventoryItemTransactionBuilder(this.Session) .WithPart(part) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(11) .Build(); // Act this.Session.Derive(true); // Assert Assert.Empty(workEffort.WorkEffortInventoryAssignmentsWhereAssignment); Assert.True(workEffort.WorkEffortState.IsCreated); // Re-arrange var inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workEffort) .WithInventoryItem(part.InventoryItemsWherePart.First) .WithQuantity(10) .Build(); // Act this.Session.Derive(true); // Assert var transactions = inventoryAssignment.InventoryItemTransactions; Assert.Single(transactions); var transaction = transactions[0]; Assert.Equal(part, transaction.Part); Assert.Equal(10, transaction.Quantity); Assert.Equal(reasons.Consumption, transaction.Reason); Assert.Equal(0, part.QuantityCommittedOut); Assert.Equal(1, part.QuantityOnHand); }
public void GivenInventoryItem_WhenQuantityOnHandIsDecreased_ThenSalesOrderItemsWithQuantityRequestsShippingAreUpdated() { // Arrange var inventoryItemKinds = new InventoryItemKinds(this.Session); var unitsOfMeasure = new UnitsOfMeasure(this.Session); var varianceReasons = new InventoryTransactionReasons(this.Session); var contactMechanisms = new ContactMechanismPurposes(this.Session); var vatRate21 = new VatRateBuilder(this.Session).WithRate(21).Build(); var category = new ProductCategoryBuilder(this.Session).WithName("category").Build(); var finishedGood = CreatePart("1", inventoryItemKinds.NonSerialised); var good = CreateGood("10101", vatRate21, "good1", unitsOfMeasure.Piece, category, finishedGood); CreateInventoryTransaction(5, varianceReasons.Unknown, finishedGood); this.Session.Derive(true); var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.Session).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = CreateShipTo(mechelenAddress, contactMechanisms.ShippingAddress, true); var customer = new PersonBuilder(this.Session).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); var internalOrganisation = this.InternalOrganisation; new CustomerRelationshipBuilder(this.Session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).Build(); this.Session.Derive(true); var order = CreateSalesOrder(customer, customer, DateTime.UtcNow, false); var salesItem = CreateSalesOrderItem("item1", good, 10, 15); // Act order.AddSalesOrderItem(salesItem); this.Session.Derive(true); order.Confirm(); this.Session.Derive(true); // Assert Assert.Equal(5, salesItem.QuantityRequestsShipping); Assert.Equal(0, salesItem.QuantityPendingShipment); Assert.Equal(10, salesItem.QuantityReserved); Assert.Equal(5, salesItem.QuantityShortFalled); // Rearrange CreateInventoryTransaction(-2, varianceReasons.Unknown, finishedGood); // Act this.Session.Derive(); // Assert Assert.Equal(3, salesItem.QuantityRequestsShipping); Assert.Equal(0, salesItem.QuantityPendingShipment); Assert.Equal(10, salesItem.QuantityReserved); Assert.Equal(7, salesItem.QuantityShortFalled); }
public void GivenWorkEffortWithInventoryAssignment_WhenCompletingThenCancelling_ThenInventoryTransactionsCancelled() { // Arrange var reasons = new InventoryTransactionReasons(this.Session); var customer = new OrganisationBuilder(this.Session).WithName("Org1").Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build(); var part = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); this.Session.Derive(true); new InventoryItemTransactionBuilder(this.Session) .WithPart(part) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(10) .Build(); this.Session.Derive(true); var inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workEffort) .WithInventoryItem(part.InventoryItemsWherePart.First) .WithQuantity(10) .Build(); this.Session.Derive(true); // Act workEffort.Complete(); this.Session.Derive(true); workEffort.Cancel(); this.Session.Derive(true); // Assert var transactions = inventoryAssignment.InventoryItemTransactions; var consumption = transactions.First(t => t.Reason.Equals(reasons.Consumption) && (t.Quantity > 0)); var consumptionCancellation = transactions.First(t => t.Reason.Equals(reasons.Consumption) && (t.Quantity < 0)); Assert.Equal(2, transactions.Count); Assert.Equal(10, consumption.Quantity); Assert.Equal(-10, consumptionCancellation.Quantity); Assert.Equal(10, part.QuantityOnHand); }
protected override void AppsSetup(Setup setup) { base.AppsSetup(setup); var reasons = new InventoryTransactionReasons(this.Session); new WorkEffortStateBuilder(this.Session) .WithUniqueId(CreatedId) .WithName("Created") .Build(); new WorkEffortStateBuilder(this.Session) .WithUniqueId(InProgressId) .WithName("In Progress") .Build(); new WorkEffortStateBuilder(this.Session) .WithUniqueId(CompletedId) .WithName("Completed") .Build(); new WorkEffortStateBuilder(this.Session) .WithUniqueId(FinishedId) .WithName("Finished") .Build(); new WorkEffortStateBuilder(this.Session) .WithUniqueId(CancelledId) .WithName("Cancelled") .Build(); // The created state is the initial and re-opened state (Cancel Consumption for Re-Open) this.Created.AddInventoryTransactionReasonsToCreate(reasons.Reservation); this.Created.AddInventoryTransactionReasonsToCancel(reasons.Consumption); // The inprogress state is the initial and re-opened state (Cancel Consumption for Re-Open) this.InProgress.AddInventoryTransactionReasonsToCreate(reasons.Reservation); // The Completed state should create a Consumption (which Decreases the Reservation) this.Completed.AddInventoryTransactionReasonsToCreate(reasons.Reservation); this.Completed.AddInventoryTransactionReasonsToCreate(reasons.Consumption); // The Cancelled state should cancel any existing Consumption and Reservation this.Cancelled.AddInventoryTransactionReasonsToCancel(reasons.Reservation); this.Cancelled.AddInventoryTransactionReasonsToCancel(reasons.Consumption); }
public void GivenWorkEffortWithInventoryAssignment_WhenCancelling_ThenInventoryReservationCancelled() { // Arrange var reasons = new InventoryTransactionReasons(this.Session); var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").Build(); var part = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); new InventoryItemTransactionBuilder(this.Session) .WithPart(part) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(10) .Build(); this.Session.Derive(true); var inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workEffort) .WithInventoryItem(part.InventoryItemsWherePart.First) .WithQuantity(10) .Build(); this.Session.Derive(true); // Act workEffort.Cancel(); this.Session.Derive(true); // Assert var transactions = inventoryAssignment.InventoryItemTransactions; Assert.Equal(2, transactions.Count); var reservation = transactions.First(t => t.Reason.Equals(reasons.Reservation) && (t.Quantity > 0)); var reservationCancellation = transactions.First(t => t.Reason.Equals(reasons.Reservation) && (t.Quantity < 0)); Assert.Equal(10, reservation.Quantity); Assert.Equal(-10, reservationCancellation.Quantity); Assert.Equal(0, part.QuantityCommittedOut); }
public void GivenSerializedItemInMultipleFacilities_WhenDeriving_ThenMultipleQuantityOnHandTracked() { // Arrange var warehouseType = new FacilityTypes(this.Session).Warehouse; var warehouse1 = CreateFacility("WH1", warehouseType, this.InternalOrganisation); var warehouse2 = CreateFacility("WH2", warehouseType, this.InternalOrganisation); var serialized = new InventoryItemKinds(this.Session).Serialised; var piece = new UnitsOfMeasure(this.Session).Piece; var unknown = new InventoryTransactionReasons(this.Session).Unknown; var vatRate21 = new VatRateBuilder(this.Session).WithRate(21).Build(); var category = new ProductCategoryBuilder(this.Session).WithName("category").Build(); var finishedGood = CreatePart("FG1", serialized); var serialItem1 = new SerialisedItemBuilder(this.Session).WithSerialNumber("1").Build(); var serialItem2 = new SerialisedItemBuilder(this.Session).WithSerialNumber("2").Build(); finishedGood.AddSerialisedItem(serialItem1); finishedGood.AddSerialisedItem(serialItem2); var good = CreateGood("10101", vatRate21, "good1", piece, category, finishedGood); // Act this.Session.Derive(true); CreateInventoryTransaction(1, unknown, finishedGood, serialItem1, warehouse1); CreateInventoryTransaction(1, unknown, finishedGood, serialItem2, warehouse2); this.Session.Derive(true); // Assert var item1 = (SerialisedInventoryItem) new InventoryItems(this.Session).Extent().First(i => i.Facility.Equals(warehouse1)); Assert.Equal(1, item1.QuantityOnHand); var item2 = (SerialisedInventoryItem) new InventoryItems(this.Session).Extent().First(i => i.Facility.Equals(warehouse2)); Assert.Equal(1, item2.QuantityOnHand); Assert.Equal(2, finishedGood.QuantityOnHand); }
public void GivenInventoryItem_WhenQuantityOnHandIsRaised_ThenSalesOrderItemsWithQuantityShortFalledAreUpdated() { // Arrange var inventoryItemKinds = new InventoryItemKinds(this.Session); var unitsOfMeasure = new UnitsOfMeasure(this.Session); var varianceReasons = new InventoryTransactionReasons(this.Session); var contactMechanisms = new ContactMechanismPurposes(this.Session); var store = this.Session.Extent <Store>().First; store.IsImmediatelyPicked = false; var vatRate21 = new VatRateBuilder(this.Session).WithRate(21).Build(); var category = new ProductCategoryBuilder(this.Session).WithName("category").Build(); var finishedGood = this.CreatePart("1", inventoryItemKinds.NonSerialised); var good = this.CreateGood("10101", vatRate21, "good1", unitsOfMeasure.Piece, category, finishedGood); this.Session.Derive(); this.CreateInventoryTransaction(5, varianceReasons.Unknown, finishedGood); this.Session.Derive(); var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = this.CreateShipTo(mechelenAddress, contactMechanisms.ShippingAddress, true); var customer = new PersonBuilder(this.Session).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).Build(); this.Session.Derive(); this.Session.Commit(); var order1 = this.CreateSalesOrder(customer, customer, this.Session.Now()); var salesItem1 = this.CreateSalesOrderItem("item1", good, 10, 15); var salesItem2 = this.CreateSalesOrderItem("item2", good, 20, 15); order1.AddSalesOrderItem(salesItem1); order1.AddSalesOrderItem(salesItem2); var order2 = this.CreateSalesOrder(customer, customer, this.Session.Now().AddDays(1)); var salesItem3 = this.CreateSalesOrderItem("item3", good, 10, 15); var salesItem4 = this.CreateSalesOrderItem("item4", good, 20, 15); order2.AddSalesOrderItem(salesItem3); order2.AddSalesOrderItem(salesItem4); this.Session.Derive(); this.Session.Commit(); // Act order1.SetReadyForPosting(); this.Session.Derive(true); order1.Post(); this.Session.Derive(); order1.Accept(); this.Session.Derive(); Assert.Equal(0, salesItem1.ReservedFromNonSerialisedInventoryItem.AvailableToPromise); Assert.Equal(5, salesItem1.ReservedFromNonSerialisedInventoryItem.QuantityOnHand); order2.SetReadyForPosting(); this.Session.Derive(true); order2.Post(); this.Session.Derive(); order2.Accept(); this.Session.Derive(); // Assert Assert.Equal(0, salesItem1.QuantityRequestsShipping); Assert.Equal(5, salesItem1.QuantityPendingShipment); Assert.Equal(10, salesItem1.QuantityReserved); Assert.Equal(5, salesItem1.QuantityShortFalled); Assert.Equal(0, salesItem2.QuantityRequestsShipping); Assert.Equal(0, salesItem2.QuantityPendingShipment); Assert.Equal(20, salesItem2.QuantityReserved); Assert.Equal(20, salesItem2.QuantityShortFalled); Assert.Equal(0, salesItem3.QuantityRequestsShipping); Assert.Equal(0, salesItem3.QuantityPendingShipment); Assert.Equal(10, salesItem3.QuantityReserved); Assert.Equal(10, salesItem3.QuantityShortFalled); Assert.Equal(0, salesItem4.QuantityRequestsShipping); Assert.Equal(0, salesItem4.QuantityPendingShipment); Assert.Equal(20, salesItem4.QuantityReserved); Assert.Equal(20, salesItem4.QuantityShortFalled); Assert.Equal(0, salesItem1.ReservedFromNonSerialisedInventoryItem.AvailableToPromise); Assert.Equal(5, salesItem1.ReservedFromNonSerialisedInventoryItem.QuantityOnHand); // Re-arrange this.CreateInventoryTransaction(15, varianceReasons.Unknown, finishedGood); // Act this.Session.Derive(true); this.Session.Commit(); // Assert // Orderitems are sorted as follows: item1, item2, item3, item4 Assert.Equal(0, salesItem1.QuantityRequestsShipping); Assert.Equal(10, salesItem1.QuantityPendingShipment); Assert.Equal(10, salesItem1.QuantityReserved); Assert.Equal(0, salesItem1.QuantityShortFalled); Assert.Equal(0, salesItem2.QuantityRequestsShipping); Assert.Equal(10, salesItem2.QuantityPendingShipment); Assert.Equal(20, salesItem2.QuantityReserved); Assert.Equal(10, salesItem2.QuantityShortFalled); Assert.Equal(0, salesItem3.QuantityRequestsShipping); Assert.Equal(0, salesItem3.QuantityPendingShipment); Assert.Equal(10, salesItem3.QuantityReserved); Assert.Equal(10, salesItem3.QuantityShortFalled); Assert.Equal(0, salesItem4.QuantityRequestsShipping); Assert.Equal(0, salesItem4.QuantityPendingShipment); Assert.Equal(20, salesItem4.QuantityReserved); Assert.Equal(20, salesItem4.QuantityShortFalled); Assert.Equal(0, salesItem1.ReservedFromNonSerialisedInventoryItem.AvailableToPromise); Assert.Equal(20, salesItem1.ReservedFromNonSerialisedInventoryItem.QuantityOnHand); // Re-arrange this.CreateInventoryTransaction(85, varianceReasons.Unknown, finishedGood); // Act this.Session.Derive(); this.Session.Commit(); // Assert // Orderitems are sorted as follows: item2, item1, item4, item 3 Assert.Equal(0, salesItem1.QuantityRequestsShipping); Assert.Equal(10, salesItem1.QuantityPendingShipment); Assert.Equal(10, salesItem1.QuantityReserved); Assert.Equal(0, salesItem1.QuantityShortFalled); Assert.Equal(0, salesItem2.QuantityRequestsShipping); Assert.Equal(20, salesItem2.QuantityPendingShipment); Assert.Equal(20, salesItem2.QuantityReserved); Assert.Equal(0, salesItem2.QuantityShortFalled); Assert.Equal(0, salesItem3.QuantityRequestsShipping); Assert.Equal(10, salesItem3.QuantityPendingShipment); Assert.Equal(10, salesItem3.QuantityReserved); Assert.Equal(0, salesItem3.QuantityShortFalled); Assert.Equal(0, salesItem4.QuantityRequestsShipping); Assert.Equal(20, salesItem4.QuantityPendingShipment); Assert.Equal(20, salesItem4.QuantityReserved); Assert.Equal(0, salesItem4.QuantityShortFalled); Assert.Equal(45, salesItem1.ReservedFromNonSerialisedInventoryItem.AvailableToPromise); Assert.Equal(105, salesItem1.ReservedFromNonSerialisedInventoryItem.QuantityOnHand); }
public SalesOrderItemInventoryAssignmentTests() { this.reasons = new InventoryTransactionReasons(this.Session); var customer = new PersonBuilder(this.Session).WithFirstName("Koen").Build(); var internalOrganisation = this.InternalOrganisation; new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); this.part = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised) .Build(); var good = new NonUnifiedGoodBuilder(this.Session) .WithProductIdentification(new ProductNumberBuilder(this.Session) .WithIdentification("10101") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Good).Build()) .WithName("good") .WithPart(this.part) .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece) .WithVatRegime(new VatRegimes(this.Session).BelgiumStandard) .Build(); this.Session.Derive(); new InventoryItemTransactionBuilder(this.Session) .WithPart(this.part) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(11) .Build(); this.Session.Derive(); var salesOrder = new SalesOrderBuilder(this.Session) .WithTakenBy(this.InternalOrganisation) .WithShipToCustomer(customer) .WithAssignedShipToAddress(new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .WithAssignedBillToContactMechanism(new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .Build(); this.salesOrderItem = new SalesOrderItemBuilder(this.Session) .WithProduct(good) .WithQuantityOrdered(3) .WithAssignedUnitPrice(5) .Build(); salesOrder.AddSalesOrderItem(this.salesOrderItem); this.Session.Derive(); salesOrder.SetReadyForPosting(); this.Session.Derive(); salesOrder.Post(); this.Session.Derive(); salesOrder.Accept(); this.Session.Derive(); this.Session.Commit(); }
public void GivenWorkEffortWithInventoryAssignment_WhenChangingPart_ThenInventoryConsumptionChange() { // Arrange var reasons = new InventoryTransactionReasons(this.Session); var customer = new OrganisationBuilder(this.Session).WithName("Org1").Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build(); var part1 = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); var part2 = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P2") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); this.Session.Derive(true); new InventoryItemTransactionBuilder(this.Session) .WithPart(part1) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(10) .Build(); new InventoryItemTransactionBuilder(this.Session) .WithPart(part2) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(10) .Build(); this.Session.Derive(true); var inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workEffort) .WithInventoryItem(part1.InventoryItemsWherePart.First) .WithQuantity(10) .Build(); // Act this.Session.Derive(true); // Assert var transactions = inventoryAssignment.InventoryItemTransactions.ToArray(); Assert.Single(transactions); Assert.Equal(part1, transactions[0].Part); Assert.Equal(10, transactions[0].Quantity); Assert.Equal(reasons.Consumption, transactions[0].Reason); // Re-arrange inventoryAssignment.InventoryItem = part2.InventoryItemsWherePart.First; // Act this.Session.Derive(true); // Assert var part1Transactions = inventoryAssignment.InventoryItemTransactions.Where(t => t.Part.Equals(part1)).ToArray(); var part2Transactions = inventoryAssignment.InventoryItemTransactions.Where(t => t.Part.Equals(part2)).ToArray(); Assert.Equal(0, part1Transactions.Sum(t => t.Quantity)); Assert.Equal(10, part2Transactions.Sum(t => t.Quantity)); Assert.Equal(10, part1.QuantityOnHand); Assert.Equal(0, part2.QuantityOnHand); }
public void GivenWorkEffortWithInventoryAssignment_WhenChangingPartAndQuantityAndReopening_ThenOldInventoryCancelledAndNewInventoryCreated() { // Arrange var reasons = new InventoryTransactionReasons(this.Session); var customer = new OrganisationBuilder(this.Session).WithName("Org1").Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build(); var part1 = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); var part2 = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P2") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); this.Session.Derive(true); new InventoryItemTransactionBuilder(this.Session) .WithPart(part1) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(10) .Build(); new InventoryItemTransactionBuilder(this.Session) .WithPart(part2) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(5) .Build(); this.Session.Derive(true); var inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workEffort) .WithInventoryItem(part1.InventoryItemsWherePart.First) .WithQuantity(10) .Build(); this.Session.Derive(true); workEffort.Complete(); this.Session.Derive(true); workEffort.Reopen(); this.Session.Derive(true); // Act inventoryAssignment.InventoryItem = part2.InventoryItemsWherePart.First; inventoryAssignment.Quantity = 4; this.Session.Derive(true); // Assert var part1Transactions = inventoryAssignment.InventoryItemTransactions.Where(t => t.Part.Equals(part1)).ToArray(); var part2Transactions = inventoryAssignment.InventoryItemTransactions.Where(t => t.Part.Equals(part2)).ToArray(); var part1Consumptions = part1Transactions.Where(t => t.Reason.Equals(reasons.Consumption)); var part2Consumptions = part2Transactions.Where(t => t.Reason.Equals(reasons.Consumption)); Assert.Equal(0, part1Consumptions.Sum(c => c.Quantity)); Assert.Equal(4, part2Consumptions.Sum(r => r.Quantity)); Assert.Equal(10, part1.QuantityOnHand); Assert.Equal(1, part2.QuantityOnHand); }
public void GivenWorkEffortWithInventoryAssignment_WhenChangingPartAndQuantityAndFinishing_ThenOldInventoryCancelledAndNewInventoryCreated() { // Arrange var reasons = new InventoryTransactionReasons(this.Session); var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").Build(); var part1 = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); var part2 = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P2") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); new InventoryItemTransactionBuilder(this.Session) .WithPart(part1) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(10) .Build(); new InventoryItemTransactionBuilder(this.Session) .WithPart(part2) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(10) .Build(); this.Session.Derive(true); var inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workEffort) .WithInventoryItem(part1.InventoryItemsWherePart.First) .WithQuantity(10) .Build(); this.Session.Derive(true); // Act inventoryAssignment.InventoryItem = part2.InventoryItemsWherePart.First; inventoryAssignment.Quantity = 5; workEffort.Complete(); this.Session.Derive(true); // Assert var part1Transactions = inventoryAssignment.InventoryItemTransactions.Where(t => t.Part.Equals(part1)).ToArray(); var part2Transactions = inventoryAssignment.InventoryItemTransactions.Where(t => t.Part.Equals(part2)).ToArray(); var part1Reservations = part1Transactions.Where(t => t.Reason.Equals(reasons.Reservation)); var part2Reservations = part2Transactions.Where(t => t.Reason.Equals(reasons.Reservation)); var part2Consumption = part2Transactions.Where(t => t.Reason.Equals(reasons.Consumption)); Assert.Equal(0, part1Reservations.Sum(r => r.Quantity)); Assert.Equal(5, part2Reservations.Sum(r => r.Quantity)); Assert.Equal(5, part2Consumption.Sum(c => c.Quantity)); Assert.Equal(0, part1.QuantityCommittedOut); Assert.Equal(10, part1.QuantityOnHand); Assert.Equal(0, part2.QuantityCommittedOut); Assert.Equal(5, part2.QuantityOnHand); }
public void GivenWorkEffortWithInventoryAssignment_WhenChangingQuantity_ThenInventoryTransactionsCreated() { // Arrage var reasons = new InventoryTransactionReasons(this.Session); var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").Build(); var part = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); new InventoryItemTransactionBuilder(this.Session) .WithPart(part) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(20) .Build(); this.Session.Derive(true); var inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workEffort) .WithInventoryItem(part.InventoryItemsWherePart.First) .WithQuantity(5) .Build(); // Act this.Session.Derive(true); // Assert var reservation = inventoryAssignment.InventoryItemTransactions.First(t => t.Reason.Equals(reasons.Reservation) && (t.Quantity > 0)); Assert.Equal(5, reservation.Quantity); // Re-arrange inventoryAssignment.Quantity = 10; // Act this.Session.Derive(true); // Assert var reservations = inventoryAssignment.InventoryItemTransactions.Where(t => t.Reason.Equals(reasons.Reservation)); Assert.Equal(10, reservations.Sum(r => r.Quantity)); // Re-arrange workEffort.Complete(); // Act this.Session.Derive(true); // Assert reservations = inventoryAssignment.InventoryItemTransactions.Where(t => t.Reason.Equals(reasons.Reservation)); var consumption = inventoryAssignment.InventoryItemTransactions.First(t => t.Reason.Equals(reasons.Consumption)); Assert.Equal(3, inventoryAssignment.InventoryItemTransactions.Count); Assert.Equal(10, reservations.Sum(r => r.Quantity)); Assert.Equal(10, consumption.Quantity); Assert.Equal(0, part.QuantityCommittedOut); Assert.Equal(10, part.QuantityOnHand); }
public void GivenWorkEffortWithInventoryAssignment_WhenChangingPart_ThenInventoryReservationsChange() { // Arrange var reasons = new InventoryTransactionReasons(this.Session); var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").Build(); var part1 = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); var part2 = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P2") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); new InventoryItemTransactionBuilder(this.Session) .WithPart(part1) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(10) .Build(); new InventoryItemTransactionBuilder(this.Session) .WithPart(part2) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(10) .Build(); this.Session.Derive(true); var inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workEffort) .WithInventoryItem(part1.InventoryItemsWherePart.First) .WithQuantity(10) .Build(); // Act this.Session.Derive(true); // Assert var transactions = inventoryAssignment.InventoryItemTransactions.ToArray(); Assert.Single(transactions); Assert.Equal(part1, transactions[0].Part); Assert.Equal(10, transactions[0].Quantity); Assert.Equal(reasons.Reservation, transactions[0].Reason); // Re-arrange inventoryAssignment.InventoryItem = part2.InventoryItemsWherePart.First; // Act this.Session.Derive(true); // Assert var part1Transactions = inventoryAssignment.InventoryItemTransactions.Where(t => t.Part.Equals(part1)).ToArray(); var part2Transactions = inventoryAssignment.InventoryItemTransactions.Where(t => t.Part.Equals(part2)).ToArray(); Assert.Equal(0, part1Transactions.Sum(t => t.Quantity)); Assert.Equal(10, part2Transactions.Sum(t => t.Quantity)); Assert.Equal(0, part1.QuantityCommittedOut); Assert.Equal(10, part2.QuantityCommittedOut); }