Exemple #1
0
        public void GivenPackingingContent_WhenDeriving_ThenAssertQuantityPackedIsNotGreaterThanQuantityShipped()
        {
            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen  = new PartyContactMechanismBuilder(this.Session)
                                  .WithContactMechanism(mechelenAddress)
                                  .WithContactPurpose(new ContactMechanismPurposes(this.Session).ShippingAddress)
                                  .WithUseAsDefault(true)
                                  .Build();

            var customer = new PersonBuilder(this.Session).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build();

            new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");
            var good2 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good2");

            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good1.Part).Build();
            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good2.Part).Build();

            this.Session.Derive();

            var order = new SalesOrderBuilder(this.Session)
                        .WithBillToCustomer(customer)
                        .WithShipToCustomer(customer)
                        .Build();

            var item1 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(1).WithAssignedUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(2).WithAssignedUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.Session).WithProduct(good2).WithQuantityOrdered(5).WithAssignedUnitPrice(15).Build();

            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);

            this.Session.Derive();

            order.SetReadyForPosting();
            this.Session.Derive();

            order.Post();
            this.Session.Derive();

            order.Accept();
            this.Session.Derive();

            var shipment = (CustomerShipment)mechelenAddress.ShipmentsWhereShipToAddress[0];

            var package = new ShipmentPackageBuilder(this.Session).Build();

            package.AddPackagingContent(new PackagingContentBuilder(this.Session)
                                        .WithShipmentItem(shipment.ShipmentItems[0])
                                        .WithQuantity(shipment.ShipmentItems[0].Quantity + 1)
                                        .Build());

            Assert.True(this.Session.Derive(false).HasErrors);
        }
        public void GivenPackingingContent_WhenDerived_ThenShipmentItemsQuantityPackedIsSet()
        {
            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen  = new PartyContactMechanismBuilder(this.Session)
                                  .WithContactMechanism(mechelenAddress)
                                  .WithContactPurpose(new ContactMechanismPurposes(this.Session).ShippingAddress)
                                  .WithUseAsDefault(true)
                                  .Build();

            var customer = new PersonBuilder(this.Session).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build();

            new CustomerRelationshipBuilder(this.Session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");
            var good2 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good2");

            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good1.Part).Build();
            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good1.Part).Build();

            this.Session.Derive();

            var order = new SalesOrderBuilder(this.Session)
                        .WithBillToCustomer(customer)
                        .WithShipToCustomer(customer)
                        .Build();

            var item1 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.Session).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).Build();

            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);

            this.Session.Derive();

            order.Confirm();

            this.Session.Derive();

            var shipment = (CustomerShipment)mechelenAddress.ShipmentsWhereShipToAddress[0];
            var package  = new ShipmentPackageBuilder(this.Session).Build();

            foreach (ShipmentItem shipmentItem in shipment.ShipmentItems)
            {
                package.AddPackagingContent(new PackagingContentBuilder(this.Session).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build());
            }

            this.Session.Derive();

            foreach (ShipmentItem shipmentItem in shipment.ShipmentItems)
            {
                Assert.Equal(shipmentItem.QuantityShipped, shipmentItem.Quantity);
            }
        }
Exemple #3
0
        private SalesOrder OrderThis()
        {
            var salesOrder = new SalesOrderBuilder(this.Strategy.Session)
                             .WithTakenBy(this.Issuer)
                             .WithBillToCustomer(this.Receiver)
                             .WithDescription(this.Description)
                             .WithShipToContactPerson(this.ContactPerson)
                             .WithBillToContactPerson(this.ContactPerson)
                             .WithQuote(this)
                             .Build();

            var quoteItems = this.ValidQuoteItems
                             .Where(i => i.QuoteItemState.Equals(new QuoteItemStates(this.Strategy.Session).Ordered))
                             .ToArray();

            foreach (var quoteItem in quoteItems)
            {
                quoteItem.QuoteItemState = new QuoteItemStates(this.Strategy.Session).Ordered;

                salesOrder.AddSalesOrderItem(
                    new SalesOrderItemBuilder(this.Strategy.Session)
                    .WithInvoiceItemType(quoteItem.InvoiceItemType)
                    .WithInternalComment(quoteItem.InternalComment)
                    .WithAssignedDeliveryDate(quoteItem.EstimatedDeliveryDate)
                    .WithAssignedUnitPrice(quoteItem.UnitPrice)
                    .WithProduct(quoteItem.Product)
                    .WithSerialisedItem(quoteItem.SerialisedItem)
                    .WithDescription(quoteItem.Details)
                    .WithProductFeature(quoteItem.ProductFeature)
                    .WithQuantityOrdered(quoteItem.Quantity).Build());
            }

            return(salesOrder);
        }
        public void GivenPartyWithOpenOrders_WhenDeriving_ThenOpenOrderAmountIsUpdated()
        {
            var store = this.Session.Extent <Store>().First;

            store.IsImmediatelyPicked = false;

            var organisation         = new OrganisationBuilder(this.Session).WithName("customer").Build();
            var customerRelationship = new CustomerRelationshipBuilder(this.Session).WithCustomer(organisation).Build();

            this.Session.Derive();

            var partyFinancial = organisation.PartyFinancialRelationshipsWhereParty.First(v => Equals(v.InternalOrganisation, customerRelationship.InternalOrganisation));

            var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build();

            var postalAddress = new PostalAddressBuilder(this.Session)
                                .WithAddress1("Kleine Nieuwedijkstraat 2")
                                .WithPostalAddressBoundary(mechelen)
                                .Build();

            var good = new Goods(this.Session).FindBy(M.Good.Name, "good1");

            this.Session.Derive();

            var salesOrder1 = new SalesOrderBuilder(this.Session).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder1").Build();
            var orderItem1  = new SalesOrderItemBuilder(this.Session)
                              .WithProduct(good)
                              .WithQuantityOrdered(10)
                              .WithAssignedUnitPrice(10)
                              .Build();

            salesOrder1.AddSalesOrderItem(orderItem1);

            this.Session.Derive();

            var salesOrder2 = new SalesOrderBuilder(this.Session).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder2").Build();
            var orderItem2  = new SalesOrderItemBuilder(this.Session)
                              .WithProduct(good)
                              .WithQuantityOrdered(10)
                              .WithAssignedUnitPrice(10)
                              .Build();

            salesOrder2.AddSalesOrderItem(orderItem2);

            this.Session.Derive();

            var salesOrder3 = new SalesOrderBuilder(this.Session).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder3").Build();
            var orderItem3  = new SalesOrderItemBuilder(this.Session)
                              .WithProduct(good)
                              .WithQuantityOrdered(10)
                              .WithAssignedUnitPrice(10)
                              .Build();

            salesOrder3.AddSalesOrderItem(orderItem3);
            salesOrder3.Cancel();

            this.Session.Derive();

            Assert.Equal(242M, partyFinancial.OpenOrderAmount);
        }
        public void GivenOrderRequirementCommitment_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var shipToCustomer = new OrganisationBuilder(this.DatabaseSession).WithName("shipToCustomer").Build();
            var billToCustomer = new OrganisationBuilder(this.DatabaseSession).WithName("billToCustomer").Build();

            new CustomerRelationshipBuilder(this.DatabaseSession)
                .WithCustomer(billToCustomer)
                .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation)
                .Build();

            new CustomerRelationshipBuilder(this.DatabaseSession)
                .WithCustomer(shipToCustomer)
                .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation)
                .Build();

            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var good = new GoodBuilder(this.DatabaseSession)
                .WithName("Gizmo")
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            this.DatabaseSession.Derive(true);

            var salesOrder = new SalesOrderBuilder(this.DatabaseSession)
                .WithShipToCustomer(shipToCustomer)
                .WithBillToCustomer(billToCustomer)
                .WithVatRegime(new VatRegimes(this.DatabaseSession).Export)
                .Build();

            var goodOrderItem = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(1).Build();
            salesOrder.AddSalesOrderItem(goodOrderItem);

            var customerRequirement = new CustomerRequirementBuilder(this.DatabaseSession).WithDescription("100 gizmo's").Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            var builder = new OrderRequirementCommitmentBuilder(this.DatabaseSession);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithOrderItem(goodOrderItem);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithRequirement(customerRequirement);
            var tsts = builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Exemple #6
0
        public void GivenOrderRequirementCommitment_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var shipToCustomer = new OrganisationBuilder(this.Session).WithName("shipToCustomer").Build();
            var billToCustomer = new OrganisationBuilder(this.Session).WithName("billToCustomer").Build();

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(billToCustomer)

            .Build();

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(shipToCustomer)

            .Build();

            var good = new Goods(this.Session).FindBy(M.Good.Name, "good1");

            this.Session.Derive();

            var salesOrder = new SalesOrderBuilder(this.Session)
                             .WithShipToCustomer(shipToCustomer)
                             .WithBillToCustomer(billToCustomer)
                             .WithAssignedVatRegime(new VatRegimes(this.Session).ZeroRated)
                             .Build();

            var goodOrderItem = new SalesOrderItemBuilder(this.Session)
                                .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                .WithProduct(good)
                                .WithAssignedUnitPrice(1)
                                .WithQuantityOrdered(1)
                                .Build();

            salesOrder.AddSalesOrderItem(goodOrderItem);

            var customerRequirement = new RequirementBuilder(this.Session).WithDescription("100 gizmo's").Build();

            this.Session.Derive();
            this.Session.Commit();

            var builder = new OrderRequirementCommitmentBuilder(this.Session);

            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithOrderItem(goodOrderItem);
            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithRequirement(customerRequirement);
            var tsts = builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Exemple #7
0
        public void GivenPartyWithOpenOrders_WhenDeriving_ThenOpenOrderAmountIsUpdated()
        {
            var organisation = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new CustomerRelationshipBuilder(this.DatabaseSession).WithCustomer(organisation).WithInternalOrganisation(internalOrganisation).Build();

            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();

            var postalAddress = new PostalAddressBuilder(this.DatabaseSession)
                  .WithAddress1("Kleine Nieuwedijkstraat 2")
                  .WithGeographicBoundary(mechelen)
                  .Build();

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build())
                .WithName("good")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            this.DatabaseSession.Derive(true);

            var salesOrder1 = new SalesOrderBuilder(this.DatabaseSession).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder1").Build();
            var orderItem1 = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithQuantityOrdered(10)
                .WithActualUnitPrice(10)
                .Build();
            salesOrder1.AddSalesOrderItem(orderItem1);

            var salesOrder2 = new SalesOrderBuilder(this.DatabaseSession).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder2").Build();
            var orderItem2 = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithQuantityOrdered(10)
                .WithActualUnitPrice(10)
                .Build();
            salesOrder2.AddSalesOrderItem(orderItem2);

            var salesOrder3 = new SalesOrderBuilder(this.DatabaseSession).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder3").Build();
            var orderItem3 = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithQuantityOrdered(10)
                .WithActualUnitPrice(10)
                .Build();
            salesOrder3.AddSalesOrderItem(orderItem3);
            salesOrder3.Cancel();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(242M, organisation.OpenOrderAmount);
        }
