public void GivenFinishedGoodWithSerializedInventory_WhenDeriving_ThenQuantityOnHandUpdated() { // Arrange var goodOrder = new SerialisedInventoryItemStates(this.Session).Good; 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 vatRegime = new VatRegimes(this.Session).ZeroRated; var category = new ProductCategoryBuilder(this.Session).WithName("category").Build(); var serialPart = this.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 = this.CreateGood("10101", vatRegime, "good1", unitsOfMeasure.Piece, category, serialPart); // Act this.Session.Derive(true); this.CreateInventoryTransaction(1, unknown, serialPart, serialItem1); this.CreateInventoryTransaction(1, unknown, serialPart, serialItem2); this.CreateInventoryTransaction(1, unknown, serialPart, serialItem3); this.Session.Derive(true); // Assert Assert.Equal(3, serialPart.QuantityOnHand); }
public void GivenDiscountForVirtualProduct_WhenDeriving_ThenProductVirtualProductPriceComponentIsUpdated() { var vatRegime = new VatRegimes(this.Session).BelgiumStandard; var virtualService = new DeliverableBasedServiceBuilder(this.Session) .WithName("virtual service") .WithVatRegime(vatRegime) .Build(); var physicalService = new DeliverableBasedServiceBuilder(this.Session) .WithName("real service") .WithVatRegime(vatRegime) .Build(); virtualService.AddVariant(physicalService); this.Session.Derive(); var discount = new DiscountComponentBuilder(this.Session) .WithDescription("discount") .WithPrice(10) .WithProduct(virtualService) .WithFromDate(this.Session.Now()) .Build(); this.Session.Derive(); Assert.Single(physicalService.VirtualProductPriceComponents); Assert.Contains(discount, physicalService.VirtualProductPriceComponents); Assert.False(virtualService.ExistVirtualProductPriceComponents); }
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 GivenSurchargeForVirtualProduct_WhenDeriving_ThenProductVirtualProductPriceComponentIsUpdated() { var vatRegime = new VatRegimes(this.Session).BelgiumStandard; var virtualService = new TimeAndMaterialsServiceBuilder(this.Session) .WithName("virtual service") .WithVatRegime(vatRegime) .Build(); var physicalService = new TimeAndMaterialsServiceBuilder(this.Session) .WithName("real service") .WithVatRegime(vatRegime) .Build(); virtualService.AddVariant(physicalService); this.Session.Derive(); var surcharge = new SurchargeComponentBuilder(this.Session) .WithDescription("surcharge") .WithPrice(10) .WithProduct(virtualService) .WithFromDate(this.Session.Now()) .Build(); this.Session.Derive(); Assert.Single(physicalService.VirtualProductPriceComponents); Assert.Contains(surcharge, physicalService.VirtualProductPriceComponents); Assert.False(virtualService.ExistVirtualProductPriceComponents); }
public void GivenBasePriceForVirtualProduct_WhenDeriving_ThenProductVirtualProductPriceComponentIsUpdated() { var vatRegime = new VatRegimes(this.Session).BelgiumStandard; var virtualGood = new NonUnifiedGoodBuilder(this.Session) .WithProductIdentification(new ProductNumberBuilder(this.Session) .WithIdentification("v101") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Good).Build()) .WithName("virtual gizmo") .WithVatRegime(vatRegime) .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece) .Build(); var physicalGood = new Goods(this.Session).FindBy(M.Good.Name, "good1"); virtualGood.AddVariant(physicalGood); this.Session.Derive(); var basePrice = new BasePriceBuilder(this.Session) .WithDescription("baseprice") .WithPrice(10) .WithProduct(virtualGood) .WithFromDate(this.Session.Now()) .Build(); this.Session.Derive(); Assert.Single(physicalGood.VirtualProductPriceComponents); Assert.Contains(basePrice, physicalGood.VirtualProductPriceComponents); Assert.False(virtualGood.ExistVirtualProductPriceComponents); }
public void GivenDiscount_WhenDeriving_ThenRequiredRelationsMustExist() { var vatRegime = new VatRegimes(this.Session).BelgiumStandard; var good = new Goods(this.Session).FindBy(M.Good.Name, "good1"); var colorFeature = new ColourBuilder(this.Session) .WithVatRegime(vatRegime) .WithName("black") .Build(); this.Session.Derive(); this.Session.Commit(); var builder = new DiscountComponentBuilder(this.Session); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithPrice(1); builder.Build(); Assert.False(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithFromDate(this.Session.Now()); builder.Build(); Assert.False(this.Session.Derive(false).HasErrors); this.Session.Rollback(); Assert.False(this.Session.Derive(false).HasErrors); builder.WithProduct(good); builder.Build(); this.Session.Rollback(); Assert.False(this.Session.Derive(false).HasErrors); builder.WithProductFeature(colorFeature); builder.Build(); Assert.False(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithPercentage(10); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); }
public void GivenDiscountForNonVirtualProduct_WhenDeriving_ThenProductVirtualProductPriceComponentIsNull() { var vatRegime = new VatRegimes(this.Session).BelgiumStandard; var physicalService = new DeliverableBasedServiceBuilder(this.Session) .WithName("real service") .WithVatRegime(vatRegime) .Build(); new DiscountComponentBuilder(this.Session) .WithDescription("discount") .WithPrice(10) .WithProduct(physicalService) .WithFromDate(this.Session.Now()) .Build(); Assert.False(physicalService.ExistVirtualProductPriceComponents); }
public void GivenSurchargeForNonVirtualProduct_WhenDeriving_ThenProductVirtualProductPriceComponentIsNull() { var vatRegime = new VatRegimes(this.Session).BelgiumStandard; var physicalService = new TimeAndMaterialsServiceBuilder(this.Session) .WithName("real service") .WithVatRegime(vatRegime) .Build(); new SurchargeComponentBuilder(this.Session) .WithDescription("surcharge") .WithPrice(10) .WithProduct(physicalService) .WithFromDate(this.Session.Now()) .Build(); Assert.False(physicalService.ExistVirtualProductPriceComponents); }
public void GivenSerializedItemInMultipleFacilities_WhenDeriving_ThenMultipleQuantityOnHandTracked() { // Arrange var warehouseType = new FacilityTypes(this.Session).Warehouse; var warehouse1 = this.CreateFacility("WH1", warehouseType, this.InternalOrganisation); var warehouse2 = this.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 vatRegime = new VatRegimes(this.Session).ZeroRated; var category = new ProductCategoryBuilder(this.Session).WithName("category").Build(); var finishedGood = this.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 = this.CreateGood("10101", vatRegime, "good1", piece, category, finishedGood); // Act this.Session.Derive(true); this.CreateInventoryTransaction(1, unknown, finishedGood, serialItem1, warehouse1); this.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 GivenSalesOrderForCustomerExceedingCreditLimit_WhenOrderIsConfirmed_ThenOrderRequestsApproval() { var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem; var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First; var assessable = new VatRegimes(this.DatabaseSession).Assessable; var vatRate0 = new VatRateBuilder(this.DatabaseSession).WithRate(0).Build(); assessable.VatRate = vatRate0; var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate0) .WithName("good1") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .Build(); var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer) .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation) .WithCreditLimit(100M) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var invoice = new SalesInvoiceBuilder(this.DatabaseSession) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithInvoiceDate(DateTime.UtcNow.AddYears(-1)) .Build(); var invoiceItem = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(10).WithActualUnitPrice(11).WithSalesInvoiceItemType(productItem).Build(); invoice.AddSalesInvoiceItem(invoiceItem); this.DatabaseSession.Derive(true); var order = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithVatRegime(assessable) .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .Build(); var item = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(10) .WithActualUnitPrice(5) .Build(); order.AddSalesOrderItem(item); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).RequestsApproval, order.CurrentObjectState); Assert.AreEqual(0, item.QuantityReserved); Assert.AreEqual(0, item.QuantityPendingShipment); Assert.AreEqual(0, item.QuantityRequestsShipping); Assert.AreEqual(0, item.QuantityShortFalled); order.Approve(); this.DatabaseSession.Derive(true); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentObjectState); Assert.AreEqual(10, item.QuantityReserved); Assert.AreEqual(10, item.QuantityPendingShipment); Assert.AreEqual(0, item.QuantityRequestsShipping); Assert.AreEqual(0, item.QuantityShortFalled); }
public void GivenOrderItemWithoutVatRate_WhenDeriving_ThenItemDerivedVatRateIsFromOrderVatRegime() { this.InstantiateObjects(this.DatabaseSession); var expected = new VatRegimes(this.DatabaseSession).Export.VatRate; var salesOrder = new SalesOrderBuilder(this.DatabaseSession) .WithTakenByInternalOrganisation(this.internalOrganisation) .WithBillToCustomer(this.billToCustomer) .WithShipToAddress(this.shipToContactMechanismMechelen) .WithVatRegime(new VatRegimes(this.DatabaseSession).Export) .Build(); var orderItem = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(this.good).WithQuantityOrdered(1).Build(); salesOrder.AddSalesOrderItem(orderItem); this.DatabaseSession.Derive(true); Assert.AreEqual(salesOrder.VatRegime, orderItem.VatRegime); Assert.AreEqual(expected, orderItem.DerivedVatRate); }
public void GivenSalesOrderWithPickList_WhenOrderIsCancelled_ThenPickListIsCancelledAndSingleOrderShipmentIsCancelled() { var assessable = new VatRegimes(this.DatabaseSession).Assessable; var vatRate0 = new VatRateBuilder(this.DatabaseSession).WithRate(0).Build(); assessable.VatRate = vatRate0; var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate0) .WithName("good1") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .Build(); var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation; new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); this.DatabaseSession.Derive(true); var order1 = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithShipToAddress(mechelenAddress) .WithVatRegime(assessable) .Build(); var item = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(10) .WithActualUnitPrice(5) .Build(); order1.AddSalesOrderItem(item); this.DatabaseSession.Derive(true); order1.Confirm(); this.DatabaseSession.Derive(true); var order2 = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithShipToAddress(mechelenAddress) .WithVatRegime(assessable) .Build(); item = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(20) .WithActualUnitPrice(5) .Build(); order2.AddSalesOrderItem(item); this.DatabaseSession.Derive(true); order2.Confirm(); this.DatabaseSession.Derive(true); var shipment = (CustomerShipment)customer.ShipmentsWhereBillToParty[0]; Assert.AreEqual(30, shipment.ShipmentItems[0].Quantity); var pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem; Assert.AreEqual(30, pickList.PickListItems[0].RequestedQuantity); order1.Cancel(); this.DatabaseSession.Derive(true); Assert.AreEqual(new CustomerShipmentObjectStates(this.DatabaseSession).Created, shipment.CurrentObjectState); Assert.AreEqual(new PickListObjectStates(this.DatabaseSession).Created, pickList.CurrentObjectState); Assert.AreEqual(20, pickList.PickListItems[0].RequestedQuantity); order2.Cancel(); this.DatabaseSession.Derive(true); Assert.AreEqual(new CustomerShipmentObjectStates(this.DatabaseSession).Cancelled, shipment.CurrentObjectState); Assert.AreEqual(new PickListObjectStates(this.DatabaseSession).Cancelled, pickList.CurrentObjectState); }
public void GivenSalesOrderBelowOrderThreshold_WhenOrderIsConfirmed_ThenOrderIsNotShipped() { Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation.StoresWhereOwner.First.OrderThreshold = 1; var assessable = new VatRegimes(this.DatabaseSession).Assessable; var vatRate0 = new VatRateBuilder(this.DatabaseSession).WithRate(0).Build(); assessable.VatRate = vatRate0; var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate0) .WithName("good1") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .Build(); var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer) .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation) .Build(); this.DatabaseSession.Derive(true); var order = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithVatRegime(assessable) .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .Build(); var item = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(1) .WithActualUnitPrice(0.1M) .Build(); order.AddSalesOrderItem(item); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).RequestsApproval, order.CurrentObjectState); }
public void GivenSalesOrderShippedInMultipleParts_WhenPaymentsAreReceived_ThenObjectStateCorrespondingSalesOrderIsUpdated() { var assessable = new VatRegimes(this.DatabaseSession).Assessable; var vatRate0 = new VatRateBuilder(this.DatabaseSession).WithRate(0).Build(); assessable.VatRate = vatRate0; var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate0) .WithName("good1") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .Build(); var good1Inventory = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good1).Build(); good1Inventory.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(1).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("10102") .WithVatRate(vatRate0) .WithName("good2") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .Build(); var good2Inventory = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good2).Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress) .WithUseAsDefault(true) .Build(); var billToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).WithPartyContactMechanism(billToMechelen).Build(); var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation; new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); this.DatabaseSession.Derive(true); var order = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithVatRegime(assessable) .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .Build(); var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).WithComment("item1").Build(); var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).WithComment("item2").Build(); var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).WithComment("item3").Build(); order.AddSalesOrderItem(item1); order.AddSalesOrderItem(item2); order.AddSalesOrderItem(item3); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); var shipment = (CustomerShipment)item1.OrderShipmentsWhereSalesOrderItem[0].ShipmentItem.ShipmentWhereShipmentItem; var pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem; pickList.Picker = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "orderProcessor"); pickList.SetPicked(); this.DatabaseSession.Derive(true); var package = new ShipmentPackageBuilder(this.DatabaseSession).Build(); shipment.AddShipmentPackage(package); foreach (ShipmentItem shipmentItem in shipment.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.DatabaseSession).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build()); } this.DatabaseSession.Derive(true); shipment.SetPacked(); this.DatabaseSession.Derive(true); shipment.Ship(); this.DatabaseSession.Derive(true); var salesInvoiceitem = (SalesInvoiceItem)shipment.ShipmentItems[0].InvoiceItems[0]; var invoice1 = salesInvoiceitem.SalesInvoiceWhereSalesInvoiceItem; invoice1.Send(); new ReceiptBuilder(this.DatabaseSession) .WithAmount(15) .WithPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(invoice1.SalesInvoiceItems[0]).WithAmountApplied(15).Build()) .WithEffectiveDate(DateTime.UtcNow) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentObjectState); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).PartiallyShipped, order.CurrentShipmentStatus.SalesOrderObjectState); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).PartiallyPaid, order.CurrentPaymentStatus.SalesOrderObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Finished, item1.CurrentObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Paid, item1.CurrentPaymentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Shipped, item1.CurrentShipmentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).InProcess, item2.CurrentObjectState); Assert.IsFalse(item2.ExistCurrentPaymentStatus); Assert.IsFalse(item2.ExistCurrentShipmentStatus); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).InProcess, item3.CurrentObjectState); Assert.IsFalse(item3.ExistCurrentPaymentStatus); Assert.IsFalse(item3.ExistCurrentShipmentStatus); good1Inventory.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); shipment = (CustomerShipment)item2.OrderShipmentsWhereSalesOrderItem[0].ShipmentItem.ShipmentWhereShipmentItem; pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem; pickList.Picker = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "orderProcessor"); pickList.SetPicked(); this.DatabaseSession.Derive(true); package = new ShipmentPackageBuilder(this.DatabaseSession).Build(); shipment.AddShipmentPackage(package); foreach (ShipmentItem shipmentItem in shipment.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.DatabaseSession).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build()); } this.DatabaseSession.Derive(true); shipment.Ship(); this.DatabaseSession.Derive(true); salesInvoiceitem = (SalesInvoiceItem)shipment.ShipmentItems[0].InvoiceItems[0]; var invoice2 = salesInvoiceitem.SalesInvoiceWhereSalesInvoiceItem; invoice2.Send(); new ReceiptBuilder(this.DatabaseSession) .WithAmount(30) .WithPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(invoice2.SalesInvoiceItems[0]).WithAmountApplied(30).Build()) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentObjectState); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).PartiallyShipped, order.CurrentShipmentStatus.SalesOrderObjectState); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).PartiallyPaid, order.CurrentPaymentStatus.SalesOrderObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Finished, item1.CurrentObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Paid, item1.CurrentPaymentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Shipped, item1.CurrentShipmentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Finished, item2.CurrentObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Paid, item2.CurrentPaymentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Shipped, item2.CurrentShipmentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).InProcess, item3.CurrentObjectState); Assert.IsFalse(item3.ExistCurrentPaymentStatus); Assert.IsFalse(item3.ExistCurrentShipmentStatus); good2Inventory.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); shipment = (CustomerShipment)item3.OrderShipmentsWhereSalesOrderItem[0].ShipmentItem.ShipmentWhereShipmentItem; pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem; pickList.Picker = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "orderProcessor"); pickList.SetPicked(); this.DatabaseSession.Derive(true); package = new ShipmentPackageBuilder(this.DatabaseSession).Build(); shipment.AddShipmentPackage(package); foreach (ShipmentItem shipmentItem in shipment.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.DatabaseSession).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build()); } this.DatabaseSession.Derive(true); shipment.Ship(); this.DatabaseSession.Derive(true); salesInvoiceitem = (SalesInvoiceItem)shipment.ShipmentItems[0].InvoiceItems[0]; var invoice3 = salesInvoiceitem.SalesInvoiceWhereSalesInvoiceItem; new ReceiptBuilder(this.DatabaseSession) .WithAmount(75) .WithPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(invoice3.SalesInvoiceItems[0]).WithAmountApplied(75).Build()) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).Finished, order.CurrentObjectState); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).Shipped, order.CurrentShipmentStatus.SalesOrderObjectState); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).Paid, order.CurrentPaymentStatus.SalesOrderObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Finished, item1.CurrentObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Paid, item1.CurrentPaymentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Shipped, item1.CurrentShipmentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Finished, item2.CurrentObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Paid, item2.CurrentPaymentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Shipped, item2.CurrentShipmentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Finished, item3.CurrentObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Paid, item3.CurrentPaymentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Shipped, item3.CurrentShipmentStatus.SalesOrderItemObjectState); }
public void GivenSalesOrderWithManualShipmentSchedule_WhenOrderIsConfirmed_ThenInventoryIsNotReservedAndOrderIsNotShipped() { var assessable = new VatRegimes(this.DatabaseSession).Assessable; var vatRate0 = new VatRateBuilder(this.DatabaseSession).WithRate(0).Build(); assessable.VatRate = vatRate0; var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate0) .WithName("good1") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .Build(); var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer) .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation) .Build(); this.DatabaseSession.Derive(true); var manual = new OrderKindBuilder(this.DatabaseSession).WithDescription("manual").WithScheduleManually(true).Build(); var order = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithVatRegime(assessable) .WithOrderKind(manual) .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .Build(); var item = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(50) .WithActualUnitPrice(50) .Build(); order.AddSalesOrderItem(item); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentObjectState); Assert.AreEqual(0, item.QuantityReserved); Assert.AreEqual(0, item.QuantityPendingShipment); Assert.AreEqual(0, item.QuantityRequestsShipping); Assert.AreEqual(0, item.QuantityShortFalled); Assert.AreEqual(100, inventoryItem.QuantityOnHand); Assert.AreEqual(100, inventoryItem.AvailableToPromise); }
public void GivenSalesOrderNotPartiallyShipped_WhenInComplete_ThenOrderIsNotSelectedForShipment() { var assessable = new VatRegimes(this.DatabaseSession).Assessable; var vatRate0 = new VatRateBuilder(this.DatabaseSession).WithRate(0).Build(); assessable.VatRate = vatRate0; var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate0) .WithName("good1") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .Build(); var inventoryGood1 = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good1).Build(); inventoryGood1.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(10).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("20202") .WithVatRate(vatRate0) .WithName("good2") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .Build(); var inventoryGood2 = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good2).Build(); inventoryGood2.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(10).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation; new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); this.DatabaseSession.Derive(true); var order = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithVatRegime(assessable) .WithPartiallyShip(false) .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .Build(); var item1 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good1) .WithQuantityOrdered(20) .WithActualUnitPrice(5) .Build(); var item2 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good2) .WithQuantityOrdered(20) .WithActualUnitPrice(5) .Build(); order.AddSalesOrderItem(item1); order.AddSalesOrderItem(item2); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); Assert.IsFalse(customer.ExistShipmentsWhereShipToParty); Assert.AreEqual(10, item1.QuantityRequestsShipping); Assert.AreEqual(0, item1.QuantityPendingShipment); Assert.AreEqual(10, item1.QuantityShortFalled); Assert.AreEqual(10, item2.QuantityRequestsShipping); Assert.AreEqual(0, item2.QuantityPendingShipment); Assert.AreEqual(10, item2.QuantityShortFalled); inventoryGood1.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); Assert.IsFalse(customer.ExistShipmentsWhereShipToParty); Assert.AreEqual(20, item1.QuantityRequestsShipping); Assert.AreEqual(0, item1.QuantityPendingShipment); Assert.AreEqual(0, item1.QuantityShortFalled); Assert.AreEqual(10, item2.QuantityRequestsShipping); Assert.AreEqual(0, item2.QuantityPendingShipment); Assert.AreEqual(10, item2.QuantityShortFalled); inventoryGood2.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); Assert.IsTrue(customer.ExistShipmentsWhereShipToParty); Assert.AreEqual(0, item1.QuantityRequestsShipping); Assert.AreEqual(20, item1.QuantityPendingShipment); Assert.AreEqual(0, item1.QuantityShortFalled); Assert.AreEqual(0, item2.QuantityRequestsShipping); Assert.AreEqual(20, item2.QuantityPendingShipment); Assert.AreEqual(0, item2.QuantityShortFalled); }
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 vatRegime = new VatRegimes(this.Session).BelgiumStandard; var category = new ProductCategoryBuilder(this.Session).WithName("category").Build(); var finishedGood = this.CreatePart("1", inventoryItemKinds.NonSerialised); var good = this.CreateGood("10101", vatRegime, "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(); var internalOrganisation = this.InternalOrganisation; new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).Build(); this.Session.Derive(); var order = this.CreateSalesOrder(customer, customer, this.Session.Now(), false); var salesItem = this.CreateSalesOrderItem("item1", good, 10, 15); // Act order.AddSalesOrderItem(salesItem); this.Session.Derive(); order.SetReadyForPosting(); this.Session.Derive(); order.Post(); this.Session.Derive(); order.Accept(); this.Session.Derive(); // Assert Assert.Equal(5, salesItem.QuantityRequestsShipping); Assert.Equal(0, salesItem.QuantityPendingShipment); Assert.Equal(10, salesItem.QuantityReserved); Assert.Equal(5, salesItem.QuantityShortFalled); // Rearrange this.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 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 vatRegime = new VatRegimes(this.Session).BelgiumStandard; var category = new ProductCategoryBuilder(this.Session).WithName("category").Build(); var finishedGood = this.CreatePart("1", inventoryItemKinds.NonSerialised); var good = this.CreateGood("10101", vatRegime, "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); }
protected override void BaseSetup(Setup setup) { var dutchLocale = new Locales(this.Session).DutchNetherlands; var netherlands = new Countries(this.Session).FindBy(M.Country.IsoCode, "NL"); var belgium = new Countries(this.Session).FindBy(M.Country.IsoCode, "BE"); var spain = new Countries(this.Session).FindBy(M.Country.IsoCode, "ES"); var merge = this.Cache.Merger().Action(); var localisedName = new LocalisedTextAccessor(this.Meta.LocalisedNames); merge(DutchStandardId, v => { v.Name = "Dutch standard VAT tariff"; localisedName.Set(v, dutchLocale, "Nederland hoog BTW-tarief"); v.Country = netherlands; v.IsActive = true; }); var vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, DutchStandardId); vatregime.AddVatRate(new VatRates(this.Session).Dutch21); merge(DutchReducedId, v => { v.Name = "Dutch reduced VAT tariff"; localisedName.Set(v, dutchLocale, "Nederland laag BTW-tarief"); v.Country = netherlands; v.IsActive = true; }); vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, DutchReducedId); vatregime.AddVatRate(new VatRates(this.Session).Dutch9); merge(BelgiumStandardId, v => { v.Name = "Belgium standard VAT tariff"; localisedName.Set(v, dutchLocale, "Belgie hoog BTW-tarief"); v.Country = belgium; v.IsActive = true; }); vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, BelgiumStandardId); vatregime.AddVatRate(new VatRates(this.Session).Belgium21); merge(BelgiumReducedTableAId, v => { v.Name = "Belgium reduced VAT 6%"; localisedName.Set(v, dutchLocale, "Belgie laag BTW-tarief 6%"); v.Country = belgium; v.IsActive = true; }); vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, BelgiumReducedTableAId); vatregime.AddVatRate(new VatRates(this.Session).Belgium6); merge(BelgiumReducedTableBId, v => { v.Name = "Belgium reduced VAT tariff 12%"; localisedName.Set(v, dutchLocale, "Belgie laag BTW-tarief 12%"); v.Country = belgium; v.IsActive = true; }); vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, BelgiumReducedTableBId); vatregime.AddVatRate(new VatRates(this.Session).Belgium12); merge(ServiceB2BId, v => { v.Name = "Service B2B: Not VAT assessable"; localisedName.Set(v, dutchLocale, "Service B2B: Niet BTW-plichtig"); v.VatClause = new VatClauses(this.Session).ServiceB2B; v.Country = belgium; v.IsActive = true; }); vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, ServiceB2BId); vatregime.AddVatRate(new VatRates(this.Session).BelgiumServiceB2B0); merge(SpainStandardId, v => { v.Name = "Spain standard VAT tariff"; localisedName.Set(v, dutchLocale, "Spanje hoog BTW-tarief"); v.Country = spain; v.IsActive = true; }); vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, SpainStandardId); vatregime.AddVatRate(new VatRates(this.Session).Spain21); merge(SpainReducedId, v => { v.Name = "Spain reduced VAT tariff"; localisedName.Set(v, dutchLocale, "Spanje laag BTW-tarief"); v.Country = spain; v.IsActive = true; }); vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, SpainReducedId); vatregime.AddVatRate(new VatRates(this.Session).Spain10); merge(SpainSuperReducedId, v => { v.Name = "Spain super reduced VAT tariff"; localisedName.Set(v, dutchLocale, "Spanje extra laag BTW-tarief"); v.Country = spain; v.IsActive = true; }); vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, SpainSuperReducedId); vatregime.AddVatRate(new VatRates(this.Session).Spain4); merge(SpainCanaryIslandsId, v => { v.Name = "Spain Canary islands VAT tariff"; localisedName.Set(v, dutchLocale, "Spanje Canarische eilanden BTW-tarief"); v.Country = spain; v.IsActive = true; }); vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, SpainCanaryIslandsId); vatregime.AddVatRate(new VatRates(this.Session).Spain7); merge(ZeroRatedId, v => { v.Name = "VAT Zero rated tariff"; localisedName.Set(v, dutchLocale, "BTW nul tarief"); v.IsActive = true; }); var zeroRatedvatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, ZeroRatedId); zeroRatedvatregime.AddVatRate(new VatRates(this.Session).ZeroRated0); merge(ExemptId, v => { v.Name = "VAT Exempt"; localisedName.Set(v, dutchLocale, "Vrijgesteld van BTW"); v.IsActive = true; }); var exemptVatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, ExemptId); exemptVatregime.AddVatRate(new VatRates(this.Session).Exempt0); merge(IntraCommunautairId, v => { v.Name = "VAT intra-community"; localisedName.Set(v, dutchLocale, "BTW Intracommunautair"); v.VatClause = new VatClauses(this.Session).Intracommunautair; v.IsActive = true; }); var EuVatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, IntraCommunautairId); EuVatregime.AddVatRate(new VatRates(this.Session).Intracommunity0); foreach (Country country in this.Session.Extent <Country>()) { ((CountryDerivedRoles)country).AddDerivedVatRegime(zeroRatedvatregime); ((CountryDerivedRoles)country).AddDerivedVatRegime(exemptVatregime); if (Countries.EuMemberStates.Contains(country.IsoCode)) { ((CountryDerivedRoles)country).AddDerivedVatRegime(EuVatregime); } } }
public void GivenCustomerShipmentWithQuantityPackagedDifferentFromShippingQuantity_WhenTrySetStateToShipped_ThenActionIsNotAllowed() { var assessable = new VatRegimes(this.DatabaseSession).Assessable; var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(0).Build(); assessable.VatRate = vatRate21; var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good1") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithVatRate(vatRate21).Build(); var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good1).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Ruined).Build()); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); this.DatabaseSession.Derive(true); var order = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithVatRegime(assessable) .Build(); var item = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(5).WithActualUnitPrice(15).Build(); order.AddSalesOrderItem(item); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); var shipment = (CustomerShipment)item.OrderShipmentsWhereSalesOrderItem[0].ShipmentItem.ShipmentWhereShipmentItem; var pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem; pickList.Picker = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "orderProcessor"); pickList.SetPicked(); this.DatabaseSession.Derive(true); var package = new ShipmentPackageBuilder(this.DatabaseSession).Build(); shipment.AddShipmentPackage(package); foreach (ShipmentItem shipmentItem in shipment.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.DatabaseSession).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build()); } this.DatabaseSession.Derive(true); item.QuantityOrdered = 4; this.DatabaseSession.Derive(true); shipment.Ship(); Assert.AreEqual(new CustomerShipmentObjectStates(this.DatabaseSession).Picked, shipment.CurrentObjectState); }