public static CustomerShipmentBuilder WithDefaults(this CustomerShipmentBuilder @this, Organisation internalOrganisation)
        {
            var faker = @this.Session.Faker();

            var customer     = faker.Random.ListItem(internalOrganisation.ActiveCustomers);
            var shipmentItem = new ShipmentItemBuilder(@this.Session).WithSerializedUnifiedGoodDefaults(internalOrganisation).Build();

            @this.WithShipFromParty(internalOrganisation);
            @this.WithShipFromContactPerson(internalOrganisation.CurrentContacts.FirstOrDefault());
            @this.WithShipToParty(customer);
            @this.WithShipToContactPerson(customer.CurrentContacts.FirstOrDefault());
            @this.WithShipmentMethod(faker.Random.ListItem(@this.Session.Extent <ShipmentMethod>()));
            @this.WithCarrier(faker.Random.ListItem(@this.Session.Extent <Carrier>()));
            @this.WithEstimatedReadyDate(@this.Session.Now());
            @this.WithEstimatedShipDate(faker.Date.Between(start: @this.Session.Now(), end: @this.Session.Now().AddDays(5)));
            @this.WithLatestCancelDate(faker.Date.Between(start: @this.Session.Now(), end: @this.Session.Now().AddDays(2)));
            @this.WithEstimatedArrivalDate(faker.Date.Between(start: @this.Session.Now().AddDays(6), end: @this.Session.Now().AddDays(10)));

            @this.WithElectronicDocument(new MediaBuilder(@this.Session).WithInFileName("doc1.en.pdf").WithInData(faker.Random.Bytes(1000)).Build());
            @this.WithEstimatedShipCost(faker.Finance.Amount(100, 1000, 2));
            @this.WithHandlingInstruction(faker.Lorem.Paragraph());
            @this.WithComment(faker.Lorem.Sentence());
            @this.WithShipmentItem(shipmentItem);

            foreach (Locale additionalLocale in @this.Session.GetSingleton().AdditionalLocales)
            {
                @this.WithLocalisedComment(new LocalisedTextBuilder(@this.Session).WithText(faker.Lorem.Sentence()).WithLocale(additionalLocale).Build());
            }

            return(@this);
        }
Example #2
0
        public void CreateFull()
        {
            var before = new CustomerShipments(this.Session).Extent().ToArray();

            var expected = new CustomerShipmentBuilder(this.Session).WithDefaults(this.internalOrganisation).Build();

            this.Session.Derive();

            var expectedShipToPartyPartyName         = expected.ShipToParty?.DisplayName();
            var expectedShipToAddressDisplayName     = expected.ShipToAddress?.DisplayName();
            var expectedShipToContactPersonPartyName = expected.ShipToContactPerson?.DisplayName();
            var expectedShipFromAddressDisplayName   = expected.ShipFromAddress?.DisplayName();
            var expectedShipFromFacilityName         = expected.ShipFromFacility.Name;
            var expectedShipmentMethodName           = expected.ShipmentMethod.Name;
            var expectedCarrierName          = expected.Carrier.Name;
            var expectedEstimatedShipDate    = expected.EstimatedShipDate.Value.Date;
            var expectedEstimatedArrivalDate = expected.EstimatedArrivalDate.Value.Date;
            var expectedHandlingInstruction  = expected.HandlingInstruction;
            var expectedComment = expected.Comment;

            var customerShipmentCreate = this.shipmentListPage
                                         .CreateCustomerShipment()
                                         .Build(expected);

            customerShipmentCreate.AssertFull(expected);

            this.Session.Rollback();
            customerShipmentCreate.SAVE.Click();

            this.Driver.WaitForAngular();
            this.Session.Rollback();

            var after = new CustomerShipments(this.Session).Extent().ToArray();

            Assert.Equal(after.Length, before.Length + 1);

            var actual = after.Except(before).First();

            Assert.Equal(expectedShipToPartyPartyName, actual.ShipToParty?.DisplayName());
            Assert.Equal(expectedShipToAddressDisplayName, actual.ShipToAddress?.DisplayName());
            Assert.Equal(expectedShipToContactPersonPartyName, actual.ShipToContactPerson?.DisplayName());
            Assert.Equal(expectedShipFromAddressDisplayName, actual.ShipFromAddress?.DisplayName());
            Assert.Equal(expectedShipFromFacilityName, actual.ShipFromFacility.Name);
            Assert.Equal(expectedShipmentMethodName, actual.ShipmentMethod.Name);
            Assert.Equal(expectedCarrierName, actual.Carrier.Name);
            Assert.Equal(expectedEstimatedShipDate, actual.EstimatedShipDate);
            Assert.Equal(expectedEstimatedArrivalDate, actual.EstimatedArrivalDate);
            Assert.Equal(expectedHandlingInstruction, actual.HandlingInstruction);
            Assert.Equal(expectedComment, actual.Comment);
        }