Exemple #8
0
        public static SalesOrder CreateB2CSalesOrder(this Organisation @this, Faker faker)
        {
            var salesOrder = new SalesOrderBuilder(@this.Session()).WithPersonExternalDefaults(@this).Build();

            @this.Session().Derive();

            var productItem = new SalesOrderItemBuilder(@this.Session()).WithSerialisedProductDefaults().Build();

            salesOrder.AddSalesOrderItem(productItem);
            @this.Session().Derive();

            var partItem = new SalesOrderItemBuilder(@this.Session()).WithPartItemDefaults().Build();

            salesOrder.AddSalesOrderItem(partItem);
            @this.Session().Derive();

            var otherItem = new SalesOrderItemBuilder(@this.Session()).WithDefaults().Build();

            salesOrder.AddSalesOrderItem(otherItem);
            @this.Session().Derive();

            return(salesOrder);
        }
Exemple #9
0
        public void GivenOrderItemWithOrderedWithFeature_WhenDeriving_ThenOrderedWithFeatureOrderItemMustBeForProductFeature()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var salesOrder = new SalesOrderBuilder(this.DatabaseSession)
                .WithTakenByInternalOrganisation(this.internalOrganisation)
                .WithShipToAddress(this.shipToContactMechanismMechelen)
                .WithBillToCustomer(this.billToCustomer)
                .Build();

            var productOrderItem = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProduct(this.good)
                .WithQuantityOrdered(3)
                .WithActualUnitPrice(5)
                .Build();

            var productFeatureOrderItem = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProductFeature(this.feature1)
                .WithQuantityOrdered(3)
                .WithActualUnitPrice(5)
                .Build();

            productOrderItem.AddOrderedWithFeature(productFeatureOrderItem);
            salesOrder.AddSalesOrderItem(productOrderItem);
            salesOrder.AddSalesOrderItem(productFeatureOrderItem);

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);

            productFeatureOrderItem.RemoveProductFeature();
            productFeatureOrderItem.Product = this.good;

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);
        }
Exemple #10
0
        public void GivenManuallyScheduledOrderItemWithPendingShipmentAndAssignedPickList_WhenQuantityRequestsShippingIsDecreased_ThenNegativePickListIsCreatedAndShipmentQuantityIsDecreased()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var inventoryItem = (NonSerializedInventoryItem)this.part.InventoryItemsWherePart.First;
            inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(10).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var manual = new OrderKindBuilder(this.DatabaseSession).WithDescription("manual").WithScheduleManually(true).Build();

            var order1 = new SalesOrderBuilder(this.DatabaseSession)
                .WithShipToCustomer(this.shipToCustomer)
                .WithBillToCustomer(this.billToCustomer)
                .WithTakenByInternalOrganisation(this.internalOrganisation)
                .WithShipToAddress(this.shipToContactMechanismMechelen)
                .WithOrderKind(manual)
                .Build();

            var item = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProduct(this.good)
                .WithQuantityOrdered(10)
                .WithActualUnitPrice(5)
                .Build();

            order1.AddSalesOrderItem(item);

            this.DatabaseSession.Derive(true);

            order1.Confirm();

            this.DatabaseSession.Derive(true);

            item.QuantityShipNow = 10;

            this.DatabaseSession.Derive(true);

            var shipment = (CustomerShipment)item.OrderShipmentsWhereSalesOrderItem[0].ShipmentItem.ShipmentWhereShipmentItem;
            Assert.AreEqual(10, shipment.ShipmentItems[0].Quantity);

            var pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem;
            Assert.AreEqual(10, pickList.PickListItems[0].RequestedQuantity);

            pickList.Picker = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "orderProcessor");

            item.QuantityShipNow = -7;
            this.DatabaseSession.Derive(true);

            var negativePickList = order1.ShipToCustomer.PickListsWhereShipToParty[1];

            Assert.AreEqual(3, item.QuantityPendingShipment);
            Assert.AreEqual(3, shipment.ShipmentItems[0].Quantity);
            Assert.AreEqual(10, pickList.PickListItems[0].RequestedQuantity);
            Assert.AreEqual(-7, negativePickList.PickListItems[0].RequestedQuantity);
        }
        public void GivenInventoryItem_WhenQuantityOnHandIsRaised_ThenSalesOrderItemsWithQuantityShortFalledAreUpdated()
        {
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();

            var category = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("category").Build();

            var good = new GoodBuilder(this.DatabaseSession)
             .WithSku("10101")
             .WithVatRate(vatRate21)
             .WithName("good1")
             .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
             .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
             .WithPrimaryProductCategory(category)
             .Build();

            var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build();
            inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(5).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 = 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);
            this.DatabaseSession.Commit();

            var order1 = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .WithDeliveryDate(DateTime.UtcNow)
                .Build();

            var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item1").WithProduct(good).WithQuantityOrdered(10).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item2").WithProduct(good).WithQuantityOrdered(20).WithActualUnitPrice(15).Build();
            order1.AddSalesOrderItem(item1);
            order1.AddSalesOrderItem(item2);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            order1.Confirm();

            this.DatabaseSession.Derive(true);

            var order2 = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .WithDeliveryDate(DateTime.UtcNow.AddDays(1))
                .Build();

            var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item3").WithProduct(good).WithQuantityOrdered(10).WithActualUnitPrice(15).Build();
            var item4 = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item4").WithProduct(good).WithQuantityOrdered(20).WithActualUnitPrice(15).Build();
            order2.AddSalesOrderItem(item3);
            order2.AddSalesOrderItem(item4);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            order2.Confirm();

            this.DatabaseSession.Derive(true);

            //Assert.AreEqual(0, item1.QuantityRequestsShipping);
            //Assert.AreEqual(5, item1.QuantityPendingShipment);
            //Assert.AreEqual(10, item1.QuantityReserved);
            //Assert.AreEqual(5, item1.QuantityShortFalled);

            //Assert.AreEqual(0, item2.QuantityRequestsShipping);
            //Assert.AreEqual(0, item2.QuantityPendingShipment);
            //Assert.AreEqual(20, item2.QuantityReserved);
            //Assert.AreEqual(20, item2.QuantityShortFalled);

            //Assert.AreEqual(0, item3.QuantityRequestsShipping);
            //Assert.AreEqual(0, item3.QuantityPendingShipment);
            //Assert.AreEqual(10, item3.QuantityReserved);
            //Assert.AreEqual(10, item3.QuantityShortFalled);

            //Assert.AreEqual(0, item4.QuantityRequestsShipping);
            //Assert.AreEqual(0, item4.QuantityPendingShipment);
            //Assert.AreEqual(20, item4.QuantityReserved);
            //Assert.AreEqual(20, item4.QuantityShortFalled);

            Assert.AreEqual(0, item1.ReservedFromInventoryItem.AvailableToPromise);
            Assert.AreEqual(5, item1.ReservedFromInventoryItem.QuantityOnHand);

            inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(15).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            //// Orderitems are sorted as follows: item1, item2, item3, item4
            //Assert.AreEqual(0, item1.QuantityRequestsShipping);
            //Assert.AreEqual(10, item1.QuantityPendingShipment);
            //Assert.AreEqual(10, item1.QuantityReserved);
            //Assert.AreEqual(0, item1.QuantityShortFalled);

            //Assert.AreEqual(0, item2.QuantityRequestsShipping);
            //Assert.AreEqual(10, item2.QuantityPendingShipment);
            //Assert.AreEqual(20, item2.QuantityReserved);
            //Assert.AreEqual(10, item2.QuantityShortFalled);

            //Assert.AreEqual(0, item3.QuantityRequestsShipping);
            //Assert.AreEqual(0, item3.QuantityPendingShipment);
            //Assert.AreEqual(10, item3.QuantityReserved);
            //Assert.AreEqual(10, item3.QuantityShortFalled);

            //Assert.AreEqual(0, item4.QuantityRequestsShipping);
            //Assert.AreEqual(0, item4.QuantityPendingShipment);
            //Assert.AreEqual(20, item4.QuantityReserved);
            //Assert.AreEqual(20, item4.QuantityShortFalled);

            Assert.AreEqual(0, item1.ReservedFromInventoryItem.AvailableToPromise);
            Assert.AreEqual(20, item1.ReservedFromInventoryItem.QuantityOnHand);

            inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(85).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            //// Orderitems are sorted as follows: item2, item1, item4, item 3
            Assert.AreEqual(0, item1.QuantityRequestsShipping);
            Assert.AreEqual(10, item1.QuantityPendingShipment);
            Assert.AreEqual(10, item1.QuantityReserved);
            Assert.AreEqual(0, item1.QuantityShortFalled);

            Assert.AreEqual(0, item2.QuantityRequestsShipping);
            Assert.AreEqual(20, item2.QuantityPendingShipment);
            Assert.AreEqual(20, item2.QuantityReserved);
            Assert.AreEqual(0, item2.QuantityShortFalled);

            Assert.AreEqual(0, item3.QuantityRequestsShipping);
            Assert.AreEqual(10, item3.QuantityPendingShipment);
            Assert.AreEqual(10, item3.QuantityReserved);
            Assert.AreEqual(0, item3.QuantityShortFalled);

            Assert.AreEqual(0, item4.QuantityRequestsShipping);
            Assert.AreEqual(20, item4.QuantityPendingShipment);
            Assert.AreEqual(20, item4.QuantityReserved);
            Assert.AreEqual(0, item4.QuantityShortFalled);

            Assert.AreEqual(45, item1.ReservedFromInventoryItem.AvailableToPromise);
            Assert.AreEqual(105, item1.ReservedFromInventoryItem.QuantityOnHand);
        }
Exemple #12
0
        public void GivenSalesOrder_WhenDeriving_ThenDerivedSalesRepMustExist()
        {
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build();
            var salesrep = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep").Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            new CustomerRelationshipBuilder(this.DatabaseSession)
                .WithCustomer(customer)
                .WithInternalOrganisation(internalOrganisation)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithCustomer(customer)
                .WithSalesRepresentative(salesrep)
                .Build();

            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var part1 = new FinishedGoodBuilder(this.DatabaseSession).WithName("part1").Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithFinishedGood(part1)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            this.DatabaseSession.Derive(true);

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithShipToCustomer(customer)
                .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build())
                .Build();

            order.AddSalesOrderItem(new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(10).Build());

            this.DatabaseSession.Derive(true);

            Assert.Contains(salesrep, order.SalesReps);
        }
