/* * Create PurchaseOrder with both Serialized & NonSerialized PurchaseOrder Items */ public static PurchaseOrder CreatePurchaseOrderWithBothItems(this Organisation @this, Faker faker) { var serializedPart = new UnifiedGoodBuilder(@this.Session()).WithSerialisedDefaults(@this).Build(); var serializedItem = new SerialisedItemBuilder(@this.Session()).WithDefaults(@this).Build(); serializedPart.AddSerialisedItem(serializedItem); var nonSerializedPart = new NonUnifiedPartBuilder(@this.Session()).WithNonSerialisedDefaults(@this).Build(); var purchaseOrder = new PurchaseOrderBuilder(@this.Session()).WithDefaults(@this).Build(); new SupplierOfferingBuilder(@this.Session()) .WithPart(nonSerializedPart) .WithSupplier(purchaseOrder.TakenViaSupplier) .WithFromDate(@this.Session().Now().AddMinutes(-1)) .WithUnitOfMeasure(new UnitsOfMeasure(@this.Session()).Piece) .WithPrice(faker.Random.Decimal(0, 10)) .Build(); var nonSerializedPartItem = new PurchaseOrderItemBuilder(@this.Session()).WithNonSerializedPartDefaults(nonSerializedPart).Build(); var serializedPartItem = new PurchaseOrderItemBuilder(@this.Session()).WithSerializedPartDefaults(serializedPart, serializedItem).Build(); purchaseOrder.AddPurchaseOrderItem(nonSerializedPartItem); purchaseOrder.AddPurchaseOrderItem(serializedPartItem); return(purchaseOrder); }
public void GivenOrderItem_WhenDeriving_ThenRequiredRelationsMustExist() { this.InstantiateObjects(this.Session); var buyer = new OrganisationBuilder(this.Session).WithName("buyer").Build(); var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); var shipToContactMechanism = new PostalAddressBuilder(this.Session).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var partyContactMechanism = new PartyContactMechanismBuilder(this.Session).WithContactMechanism(shipToContactMechanism).Build(); var part = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); buyer.AddPartyContactMechanism(partyContactMechanism); this.Session.Derive(); this.Session.Commit(); var builder = new PurchaseOrderItemBuilder(this.Session); order.AddPurchaseOrderItem(builder.Build()); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithPart(part); order.AddPurchaseOrderItem(builder.Build()); Assert.False(this.Session.Derive(false).HasErrors); }
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 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); }
public void GivenPart_WhenBuild_ThenPostBuildRelationsMustExist() { var finishedGood = 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(); Assert.Equal(new InventoryItemKinds(this.Session).NonSerialised, finishedGood.InventoryItemKind); }
public void GivenInventoryItemForPart_WhenDerived_ThenNameIsPartName() { var 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(); this.Session.Derive(); Assert.Equal("Part 1 at facility with state Good", part.InventoryItemsWherePart.Single().Name); }
public void GivenSupplierOffering_WhenDeriving_ThenRequiredRelationsMustExist() { var supplier = new OrganisationBuilder(this.Session).WithName("organisation").Build(); var part = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised) .Build(); this.Session.Commit(); var builder = new SupplierOfferingBuilder(this.Session); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithPrice(1); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithSupplier(supplier); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Pack); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithCurrency(new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR")); builder.Build(); Assert.False(this.Session.Derive(false).HasErrors); builder.WithPart(part); builder.Build(); Assert.False(this.Session.Derive(false).HasErrors); }
public void GivenNewPart_WhenDeriving_ThenInventoryItemIsCreated() { var finishedGood = 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(); this.Session.Derive(); Assert.Equal(1, finishedGood.InventoryItemsWherePart.Count); Assert.Equal(new Facilities(this.Session).FindBy(M.Facility.FacilityType, new FacilityTypes(this.Session).Warehouse), finishedGood.InventoryItemsWherePart.First.Facility); }
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 GivenInventoryItemForPart_WhenDerived_ThenUnitOfMeasureIsPartUnitOfMeasure() { var uom = new UnitsOfMeasure(this.Session).Centimeter; var 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) .WithUnitOfMeasure(uom) .Build(); this.Session.Derive(); Assert.Equal(part.UnitOfMeasure, part.InventoryItemsWherePart.Single().UnitOfMeasure); }
public static Part CreateSerialisedNonUnifiedPart(this Organisation @this, Faker faker) { var part = new NonUnifiedPartBuilder(@this.Session()).WithSerialisedDefaults(@this, faker).Build(); foreach (Organisation supplier in @this.CurrentSuppliers) { new SupplierOfferingBuilder(@this.Session()) .WithFromDate(faker.Date.Past(refDate: @this.Session().Now())) .WithSupplier(supplier) .WithPart(part) .WithUnitOfMeasure(part.UnitOfMeasure) .Build(); } return(part); }
public void GivenGood_WhenDeriving_ThenRequiredRelationsMustExist() { var vatRate21 = new VatRateBuilder(this.Session).WithRate(21).Build(); var finishedGood = 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(); this.Session.Derive(); this.Session.Commit(); var builder = new NonUnifiedGoodBuilder(this.Session); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithName("good"); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithVatRate(vatRate21); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithPart(finishedGood); builder.Build(); Assert.False(this.Session.Derive(false).HasErrors); }
public void GivenPurchaseOrder_WhenConfirming_ThenAllValidItemsAreInConfirmedState() { var supplier = new OrganisationBuilder(this.Session).WithName("customer2").Build(); new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build(); var part = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .Build(); var order = new PurchaseOrderBuilder(this.Session) .WithTakenViaSupplier(supplier) .WithVatRegime(new VatRegimes(this.Session).Exempt) .Build(); var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(1).Build(); var item2 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(2).Build(); var item3 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(3).Build(); var item4 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(4).Build(); order.AddPurchaseOrderItem(item1); order.AddPurchaseOrderItem(item2); order.AddPurchaseOrderItem(item3); order.AddPurchaseOrderItem(item4); this.Session.Derive(); order.Confirm(); this.Session.Derive(); item4.Cancel(); this.Session.Derive(); Assert.Equal(3, order.ValidOrderItems.Count); Assert.Contains(item1, order.ValidOrderItems); Assert.Contains(item2, order.ValidOrderItems); Assert.Contains(item3, order.ValidOrderItems); Assert.Equal(new PurchaseOrderItemStates(this.Session).InProcess, item1.PurchaseOrderItemState); Assert.Equal(new PurchaseOrderItemStates(this.Session).InProcess, item2.PurchaseOrderItemState); Assert.Equal(new PurchaseOrderItemStates(this.Session).InProcess, item3.PurchaseOrderItemState); Assert.Equal(new PurchaseOrderItemStates(this.Session).Cancelled, item4.PurchaseOrderItemState); }
public void GivenInventoryItemForPart_WhenDerived_ThenNameIsPartName() { var 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 item = new NonSerialisedInventoryItemBuilder(this.Session) .WithPart(part) .Build(); this.Session.Derive(); Assert.Equal(part.Name, item.Name); }
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 GivenInventoryItem_WhenBuild_ThenLastObjectStateEqualsCurrencObjectState() { var 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(); this.Session.Derive(); var item = new NonSerialisedInventoryItemBuilder(this.Session) .WithPart(part) .Build(); this.Session.Derive(); Assert.Equal(new NonSerialisedInventoryItemStates(this.Session).Good, item.NonSerialisedInventoryItemState); Assert.Equal(item.LastNonSerialisedInventoryItemState, item.NonSerialisedInventoryItemState); }
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.SetReadyForProcessing(); this.Session.Derive(); order.QuickReceive(); this.Session.Derive(); var shipment = (PurchaseShipment)item1.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem; shipment.Receive(); this.Session.Derive(); var receipt = item1.ShipmentReceiptsWhereOrderItem.Single(); 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); }
public static Part CreateNonSerialisedNonUnifiedPart(this Organisation @this, Faker faker) { var part = new NonUnifiedPartBuilder(@this.Session()).WithNonSerialisedDefaults(@this).Build(); foreach (Organisation supplier in @this.CurrentSuppliers) { new SupplierOfferingBuilder(@this.Session()) .WithFromDate(faker.Date.Past(refDate: @this.Session().Now())) .WithSupplier(supplier) .WithPart(part) .WithUnitOfMeasure(part.UnitOfMeasure) .Build(); } new InventoryItemTransactionBuilder(@this.Session()) .WithPart(part) .WithFacility(@this.FacilitiesWhereOwner.First) .WithQuantity(faker.Random.Number(1000)) .WithReason(new InventoryTransactionReasons(@this.Session()).Unknown) .Build(); return(part); }
public void GivenInventoryItem_WhenDeriving_ThenRequiredRelationsMustExist() { // Arrange var serialItem = new SerialisedItemBuilder(this.Session).WithSerialNumber("1").Build(); var part = new NonUnifiedPartBuilder(this.Session).WithName("part") .WithInventoryItemKind(new InventoryItemKinds(this.Session).Serialised) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .WithSerialisedItem(serialItem) .Build(); this.Session.Derive(true); this.Session.Commit(); var builder = new SerialisedInventoryItemBuilder(this.Session).WithPart(part); builder.Build(); // Act var derivation = this.Session.Derive(false); // Assert Assert.True(derivation.HasErrors); // Re-arrange this.Session.Rollback(); builder.WithSerialisedItem(serialItem); builder.Build(); // Act derivation = this.Session.Derive(false); // Assert Assert.False(derivation.HasErrors); }
public void GivenInventoryItem_WhenBuild_ThenPostBuildRelationsMustExist() { var 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(); this.Session.Derive(); var item = new NonSerialisedInventoryItemBuilder(this.Session) .WithPart(part) .Build(); this.Session.Derive(); Assert.Equal(0M, item.AvailableToPromise); Assert.Equal(0M, item.QuantityCommittedOut); Assert.Equal(0M, item.QuantityExpectedIn); Assert.Equal(0M, item.QuantityOnHand); Assert.Equal(new NonSerialisedInventoryItemStates(this.Session).Good, item.NonSerialisedInventoryItemState); Assert.Equal(new Facilities(this.Session).FindBy(M.Facility.FacilityType, new FacilityTypes(this.Session).Warehouse), item.Facility); }
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 Execute() { var singleton = this.Session.GetSingleton(); var dutchLocale = new Locales(this.Session).DutchNetherlands; singleton.AddAdditionalLocale(dutchLocale); var euro = new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR"); var be = new Countries(this.Session).FindBy(M.Country.IsoCode, "BE"); var us = new Countries(this.Session).FindBy(M.Country.IsoCode, "US"); var email2 = new EmailAddressBuilder(this.Session) .WithElectronicAddressString("*****@*****.**") .Build(); var allorsLogo = this.DataPath + @"\www\admin\images\logo.png"; var allors = Organisations.CreateInternalOrganisation( session: this.Session, name: "Allors BVBA", address: "Kleine Nieuwedijkstraat 4", postalCode: "2800", locality: "Mechelen", country: be, phone1CountryCode: "+32", phone1: "2 335 2335", phone1Purpose: new ContactMechanismPurposes(this.Session).GeneralPhoneNumber, phone2CountryCode: string.Empty, phone2: string.Empty, phone2Purpose: null, emailAddress: "*****@*****.**", websiteAddress: "www.allors.com", taxNumber: "BE 0476967014", bankName: "ING", facilityName: "Allors warehouse 1", bic: "BBRUBEBB", iban: "BE89 3200 1467 7685", currency: euro, logo: allorsLogo, storeName: "Allors Store", billingProcess: new BillingProcesses(this.Session).BillingForOrderItems, outgoingShipmentNumberPrefix: "a-CS", salesInvoiceNumberPrefix: "a-SI", salesOrderNumberPrefix: "a-SO", requestNumberPrefix: "a-RFQ", quoteNumberPrefix: "a-Q", productNumberPrefix: "A-", requestCounterValue: 1, quoteCounterValue: 1, orderCounterValue: 1, invoiceCounterValue: 1); var dipu = Organisations.CreateInternalOrganisation( session: this.Session, name: "Dipu BVBA", address: "Kleine Nieuwedijkstraat 2", postalCode: "2800", locality: "Mechelen", country: be, phone1CountryCode: "+32", phone1: "2 15 49 49 49", phone1Purpose: new ContactMechanismPurposes(this.Session).GeneralPhoneNumber, phone2CountryCode: string.Empty, phone2: string.Empty, phone2Purpose: null, emailAddress: "*****@*****.**", websiteAddress: "www.dipu.com", taxNumber: "BE 0445366489", bankName: "ING", facilityName: "Dipu Facility", bic: "BBRUBEBB", iban: "BE23 3300 6167 6391", currency: euro, logo: allorsLogo, storeName: "Dipu Store", billingProcess: new BillingProcesses(this.Session).BillingForOrderItems, outgoingShipmentNumberPrefix: "d-CS", salesInvoiceNumberPrefix: "d-SI", salesOrderNumberPrefix: "d-SO", requestNumberPrefix: "d-RFQ", quoteNumberPrefix: "d-Q", productNumberPrefix: "D-", requestCounterValue: 1, quoteCounterValue: 1, orderCounterValue: 1, invoiceCounterValue: 1); singleton.Settings.DefaultFacility = allors.FacilitiesWhereOwner.First; this.SetupUser(allors, "*****@*****.**", "first", "allors employee", "letmein"); this.SetupUser(allors, "*****@*****.**", "second", "allors employee", "letmein"); this.SetupUser(dipu, "*****@*****.**", "first", "dipu employee", "letmein"); new FacilityBuilder(this.Session) .WithName("Allors warehouse 2") .WithFacilityType(new FacilityTypes(this.Session).Warehouse) .WithOwner(allors) .Build(); var manufacturer = new OrganisationBuilder(this.Session).WithName("Gizmo inc.").WithIsManufacturer(true).Build(); var productType = new ProductTypeBuilder(this.Session) .WithName($"Gizmo Serialized") .WithSerialisedItemCharacteristicType(new SerialisedItemCharacteristicTypeBuilder(this.Session) .WithName("Size") .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Afmeting").WithLocale(dutchLocale).Build()) .Build()) .WithSerialisedItemCharacteristicType(new SerialisedItemCharacteristicTypeBuilder(this.Session) .WithName("Weight") .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Gewicht").WithLocale(dutchLocale).Build()) .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Kilogram) .Build()) .Build(); var vatRate = new VatRateBuilder(this.Session).WithRate(21).Build(); var brand = new BrandBuilder(this.Session) .WithName("brand1") .WithModel(new ModelBuilder(this.Session).WithName("model1").Build()) .Build(); var finishedGood = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new SkuIdentificationBuilder(this.Session) .WithIdentification("10101") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Sku).Build()) .WithName("finished good") .WithBrand(brand) .WithModel(brand.Models[0]) .WithManufacturedBy(manufacturer) .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised) .Build(); var good1 = new NonUnifiedGoodBuilder(this.Session) .WithName("Tiny blue round gizmo") .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Zeer kleine blauwe ronde gizmo").WithLocale(dutchLocale).Build()) .WithDescription("Perfect blue with nice curves") .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Perfect blauw met mooie rondingen").WithLocale(dutchLocale).Build()) .WithVatRate(vatRate) .WithPart(finishedGood) .Build(); new InventoryItemTransactionBuilder(this.Session).WithPart(finishedGood).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).Unknown).Build(); var finishedGood2 = new NonUnifiedPartBuilder(this.Session) .WithName("finished good2") .WithInventoryItemKind(new InventoryItemKinds(this.Session).Serialised) .WithProductType(productType) .WithProductIdentification(new SkuIdentificationBuilder(this.Session) .WithIdentification("10102") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Sku).Build()) .WithManufacturedBy(manufacturer) .Build(); var good2 = new NonUnifiedGoodBuilder(this.Session) .WithName("Tiny red round gizmo") .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Zeer kleine rode ronde gizmo").WithLocale(dutchLocale).Build()) .WithDescription("Perfect red with nice curves") .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Perfect rood met mooie rondingen").WithLocale(dutchLocale).Build()) .WithVatRate(vatRate) .WithPart(finishedGood2) .Build(); var serialisedItem = new SerialisedItemBuilder(this.Session).WithSerialNumber("1").Build(); finishedGood2.AddSerialisedItem(serialisedItem); new SerialisedInventoryItemBuilder(this.Session).WithPart(finishedGood2).WithSerialisedItem(serialisedItem).WithFacility(allors.StoresWhereInternalOrganisation.First.DefaultFacility).Build(); var finishedGood3 = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new SkuIdentificationBuilder(this.Session) .WithIdentification("10103") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Sku).Build()) .WithName("finished good3") .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised) .WithManufacturedBy(manufacturer) .Build(); var good3 = new NonUnifiedGoodBuilder(this.Session) .WithName("Tiny green round gizmo") .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Zeer kleine groene ronde gizmo").WithLocale(dutchLocale).Build()) .WithDescription("Perfect red with nice curves") .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Perfect groen met mooie rondingen").WithLocale(dutchLocale).Build()) .WithVatRate(vatRate) .WithPart(finishedGood3) .Build(); var productCategory1 = new ProductCategoryBuilder(this.Session) .WithInternalOrganisation(allors) .WithName("Best selling gizmo's") .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Meest verkochte gizmo's").WithLocale(dutchLocale).Build()) .Build(); var productCategory2 = new ProductCategoryBuilder(this.Session) .WithInternalOrganisation(allors) .WithName("Big Gizmo's") .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Grote Gizmo's").WithLocale(dutchLocale).Build()) .Build(); var productCategory3 = new ProductCategoryBuilder(this.Session) .WithInternalOrganisation(allors) .WithName("Small gizmo's") .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Kleine gizmo's").WithLocale(dutchLocale).Build()) .WithProduct(good1) .WithProduct(good2) .WithProduct(good3) .Build(); new CatalogueBuilder(this.Session) .WithInternalOrganisation(allors) .WithName("New gizmo's") .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Nieuwe gizmo's").WithLocale(dutchLocale).Build()) .WithDescription("Latest in the world of Gizmo's") .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Laatste in de wereld van Gizmo's").WithLocale(dutchLocale).Build()) .WithProductCategory(productCategory1) .Build(); this.Session.Derive(); for (int i = 0; i < 1; i++) { var acmePostalAddress = new PostalAddressBuilder(this.Session) .WithAddress1($"Acme{i} address 1") .WithPostalBoundary(new PostalBoundaryBuilder(this.Session).WithLocality($"Acme{i} city").WithPostalCode("1111").WithCountry(us).Build()) .Build(); var acmeBillingAddress = new PartyContactMechanismBuilder(this.Session) .WithContactMechanism(acmePostalAddress) .WithContactPurpose(new ContactMechanismPurposes(this.Session).GeneralCorrespondence) .WithUseAsDefault(true) .Build(); var acmeInquiries = new PartyContactMechanismBuilder(this.Session) .WithContactMechanism(new TelecommunicationsNumberBuilder(this.Session).WithCountryCode("+1").WithContactNumber("111 222 333").Build()) .WithContactPurpose(new ContactMechanismPurposes(this.Session).GeneralPhoneNumber) .WithContactPurpose(new ContactMechanismPurposes(this.Session).OrderInquiriesPhone) .WithUseAsDefault(true) .Build(); var acme = new OrganisationBuilder(this.Session) .WithName($"Acme{i}") .WithLocale(new Locales(this.Session).EnglishUnitedStates) .WithPartyContactMechanism(acmeBillingAddress) .WithPartyContactMechanism(acmeInquiries) .Build(); var contact1Email = new PartyContactMechanismBuilder(this.Session) .WithContactMechanism(new EmailAddressBuilder(this.Session).WithElectronicAddressString($"employee1@acme{i}.com").Build()) .WithContactPurpose(new ContactMechanismPurposes(this.Session).PersonalEmailAddress) .WithUseAsDefault(true) .Build(); var contact2PhoneNumber = new PartyContactMechanismBuilder(this.Session) .WithContactMechanism(new TelecommunicationsNumberBuilder(this.Session).WithCountryCode("+1").WithAreaCode("123").WithContactNumber("456").Build()) .WithContactPurpose(new ContactMechanismPurposes(this.Session).GeneralPhoneNumber) .WithUseAsDefault(true) .Build(); var contact1 = new PersonBuilder(this.Session) .WithFirstName($"John{i}") .WithLastName($"Doe{i}") .WithGender(new GenderTypes(this.Session).Male) .WithLocale(new Locales(this.Session).EnglishUnitedStates) .WithPartyContactMechanism(contact1Email) .Build(); var contact2 = new PersonBuilder(this.Session) .WithFirstName($"Jane{i}") .WithLastName($"Doe{i}") .WithGender(new GenderTypes(this.Session).Male) .WithLocale(new Locales(this.Session).EnglishUnitedStates) .WithPartyContactMechanism(contact2PhoneNumber) .Build(); new CustomerRelationshipBuilder(this.Session) .WithCustomer(acme) .WithInternalOrganisation(allors) .WithFromDate(DateTime.UtcNow) .Build(); new SupplierRelationshipBuilder(this.Session) .WithSupplier(acme) .WithInternalOrganisation(allors) .WithFromDate(DateTime.UtcNow) .Build(); new OrganisationContactRelationshipBuilder(this.Session) .WithOrganisation(acme) .WithContact(contact1) .WithContactKind(new OrganisationContactKinds(this.Session).FindBy(M.OrganisationContactKind.Description, "General contact")) .WithFromDate(DateTime.UtcNow) .Build(); new OrganisationContactRelationshipBuilder(this.Session) .WithOrganisation(acme) .WithContact(contact2) .WithContactKind(new OrganisationContactKinds(this.Session).FindBy(M.OrganisationContactKind.Description, "General contact")) .WithFromDate(DateTime.UtcNow) .Build(); var administrator = (Person) new UserGroups(this.Session).Administrators.Members.First; new FaceToFaceCommunicationBuilder(this.Session) .WithDescription($"Meeting {i}") .WithSubject($"meeting {i}") .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting) .WithFromParty(contact1) .WithToParty(contact2) .WithOwner(administrator) .WithActualStart(DateTime.UtcNow) .Build(); new EmailCommunicationBuilder(this.Session) .WithDescription($"Email {i}") .WithSubject($"email {i}") .WithFromEmail(email2) .WithToEmail(email2) .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting) .WithOwner(administrator) .WithActualStart(DateTime.UtcNow) .Build(); new LetterCorrespondenceBuilder(this.Session) .WithDescription($"Letter {i}") .WithSubject($"letter {i}") .WithFromParty(administrator) .WithToParty(contact1) .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting) .WithOwner(administrator) .WithActualStart(DateTime.UtcNow) .Build(); new PhoneCommunicationBuilder(this.Session) .WithDescription($"Phone {i}") .WithSubject($"phone {i}") .WithFromParty(administrator) .WithToParty(contact1) .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting) .WithOwner(administrator) .WithActualStart(DateTime.UtcNow) .Build(); var salesOrderItem1 = new SalesOrderItemBuilder(this.Session) .WithDescription("first item") .WithProduct(good1) .WithActualUnitPrice(3000) .WithQuantityOrdered(1) .WithMessage(@"line1 line2") .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem) .Build(); var salesOrderItem2 = new SalesOrderItemBuilder(this.Session) .WithDescription("second item") .WithActualUnitPrice(2000) .WithQuantityOrdered(2) .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem) .Build(); var salesOrderItem3 = new SalesOrderItemBuilder(this.Session) .WithDescription("Fee") .WithActualUnitPrice(100) .WithQuantityOrdered(1) .WithInvoiceItemType(new InvoiceItemTypes(this.Session).Fee) .Build(); var order = new SalesOrderBuilder(this.Session) .WithTakenBy(allors) .WithBillToCustomer(acme) .WithBillToEndCustomerContactMechanism(acmeBillingAddress.ContactMechanism) .WithSalesOrderItem(salesOrderItem1) .WithSalesOrderItem(salesOrderItem2) .WithSalesOrderItem(salesOrderItem3) .WithCustomerReference("a reference number") .WithDescription("Sale of 1 used Aircraft Towbar") .WithVatRegime(new VatRegimes(this.Session).Assessable) .Build(); var salesInvoiceItem1 = new SalesInvoiceItemBuilder(this.Session) .WithDescription("first item") .WithProduct(good1) .WithActualUnitPrice(3000) .WithQuantity(1) .WithMessage(@"line1 line2") .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem) .Build(); var salesInvoiceItem2 = new SalesInvoiceItemBuilder(this.Session) .WithDescription("second item") .WithActualUnitPrice(2000) .WithQuantity(2) .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem) .Build(); var salesInvoiceItem3 = new SalesInvoiceItemBuilder(this.Session) .WithDescription("Fee") .WithActualUnitPrice(100) .WithQuantity(1) .WithInvoiceItemType(new InvoiceItemTypes(this.Session).Fee) .Build(); var salesInvoice = new SalesInvoiceBuilder(this.Session) .WithBilledFrom(allors) .WithInvoiceNumber("1") .WithBillToCustomer(acme) .WithBillToContactMechanism(acme.PartyContactMechanisms[0].ContactMechanism) .WithBillToEndCustomerContactMechanism(acmeBillingAddress.ContactMechanism) .WithSalesInvoiceItem(salesInvoiceItem1) .WithSalesInvoiceItem(salesInvoiceItem2) .WithSalesInvoiceItem(salesInvoiceItem3) .WithCustomerReference("a reference number") .WithDescription("Sale of 1 used Aircraft Towbar") .WithSalesInvoiceType(new SalesInvoiceTypes(this.Session).SalesInvoice) .WithVatRegime(new VatRegimes(this.Session).Assessable) .Build(); var purchaseInvoiceItem1 = new PurchaseInvoiceItemBuilder(this.Session) .WithDescription("first item") .WithProduct(good1) .WithActualUnitPrice(3000) .WithQuantity(1) .WithMessage(@"line1 line2") .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem) .Build(); var purchaseInvoiceItem2 = new PurchaseInvoiceItemBuilder(this.Session) .WithDescription("second item") .WithActualUnitPrice(2000) .WithQuantity(2) .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem) .Build(); var purchaseInvoiceItem3 = new PurchaseInvoiceItemBuilder(this.Session) .WithDescription("Fee") .WithActualUnitPrice(100) .WithQuantity(1) .WithInvoiceItemType(new InvoiceItemTypes(this.Session).Fee) .Build(); var purchaseInvoice = new PurchaseInvoiceBuilder(this.Session) .WithBilledTo(allors) .WithInvoiceNumber("1") .WithBilledFrom(acme) .WithPurchaseInvoiceItem(purchaseInvoiceItem1) .WithPurchaseInvoiceItem(purchaseInvoiceItem2) .WithPurchaseInvoiceItem(purchaseInvoiceItem3) .WithCustomerReference("a reference number") .WithDescription("Purchase of 1 used Aircraft Towbar") .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.Session).PurchaseInvoice) .WithVatRegime(new VatRegimes(this.Session).Assessable) .Build(); } this.Session.Derive(); }
public static NonUnifiedPartBuilder WithSerialisedDefaults(this NonUnifiedPartBuilder @this, Organisation internalOrganisation, Faker faker) { var dutchLocale = new Locales(@this.Session).DutchNetherlands; var brand = new BrandBuilder(@this.Session).WithDefaults().Build(); var serialisedProductType = new ProductTypes(@this.Session).FindBy(M.ProductType.Name, "serialisedProductType"); if (serialisedProductType == null) { var size = new SerialisedItemCharacteristicTypeBuilder(@this.Session) .WithName("Size") .WithLocalisedName(new LocalisedTextBuilder(@this.Session).WithText("Afmeting").WithLocale(dutchLocale).Build()) .Build(); var weight = new SerialisedItemCharacteristicTypeBuilder(@this.Session) .WithName("Weight") .WithLocalisedName(new LocalisedTextBuilder(@this.Session).WithText("Gewicht").WithLocale(dutchLocale).Build()) .WithUnitOfMeasure(new UnitsOfMeasure(@this.Session).Kilogram) .Build(); serialisedProductType = new ProductTypeBuilder(@this.Session) .WithName("serialisedProductType") .WithSerialisedItemCharacteristicType(size) .WithSerialisedItemCharacteristicType(weight) .Build(); } @this.WithInventoryItemKind(new InventoryItemKinds(@this.Session).Serialised); @this.WithName(faker.Commerce.ProductName()); @this.WithDescription(faker.Lorem.Sentence()); @this.WithComment(faker.Lorem.Sentence()); @this.WithInternalComment(faker.Lorem.Sentence()); @this.WithKeywords(faker.Lorem.Sentence()); @this.WithUnitOfMeasure(new UnitsOfMeasure(@this.Session).Piece); @this.WithPrimaryPhoto(new MediaBuilder(@this.Session).WithInDataUri(faker.Image.DataUri(width: 200, height: 56)).Build()); @this.WithPhoto(new MediaBuilder(@this.Session).WithInDataUri(faker.Image.DataUri(width: 200, height: 56)).Build()); @this.WithPhoto(new MediaBuilder(@this.Session).WithInDataUri(faker.Image.DataUri(width: 200, height: 56)).Build()); @this.WithPublicElectronicDocument(new MediaBuilder(@this.Session).WithInFileName("doc1.en.pdf").WithInData(faker.Random.Bytes(1000)).Build()); @this.WithPrivateElectronicDocument(new MediaBuilder(@this.Session).WithInFileName("doc2.en.pdf").WithInData(faker.Random.Bytes(1000)).Build()); @this.WithProductIdentification(new SkuIdentificationBuilder(@this.Session).WithDefaults().Build()); @this.WithProductIdentification(new EanIdentificationBuilder(@this.Session).WithDefaults().Build()); @this.WithProductIdentification(new ManufacturerIdentificationBuilder(@this.Session).WithDefaults().Build()); @this.WithDefaultFacility(internalOrganisation.FacilitiesWhereOwner?.First); @this.WithProductType(serialisedProductType); @this.WithBrand(brand); @this.WithModel(brand.Models.First); @this.WithHsCode(faker.Random.Number(99999999).ToString()); @this.WithManufacturedBy(new OrganisationBuilder(@this.Session).WithManufacturerDefaults(faker).Build()); foreach (Locale additionalLocale in @this.Session.GetSingleton().AdditionalLocales) { @this.WithLocalisedName(new LocalisedTextBuilder(@this.Session).WithText(faker.Lorem.Word()).WithLocale(additionalLocale).Build()); @this.WithLocalisedDescription(new LocalisedTextBuilder(@this.Session).WithText(faker.Lorem.Sentence()).WithLocale(additionalLocale).Build()); @this.WithLocalisedComment(new LocalisedTextBuilder(@this.Session).WithText(faker.Lorem.Sentence()).WithLocale(additionalLocale).Build()); @this.WithLocalisedKeyword(new LocalisedTextBuilder(@this.Session).WithText(faker.Lorem.Sentence()).WithLocale(additionalLocale).Build()); var localisedDocument = new MediaBuilder(@this.Session).WithInFileName($"doc1.{additionalLocale.Country.IsoCode}.pdf").WithInData(faker.Random.Bytes(1000)).Build(); @this.WithPublicLocalisedElectronicDocument(new LocalisedMediaBuilder(@this.Session).WithMedia(localisedDocument).WithLocale(additionalLocale).Build()); @this.WithPrivateLocalisedElectronicDocument(new LocalisedMediaBuilder(@this.Session).WithMedia(localisedDocument).WithLocale(additionalLocale).Build()); } return(@this); }
public void GivenSupplierOffering_WhenCalculatingUnitSellingPrice_ThenConsiderHighestHistoricalPurchaseRate() { var settings = this.Session.GetSingleton().Settings; var supplier_1 = new OrganisationBuilder(this.Session).WithName("supplier uno").Build(); var supplier_2 = new OrganisationBuilder(this.Session).WithName("supplier dos").Build(); var supplier_3 = new OrganisationBuilder(this.Session).WithName("supplier tres").Build(); var supplier_4 = new OrganisationBuilder(this.Session).WithName("supplier cuatro").Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(v => Equals(v.Name, "internalOrganisation")); new SupplierRelationshipBuilder(this.Session) .WithSupplier(supplier_1) .WithInternalOrganisation(internalOrganisation) .WithFromDate(this.Session.Now().AddYears(-3)) .Build(); new SupplierRelationshipBuilder(this.Session) .WithSupplier(supplier_2) .WithInternalOrganisation(internalOrganisation) .WithFromDate(this.Session.Now().AddYears(-2)) .Build(); new SupplierRelationshipBuilder(this.Session) .WithSupplier(supplier_3) .WithInternalOrganisation(internalOrganisation) .WithFromDate(this.Session.Now().AddYears(-1)) .Build(); new SupplierRelationshipBuilder(this.Session) .WithSupplier(supplier_4) .WithInternalOrganisation(internalOrganisation) .WithFromDate(this.Session.Now().AddMonths(-6)) .Build(); var finishedGood = new NonUnifiedPartBuilder(this.Session) .WithNonSerialisedDefaults(internalOrganisation) .Build(); this.Session.Derive(); new InventoryItemTransactionBuilder(this.Session).WithQuantity(10).WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment).WithPart(finishedGood).Build(); this.Session.Derive(); var euro = new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR"); var piece = new UnitsOfMeasure(this.Session).Piece; new BasePriceBuilder(this.Session) .WithPart(finishedGood) .WithFromDate(this.Session.Now()) .WithPrice(100) .Build(); new SupplierOfferingBuilder(this.Session) .WithPart(finishedGood) .WithSupplier(supplier_1) .WithFromDate(this.Session.Now().AddMonths(-6)) .WithThroughDate(this.Session.Now().AddMonths(-3)) .WithUnitOfMeasure(piece) .WithPrice(100) .WithCurrency(euro) .Build(); new SupplierOfferingBuilder(this.Session) .WithPart(finishedGood) .WithSupplier(supplier_2) .WithFromDate(this.Session.Now().AddYears(-1)) .WithThroughDate(this.Session.Now().AddDays(-1)) .WithUnitOfMeasure(piece) .WithPrice(120) .WithCurrency(euro) .Build(); new SupplierOfferingBuilder(this.Session) .WithPart(finishedGood) .WithSupplier(supplier_3) .WithFromDate(this.Session.Now()) .WithUnitOfMeasure(piece) .WithPrice(99) .WithCurrency(euro) .Build(); new SupplierOfferingBuilder(this.Session) .WithPart(finishedGood) .WithSupplier(supplier_4) .WithFromDate(this.Session.Now().AddDays(7)) .WithThroughDate(this.Session.Now().AddDays(30)) .WithUnitOfMeasure(piece) .WithPrice(135) .WithCurrency(euro) .Build(); this.Session.Derive(); var customer = internalOrganisation.CreateB2BCustomer(this.Session.Faker()); var workEffort = new WorkTaskBuilder(this.Session) .WithName("Activity") .WithCustomer(customer) .WithTakenBy(internalOrganisation) .Build(); var workEffortInventoryAssignement = new WorkEffortInventoryAssignmentBuilder(this.Session) .WithAssignment(workEffort) .WithInventoryItem(finishedGood.InventoryItemsWherePart.First()) .WithQuantity(1) .Build(); this.Session.Derive(); /*Purchase price times InternalSurchargePercentage * var sellingPrice = Math.Round(135 * (1 + (this.Session.GetSingleton().Settings.PartSurchargePercentage / 100)), 2);*/ Assert.Equal(100, workEffortInventoryAssignement.UnitSellingPrice); }
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 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_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_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); }
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); }