Example #3
0
        public void CreateMinimal()
        {
            var before = new CustomerShipments(this.Session).Extent().ToArray();

            var expected = new CustomerShipmentBuilder(this.Session).WithDefaults(this.internalOrganisation).Build();

            this.Session.Derive();

            var expectedShipToPartyPartyName       = expected.ShipToParty?.DisplayName();
            var expectedShipToAddressDisplayName   = expected.ShipToAddress?.DisplayName();
            var expectedShipFromAddressDisplayName = expected.ShipFromAddress?.DisplayName();
            var expectedShipFromFacilityName       = expected.ShipFromFacility.Name;

            var customerShipmentCreate = this.shipmentListPage
                                         .CreateCustomerShipment()
                                         .Build(expected, true);

            customerShipmentCreate.AssertFull(expected);

            this.Session.Rollback();
            customerShipmentCreate.SAVE.Click();

            this.Driver.WaitForAngular();
            this.Session.Rollback();

            var after = new CustomerShipments(this.Session).Extent().ToArray();

            Assert.Equal(after.Length, before.Length + 1);

            var actual = after.Except(before).First();

            Assert.Equal(expectedShipToPartyPartyName, actual.ShipToParty?.DisplayName());
            Assert.Equal(expectedShipToAddressDisplayName, actual.ShipToAddress?.DisplayName());
            Assert.Equal(expectedShipFromAddressDisplayName, actual.ShipFromAddress?.DisplayName());
            Assert.Equal(expectedShipFromFacilityName, actual.ShipFromFacility.Name);
        }
Example #4
0
        public void GivenCustomerShipmentCreatedByOrderProcessor_WhenCurrentUserInSameOrderProcessorUserGroup_ThenAccessIsGranted()
        {
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var orderProcessor2 = new PersonBuilder(this.DatabaseSession).WithLastName("orderProcessor2").WithUserName("orderProcessor2").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var shipToAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();

            var usergroups = internalOrganisation.UserGroupsWhereParty;
            var orderProcessorUserGroup = usergroups.First;

            new EmploymentBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithEmployee(orderProcessor2)
                .WithEmployer(internalOrganisation)
                .Build();

            orderProcessorUserGroup.AddMember(orderProcessor2);

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

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("orderProcessor", "Forms"), new string[0]);

            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build();
            var shipment = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithShipToParty(customer)
                .WithShipToAddress(shipToAddress)
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Boat)
                .Build();

            this.DatabaseSession.Derive(true);

            var acl = new AccessControlList(shipment, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsTrue(acl.CanWrite(CustomerShipments.Meta.ShipToParty));
            Assert.IsTrue(acl.CanRead(CustomerShipments.Meta.ShipToParty));
            Assert.IsTrue(acl.CanExecute(CustomerShipments.Meta.Cancel));

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("orderProcessor2", "Forms"), new string[0]);
            acl = new AccessControlList(shipment, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsTrue(acl.CanWrite(CustomerShipments.Meta.ShipToParty));
            Assert.IsTrue(acl.CanRead(CustomerShipments.Meta.ShipToParty));
            Assert.IsTrue(acl.CanExecute(CustomerShipments.Meta.Cancel));
        }
Example #5
0
        public void GivenCustomerShipmentCreatedByOrderProcessor_WhenCurrentUserInAnotherOrderProcessorUserGroup_ThenAccessIsDenied()
        {
            var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"];
            var euro = belgium.Currency;

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

            var billToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(mechelenAddress)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress)
                .WithUseAsDefault(true)
                .Build();

            var bank = new BankBuilder(this.DatabaseSession).WithCountry(belgium).WithName("ING Belgiƫ").WithBic("BBRUBEBB").Build();

            var ownBankAccount = new OwnBankAccountBuilder(this.DatabaseSession)
                .WithDescription("BE23 3300 6167 6391")
                .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build())
                .Build();

            var orderProcessor2 = new PersonBuilder(this.DatabaseSession).WithLastName("orderProcessor2").WithUserName("orderProcessor2").Build();

            var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession)
                .WithName("employer2")
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator)
                .WithEmployeeRole(new Roles(this.DatabaseSession).Operations)
                .WithPreferredCurrency(euro)
                .WithDefaultPaymentMethod(ownBankAccount)
                .WithPartyContactMechanism(billToMechelen)
                .Build();

            new EmploymentBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithEmployee(orderProcessor2)
                .WithEmployer(internalOrganisation)
                .Build();

            var shipToAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();

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

            var usergroups = internalOrganisation.UserGroupsWhereParty;
            usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(this.DatabaseSession).Operations.UserGroupWhereRole);
            var orderProcessorUserGroup = usergroups.First;

            orderProcessorUserGroup.AddMember(orderProcessor2);

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

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("orderProcessor", "Forms"), new string[0]);

            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build();
            var shipment = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithShipToParty(customer)
                .WithShipToAddress(shipToAddress)
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Boat)
                .Build();

            this.DatabaseSession.Derive(true);

            var acl = new AccessControlList(shipment, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsTrue(acl.CanWrite(CustomerShipments.Meta.ShipToParty));
            Assert.IsTrue(acl.CanRead(CustomerShipments.Meta.ShipToParty));
            Assert.IsTrue(acl.CanExecute(CustomerShipments.Meta.Cancel));

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("orderProcessor2", "Forms"), new string[0]);
            acl = new AccessControlList(shipment, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsFalse(acl.HasReadOperation);
        }