Exemple #13
0
        public void GivenCustomerShipmentWithValueBelowThreshold_WhenShippingToBelgium_TheninvoiceIncludesCosts()
        {
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();

            new ShippingAndHandlingComponentBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithGeographicBoundary(mechelen)
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground)
                .WithShipmentValue(new ShipmentValueBuilder(this.DatabaseSession).WithThroughAmount(300M).Build())
                .WithCost(15M)
                .Build();

            new ShippingAndHandlingComponentBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithShipmentValue(new ShipmentValueBuilder(this.DatabaseSession).WithThroughAmount(300M).Build())
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground)
                .WithCost(20M)
                .Build();

            new ShippingAndHandlingComponentBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithShipmentValue(new ShipmentValueBuilder(this.DatabaseSession).WithThroughAmount(300M).Build())
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).FirstClassAir)
                .WithCost(50M)
                .Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good1")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithVatRate(vatRate21)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .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 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 billToContactMechanismMechelen = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Mechelen").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)
                .WithBillToContactMechanism(billToContactMechanismMechelen)
                .WithShipToCustomer(customer)
                .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);

            shipment.Ship();

            this.DatabaseSession.Derive(true);

            var invoice = customer.SalesInvoicesWhereBillToCustomer.First;
            Assert.AreEqual(15M, invoice.ShippingAndHandlingCharge.Amount);
        }
        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 serialisedItemSoldOns = new SerialisedItemSoldOn[] { new SerialisedItemSoldOns(this.Session).SalesInvoiceSend, new SerialisedItemSoldOns(this.Session).PurchaseInvoiceConfirm };

            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",
                purchaseOrderNumberPrefix: "a-PO",
                purchaseInvoiceNumberPrefix: "a-PI",
                requestNumberPrefix: "a-RFQ",
                quoteNumberPrefix: "a-Q",
                productNumberPrefix: "A-",
                workEffortPrefix: "a-WO-",
                creditNoteNumberPrefix: "a-CN-",
                isImmediatelyPicked: true,
                autoGenerateShipmentPackage: true,
                isImmediatelyPacked: true,
                isAutomaticallyShipped: true,
                autoGenerateCustomerShipment: true,
                isAutomaticallyReceived: false,
                autoGeneratePurchaseShipment: false,
                useCreditNoteSequence: true,
                requestCounterValue: 1,
                quoteCounterValue: 1,
                orderCounterValue: 1,
                purchaseOrderCounterValue: 1,
                purchaseInvoiceCounterValue: 1,
                invoiceCounterValue: 1,
                purchaseOrderNeedsApproval: true,
                purchaseOrderApprovalThresholdLevel1: 1000M,
                purchaseOrderApprovalThresholdLevel2: 5000M,
                serialisedItemSoldOns: serialisedItemSoldOns,
                collectiveWorkEffortInvoice: true);

            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",
                purchaseOrderNumberPrefix: "d-PO",
                purchaseInvoiceNumberPrefix: "d-PI",
                requestNumberPrefix: "d-RFQ",
                quoteNumberPrefix: "d-Q",
                productNumberPrefix: "D-",
                workEffortPrefix: "d-WO-",
                creditNoteNumberPrefix: "d-CN-",
                isImmediatelyPicked: true,
                autoGenerateShipmentPackage: true,
                isImmediatelyPacked: true,
                isAutomaticallyShipped: true,
                autoGenerateCustomerShipment: true,
                isAutomaticallyReceived: false,
                autoGeneratePurchaseShipment: false,
                useCreditNoteSequence: true,
                requestCounterValue: 1,
                quoteCounterValue: 1,
                orderCounterValue: 1,
                purchaseOrderCounterValue: 1,
                purchaseInvoiceCounterValue: 1,
                invoiceCounterValue: 1,
                purchaseOrderNeedsApproval: false,
                purchaseOrderApprovalThresholdLevel1: null,
                purchaseOrderApprovalThresholdLevel2: null,
                serialisedItemSoldOns: serialisedItemSoldOns,
                collectiveWorkEffortInvoice: true);

            singleton.Settings.DefaultFacility = allors.FacilitiesWhereOwner.First;
            var faker = this.Session.Faker();

            allors.CreateEmployee("letmein", faker);
            allors.CreateAdministrator("letmein", faker);
            var allorsB2BCustomer = allors.CreateB2BCustomer(this.Session.Faker());
            var allorsB2CCustomer = allors.CreateB2CCustomer(this.Session.Faker());

            allors.CreateSupplier(this.Session.Faker());
            allors.CreateSubContractor(this.Session.Faker());

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(allorsB2BCustomer)
            .WithInternalOrganisation(dipu)
            .WithFromDate(this.Session.Now())
            .Build();

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(allorsB2CCustomer)
            .WithInternalOrganisation(dipu)
            .WithFromDate(this.Session.Now())
            .Build();

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(dipu)
            .WithInternalOrganisation(allors)
            .WithFromDate(this.Session.Now())
            .Build();

            dipu.CreateEmployee("letmein", faker);
            dipu.CreateAdministrator("letmein", faker);
            var dipuB2BCustomer = dipu.CreateB2BCustomer(this.Session.Faker());
            var dipuB2CCustomer = dipu.CreateB2CCustomer(this.Session.Faker());

            dipu.CreateSupplier(this.Session.Faker());
            dipu.CreateSubContractor(this.Session.Faker());

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(dipuB2BCustomer)
            .WithInternalOrganisation(allors)
            .WithFromDate(this.Session.Now())
            .Build();

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(dipuB2CCustomer)
            .WithInternalOrganisation(allors)
            .WithFromDate(this.Session.Now())
            .Build();

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(allors)
            .WithInternalOrganisation(dipu)
            .WithFromDate(this.Session.Now())
            .Build();

            this.Session.Derive();

            var facility = new FacilityBuilder(this.Session)
                           .WithName("Allors warehouse 2")
                           .WithFacilityType(new FacilityTypes(this.Session).Warehouse)
                           .WithOwner(allors)
                           .Build();

            var store = new StoreBuilder(this.Session).WithName("store")
                        .WithInternalOrganisation(allors)
                        .WithDefaultFacility(facility)
                        .WithDefaultShipmentMethod(new ShipmentMethods(this.Session).Ground)
                        .WithDefaultCarrier(new Carriers(this.Session).Fedex)
                        .Build();

            var productType = new ProductTypeBuilder(this.Session)
                              .WithName($"Gizmo Serialised")
                              .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).WithDefaults().Build();

            var good_1 = new UnifiedGoodBuilder(this.Session).WithNonSerialisedDefaults(allors).Build();

            this.Session.Derive();

            new InventoryItemTransactionBuilder(this.Session)
            .WithPart(good_1)
            .WithQuantity(100)
            .WithReason(new InventoryTransactionReasons(this.Session).Unknown)
            .Build();

            var good_2 = new NonUnifiedGoodBuilder(this.Session)
                         .WithSerialisedPartDefaults(allors)
                         .Build();

            var serialisedItem1 = new SerialisedItemBuilder(this.Session).WithDefaults(allors).Build();

            good_2.Part.AddSerialisedItem(serialisedItem1);

            this.Session.Derive();

            new SerialisedInventoryItemBuilder(this.Session)
            .WithPart(good_2.Part)
            .WithSerialisedItem(serialisedItem1)
            .WithFacility(allors.StoresWhereInternalOrganisation.First.DefaultFacility)
            .Build();

            var good_3 = new NonUnifiedGoodBuilder(this.Session)
                         .WithNonSerialisedPartDefaults(allors)
                         .Build();

            var good_4 = new UnifiedGoodBuilder(this.Session).WithSerialisedDefaults(allors).Build();

            var productCategory_1 = 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 productCategory_2 = new ProductCategoryBuilder(this.Session)
                                    .WithInternalOrganisation(allors)
                                    .WithName("Big Gizmo's")
                                    .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Grote Gizmo's").WithLocale(dutchLocale).Build())
                                    .Build();

            var productCategory_3 = new ProductCategoryBuilder(this.Session)
                                    .WithInternalOrganisation(allors)
                                    .WithName("Small gizmo's")
                                    .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Kleine gizmo's").WithLocale(dutchLocale).Build())
                                    .WithProduct(good_1)
                                    .WithProduct(good_2)
                                    .WithProduct(good_3)
                                    .WithProduct(good_4)
                                    .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(productCategory_1)
            .Build();

            this.Session.Derive();

            var administrator = (Person) new UserGroups(this.Session).Administrators.Members.First;

            new FaceToFaceCommunicationBuilder(this.Session)
            .WithDescription($"Meeting")
            .WithSubject($"meeting")
            .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
            .WithFromParty(allors.ActiveEmployees.First)
            .WithToParty(allors.ActiveCustomers.First)
            .WithOwner(administrator)
            .WithActualStart(DateTime.UtcNow)
            .Build();

            new EmailCommunicationBuilder(this.Session)
            .WithDescription($"Email")
            .WithSubject($"email")
            .WithFromParty(allors.ActiveEmployees.First)
            .WithToParty(allors.ActiveCustomers.First)
            .WithFromEmail(allors.ActiveEmployees.First.GeneralEmail)
            .WithToEmail(allors.ActiveCustomers.First.GeneralEmail)
            .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
            .WithOwner(administrator)
            .WithActualStart(DateTime.UtcNow)
            .Build();

            new LetterCorrespondenceBuilder(this.Session)
            .WithDescription($"Letter")
            .WithSubject($"letter")
            .WithFromParty(administrator)
            .WithToParty(allors.ActiveCustomers.First)
            .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
            .WithOwner(administrator)
            .WithActualStart(DateTime.UtcNow)
            .Build();

            new PhoneCommunicationBuilder(this.Session)
            .WithDescription($"Phone")
            .WithSubject($"phone")
            .WithFromParty(administrator)
            .WithToParty(allors.ActiveCustomers.First)
            .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
            .WithOwner(administrator)
            .WithActualStart(DateTime.UtcNow)
            .Build();

            new SalesOrderBuilder(this.Session).WithOrganisationInternalDefaults(allors).Build();
            new SalesOrderBuilder(this.Session).WithOrganisationExternalDefaults(allors).Build();
            new SalesOrderBuilder(this.Session).WithPersonInternalDefaults(allors).Build();
            new SalesOrderBuilder(this.Session).WithPersonExternalDefaults(allors).Build();

            new SalesInvoiceBuilder(this.Session).WithSalesExternalB2BInvoiceDefaults(allors).Build();

            new SupplierOfferingBuilder(this.Session)
            .WithPart(good_1)
            .WithSupplier(allors.ActiveSuppliers.First)
            .WithFromDate(this.Session.Now().AddMinutes(-1))
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .WithPrice(7)
            .WithCurrency(euro)
            .Build();

            var purchaseInvoiceItem_1 = new PurchaseInvoiceItemBuilder(this.Session)
                                        .WithDescription("first item")
                                        .WithPart(good_1)
                                        .WithAssignedUnitPrice(3000)
                                        .WithQuantity(1)
                                        .WithMessage(@"line1
line2")
                                        .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                        .Build();

            var purchaseInvoiceItem_2 = new PurchaseInvoiceItemBuilder(this.Session)
                                        .WithDescription("second item")
                                        .WithAssignedUnitPrice(2000)
                                        .WithQuantity(2)
                                        .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                        .Build();

            var purchaseInvoiceItem_3 = new PurchaseInvoiceItemBuilder(this.Session)
                                        .WithDescription("Service")
                                        .WithAssignedUnitPrice(100)
                                        .WithQuantity(1)
                                        .WithInvoiceItemType(new InvoiceItemTypes(this.Session).Service)
                                        .Build();

            var purchaseInvoice = new PurchaseInvoiceBuilder(this.Session)
                                  .WithBilledTo(allors)
                                  .WithInvoiceNumber("1")
                                  .WithBilledFrom(allors.ActiveSuppliers.First)
                                  .WithPurchaseInvoiceItem(purchaseInvoiceItem_1)
                                  .WithPurchaseInvoiceItem(purchaseInvoiceItem_2)
                                  .WithPurchaseInvoiceItem(purchaseInvoiceItem_3)
                                  .WithCustomerReference("a reference number")
                                  .WithDescription("Purchase of 1 used Aircraft Towbar")
                                  .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.Session).PurchaseInvoice)
                                  .WithVatRegime(new VatRegimes(this.Session).Assessable21)
                                  .Build();

            var purchaseOrderItem_1 = new PurchaseOrderItemBuilder(this.Session)
                                      .WithDescription("first purchase order item")
                                      .WithPart(good_1)
                                      .WithQuantityOrdered(1)
                                      .Build();

            var purchaseOrder = new PurchaseOrderBuilder(this.Session)
                                .WithOrderedBy(allors)
                                .WithTakenViaSupplier(allors.ActiveSuppliers.First)
                                .WithPurchaseOrderItem(purchaseOrderItem_1)
                                .WithCustomerReference("reference 123")
                                .WithStoredInFacility(facility)
                                .Build();

            var workTask = new WorkTaskBuilder(this.Session)
                           .WithTakenBy(allors)
                           .WithCustomer(allors.ActiveCustomers.First)
                           .WithName("maintenance")
                           .Build();

            new PositionTypeBuilder(this.Session)
            .WithTitle("Mechanic")
            .WithUniqueId(new Guid("E62A8F4B-8045-472E-AB18-E39C51A02696"))
            .Build();

            new PositionTypeRateBuilder(this.Session)
            .WithRate(100)
            .WithRateType(new RateTypes(this.Session).StandardRate)
            .WithFrequency(new TimeFrequencies(this.Session).Hour)
            .Build();

            this.Session.Derive();

            // Serialized RFQ with Serialized Unified-Good
            var serializedRFQ = new RequestForQuoteBuilder(this.Session).WithSerializedDefaults(allors).Build();

            // NonSerialized RFQ with NonSerialized Unified-Good
            var nonSerializedRFQ = new RequestForQuoteBuilder(this.Session).WithNonSerializedDefaults(allors).Build();

            var quote = new ProductQuoteBuilder(this.Session)
                        .WithIssuer(allors)
                        .WithDescription("quote")
                        .WithReceiver(allors.ActiveCustomers.First)
                        .WithFullfillContactMechanism(allors.ActiveCustomers.First.GeneralCorrespondence)
                        .Build();

            this.Session.Derive();

            var quoteItem = new QuoteItemBuilder(this.Session)
                            .WithProduct(new Goods(this.Session).Extent().First)
                            .WithQuantity(1)
                            .WithAssignedUnitPrice(10)
                            .Build();

            quote.AddQuoteItem(quoteItem);

            this.Session.Derive();

            var salesOrder = new SalesOrderBuilder(this.Session)
                             .WithTakenBy(allors)
                             .WithShipToCustomer(allors.ActiveCustomers.First)
                             .Build();

            this.Session.Derive();

            var salesOrderItem = new SalesOrderItemBuilder(this.Session)
                                 .WithProduct(good_1)
                                 .WithQuantityOrdered(1)
                                 .WithAssignedUnitPrice(10)
                                 .Build();

            salesOrder.AddSalesOrderItem(salesOrderItem);

            this.Session.Derive();

            new CustomerShipmentBuilder(this.Session).WithDefaults(allors).Build();

            this.Session.Derive();

            new PurchaseShipmentBuilder(this.Session).WithDefaults(allors).Build();

            this.Session.Derive();
        }
Exemple #15
0
        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);
        }
Exemple #16
0
        public void GivenPickList_WhenPicked_ThenInventoryIsAdjustedAndOrderItemsQuantityPickedIsSet()
        {
            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 supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("person1").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();

            new SupplierRelationshipBuilder(this.DatabaseSession)
                .WithInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"))
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10102")
                .WithVatRate(vatRate21)
                .WithName("good2")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good1PurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"))
                .WithFromDate(DateTime.UtcNow)
                .WithPrice(7)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good2PurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"))
                .WithFromDate(DateTime.UtcNow)
                .WithPrice(7)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            new SupplierOfferingBuilder(this.DatabaseSession)
                .WithProduct(good1)
                .WithProductPurchasePrice(good1PurchasePrice)
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            new SupplierOfferingBuilder(this.DatabaseSession)
                .WithProduct(good2)
                .WithProductPurchasePrice(good2PurchasePrice)
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            this.DatabaseSession.Derive(true);

            var good1Inventory = (NonSerializedInventoryItem)good1.InventoryItemsWhereGood[0];
            good1Inventory.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var good2Inventory = (NonSerializedInventoryItem)good2.InventoryItemsWhereGood[0];
            good2Inventory.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var colorWhite = new ColourBuilder(this.DatabaseSession)
                .WithName("white")
                .WithLocalisedName(new LocalisedTextBuilder(this.DatabaseSession)
                            .WithText("white")
                            .WithLocale(Singleton.Instance(this.DatabaseSession).DefaultLocale)
                            .Build())

                .Build();
            var extraLarge = new SizeBuilder(this.DatabaseSession)
                .WithName("extra large")
                .WithLocalisedName(new LocalisedTextBuilder(this.DatabaseSession)
                            .WithText("Extra large")
                            .WithLocale(Singleton.Instance(this.DatabaseSession).DefaultLocale)
                            .Build())
                .Build();

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .WithVatRegime(new VatRegimes(this.DatabaseSession).Export)
                .Build();

            var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithProductFeature(colorWhite).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithProductFeature(extraLarge).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            item1.AddOrderedWithFeature(item2);
            item1.AddOrderedWithFeature(item3);
            var item4 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item5 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).Build();
            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);
            order.AddSalesOrderItem(item4);
            order.AddSalesOrderItem(item5);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            var shipment = (CustomerShipment)mechelenAddress.ShipmentsWhereShipToAddress[0];

            var pickList = good1.InventoryItemsWhereGood[0].PickListItemsWhereInventoryItem[0].PickListWherePickListItem;
            pickList.Picker = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "orderProcessor");

            //// item5: only 4 out of 5 are actually picked
            foreach (PickListItem pickListItem in pickList.PickListItems)
            {
                if (pickListItem.RequestedQuantity == 5)
                {
                    pickListItem.ActualQuantity = 4;
                }
            }

            pickList.SetPicked();

            this.DatabaseSession.Derive(true);

            //// all orderitems have same physical finished good, so there is only one picklist item.
            Assert.AreEqual(new CustomerShipmentObjectStates(this.DatabaseSession).Picked, shipment.CurrentShipmentStatus.CustomerShipmentObjectState);
            Assert.AreEqual(new PickListObjectStates(this.DatabaseSession).Picked, pickList.CurrentPickListStatus.PickListObjectState);
            Assert.AreEqual(1, item1.QuantityPicked);
            Assert.AreEqual(0, item1.QuantityReserved);
            Assert.AreEqual(0, item1.QuantityRequestsShipping);
            Assert.AreEqual(2, item4.QuantityPicked);
            Assert.AreEqual(0, item4.QuantityReserved);
            Assert.AreEqual(0, item4.QuantityRequestsShipping);
            Assert.AreEqual(4, item5.QuantityPicked);
            Assert.AreEqual(1, item5.QuantityReserved);
            Assert.AreEqual(0, item5.QuantityRequestsShipping);
            Assert.AreEqual(97, good1Inventory.QuantityOnHand);
            Assert.AreEqual(0, good1Inventory.QuantityCommittedOut);
            Assert.AreEqual(96, good2Inventory.QuantityOnHand);
            Assert.AreEqual(1, good2Inventory.QuantityCommittedOut);
        }
Exemple #17
0
        public void GivenSalesOrder_WhenShipmentIsCreated_ThenOrdertemsAreAddedToPickList()
        {
            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 supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();

            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("person1").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();

            new SupplierRelationshipBuilder(this.DatabaseSession)
                .WithInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"))
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10102")
                .WithVatRate(vatRate21)
                .WithName("good2")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good1PurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"))
                .WithFromDate(DateTime.UtcNow)
                .WithPrice(7)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good2PurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"))
                .WithFromDate(DateTime.UtcNow)
                .WithPrice(7)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            new SupplierOfferingBuilder(this.DatabaseSession)
                .WithProduct(good1)
                .WithProductPurchasePrice(good1PurchasePrice)
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            new SupplierOfferingBuilder(this.DatabaseSession)
                .WithProduct(good2)
                .WithProductPurchasePrice(good2PurchasePrice)
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            this.DatabaseSession.Derive(true);

            var good1Inventory = (NonSerializedInventoryItem)good1.InventoryItemsWhereGood[0];
            good1Inventory.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Ruined).Build());

            this.DatabaseSession.Derive(true);

            var good2Inventory = (NonSerializedInventoryItem)good2.InventoryItemsWhereGood[0];
            good2Inventory.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Ruined).Build());

            this.DatabaseSession.Derive(true);

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .Build();

            var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).Build();
            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            var pickList = good1.InventoryItemsWhereGood[0].PickListItemsWhereInventoryItem[0].PickListWherePickListItem;

            Assert.AreEqual(2, pickList.PickListItems.Count);

            var extent1 = pickList.PickListItems;
            extent1.Filter.AddEquals(PickListItems.Meta.InventoryItem, good1Inventory);
            Assert.AreEqual(3, extent1.First.RequestedQuantity);

            var extent2 = pickList.PickListItems;
            extent2.Filter.AddEquals(PickListItems.Meta.InventoryItem, good2Inventory);
            Assert.AreEqual(5, extent2.First.RequestedQuantity);
        }
Exemple #18
0
        public void GivenMultipleOrders_WhenCombinedPickListIsPicked_ThenSingleShipmentIsPickedState()
        {
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf").Build();
            var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(mechelenAddress)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress)
                .WithUseAsDefault(true)
                .Build();

            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("person1").WithPartyContactMechanism(shipToMechelen).Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build();

            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();

            new SupplierRelationshipBuilder(this.DatabaseSession)
                .WithInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"))
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10102")
                .WithVatRate(vatRate21)
                .WithName("good2")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good1PurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"))
                .WithFromDate(DateTime.UtcNow)
                .WithPrice(7)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good2PurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"))
                .WithFromDate(DateTime.UtcNow)
                .WithPrice(7)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            new SupplierOfferingBuilder(this.DatabaseSession)
                .WithProduct(good1)
                .WithProductPurchasePrice(good1PurchasePrice)
                .WithFromDate(DateTime.UtcNow)
                .WithSupplier(supplier)
                .Build();

            new SupplierOfferingBuilder(this.DatabaseSession)
                .WithProduct(good2)
                .WithProductPurchasePrice(good2PurchasePrice)
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            this.DatabaseSession.Derive(true);

            var good1Inventory = (NonSerializedInventoryItem)good1.InventoryItemsWhereGood[0];
            good1Inventory.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Ruined).Build());

            this.DatabaseSession.Derive(true);

            var good2Inventory = (NonSerializedInventoryItem)good2.InventoryItemsWhereGood[0];
            good2Inventory.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Ruined).Build());

            this.DatabaseSession.Derive(true);

            var order1 = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .Build();

            var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).Build();
            order1.AddSalesOrderItem(item1);
            order1.AddSalesOrderItem(item2);
            order1.AddSalesOrderItem(item3);

            this.DatabaseSession.Derive(true);

            order1.Confirm();

            this.DatabaseSession.Derive(true);

            var order2 = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .Build();

            var itema = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var itemb = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            order2.AddSalesOrderItem(itema);
            order2.AddSalesOrderItem(itemb);

            this.DatabaseSession.Derive(true);

            order2.Confirm();

            this.DatabaseSession.Derive(true);

            var pickList = good1.InventoryItemsWhereGood[0].PickListItemsWhereInventoryItem[0].PickListWherePickListItem;
            pickList.Picker = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "orderProcessor");

            pickList.SetPicked();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(1, customer.ShipmentsWhereBillToParty.Count);

            var customerShipment = customer.ShipmentsWhereBillToParty.First;
            Assert.AreEqual(new CustomerShipmentObjectStates(this.DatabaseSession).Picked, customerShipment.CurrentObjectState);
        }