Example #6
0
        public void GivenCustomerShipment_WhenObjectStateIsCreated_ThenCheckTransitions()
        {
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var shipToAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("orderProcessor", "Forms"), new string[0]);

            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build();

            var shipment = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithShipToParty(customer)
                .WithShipToAddress(shipToAddress)
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground)
                .Build();

            this.DatabaseSession.Derive(true);

            var acl = new AccessControlList(shipment, new Users(this.DatabaseSession).GetCurrentUser());
            Assert.IsTrue(acl.CanExecute(CustomerShipments.Meta.Cancel));
        }
Example #7
0
        public void GivenCustomerShipment_WhenGettingShipmentNumberWithoutFormat_ThenShipmentNumberShouldBeReturned()
        {
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();

            var store = new StoreBuilder(this.DatabaseSession).WithName("store")
                .WithDefaultFacility(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"))
                .WithOwner(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"))
                .WithDefaultShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground)
                .WithDefaultCarrier(new Carriers(this.DatabaseSession).Fedex)
                .Build();

            var shipToAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();

            var shipment1 = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithShipToParty(new PersonBuilder(this.DatabaseSession).WithLastName("person1").Build())
                .WithShipToAddress(shipToAddress)
                .WithStore(store)
                .WithShipmentMethod(store.DefaultShipmentMethod)
                .Build();

            Assert.AreEqual("1", shipment1.ShipmentNumber);

            var shipment2 = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithShipToParty(new PersonBuilder(this.DatabaseSession).WithLastName("person1").Build())
                .WithStore(store)
                .WithShipmentMethod(store.DefaultShipmentMethod)
                .Build();

            Assert.AreEqual("2", shipment2.ShipmentNumber);
        }
Example #8
0
        public void BaseShip(SalesOrderShip method)
        {
            if (this.CanShip)
            {
                var addresses = this.ShipToAddresses();
                var shipments = new List <Shipment>();
                if (addresses.Count > 0)
                {
                    foreach (var address in addresses)
                    {
                        var pendingShipment = address.Value.BaseGetPendingCustomerShipmentForStore(address.Key, this.Store, this.ShipmentMethod);

                        if (pendingShipment == null)
                        {
                            pendingShipment = new CustomerShipmentBuilder(this.Strategy.Session)
                                              .WithShipFromParty(this.TakenBy)
                                              .WithShipFromAddress(this.ShipFromAddress)
                                              .WithShipToAddress(address.Key)
                                              .WithShipToParty(address.Value)
                                              .WithStore(this.Store)
                                              .WithShipmentMethod(this.ShipmentMethod)
                                              .WithPaymentMethod(this.PaymentMethod)
                                              .Build();

                            if (this.Store.AutoGenerateShipmentPackage)
                            {
                                pendingShipment.AddShipmentPackage(new ShipmentPackageBuilder(this.Strategy.Session).Build());
                            }
                        }

                        foreach (SalesOrderItem orderItem in this.ValidOrderItems)
                        {
                            var orderItemDerivedRoles = (SalesOrderItemDerivedRoles)orderItem;

                            if (orderItem.ExistProduct && orderItem.ShipToAddress.Equals(address.Key) && orderItem.QuantityRequestsShipping > 0)
                            {
                                var good              = orderItem.Product as Good;
                                var nonUnifiedGood    = orderItem.Product as NonUnifiedGood;
                                var unifiedGood       = orderItem.Product as UnifiedGood;
                                var inventoryItemKind = unifiedGood?.InventoryItemKind ?? nonUnifiedGood?.Part.InventoryItemKind;
                                var part              = unifiedGood ?? nonUnifiedGood?.Part;

                                ShipmentItem shipmentItem = null;
                                foreach (ShipmentItem item in pendingShipment.ShipmentItems)
                                {
                                    if (inventoryItemKind != null &&
                                        inventoryItemKind.Equals(new InventoryItemKinds(this.Session()).NonSerialised) &&
                                        item.Good.Equals(good) &&
                                        !item.ItemIssuancesWhereShipmentItem.Any(v => v.PickListItem.PickListWherePickListItem.PickListState.Equals(new PickListStates(this.Session()).Picked)))
                                    {
                                        shipmentItem = item;
                                        break;
                                    }
                                }

                                if (shipmentItem != null)
                                {
                                    shipmentItem.ContentsDescription = $"{shipmentItem.Quantity} * {good.Name}";
                                }
                                else
                                {
                                    shipmentItem = new ShipmentItemBuilder(this.Strategy.Session)
                                                   .WithGood(good)
                                                   .WithContentsDescription($"{orderItem.QuantityRequestsShipping} * {good}")
                                                   .Build();

                                    if (orderItem.ExistSerialisedItem)
                                    {
                                        shipmentItem.SerialisedItem = orderItem.SerialisedItem;
                                    }

                                    if (orderItem.ExistNextSerialisedItemAvailability)
                                    {
                                        shipmentItem.NextSerialisedItemAvailability = orderItem.NextSerialisedItemAvailability;
                                    }

                                    if (orderItem.ExistReservedFromNonSerialisedInventoryItem)
                                    {
                                        shipmentItem.AddReservedFromInventoryItem(orderItem.ReservedFromNonSerialisedInventoryItem);
                                    }

                                    if (orderItem.ExistReservedFromSerialisedInventoryItem)
                                    {
                                        shipmentItem.AddReservedFromInventoryItem(orderItem.ReservedFromSerialisedInventoryItem);
                                    }

                                    pendingShipment.AddShipmentItem(shipmentItem);
                                }

                                foreach (SalesOrderItem featureItem in orderItem.OrderedWithFeatures)
                                {
                                    shipmentItem.AddProductFeature(featureItem.ProductFeature);
                                }

                                new OrderShipmentBuilder(this.Strategy.Session)
                                .WithOrderItem(orderItem)
                                .WithShipmentItem(shipmentItem)
                                .WithQuantity(orderItem.QuantityRequestsShipping)
                                .Build();

                                shipmentItem.Quantity = shipmentItem.OrderShipmentsWhereShipmentItem.Sum(v => v.Quantity);

                                orderItemDerivedRoles.QuantityRequestsShipping = 0;

                                orderItemDerivedRoles.CostOfGoodsSold = orderItem.QuantityOrdered * part.PartWeightedAverage.AverageCost;
                            }
                        }

                        shipments.Add(pendingShipment);
                        this.AddDeniedPermission(new Permissions(this.Strategy.Session).Get(this.Meta.Class, this.Meta.Ship, Operations.Execute));
                    }
                }
            }
        }
Example #9
0
        private CustomerShipment AppsShip(IDerivation derivation, KeyValuePair<PostalAddress, Party> address)
        {
            var pendingShipment = address.Value.AppsGetPendingCustomerShipmentForStore(address.Key, this.Store, this.ShipmentMethod);

            if (pendingShipment == null)
            {
                pendingShipment = new CustomerShipmentBuilder(this.Strategy.Session)
                    .WithBillFromInternalOrganisation(this.TakenByInternalOrganisation)
                    .WithShipFromParty(this.TakenByInternalOrganisation)
                    .WithShipFromAddress(this.TakenByInternalOrganisation.ShippingAddress)
                    .WithBillToParty(this.BillToCustomer)
                    .WithBillToContactMechanism(this.BillToContactMechanism)
                    .WithShipToAddress(address.Key)
                    .WithShipToParty(address.Value)
                    .WithShipmentPackage(new ShipmentPackageBuilder(this.Strategy.Session).Build())
                    .WithStore(this.Store)
                    .WithShipmentMethod(this.ShipmentMethod)
                    .WithPaymentMethod(this.PaymentMethod)
                    .Build();
            }

            foreach (SalesOrderItem orderItem in this.ValidOrderItems)
            {
                if (orderItem.ExistProduct && orderItem.ShipToAddress.Equals(address.Key) && orderItem.QuantityRequestsShipping > 0)
                {
                    var good = orderItem.Product as Good;

                    ShipmentItem shipmentItem = null;
                    foreach (ShipmentItem item in pendingShipment.ShipmentItems)
                    {
                        if (item.Good.Equals(good))
                        {
                            shipmentItem = item;
                            break;
                        }
                    }

                    if (shipmentItem != null)
                    {
                        shipmentItem.Quantity += orderItem.QuantityRequestsShipping;
                        shipmentItem.ContentsDescription = $"{shipmentItem.Quantity} * {good}";
                    }
                    else
                    {
                        shipmentItem = new ShipmentItemBuilder(this.Strategy.Session)
                            .WithGood(good)
                            .WithQuantity(orderItem.QuantityRequestsShipping)
                            .WithContentsDescription($"{orderItem.QuantityRequestsShipping} * {good}")
                            .Build();

                        pendingShipment.AddShipmentItem(shipmentItem);
                    }

                    foreach (SalesOrderItem featureItem in orderItem.OrderedWithFeatures)
                    {
                        shipmentItem.AddProductFeature(featureItem.ProductFeature);
                    }

                    var orderShipmentsWhereShipmentItem = shipmentItem.OrderShipmentsWhereShipmentItem;
                    orderShipmentsWhereShipmentItem.Filter.AddEquals(OrderShipments.Meta.SalesOrderItem, orderItem);

                    if (orderShipmentsWhereShipmentItem.First == null)
                    {
                        new OrderShipmentBuilder(this.Strategy.Session)
                            .WithSalesOrderItem(orderItem)
                            .WithShipmentItem(shipmentItem)
                            .WithQuantity(orderItem.QuantityRequestsShipping)
                            .Build();
                    }
                    else
                    {
                        orderShipmentsWhereShipmentItem.First.Quantity += orderItem.QuantityRequestsShipping;
                    }

                    orderItem.AppsOnDeriveOnShip(derivation);
                }
            }

            // TODO: Check
            pendingShipment.OnDerive(x => x.WithDerivation(derivation));
            return pendingShipment;
        }
        public void GivenShipmentItem_WhenProcessed_ThenDeleteIsNotAllowed()
        {
            var mechelen      = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var shipToAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").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();

            User user = this.Administrator;

            this.Session.SetUser(user);

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

            var shipment = new CustomerShipmentBuilder(this.Session)
                           .WithShipToParty(customer)
                           .WithShipToAddress(shipToAddress)
                           .WithShipmentMethod(new ShipmentMethods(this.Session).Ground)
                           .Build();

            var shipmentItem = new ShipmentItemBuilder(this.Session).WithGood(good1).WithQuantity(10).Build();

            shipment.AddShipmentItem(shipmentItem);

            this.Session.Derive();

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

            var acl = new AccessControlLists(this.Session.GetUser())[shipmentItem];

            Assert.Equal(new ShipmentItemStates(this.Session).Picking, shipmentItem.ShipmentItemState);
            Assert.False(acl.CanExecute(M.ShipmentItem.Delete));

            var pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem;

            pickList.Picker = this.OrderProcessor;

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

            acl = new AccessControlLists(this.Session.GetUser())[shipmentItem];
            Assert.Equal(new ShipmentItemStates(this.Session).Picked, shipmentItem.ShipmentItemState);
            Assert.False(acl.CanExecute(M.ShipmentItem.Delete));

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

            shipment.AddShipmentPackage(package);

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

            this.Session.Derive();

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

            acl = new AccessControlLists(this.Session.GetUser())[shipmentItem];
            Assert.Equal(new ShipmentItemStates(this.Session).Packed, shipmentItem.ShipmentItemState);
            Assert.False(acl.CanExecute(M.ShipmentItem.Delete));

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

            acl = new AccessControlLists(this.Session.GetUser())[shipmentItem];
            Assert.Equal(new ShipmentItemStates(this.Session).Shipped, shipmentItem.ShipmentItemState);
            Assert.False(acl.CanExecute(M.ShipmentItem.Delete));
        }
Example #11
0
        public void GivenCustomerShipment_WhenCancelled_ThenCurrentShipmentStatusEqualsCancelled()
        {
            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build();
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var shipToAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();

            var shipment = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithShipToParty(customer)
                .WithShipToAddress(shipToAddress)
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(1, shipment.ShipmentStatuses.Count);
            Assert.AreEqual(new CustomerShipmentObjectStates(this.DatabaseSession).Created, shipment.CurrentShipmentStatus.CustomerShipmentObjectState);

            shipment.Cancel();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(2, shipment.ShipmentStatuses.Count);
            Assert.AreEqual(new CustomerShipmentObjectStates(this.DatabaseSession).Cancelled, shipment.CurrentShipmentStatus.CustomerShipmentObjectState);
        }
Example #12
0
        public void GivenCustomerShipment_WhenBuild_ThenPreviousObjectStateIsNull()
        {
            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build();
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var shipToAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();

            var shipment = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithShipToParty(customer)
                .WithShipToAddress(shipToAddress)
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.IsNull(shipment.PreviousObjectState);
        }
Example #13
0
        public void GivenCustomerShipment_WhenAddingAndRemovingPackages_ThenPackageSequenceNumberIsRecalculated()
        {
            var shipment = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithShipToAddress(new PostalAddresses(this.DatabaseSession).Extent().First)
                .WithShipToParty(new Organisations(this.DatabaseSession).Extent().First)
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Boat)
                .Build();

            var package1 = new ShipmentPackageBuilder(this.DatabaseSession).Build();
            shipment.AddShipmentPackage(package1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(1, package1.SequenceNumber);

            var package2 = new ShipmentPackageBuilder(this.DatabaseSession).Build();
            shipment.AddShipmentPackage(package2);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(2, package2.SequenceNumber);

            var package3 = new ShipmentPackageBuilder(this.DatabaseSession).Build();
            shipment.AddShipmentPackage(package3);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(3, package3.SequenceNumber);

            shipment.RemoveShipmentPackage(package1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(2, package2.SequenceNumber);
            Assert.AreEqual(3, package3.SequenceNumber);

            var package4 = new ShipmentPackageBuilder(this.DatabaseSession).Build();
            shipment.AddShipmentPackage(package4);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(2, package2.SequenceNumber);
            Assert.AreEqual(3, package3.SequenceNumber);
            Assert.AreEqual(4, package4.SequenceNumber);

            shipment.RemoveShipmentPackage(package4);

            this.DatabaseSession.Derive(true);

            var package5 = new ShipmentPackageBuilder(this.DatabaseSession).Build();
            shipment.AddShipmentPackage(package5);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(2, package2.SequenceNumber);
            Assert.AreEqual(3, package3.SequenceNumber);
            Assert.AreEqual(4, package5.SequenceNumber);
        }
Example #14
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);
        }