Exemple #19
0
        public void GivenPickList_WhenActualQuantityPickedIsLess_ThenShipmentItemQuantityIsAdjusted()
        {
            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 supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("person1").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();

            new SupplierRelationshipBuilder(this.DatabaseSession)
                .WithInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"))
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10102")
                .WithVatRate(vatRate21)
                .WithName("good2")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good1PurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"))
                .WithFromDate(DateTime.UtcNow)
                .WithPrice(7)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good2PurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"))
                .WithFromDate(DateTime.UtcNow)
                .WithPrice(7)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            new SupplierOfferingBuilder(this.DatabaseSession)
                .WithProduct(good1)
                .WithProductPurchasePrice(good1PurchasePrice)
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            new SupplierOfferingBuilder(this.DatabaseSession)
                .WithProduct(good2)
                .WithProductPurchasePrice(good2PurchasePrice)
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            this.DatabaseSession.Derive(true);

            var good1Inventory = (NonSerializedInventoryItem)good1.InventoryItemsWhereGood[0];
            good1Inventory.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var good2Inventory = (NonSerializedInventoryItem)good2.InventoryItemsWhereGood[0];
            good2Inventory.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .Build();

            var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).Build();
            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            var pickList = good1.InventoryItemsWhereGood[0].PickListItemsWhereInventoryItem[0].PickListWherePickListItem;
            pickList.Picker = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "orderProcessor");

            //// item3: only 4 out of 5 are actually picked
            PickListItem adjustedPicklistItem = null;
            foreach (PickListItem pickListItem in pickList.PickListItems)
            {
                if (pickListItem.RequestedQuantity == 5)
                {
                    adjustedPicklistItem = pickListItem;
                }
            }

            var itemIssuance = adjustedPicklistItem.ItemIssuancesWherePickListItem[0];
            var shipmentItem = adjustedPicklistItem.ItemIssuancesWherePickListItem[0].ShipmentItem;

            Assert.AreEqual(5, itemIssuance.Quantity);
            Assert.AreEqual(5, shipmentItem.Quantity);

            adjustedPicklistItem.ActualQuantity = 4;

            pickList.SetPicked();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(4, itemIssuance.Quantity);
            Assert.AreEqual(4, shipmentItem.Quantity);
        }
        public void GivenShipmentReceiptWhenDerivingThenInventoryItemQuantityOnHandIsUpdated()
        {
            var store = this.Session.Extent <Store>().First;

            store.IsImmediatelyPicked = false;

            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen  = new PartyContactMechanismBuilder(this.Session)
                                  .WithContactMechanism(mechelenAddress)
                                  .WithContactPurpose(new ContactMechanismPurposes(this.Session).ShippingAddress)
                                  .WithUseAsDefault(true)
                                  .Build();

            var customer = new PersonBuilder(this.Session).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build();

            new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");

            new InventoryItemTransactionBuilder(this.Session).WithQuantity(20).WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good1.Part).Build();

            this.Session.Derive();

            var inventoryItem = good1.Part.InventoryItemsWherePart.First;

            var order1 = new SalesOrderBuilder(this.Session)
                         .WithBillToCustomer(customer)
                         .WithShipToCustomer(customer)
                         .WithDeliveryDate(this.Session.Now())
                         .Build();

            var salesItem = new SalesOrderItemBuilder(this.Session).WithDescription("item1").WithProduct(good1).WithQuantityOrdered(30).WithAssignedUnitPrice(15).Build();

            order1.AddSalesOrderItem(salesItem);

            this.Session.Derive();
            this.Session.Commit();

            order1.SetReadyForPosting();

            this.Session.Derive();

            order1.Post();
            this.Session.Derive();

            order1.Accept();
            this.Session.Derive();

            var sessionInventoryItem = (NonSerialisedInventoryItem)this.Session.Instantiate(inventoryItem);
            var sessionSalesItem     = (SalesOrderItem)this.Session.Instantiate(salesItem);

            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

            new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build();

            Assert.Equal(20, sessionSalesItem.QuantityPendingShipment);
            Assert.Equal(30, sessionSalesItem.QuantityReserved);
            Assert.Equal(10, sessionSalesItem.QuantityShortFalled);

            var order = new PurchaseOrderBuilder(this.Session).WithTakenViaSupplier(supplier).Build();

            var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(good1.Part).WithQuantityOrdered(10).Build();

            order.AddPurchaseOrderItem(item1);

            this.Session.Derive();
            this.Session.Commit();

            order.SetReadyForProcessing();

            order.OrderedBy.IsAutomaticallyReceived = true;
            order.QuickReceive();

            this.Session.Derive();
            this.Session.Commit();

            Assert.Equal(30, sessionInventoryItem.QuantityOnHand);

            Assert.Equal(30, sessionSalesItem.QuantityPendingShipment);
            Assert.Equal(30, sessionSalesItem.QuantityReserved);
            Assert.Equal(0, sessionSalesItem.QuantityShortFalled);
        }
Exemple #21
0
        public void GivenOrderItemWithoutShipToParty_WhenDeriving_ThenDerivedShipToPartyIsFromOrder()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var salesOrder = new SalesOrderBuilder(this.DatabaseSession)
                .WithTakenByInternalOrganisation(this.internalOrganisation)
                .WithShipToCustomer(this.shipToCustomer)
                .WithBillToCustomer(this.billToCustomer)
                .Build();

            var orderItem = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(this.good).WithQuantityOrdered(1).Build();
            salesOrder.AddSalesOrderItem(orderItem);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(this.shipToCustomer, orderItem.ShipToParty);
        }
Exemple #22
0
        public void GivenConfirmedOrder_WhenOrderIsCancelled_ThenNonSerializedInventoryQuantitiesAreReleased()
        {
            var billToCustomer = new PersonBuilder(this.DatabaseSession).WithLastName("person1").Build();
            var shipToCustomer = new PersonBuilder(this.DatabaseSession).WithLastName("person2").Build();
            var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation;

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(billToCustomer).WithInternalOrganisation(internalOrganisation).Build();
            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(shipToCustomer).WithInternalOrganisation(internalOrganisation).Build();

            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var shipToContactMechanism = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();

            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var part1 = new FinishedGoodBuilder(this.DatabaseSession).WithName("part1").Build();
            var part2 = new FinishedGoodBuilder(this.DatabaseSession).WithName("part2").Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithFinishedGood(part1)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10102")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithFinishedGood(part2)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            this.DatabaseSession.Derive(true);

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(billToCustomer)
                .WithShipToCustomer(shipToCustomer)
                .WithShipToAddress(shipToContactMechanism)
                .Build();

            var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(3).WithActualUnitPrice(15).Build();
            var item4 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(4).WithActualUnitPrice(15).Build();
            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);
            order.AddSalesOrderItem(item4);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(3, item1.ReservedFromInventoryItem.QuantityCommittedOut);
            Assert.AreEqual(0, item1.ReservedFromInventoryItem.AvailableToPromise);
            Assert.AreEqual(7, item3.ReservedFromInventoryItem.QuantityCommittedOut);
            Assert.AreEqual(0, item3.ReservedFromInventoryItem.AvailableToPromise);

            order.Cancel();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(0, item1.ReservedFromInventoryItem.QuantityCommittedOut);
            Assert.AreEqual(0, item1.ReservedFromInventoryItem.AvailableToPromise);
            Assert.AreEqual(0, item3.ReservedFromInventoryItem.QuantityCommittedOut);
            Assert.AreEqual(0, item3.ReservedFromInventoryItem.AvailableToPromise);
        }
Exemple #23
0
        public void GivenCustomerBuyingFromDifferentStores_WhenShipping_ThenPickListIsCreatedForEachStore()
        {
            var store1 = new Stores(this.Session).FindBy(M.Store.Name, "store");

            var store2 = new StoreBuilder(this.Session).WithName("second store")
                         .WithDefaultFacility(new Facilities(this.Session).Extent().First)
                         .WithDefaultShipmentMethod(new ShipmentMethods(this.Session).Ground)
                         .WithDefaultCarrier(new Carriers(this.Session).Fedex)
                         .WithSalesOrderNumberPrefix("")
                         .WithOutgoingShipmentNumberPrefix("")
                         .WithIsImmediatelyPacked(true)
                         .Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");

            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).PhysicalCount).WithPart(good1.Part).Build();

            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen  = new PartyContactMechanismBuilder(this.Session)
                                  .WithContactMechanism(mechelenAddress)
                                  .WithContactPurpose(new ContactMechanismPurposes(this.Session).ShippingAddress)
                                  .WithUseAsDefault(true)
                                  .Build();

            var customer = new PersonBuilder(this.Session).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build();

            new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).Build();

            this.Session.Derive(true);

            var order1 = new SalesOrderBuilder(this.Session)
                         .WithStore(store1)
                         .WithBillToCustomer(customer)
                         .WithAssignedBillToContactMechanism(mechelenAddress)
                         .WithShipToCustomer(customer)
                         .Build();

            var order1Item = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(1).WithAssignedUnitPrice(15).Build();

            order1.AddSalesOrderItem(order1Item);

            this.Session.Derive(true);

            order1.SetReadyForPosting();
            this.Session.Derive(true);

            order1.Post();
            this.Session.Derive();

            order1.Accept();
            this.Session.Derive();

            Assert.Single(customer.ShipmentsWhereShipToParty);

            var order2 = new SalesOrderBuilder(this.Session)
                         .WithStore(store1)
                         .WithBillToCustomer(customer)
                         .WithShipToCustomer(customer)
                         .Build();

            var order2Item = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(2).WithAssignedUnitPrice(15).Build();

            order2.AddSalesOrderItem(order2Item);

            this.Session.Derive(true);

            order2.SetReadyForPosting();
            this.Session.Derive(true);

            order2.Post();
            this.Session.Derive();

            order2.Accept();
            this.Session.Derive();

            Assert.Single(customer.ShipmentsWhereShipToParty);

            var store1Shipment = (CustomerShipment)mechelenAddress.ShipmentsWhereShipToAddress.First(v => v.Store.Equals(store1));

            store1Shipment.Pick();
            this.Session.Derive();

            var order3 = new SalesOrderBuilder(this.Session)
                         .WithStore(store2)
                         .WithBillToCustomer(customer)
                         .WithShipToCustomer(customer)
                         .Build();

            var order3Item = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(5).WithAssignedUnitPrice(15).Build();

            order3.AddSalesOrderItem(order3Item);

            this.Session.Derive(true);

            order3.SetReadyForPosting();
            this.Session.Derive(true);

            order3.Post();
            this.Session.Derive();

            order3.Accept();
            this.Session.Derive();

            var store2Shipment = (CustomerShipment)mechelenAddress.ShipmentsWhereShipToAddress.First(v => v.Store.Equals(store2));

            store2Shipment.Pick();
            this.Session.Derive();

            var store1PickList = customer.PickListsWhereShipToParty.FirstOrDefault(v => v.Store.Equals(store1));
            var store2PickList = customer.PickListsWhereShipToParty.FirstOrDefault(v => v.Store.Equals(store2));

            Assert.Equal(2, customer.PickListsWhereShipToParty.Count);
            Assert.NotNull(store1PickList);
            Assert.Equal(3, store1PickList.PickListItems[0].Quantity);
            Assert.NotNull(store2PickList);
            Assert.Equal(5, store2PickList.PickListItems[0].Quantity);
        }
Exemple #24
0
        public void GivenSalesOrderForItemsThatAreAvailable_WhenShipped_ThenOrderIsCompleted()
        {
            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();

            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10102")
                .WithVatRate(vatRate21)
                .WithName("good2")
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .Build();

            var good1InventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good1).Build();
            good1InventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var good2InventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good2).Build();
            good2InventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .WithShipToAddress(mechelenAddress)
                .Build();

            var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).Build();
            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            var shipment = (CustomerShipment)mechelenAddress.ShipmentsWhereShipToAddress[0];

            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.Ship();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).Completed, order.CurrentObjectState);
            Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).Shipped, order.CurrentShipmentStatus.SalesOrderObjectState);
            Assert.IsFalse(order.ExistCurrentPaymentStatus);
            Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Completed, item1.CurrentObjectState);
            Assert.IsFalse(item1.ExistCurrentPaymentStatus);
            Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Shipped, item1.CurrentShipmentStatus.SalesOrderItemObjectState);
            Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Completed, item2.CurrentObjectState);
            Assert.IsFalse(item2.ExistCurrentPaymentStatus);
            Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Shipped, item2.CurrentShipmentStatus.SalesOrderItemObjectState);
            Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Completed, item3.CurrentObjectState);
            Assert.IsFalse(item3.ExistCurrentPaymentStatus);
            Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Shipped, item3.CurrentShipmentStatus.SalesOrderItemObjectState);
        }
Exemple #25
0
        public void GivenSalesOrder_WhenDerivingSalesReps_ThenSalesRepsAreCollectedFromSalesOrderItems()
        {
            var salesrep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for child product category").Build();
            var salesrep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for parent category").Build();
            var salesrep3 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for everything else").Build();
            var parentProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("parent").Build();
            var childProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("child").WithParent(parentProductCategory).Build();

            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();

            var customer = new OrganisationBuilder(this.DatabaseSession).WithName("company").Build();
            var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation;

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithSalesRepresentative(salesrep1)
                .WithCustomer(customer)
                .WithProductCategory(childProductCategory)
                .Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithSalesRepresentative(salesrep2)
                .WithCustomer(customer)
                .WithProductCategory(parentProductCategory)
                .Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithSalesRepresentative(salesrep3)
                .WithCustomer(customer)
                .Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build())
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithProductCategory(childProductCategory)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build())
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithProductCategory(parentProductCategory)
                .Build();

            var good3 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build())
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            this.DatabaseSession.Derive(true);

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build())
                .Build();

            var item1 = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good1)
                .WithQuantityOrdered(3)
                .WithActualUnitPrice(5)
                .Build();

            order.AddSalesOrderItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(1, order.SalesReps.Count);
            Assert.Contains(salesrep1, order.SalesReps);

            var item2 = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good2)
                .WithQuantityOrdered(3)
                .WithActualUnitPrice(5)
                .Build();

            order.AddSalesOrderItem(item2);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(2, order.SalesReps.Count);
            Assert.Contains(salesrep1, order.SalesReps);
            Assert.Contains(salesrep2, order.SalesReps);

            var item3 = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good3)
                .WithQuantityOrdered(3)
                .WithActualUnitPrice(5)
                .Build();

            order.AddSalesOrderItem(item3);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(3, order.SalesReps.Count);
            Assert.Contains(salesrep1, order.SalesReps);
            Assert.Contains(salesrep2, order.SalesReps);
            Assert.Contains(salesrep3, order.SalesReps);
        }
Exemple #26
0
        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);
        }
Exemple #27
0
        public void GivenSalesOrder_WhenOrderItemIsWithoutBasePrice_ThenItemIsInvalid()
        {
            var billToCustomer = new PersonBuilder(this.DatabaseSession).WithLastName("person1").Build();
            var shipToCustomer = new PersonBuilder(this.DatabaseSession).WithLastName("person2").Build();
            var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation;

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(billToCustomer).WithInternalOrganisation(internalOrganisation).Build();
            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(shipToCustomer).WithInternalOrganisation(internalOrganisation).Build();

            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var part1 = new FinishedGoodBuilder(this.DatabaseSession).WithName("part1").Build();
            var part2 = new FinishedGoodBuilder(this.DatabaseSession).WithName("part2").Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithFinishedGood(part1)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10102")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithFinishedGood(part2)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            this.DatabaseSession.Derive(true);

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(billToCustomer)
                .WithShipToCustomer(shipToCustomer)
                .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build())
                .Build();

            var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(3).WithActualUnitPrice(15).Build();
            var item4 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(4).WithActualUnitPrice(15).Build();
            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);
            order.AddSalesOrderItem(item4);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            item4.RemoveActualUnitPrice();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(0, item4.UnitBasePrice);
            Assert.AreEqual(3, order.ValidOrderItems.Count);
            Assert.Contains(item1, order.ValidOrderItems);
            Assert.Contains(item2, order.ValidOrderItems);
            Assert.Contains(item3, order.ValidOrderItems);
        }
Exemple #28
0
        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);
        }
Exemple #29
0
        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);
        }
Exemple #30
0
        public void GivenPickList_WhenPicked_ThenInventoryIsAdjustedAndOrderItemsQuantityPickedIsSet()
        {
            var store = this.Session.Extent <Store>().First;

            store.IsImmediatelyPicked = false;

            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen  = new PartyContactMechanismBuilder(this.Session)
                                  .WithContactMechanism(mechelenAddress)
                                  .WithContactPurpose(new ContactMechanismPurposes(this.Session).ShippingAddress)
                                  .WithUseAsDefault(true)
                                  .Build();

            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();
            var customer = new PersonBuilder(this.Session).WithLastName("person1").WithPartyContactMechanism(shipToMechelen).Build();

            new CustomerRelationshipBuilder(this.Session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).Build();

            new SupplierRelationshipBuilder(this.Session)
            .WithSupplier(supplier)
            .WithFromDate(DateTime.UtcNow)
            .Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");
            var good2 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good2");

            new SupplierOfferingBuilder(this.Session)
            .WithPart(good1.Part)
            .WithSupplier(supplier)
            .WithFromDate(DateTime.UtcNow)
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .WithCurrency(new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR"))
            .WithPrice(7)
            .Build();

            this.Session.Derive();

            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good1.Part).Build();
            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good2.Part).Build();

            this.Session.Derive();

            var good1Inventory = (NonSerialisedInventoryItem)good1.Part.InventoryItemsWherePart.First;
            var good2Inventory = (NonSerialisedInventoryItem)good2.Part.InventoryItemsWherePart.First;

            var colorWhite = new ColourBuilder(this.Session)
                             .WithName("white")
                             .Build();
            var extraLarge = new SizeBuilder(this.Session)
                             .WithName("Extra large")
                             .Build();

            var order = new SalesOrderBuilder(this.Session)
                        .WithBillToCustomer(customer)
                        .WithShipToCustomer(customer)
                        .WithVatRegime(new VatRegimes(this.Session).Export)
                        .Build();

            var item1 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.Session).WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductFeatureItem).WithProductFeature(colorWhite).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.Session).WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductFeatureItem).WithProductFeature(extraLarge).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();

            item1.AddOrderedWithFeature(item2);
            item1.AddOrderedWithFeature(item3);
            var item4 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item5 = new SalesOrderItemBuilder(this.Session).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).Build();

            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);
            order.AddSalesOrderItem(item4);
            order.AddSalesOrderItem(item5);

            this.Session.Derive();

            order.Confirm();

            this.Session.Derive();

            var shipment = (CustomerShipment)mechelenAddress.ShipmentsWhereShipToAddress[0];

            var pickList = good1.Part.InventoryItemsWherePart[0].PickListItemsWhereInventoryItem[0].PickListWherePickListItem;

            pickList.Picker = new People(this.Session).FindBy(M.Person.LastName, "orderProcessor");

            //// item5: only 4 out of 5 are actually picked
            foreach (PickListItem pickListItem in pickList.PickListItems)
            {
                if (pickListItem.RequestedQuantity == 5)
                {
                    pickListItem.ActualQuantity = 4;
                }
            }

            pickList.SetPicked();

            this.Session.Derive();

            //// all orderitems have same physical finished good, so there is only one picklist item.
            Assert.Equal(1, item1.QuantityPicked);
            Assert.Equal(0, item1.QuantityReserved);
            Assert.Equal(0, item1.QuantityRequestsShipping);
            Assert.Equal(2, item4.QuantityPicked);
            Assert.Equal(0, item4.QuantityReserved);
            Assert.Equal(0, item4.QuantityRequestsShipping);
            Assert.Equal(4, item5.QuantityPicked);
            Assert.Equal(1, item5.QuantityReserved);
            Assert.Equal(0, item5.QuantityRequestsShipping);
            Assert.Equal(97, good1Inventory.QuantityOnHand);
            Assert.Equal(0, good1Inventory.QuantityCommittedOut);
            Assert.Equal(96, good2Inventory.QuantityOnHand);
            Assert.Equal(1, good2Inventory.QuantityCommittedOut);
        }
Exemple #31
0
        public SalesOrderItemInventoryAssignmentTests()
        {
            this.reasons = new InventoryTransactionReasons(this.Session);

            var customer             = new PersonBuilder(this.Session).WithFirstName("Koen").Build();
            var internalOrganisation = this.InternalOrganisation;

            new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build();

            var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build();

            this.part = new NonUnifiedPartBuilder(this.Session)
                        .WithProductIdentification(new PartNumberBuilder(this.Session)
                                                   .WithIdentification("1")
                                                   .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build())
                        .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised)
                        .Build();

            var good = new NonUnifiedGoodBuilder(this.Session)
                       .WithProductIdentification(new ProductNumberBuilder(this.Session)
                                                  .WithIdentification("10101")
                                                  .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Good).Build())
                       .WithName("good")
                       .WithPart(this.part)
                       .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
                       .WithVatRegime(new VatRegimes(this.Session).BelgiumStandard)
                       .Build();

            this.Session.Derive();

            new InventoryItemTransactionBuilder(this.Session)
            .WithPart(this.part)
            .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment)
            .WithQuantity(11)
            .Build();

            this.Session.Derive();

            var salesOrder = new SalesOrderBuilder(this.Session)
                             .WithTakenBy(this.InternalOrganisation)
                             .WithShipToCustomer(customer)
                             .WithAssignedShipToAddress(new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build())
                             .WithAssignedBillToContactMechanism(new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build())
                             .Build();

            this.salesOrderItem = new SalesOrderItemBuilder(this.Session)
                                  .WithProduct(good)
                                  .WithQuantityOrdered(3)
                                  .WithAssignedUnitPrice(5)
                                  .Build();

            salesOrder.AddSalesOrderItem(this.salesOrderItem);

            this.Session.Derive();

            salesOrder.SetReadyForPosting();
            this.Session.Derive();

            salesOrder.Post();
            this.Session.Derive();

            salesOrder.Accept();
            this.Session.Derive();

            this.Session.Commit();
        }