Example #15
0
        public void GivenCustomerShipmentCreatedByOrderProcessor_WhenCurrentUserIsCustomerContact_ThenReadAccessIsGranted()
        {
            var customerContact = new PersonBuilder(this.DatabaseSession).WithUserName("customercontact").WithLastName("customercontact").Build();
            var employee = new PersonBuilder(this.DatabaseSession).WithUserName("employee").WithLastName("employee").Build();
            var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build();

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

            new CustomerRelationshipBuilder(this.DatabaseSession)
                .WithCustomer(customer)
                .WithInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"))
                .WithFromDate(DateTime.UtcNow)
                .Build();

            new OrganisationContactRelationshipBuilder(this.DatabaseSession).WithContact(customerContact).WithOrganisation(customer).WithFromDate(DateTime.UtcNow).Build();

            new EmploymentBuilder(this.DatabaseSession)
                .WithEmployee(employee)
                .WithEmployer(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"))
                .WithFromDate(DateTime.UtcNow)
                .Build();

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

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("orderProcessor", "Forms"), new string[0]);
            var shipment = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithShipToParty(customer)
                .WithShipToAddress(shipToAddress)
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Boat)
                .Build();

            this.DatabaseSession.Derive(true);

            var acl = new AccessControlList(shipment, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsTrue(acl.CanWrite(CustomerShipments.Meta.ShipToParty));
            Assert.IsTrue(acl.CanRead(CustomerShipments.Meta.ShipToParty));
            Assert.IsTrue(acl.CanExecute(CustomerShipments.Meta.Cancel));

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("customercontact", "Forms"), new string[0]);
            acl = new AccessControlList(shipment, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsFalse(acl.CanWrite(CustomerShipments.Meta.ShipToParty));
            Assert.IsTrue(acl.CanRead(CustomerShipments.Meta.ShipToParty));
            Assert.IsFalse(acl.CanExecute(CustomerShipments.Meta.Cancel));
        }