Exemple #32
0
        public void GivenSalesOrder_WhenShipmentIsCreated_ThenOrderItemsAreAddedToPickList()
        {
            var store = this.Session.Extent <Store>().First;

            store.IsImmediatelyPicked = false;

            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen  = new PartyContactMechanismBuilder(this.Session)
                                  .WithContactMechanism(mechelenAddress)
                                  .WithContactPurpose(new ContactMechanismPurposes(this.Session).ShippingAddress)
                                  .WithUseAsDefault(true)
                                  .Build();

            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

            var customer = new PersonBuilder(this.Session).WithLastName("person1").WithPartyContactMechanism(shipToMechelen).Build();

            new CustomerRelationshipBuilder(this.Session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).Build();

            new SupplierRelationshipBuilder(this.Session)
            .WithSupplier(supplier)
            .WithFromDate(DateTime.UtcNow)
            .Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");
            var good2 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good2");

            new SupplierOfferingBuilder(this.Session)
            .WithPart(good1.Part)
            .WithSupplier(supplier)
            .WithFromDate(DateTime.UtcNow)
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .WithCurrency(new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR"))
            .WithPrice(7)
            .Build();

            new SupplierOfferingBuilder(this.Session)
            .WithPart(good2.Part)
            .WithSupplier(supplier)
            .WithFromDate(DateTime.UtcNow)
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .WithCurrency(new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR"))
            .WithPrice(7)
            .Build();

            this.Session.Derive();

            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).PhysicalCount).WithPart(good1.Part).Build();
            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).PhysicalCount).WithPart(good2.Part).Build();

            this.Session.Derive();

            var good1Inventory = good1.Part.InventoryItemsWherePart.First;
            var good2Inventory = good2.Part.InventoryItemsWherePart.First;

            var order = new SalesOrderBuilder(this.Session)
                        .WithBillToCustomer(customer)
                        .WithShipToCustomer(customer)
                        .Build();

            var item1 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.Session).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).Build();

            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);

            this.Session.Derive();

            order.Confirm();

            this.Session.Derive();

            var pickList = good1.Part.InventoryItemsWherePart[0].PickListItemsWhereInventoryItem[0].PickListWherePickListItem;

            Assert.Equal(2, pickList.PickListItems.Count);

            var extent1 = pickList.PickListItems;

            extent1.Filter.AddEquals(M.PickListItem.InventoryItem, good1Inventory);
            Assert.Equal(3, extent1.First.RequestedQuantity);

            var extent2 = pickList.PickListItems;

            extent2.Filter.AddEquals(M.PickListItem.InventoryItem, good2Inventory);
            Assert.Equal(5, extent2.First.RequestedQuantity);
        }
Exemple #33
0
        public void GivenPickList_WhenActualQuantityPickedIsLess_ThenShipmentItemQuantityIsAdjusted()
        {
            var store = this.Session.Extent <Store>().First;

            store.IsImmediatelyPicked = false;

            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen  = new PartyContactMechanismBuilder(this.Session)
                                  .WithContactMechanism(mechelenAddress)
                                  .WithContactPurpose(new ContactMechanismPurposes(this.Session).ShippingAddress)
                                  .WithUseAsDefault(true)
                                  .Build();

            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();
            var customer = new PersonBuilder(this.Session).WithLastName("person1").WithPartyContactMechanism(shipToMechelen).Build();

            new CustomerRelationshipBuilder(this.Session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).Build();

            new SupplierRelationshipBuilder(this.Session)
            .WithSupplier(supplier)
            .WithFromDate(DateTime.UtcNow)
            .Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");
            var good2 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good2");

            new SupplierOfferingBuilder(this.Session)
            .WithPart(good1.Part)
            .WithSupplier(supplier)
            .WithFromDate(DateTime.UtcNow)
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .WithPrice(7)
            .WithCurrency(new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR"))
            .Build();

            new SupplierOfferingBuilder(this.Session)
            .WithPart(good2.Part)
            .WithSupplier(supplier)
            .WithFromDate(DateTime.UtcNow)
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .WithPrice(7)
            .WithCurrency(new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR"))
            .Build();

            this.Session.Derive();

            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good1.Part).Build();
            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good2.Part).Build();

            this.Session.Derive();

            var order = new SalesOrderBuilder(this.Session)
                        .WithBillToCustomer(customer)
                        .WithShipToCustomer(customer)
                        .Build();

            var item1 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.Session).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).Build();

            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);

            this.Session.Derive();

            order.Confirm();

            this.Session.Derive();

            var pickList = good1.Part.InventoryItemsWherePart[0].PickListItemsWhereInventoryItem[0].PickListWherePickListItem;

            pickList.Picker = new People(this.Session).FindBy(M.Person.LastName, "orderProcessor");

            //// item3: only 4 out of 5 are actually picked
            PickListItem adjustedPicklistItem = null;

            foreach (PickListItem pickListItem in pickList.PickListItems)
            {
                if (pickListItem.RequestedQuantity == 5)
                {
                    adjustedPicklistItem = pickListItem;
                }
            }

            var itemIssuance = adjustedPicklistItem.ItemIssuancesWherePickListItem[0];
            var shipmentItem = adjustedPicklistItem.ItemIssuancesWherePickListItem[0].ShipmentItem;

            Assert.Equal(5, itemIssuance.Quantity);
            Assert.Equal(5, shipmentItem.Quantity);

            adjustedPicklistItem.ActualQuantity = 4;

            pickList.SetPicked();

            this.Session.Derive();

            Assert.Equal(4, itemIssuance.Quantity);
            Assert.Equal(4, shipmentItem.Quantity);
        }
Exemple #34
0
        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);
        }
Exemple #35
0
        public void GivenMultipleOrders_WhenCombinedPickListIsPicked_ThenSingleShipmentIsPickedState()
        {
            var store = this.Session.Extent <Store>().First;

            store.IsImmediatelyPicked = false;

            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf").Build();
            var shipToMechelen  = new PartyContactMechanismBuilder(this.Session)
                                  .WithContactMechanism(mechelenAddress)
                                  .WithContactPurpose(new ContactMechanismPurposes(this.Session).ShippingAddress)
                                  .WithUseAsDefault(true)
                                  .Build();

            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();
            var customer = new PersonBuilder(this.Session).WithLastName("person1").WithPartyContactMechanism(shipToMechelen).Build();

            new CustomerRelationshipBuilder(this.Session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).Build();

            new SupplierRelationshipBuilder(this.Session)
            .WithSupplier(supplier)
            .WithFromDate(DateTime.UtcNow)
            .Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");
            var good2 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good2");

            new SupplierOfferingBuilder(this.Session)
            .WithPart(good1.Part)
            .WithFromDate(DateTime.UtcNow)
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .WithCurrency(new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR"))
            .WithPrice(7)
            .WithSupplier(supplier)
            .Build();

            new SupplierOfferingBuilder(this.Session)
            .WithPart(good2.Part)
            .WithFromDate(DateTime.UtcNow)
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .WithCurrency(new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR"))
            .WithPrice(7)
            .WithSupplier(supplier)
            .Build();

            this.Session.Derive();

            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).PhysicalCount).WithPart(good1.Part).Build();
            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).PhysicalCount).WithPart(good2.Part).Build();

            this.Session.Derive();

            var order1 = new SalesOrderBuilder(this.Session)
                         .WithBillToCustomer(customer)
                         .WithShipToCustomer(customer)
                         .Build();

            var item1 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.Session).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).Build();

            order1.AddSalesOrderItem(item1);
            order1.AddSalesOrderItem(item2);
            order1.AddSalesOrderItem(item3);

            this.Session.Derive();

            order1.Confirm();

            this.Session.Derive();

            var order2 = new SalesOrderBuilder(this.Session)
                         .WithBillToCustomer(customer)
                         .WithShipToCustomer(customer)
                         .Build();

            var itema = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var itemb = new SalesOrderItemBuilder(this.Session).WithProduct(good2).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();

            order2.AddSalesOrderItem(itema);
            order2.AddSalesOrderItem(itemb);

            this.Session.Derive();

            order2.Confirm();

            this.Session.Derive();

            var pickList = good1.Part.InventoryItemsWherePart[0].PickListItemsWhereInventoryItem[0].PickListWherePickListItem;

            pickList.Picker = new People(this.Session).FindBy(M.Person.LastName, "orderProcessor");

            pickList.SetPicked();

            this.Session.Derive();

            Assert.Single(customer.ShipmentsWhereBillToParty);

            var customerShipment = (CustomerShipment)customer.ShipmentsWhereBillToParty.First;

            Assert.Equal(new CustomerShipmentStates(this.Session).Picked, customerShipment.CustomerShipmentState);
        }
Exemple #36
0
        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);
        }
Exemple #37
0
        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);
        }
Exemple #38
0
        public void GivenSalesOrderWithMultipleRecipients_WhenConfirmed_ThenShipmentIsCreatedForEachRecipientAndPickListIsCreated()
        {
            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 baal = new CityBuilder(this.DatabaseSession).WithName("Baal").Build();
            var baalAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(baal).WithAddress1("Haverwerf 15").Build();
            var shipToBaal = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(baalAddress)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress)
                .WithUseAsDefault(true)
                .Build();

            var person1 = new PersonBuilder(this.DatabaseSession).WithLastName("person1").WithPartyContactMechanism(shipToMechelen).Build();
            var person2 = new PersonBuilder(this.DatabaseSession).WithLastName("person2").WithPartyContactMechanism(shipToBaal).Build();
            var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation;

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(person1).WithInternalOrganisation(internalOrganisation).Build();
            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(person2).WithInternalOrganisation(internalOrganisation).Build();

            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var part = new FinishedGoodBuilder(this.DatabaseSession)
                .WithName("part1")
                .WithOwnedByParty(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"))
                .Build();

            this.DatabaseSession.Derive(true);

            var partInventory = (NonSerializedInventoryItem)part.InventoryItemsWherePart[0];
            partInventory.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithFinishedGood(part)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10102")
                .WithVatRate(vatRate21)
                .WithName("good2")
                .WithFinishedGood(part)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var colorBlack = new ColourBuilder(this.DatabaseSession)
                .WithName("white")
                .WithLocalisedName(new LocalisedTextBuilder(this.DatabaseSession)
                                            .WithText("White")
                                            .WithLocale(Singleton.Instance(this.DatabaseSession).DefaultLocale)
                                            .Build())
                .Build();

            var extraLarge = new SizeBuilder(this.DatabaseSession)
                .WithName("Extra large")
                .WithLocalisedName(new LocalisedTextBuilder(this.DatabaseSession)
                                            .WithText("White")
                                            .WithLocale(Singleton.Instance(this.DatabaseSession).DefaultLocale)
                                            .Build())
                .Build();

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(person1)
                .WithShipToCustomer(person1)
                .WithShipToAddress(mechelenAddress)
                .WithVatRegime(new VatRegimes(this.DatabaseSession).Export)
                .Build();

            var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithProductFeature(colorBlack).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithProductFeature(extraLarge).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            item1.AddOrderedWithFeature(item2);
            item1.AddOrderedWithFeature(item3);
            var item4 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item5 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).WithAssignedShipToParty(person2).Build();
            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);
            order.AddSalesOrderItem(item4);
            order.AddSalesOrderItem(item5);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            var shipmentToMechelen = mechelenAddress.ShipmentsWhereShipToAddress[0];

            var shipmentToBaal = baalAddress.ShipmentsWhereShipToAddress[0];

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(mechelenAddress, shipmentToMechelen.ShipToAddress);
            Assert.AreEqual(1, shipmentToMechelen.ShipmentItems.Count);
            Assert.AreEqual(3, shipmentToMechelen.ShipmentItems[0].Quantity);

            Assert.AreEqual(baalAddress, shipmentToBaal.ShipToAddress);
            Assert.AreEqual(1, shipmentToBaal.ShipmentItems.Count);
            Assert.AreEqual(good2, shipmentToBaal.ShipmentItems[0].Good);
            Assert.AreEqual(5, shipmentToBaal.ShipmentItems[0].Quantity);
        }