Example #16
0
        public void GivenCustomerShipmentWithShipToCustomerWithShippingAddress_WhenDeriving_ThenShipToAddressMustExist()
        {
            var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build();
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var shipToAddress = new PostalAddressBuilder(this.DatabaseSession).WithAddress1("Haverwerf 15").WithGeographicBoundary(mechelen).Build();

            var shippingAddress = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(shipToAddress)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress)
                .WithUseAsDefault(true)
                .Build();

            customer.AddPartyContactMechanism(shippingAddress);

            this.DatabaseSession.Derive(true);

            var customerShipment = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithShipToParty(customer)
                .WithShipToAddress(shipToAddress)
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(shippingAddress.ContactMechanism, customerShipment.ShipToAddress);
        }
Example #17
0
        public void GivenCustomerShipment_WhenDeriving_ThenBillFromContactMechanismMustExist()
        {
            var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"];
            var euro = belgium.Currency;

            var bank = new BankBuilder(this.DatabaseSession).WithCountry(belgium).WithName("ING Belgiƫ").WithBic("BBRUBEBB").Build();

            var ownBankAccount = new OwnBankAccountBuilder(this.DatabaseSession)
                .WithDescription("own account")
                .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build())
                .Build();

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

            var billingAddress = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(address1)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress)
                .WithUseAsDefault(true)
                .Build();

            var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession)
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .WithName("internalOrganisation")
                .WithPreferredCurrency(euro)
                .WithDefaultPaymentMethod(ownBankAccount)
                .Build();

            internalOrganisation.AddPartyContactMechanism(billingAddress);

            this.DatabaseSession.Derive(true);

            var shipment1 = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithBillFromInternalOrganisation(internalOrganisation)
                .WithShipToParty(customer)
                .WithShipToAddress(new PostalAddresses(this.DatabaseSession).Extent().First)
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Boat)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(address1, shipment1.BillFromContactMechanism);
        }
        public void Edit()
        {
            var before = new CustomerShipments(this.Session).Extent().ToArray();

            var expected = new CustomerShipmentBuilder(this.Session).WithDefaults(this.internalOrganisation).Build();

            this.Session.Derive();

            var expectedShipToPartyPartyName = expected.ShipToParty?.DisplayName();
            var expectedShipToAddressDisplayName = expected.ShipToAddress?.DisplayName();
            var expectedShipToContactPersonPartyName = expected.ShipToContactPerson?.DisplayName();
            var expectedShipFromAddressDisplayName = expected.ShipFromAddress?.DisplayName();
            var expectedShipFromFacilityName = expected.ShipFromFacility.Name;
            var expectedShipmentMethodName = expected.ShipmentMethod.Name;
            var expectedCarrierName = expected.Carrier.Name;
            var expectedEstimatedShipDate = expected.EstimatedShipDate.Value.Date;
            var expectedEstimatedArrivalDate = expected.EstimatedArrivalDate.Value.Date;
            var expectedHandlingInstruction = expected.HandlingInstruction;
            var expectedComment = expected.Comment;

            var shipment = before.First(v => ((Organisation)v.ShipFromParty).IsInternalOrganisation.Equals(true));
            var id = shipment.Id;

            this.shipmentListPage.Table.DefaultAction(shipment);
            var shipmentOverview = new CustomerShipmentOverviewComponent(this.shipmentListPage.Driver);
            var shipmentOverviewDetail = shipmentOverview.CustomershipmentOverviewDetail.Click();

            shipmentOverviewDetail
                .ShipToParty.Select(expected.ShipToParty?.DisplayName());

            this.Driver.WaitForAngular();

            shipmentOverviewDetail
                .ShipToAddress.Select(expected.ShipToAddress)
                .ShipFromAddress.Select(expected.ShipFromParty?.ShippingAddress)
                .ShipmentMethod.Select(expected.ShipmentMethod)
                .ShipFromFacility.Select(((Organisation)expected.ShipFromParty)?.FacilitiesWhereOwner?.First)
                .Carrier.Select(expected.Carrier)
                .EstimatedShipDate.Set(expected.EstimatedShipDate.Value.Date)
                .EstimatedArrivalDate.Set(expected.EstimatedArrivalDate.Value.Date)
                .HandlingInstruction.Set(expected.HandlingInstruction)
                .Comment.Set(expected.Comment);

            if (expected.ExistShipToContactPerson)
            {
                shipmentOverviewDetail.ShipToContactPerson.Select(expected.ShipToContactPerson);
            }

            this.Session.Rollback();
            shipmentOverviewDetail.SAVE.Click();

            this.Driver.WaitForAngular();
            this.Session.Rollback();

            var after = new CustomerShipments(this.Session).Extent().ToArray();
            shipment = (CustomerShipment) this.Session.Instantiate(id);

            Assert.Equal(after.Length, before.Length);

            Assert.Equal(expectedShipToPartyPartyName, shipment.ShipToParty?.DisplayName());
            Assert.Equal(expectedShipToAddressDisplayName, shipment.ShipToAddress?.DisplayName());
            Assert.Equal(expectedShipToContactPersonPartyName, shipment.ShipToContactPerson?.DisplayName());
            Assert.Equal(expectedShipFromAddressDisplayName, shipment.ShipFromAddress?.DisplayName());
            Assert.Equal(expectedShipFromFacilityName, shipment.ShipFromFacility.Name);
            Assert.Equal(expectedShipmentMethodName, shipment.ShipmentMethod.Name);
            Assert.Equal(expectedCarrierName, shipment.Carrier.Name);
            Assert.Equal(expectedEstimatedShipDate, shipment.EstimatedShipDate);
            Assert.Equal(expectedEstimatedArrivalDate, shipment.EstimatedArrivalDate);
            Assert.Equal(expectedHandlingInstruction, shipment.HandlingInstruction);
            Assert.Equal(expectedComment, shipment.Comment);
        }
Example #19
0
        public void GivenCustomerShipment_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var shipToAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build();

            this.DatabaseSession.Commit();

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

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

            this.DatabaseSession.Rollback();

            builder.WithShipToParty(customer);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithCarrier(new Carriers(this.DatabaseSession).Fedex);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithShipToAddress(shipToAddress);
            builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Example #20
0
        private CustomerShipment AppsShipToAddress(IDerivation derivation, KeyValuePair <PostalAddress, Party> address)
        {
            var pendingShipment = address.Value.AppsGetPendingCustomerShipmentForStore(address.Key, this.Store, this.ShipmentMethod);

            if (pendingShipment == null)
            {
                pendingShipment = new CustomerShipmentBuilder(this.Strategy.Session)
                                  .WithShipFromAddress(this.TakenBy.ShippingAddress)
                                  .WithBillToParty(this.BillToCustomer)
                                  .WithBillToContactMechanism(this.BillToEndCustomerContactMechanism)
                                  .WithShipToAddress(address.Key)
                                  .WithShipToParty(address.Value)
                                  .WithShipmentPackage(new ShipmentPackageBuilder(this.Strategy.Session).Build())
                                  .WithStore(this.Store)
                                  .WithShipmentMethod(this.ShipmentMethod)
                                  .WithPaymentMethod(this.PaymentMethod)
                                  .Build();
            }

            foreach (SalesOrderItem orderItem in this.ValidOrderItems)
            {
                if (orderItem.ExistProduct && orderItem.ShipToAddress.Equals(address.Key) && orderItem.QuantityRequestsShipping > 0)
                {
                    var good = orderItem.Product as Good;

                    ShipmentItem shipmentItem = null;
                    foreach (ShipmentItem item in pendingShipment.ShipmentItems)
                    {
                        if (item.Good.Equals(good))
                        {
                            shipmentItem = item;
                            break;
                        }
                    }

                    if (shipmentItem != null)
                    {
                        shipmentItem.Quantity           += orderItem.QuantityRequestsShipping;
                        shipmentItem.ContentsDescription = $"{shipmentItem.Quantity} * {good}";
                    }
                    else
                    {
                        shipmentItem = new ShipmentItemBuilder(this.Strategy.Session)
                                       .WithGood(good)
                                       .WithQuantity(orderItem.QuantityRequestsShipping)
                                       .WithContentsDescription($"{orderItem.QuantityRequestsShipping} * {good}")
                                       .Build();

                        pendingShipment.AddShipmentItem(shipmentItem);
                    }

                    foreach (SalesOrderItem featureItem in orderItem.OrderedWithFeatures)
                    {
                        shipmentItem.AddProductFeature(featureItem.ProductFeature);
                    }

                    var orderShipmentsWhereShipmentItem = shipmentItem.OrderShipmentsWhereShipmentItem;
                    orderShipmentsWhereShipmentItem.Filter.AddEquals(M.OrderShipment.OrderItem, orderItem);

                    if (orderShipmentsWhereShipmentItem.First == null)
                    {
                        new OrderShipmentBuilder(this.Strategy.Session)
                        .WithOrderItem(orderItem)
                        .WithShipmentItem(shipmentItem)
                        .WithQuantity(orderItem.QuantityRequestsShipping)
                        .Build();
                    }
                    else
                    {
                        orderShipmentsWhereShipmentItem.First.Quantity += orderItem.QuantityRequestsShipping;
                    }

                    orderItem.AppsOnDeriveOnShip(derivation);
                }
            }

            // TODO: Check

            if (this.Store.IsAutomaticallyShipped)
            {
                pendingShipment.Ship();
            }

            pendingShipment.OnDerive(x => x.WithDerivation(derivation));
            return(pendingShipment);
        }
Example #21
0
        public void GivenCustomerShipmentBuilder_WhenBuild_ThenPostBuildRelationsMustExist()
        {
            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build();
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var shipFromAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var partyContactMechanism = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(shipFromAddress)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress)
                .WithUseAsDefault(true)
                .Build();

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

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

            var shipment = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithShipToParty(customer)
                .WithShipToAddress(new PostalAddresses(this.DatabaseSession).Extent().First)
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Boat)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new CustomerShipmentObjectStates(this.DatabaseSession).Created, shipment.CurrentObjectState);
            Assert.AreEqual(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"), shipment.ShipFromParty);
            Assert.AreEqual(shipFromAddress, shipment.ShipFromAddress);
            Assert.AreEqual(shipment.ShipFromParty, shipment.ShipFromParty);
            Assert.AreEqual(new Stores(this.DatabaseSession).FindBy(Stores.Meta.Name, "store"), shipment.Store);
        }