Exemple #39
0
        public void GivenShipmentReceiptWhenDerivingThenInventoryItemQuantityOnHandIsUpdated()
        {
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(mechelenAddress)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress)
                .WithUseAsDefault(true)
                .Build();

            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build();

            var good = new GoodBuilder(this.DatabaseSession)
                .WithName("Good")
                .WithSku("10101")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build())
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build();
            inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(20).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var order1 = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .WithDeliveryDate(DateTime.UtcNow)
                .Build();

            var salesItem = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item1").WithProduct(good).WithQuantityOrdered(30).WithActualUnitPrice(15).Build();
            order1.AddSalesOrderItem(salesItem);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            order1.Confirm();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            var sessionInventoryItem = (NonSerializedInventoryItem)this.DatabaseSession.Instantiate(inventoryItem);
            var sessionSalesItem = (SalesOrderItem)this.DatabaseSession.Instantiate(salesItem);

            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            Assert.AreEqual(20, sessionSalesItem.QuantityPendingShipment);
            Assert.AreEqual(30, sessionSalesItem.QuantityReserved);
            Assert.AreEqual(10, sessionSalesItem.QuantityShortFalled);

            var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build();

            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(10).Build();
            order.AddPurchaseOrderItem(item1);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            order.Confirm();

            var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build();
            var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build();
            shipment.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(10)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item1)
                .Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            shipment.AppsComplete();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            Assert.AreEqual(30, sessionInventoryItem.QuantityOnHand);

            Assert.AreEqual(30, sessionSalesItem.QuantityPendingShipment);
            Assert.AreEqual(30, sessionSalesItem.QuantityReserved);
            Assert.AreEqual(0, sessionSalesItem.QuantityShortFalled);
        }
Exemple #40
0
        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);
        }
Exemple #41
0
        public void GivenManuallyScheduledOrderItem_WhenScheduled_ThenQuantityCannotExceedInventoryAvailableToPromise()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var inventoryItem = (NonSerializedInventoryItem)this.part.InventoryItemsWherePart.First;
            inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(3).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var manual = new OrderKindBuilder(this.DatabaseSession).WithDescription("manual").WithScheduleManually(true).Build();

            var order1 = new SalesOrderBuilder(this.DatabaseSession)
                .WithShipToCustomer(this.shipToCustomer)
                .WithBillToCustomer(this.billToCustomer)
                .WithShipToAddress(this.shipToContactMechanismMechelen)
                .WithTakenByInternalOrganisation(this.internalOrganisation)
                .WithOrderKind(manual)
                .Build();

            var item1 = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProduct(this.good)
                .WithQuantityOrdered(5)
                .WithActualUnitPrice(5)
                .Build();

            order1.AddSalesOrderItem(item1);
            this.DatabaseSession.Derive(true);

            order1.Confirm();
            this.DatabaseSession.Derive(true);

            item1.QuantityShipNow = 5;
            var derivationLog = this.DatabaseSession.Derive();

            Assert.IsTrue(derivationLog.HasErrors);
            Assert.Contains(SalesOrderItems.Meta.QuantityShipNow, derivationLog.Errors[0].RoleTypes);

            item1.QuantityShipNow = 3;
            derivationLog = this.DatabaseSession.Derive();

            Assert.IsFalse(derivationLog.HasErrors);
            Assert.AreEqual(3, item1.QuantityPendingShipment);
        }
Exemple #42
0
        public void GivenSalesOrderWithShippingAndHandlingPercentage_WhenDeriving_ThenOrderTotalsMustIncludeShippingAndHandlingAmount()
        {
            var billToCustomer = new PersonBuilder(this.DatabaseSession).WithLastName("person1").Build();
            var shipToCustomer = new PersonBuilder(this.DatabaseSession).WithLastName("person2").Build();
            var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation;

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(billToCustomer).WithInternalOrganisation(internalOrganisation).Build();
            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(shipToCustomer).WithInternalOrganisation(internalOrganisation).Build();

            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR");
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var adjustment = new ShippingAndHandlingChargeBuilder(this.DatabaseSession).WithPercentage(5).WithVatRate(vatRate21).Build();

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var goodPurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(euro)
                .WithFromDate(DateTime.UtcNow)
                .WithPrice(7)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            new SupplierOfferingBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .WithProductPurchasePrice(goodPurchasePrice)
                .Build();

            this.DatabaseSession.Derive(true);

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(billToCustomer)
                .WithShipToCustomer(shipToCustomer)
                .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build())
                .WithShippingAndHandlingCharge(adjustment)
                .Build();

            const decimal quantityOrdered = 3;
            var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(quantityOrdered).WithActualUnitPrice(15).Build();
            order.AddSalesOrderItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(45, order.TotalBasePrice);
            Assert.AreEqual(0, order.TotalDiscount);
            Assert.AreEqual(0, order.TotalSurcharge);
            Assert.AreEqual(2.25, order.TotalShippingAndHandling);
            Assert.AreEqual(0, order.TotalFee);
            Assert.AreEqual(47.25, order.TotalExVat);
            Assert.AreEqual(9.92, order.TotalVat);
            Assert.AreEqual(57.17, order.TotalIncVat);
            Assert.AreEqual(goodPurchasePrice.Price, order.TotalPurchasePrice);
        }
Exemple #43
0
        public void GivenOrderItemWithoutCustomer_WhenDeriving_ShipToAddressIsNull()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var salesOrder = new SalesOrderBuilder(this.DatabaseSession).Build();

            var orderItem = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(this.good).WithQuantityOrdered(1).Build();
            salesOrder.AddSalesOrderItem(orderItem);

            this.DatabaseSession.Derive(true);

            Assert.IsNull(orderItem.ShipToAddress);
            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Exemple #44
0
        public void GivenSalesOrder_WhenConfirmed_ThenShipmentItemsAreCreated()
        {
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10102")
                .WithVatRate(vatRate21)
                .WithName("good2")
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .Build();

            var good1InventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good1).Build();
            good1InventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var good2InventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good2).Build();
            good2InventoryItem.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).WithFirstName("Koen").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)
                .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build())
                .Build();

            var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).Build();
            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            var shipment = customer.ShipmentsWhereBillToParty.First;

            Assert.AreEqual(2, shipment.ShipmentItems.Count);
            Assert.AreEqual(1, item1.OrderShipmentsWhereSalesOrderItem[0].Quantity);
            Assert.AreEqual(2, item2.OrderShipmentsWhereSalesOrderItem[0].Quantity);
            Assert.AreEqual(5, item3.OrderShipmentsWhereSalesOrderItem[0].Quantity);
        }
Exemple #45
0
        public void GivenOrderItemWithoutVatRegime_WhenDeriving_ThenDerivedVatRegimeIsFromOrder()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var salesOrder = new SalesOrderBuilder(this.DatabaseSession)
                .WithTakenByInternalOrganisation(this.internalOrganisation)
                .WithShipToCustomer(this.shipToCustomer)
                .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);
        }
Exemple #46
0
        public void GivenPickList_WhenActualQuantityPickedIsLess_ThenShipmentItemQuantityIsAdjusted()
        {
            var store = this.Session.Extent <Store>().First;

            store.IsImmediatelyPicked = false;

            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen)
                                  .WithAddress1("Haverwerf 15").Build();
            var shipToMechelen = new PartyContactMechanismBuilder(this.Session)
                                 .WithContactMechanism(mechelenAddress)
                                 .WithContactPurpose(new ContactMechanismPurposes(this.Session).ShippingAddress)
                                 .WithUseAsDefault(true)
                                 .Build();

            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();
            var customer = new PersonBuilder(this.Session).WithLastName("person1")
                           .WithPartyContactMechanism(shipToMechelen).Build();

            new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer)
            .Build();

            new SupplierRelationshipBuilder(this.Session)
            .WithSupplier(supplier)
            .WithFromDate(this.Session.Now())
            .Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");
            var good2 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good2");

            new SupplierOfferingBuilder(this.Session)
            .WithPart(good1.Part)
            .WithSupplier(supplier)
            .WithFromDate(this.Session.Now())
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .WithPrice(7)
            .WithCurrency(new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR"))
            .Build();

            new SupplierOfferingBuilder(this.Session)
            .WithPart(good2.Part)
            .WithSupplier(supplier)
            .WithFromDate(this.Session.Now())
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .WithPrice(7)
            .WithCurrency(new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR"))
            .Build();

            this.Session.Derive();

            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100)
            .WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good1.Part).Build();
            new InventoryItemTransactionBuilder(this.Session).WithQuantity(100)
            .WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good2.Part).Build();

            this.Session.Derive();

            var order = new SalesOrderBuilder(this.Session)
                        .WithBillToCustomer(customer)
                        .WithShipToCustomer(customer)
                        .Build();

            var item1 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(1).WithAssignedUnitPrice(15).Build();
            var item2 = new SalesOrderItemBuilder(this.Session).WithProduct(good1).WithQuantityOrdered(2).WithAssignedUnitPrice(15).Build();
            var item3 = new SalesOrderItemBuilder(this.Session).WithProduct(good2).WithQuantityOrdered(5).WithAssignedUnitPrice(15).Build();

            order.AddSalesOrderItem(item1);
            order.AddSalesOrderItem(item2);
            order.AddSalesOrderItem(item3);

            this.Session.Derive();

            order.SetReadyForPosting();
            this.Session.Derive();

            order.Post();
            this.Session.Derive();

            order.Accept();
            this.Session.Derive();

            var shipment = (CustomerShipment)mechelenAddress.ShipmentsWhereShipToAddress[0];

            shipment.Pick();
            this.Session.Derive();

            var pickList = good1.Part.InventoryItemsWherePart[0].PickListItemsWhereInventoryItem[0].PickListWherePickListItem;

            pickList.Picker = this.OrderProcessor;

            //// item3: only 4 out of 5 are actually picked
            PickListItem adjustedPicklistItem = null;

            foreach (PickListItem pickListItem in pickList.PickListItems)
            {
                if (pickListItem.Quantity == 5)
                {
                    adjustedPicklistItem = pickListItem;
                }
            }

            var itemIssuance = adjustedPicklistItem.ItemIssuancesWherePickListItem[0];
            var shipmentItem = adjustedPicklistItem.ItemIssuancesWherePickListItem[0].ShipmentItem;

            Assert.Equal(2, shipment.ShipmentItems.Count);
            Assert.Equal(5, itemIssuance.Quantity);
            Assert.Equal(5, shipmentItem.Quantity);
            Assert.Equal(5, item3.QuantityPendingShipment);

            adjustedPicklistItem.QuantityPicked = 4;

            pickList.SetPicked();
            this.Session.Derive();

            // When SalesOrder is derived 1 quantity is requested for shipping (because inventory is available and quantity ordered (5) is greater then quantity pending shipment (4)
            // A new shipment item is created with quantity 1 and QuantityPendingShipment remains 5
            Assert.Equal(4, itemIssuance.Quantity);
            Assert.Equal(4, shipmentItem.Quantity);
            Assert.Equal(3, shipment.ShipmentItems.Count);
            Assert.Equal(1, shipment.ShipmentItems.Last().Quantity);
            Assert.Equal(5, item3.QuantityPendingShipment);
        }