private static void Main()
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            var orderBuilder = new PurchaseOrderBuilder();

            var breadSupplier = new Supplier("Bulk Food Depot", "*****@*****.**", "Doug");

            var orderItems = new List <LineItem> {
                new LineItem("bread flour", 4, 1.2m),
                new LineItem("salt", 2, 0.3m),
                new LineItem("yeast", 8, 0.75m),
            };

            PurchaseOrder breadSuppliesOrder = orderBuilder
                                               .WithId("b_123")
                                               .ForCompany("Riverrun Bakery")
                                               .AtAddress("2828 Main St")
                                               .FromSupplier(breadSupplier)
                                               .ForItems(orderItems)
                                               .RequestDate(DateTime.UtcNow.AddDays(5))
                                               .BuildPurchaseOrder();

            PrintPurchaseOrder(breadSuppliesOrder);
        }
        public static PurchaseOrderBuilder WithDefaults(this PurchaseOrderBuilder @this, Organisation internalOrganisation)
        {
            var faker = @this.Session.Faker();

            var postalAddress = new PostalAddressBuilder(@this.Session).WithDefaults().Build();
            var supplier      = faker.Random.ListItem(internalOrganisation.ActiveSuppliers);

            @this.WithCustomerReference(faker.Lorem.Word());
            @this.WithDescription(faker.Lorem.Sentence());
            @this.WithComment(faker.Lorem.Sentence());
            @this.WithInternalComment(faker.Lorem.Sentence());
            @this.WithShipToContactPerson(internalOrganisation.CurrentContacts.FirstOrDefault());
            @this.WithShipToAddress(internalOrganisation.ShippingAddress);
            @this.WithBillToContactPerson(internalOrganisation.CurrentContacts.FirstOrDefault());
            @this.WithBillToContactMechanism(internalOrganisation.CurrentPartyContactMechanisms.Select(v => v.ContactMechanism).FirstOrDefault());
            @this.WithTakenViaContactPerson(supplier.CurrentContacts.FirstOrDefault());
            @this.WithTakenViaContactMechanism(supplier.CurrentPartyContactMechanisms.Select(v => v.ContactMechanism).FirstOrDefault());
            @this.WithTakenViaSupplier(supplier);
            @this.WithStoredInFacility(faker.Random.ListItem(internalOrganisation.FacilitiesWhereOwner));
            @this.WithSalesTerm(new IncoTermBuilder(@this.Session).WithDefaults().Build());
            @this.WithSalesTerm(new InvoiceTermBuilder(@this.Session).WithDefaults().Build());
            @this.WithSalesTerm(new OrderTermBuilder(@this.Session).WithDefaults().Build());
            @this.WithOrderedBy(internalOrganisation);

            return(@this);
        }
Exemple #3
0
            public void ShipmentIsNull_ReturnsTrue()
            {
                var purchaseOrder = new PurchaseOrderBuilder().Build();

                Assert.That(purchaseOrder.Shipment, Is.Null);
                Assert.That(purchaseOrder.CanShipmentBeUpdated, Is.True);
            }
Exemple #4
0
        public void GivenPurchaseOrder_WhenGettingOrderNumberWithFormat_ThenFormattedOrderNumberShouldBeReturned()
        {
            this.InternalOrganisation.InvoiceSequence = new InvoiceSequences(this.Session).EnforcedSequence;
            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

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

            this.Session.Derive();

            var internalOrganisation = this.InternalOrganisation;

            internalOrganisation.PurchaseOrderNumberPrefix = "the format is ";

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

            this.Session.Derive();

            Assert.Equal("the format is 1", order1.OrderNumber);

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

            this.Session.Derive();

            Assert.Equal("the format is 2", order2.OrderNumber);
        }
Exemple #5
0
        public void GivenOrder_WhenDeriving_ThenLocaleMustExist()
        {
            var englischLocale = new Locales(this.DatabaseSession).EnglishGreatBritain;

            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            ContactMechanism takenViaContactMechanism = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var supplierContactMechanism = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(takenViaContactMechanism)
                .WithUseAsDefault(true)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).OrderAddress)
                .Build();
            supplier.AddPartyContactMechanism(supplierContactMechanism);

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

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(englischLocale, order.Locale);
        }
        public void GivenShipmentReceiptForGoodWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility()
        {
            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

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

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

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

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

            order.AddPurchaseOrderItem(item1);

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

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

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

            var shipment = (PurchaseShipment)item1.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem;

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

            var receipt = item1.ShipmentReceiptsWhereOrderItem.Single();

            Assert.Equal(new Facilities(this.Session).FindBy(M.Facility.FacilityType, new FacilityTypes(this.Session).Warehouse), receipt.InventoryItem.Facility);
            Assert.Equal(good1.Part.InventoryItemsWherePart[0], receipt.InventoryItem);

            this.Session.Rollback();
        }
        public void GivenShipmentReceiptWhenDerivingThenOrderItemQuantityReceivedIsUpdated()
        {
            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

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

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

            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();
            this.Session.Derive();

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

            var shipment = (PurchaseShipment)item1.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem;

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

            Assert.Equal(10, item1.QuantityReceived);

            this.Session.Rollback();
        }
            public void OrderStatusDraft_ExceptionThrown()
            {
                var shipment      = new ShipmentBuilder().Build();
                var purchaseOrder = new PurchaseOrderBuilder().Build();

                Assert.Throws <PurchaseOrderTrackerException>(() => shipment.AddPurchaseOrder(purchaseOrder));
            }
Exemple #9
0
        public void GivenPurchaseOrder_WhenObjectStateIsOnHold_ThenCheckTransitions()
        {
            this.SetIdentity("orderProcessor");

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

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

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

            order.Confirm();

            this.Session.Derive();

            order.Hold();

            this.Session.Derive();

            Assert.Equal(new PurchaseOrderStates(this.Session).OnHold, order.PurchaseOrderState);
            var acl = new AccessControlList(order, this.Session.GetUser());

            Assert.True(acl.CanExecute(M.PurchaseOrder.Cancel));
            Assert.True(acl.CanExecute(M.PurchaseOrder.Continue));
            Assert.False(acl.CanExecute(M.PurchaseOrder.Confirm));
            Assert.False(acl.CanExecute(M.PurchaseOrder.Reject));
            Assert.False(acl.CanExecute(M.PurchaseOrder.Approve));
            Assert.False(acl.CanExecute(M.PurchaseOrder.Hold));
        }
        /*
         * Create PurchaseOrder with both Serialized & NonSerialized PurchaseOrder Items
         */
        public static PurchaseOrder CreatePurchaseOrderWithBothItems(this Organisation @this, Faker faker)
        {
            var serializedPart = new UnifiedGoodBuilder(@this.Session()).WithSerialisedDefaults(@this).Build();
            var serializedItem = new SerialisedItemBuilder(@this.Session()).WithDefaults(@this).Build();

            serializedPart.AddSerialisedItem(serializedItem);

            var nonSerializedPart = new NonUnifiedPartBuilder(@this.Session()).WithNonSerialisedDefaults(@this).Build();

            var purchaseOrder = new PurchaseOrderBuilder(@this.Session()).WithDefaults(@this).Build();

            new SupplierOfferingBuilder(@this.Session())
            .WithPart(nonSerializedPart)
            .WithSupplier(purchaseOrder.TakenViaSupplier)
            .WithFromDate(@this.Session().Now().AddMinutes(-1))
            .WithUnitOfMeasure(new UnitsOfMeasure(@this.Session()).Piece)
            .WithPrice(faker.Random.Decimal(0, 10))
            .Build();

            var nonSerializedPartItem = new PurchaseOrderItemBuilder(@this.Session()).WithNonSerializedPartDefaults(nonSerializedPart).Build();
            var serializedPartItem    = new PurchaseOrderItemBuilder(@this.Session()).WithSerializedPartDefaults(serializedPart, serializedItem).Build();

            purchaseOrder.AddPurchaseOrderItem(nonSerializedPartItem);
            purchaseOrder.AddPurchaseOrderItem(serializedPartItem);

            return(purchaseOrder);
        }
        public void CreateWithDefaults()
        {
            var before = new PurchaseOrders(this.Session).Extent().ToArray();

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

            Assert.True(expected.ExistTakenViaSupplier);
            Assert.True(expected.ExistTakenViaContactPerson);
            Assert.True(expected.ExistBillToContactPerson);
            Assert.True(expected.ExistShipToContactPerson);
            Assert.True(expected.ExistStoredInFacility);
            Assert.True(expected.ExistCustomerReference);
            Assert.True(expected.ExistDescription);
            Assert.True(expected.ExistInternalComment);

            this.Session.Derive();

            var expectedTakenViaSupplier         = expected.TakenViaSupplier;
            var expectedTakenViaContactMechanism = expected.DerivedTakenViaContactMechanism;
            var expectedTakenViaContactPerson    = expected.TakenViaContactPerson;
            var expectedBillToContactMechanism   = expected.DerivedBillToContactMechanism;
            var expectedBillToContactPerson      = expected.BillToContactPerson;
            var expectedShipToAddress            = expected.DerivedShipToAddress;
            var expectedShipToContactPerson      = expected.ShipToContactPerson;
            var expectedStoredInFacility         = expected.StoredInFacility;
            var expectedCustomerReference        = expected.CustomerReference;
            var expectedDescription     = expected.Description;
            var expectedInternalComment = expected.InternalComment;

            var purchaseOrderCreate = this.purchaseOrderListPage
                                      .CreatePurchaseOrder()
                                      .BuildForDefaults(expected);

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

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

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

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

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

            this.Driver.WaitForAngular();

            Assert.Equal(expectedTakenViaSupplier, actual.TakenViaSupplier);
            Assert.Equal(expectedTakenViaContactMechanism, actual.DerivedTakenViaContactMechanism);
            Assert.Equal(expectedTakenViaContactPerson, actual.TakenViaContactPerson);
            Assert.Equal(expectedBillToContactMechanism, actual.DerivedBillToContactMechanism);
            Assert.Equal(expectedBillToContactPerson, actual.BillToContactPerson);
            Assert.Equal(expectedShipToAddress, actual.DerivedShipToAddress);
            Assert.Equal(expectedShipToContactPerson, actual.ShipToContactPerson);
            Assert.Equal(expectedStoredInFacility, actual.StoredInFacility);
            Assert.Equal(expectedCustomerReference, actual.CustomerReference);
            Assert.Equal(expectedDescription, actual.Description);
            Assert.Equal(expectedInternalComment, actual.InternalComment);
        }
Exemple #12
0
            public void Always_DefaultCreatedDateToNow()
            {
                var purchaseOrder = new PurchaseOrderBuilder().Build();

                // compare date component only (ignore time) to ensure this test always passes
                // otherwise the CreateDate property would need to be abstracted so that we can
                // always set the same value as part of this test case
                Assert.That(purchaseOrder.CreatedDate.Date, Is.EqualTo(DateTime.Today));
            }
Exemple #13
0
            public void CancelledStatus_RemovesShipmentReference()
            {
                var purchaseOrder = new PurchaseOrderBuilder().Shipment(new ShipmentBuilder().Build()).Build();

                Assert.That(purchaseOrder.Shipment, Is.Not.Null);
                purchaseOrder.UpdateStatus(PurchaseOrderStatus.Trigger.Cancelled);

                Assert.That(purchaseOrder.Shipment, Is.Null);
            }
            public void OrderStatusPendingApproval_ExceptionThrown()
            {
                var shipment      = new ShipmentBuilder().Build();
                var purchaseOrder = new PurchaseOrderBuilder().Build();

                purchaseOrder.UpdateStatus(PurchaseOrderStatus.Trigger.PendingApproval);

                Assert.Throws <PurchaseOrderTrackerException>(() => shipment.AddPurchaseOrder(purchaseOrder));
            }
            public void OrderAlreadyAssignedToShipment_ExceptionThrown()
            {
                var shipment      = new ShipmentBuilder().ShipmentId(123).Build();
                var poShipment    = new ShipmentBuilder().ShipmentId(789).Build();
                var purchaseOrder = new PurchaseOrderBuilder().Shipment(poShipment).Build();

                purchaseOrder.UpdateStatus(PurchaseOrderStatus.Trigger.Approved);

                Assert.Throws <PurchaseOrderTrackerException>(() => shipment.AddPurchaseOrder(purchaseOrder));
            }
Exemple #16
0
            public void StatusIsShipped_ReturnsFalse()
            {
                var purchaseOrder = new PurchaseOrderBuilder().Build();

                // TODO: Use UpdateStatus instead of returning state machine and changing status on it
                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Approved);
                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Shipped);

                Assert.That(purchaseOrder.CanBeDeleted, Is.False);
            }
Exemple #17
0
            public void StatusIsDelivered_ReturnsFalse()
            {
                var purchaseOrder = new PurchaseOrderBuilder().Build();

                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Approved);
                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Shipped);
                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Delivered);

                Assert.That(purchaseOrder.CanBeDeleted, Is.False);
            }
            public void OrderStatusIsApproved_OrderAdded()
            {
                var shipment      = new ShipmentBuilder().Build();
                var purchaseOrder = new PurchaseOrderBuilder().Build();

                purchaseOrder.UpdateStatus(PurchaseOrderStatus.Trigger.Approved);

                shipment.AddPurchaseOrder(purchaseOrder);

                Assert.That(shipment.PurchaseOrders.Contains(purchaseOrder), Is.True);
            }
Exemple #19
0
            public void ShipmentStatusIsShipped_ReturnsFalse()
            {
                var shipment      = new ShipmentBuilder().Build();
                var purchaseOrder = new PurchaseOrderBuilder().Shipment(shipment).Build();

                purchaseOrder.UpdateStatus(PurchaseOrderStatus.Trigger.Approved);
                shipment.UpdateStatus(ShipmentStatus.Trigger.Shipped);

                Assert.That(shipment.Status.CurrentState, Is.EqualTo(ShipmentStatus.State.Shipped));
                Assert.That(purchaseOrder.CanShipmentBeUpdated, Is.False);
            }
Exemple #20
0
            public void ProductIsFromSameSupplier_LineItemAddedToCollection()
            {
                var supplier      = new SupplierBuilder().Id(123).Build();
                var purchaseOrder = new PurchaseOrderBuilder()
                                    .Supplier(supplier)
                                    .Build();
                var lineItem = new PurchaseOrderLineBuilder()
                               .Product(new ProductBuilder().SupplierId(123).Build())
                               .Build();

                purchaseOrder.AddLineItem(lineItem);
            }
Exemple #21
0
            public void ProductIsFromDifferentSupplier_ExceptionThrown()
            {
                var supplier      = new SupplierBuilder().Id(123).Build();
                var purchaseOrder = new PurchaseOrderBuilder()
                                    .Supplier(supplier)
                                    .Build();
                var lineItem = new PurchaseOrderLineBuilder()
                               .Product(new ProductBuilder().SupplierId(789).Build())
                               .Build();

                Assert.Throws <PurchaseOrderTrackerException>(() => purchaseOrder.AddLineItem(lineItem));
            }
Exemple #22
0
            public void PurchaseOrderIsNotOpen_ExceptionThrown()
            {
                var purchaseOrder = new PurchaseOrderBuilder()
                                    .Supplier(new SupplierBuilder().Id(111).Build())
                                    .Build();
                var newSupplier = new SupplierBuilder().Id(222).Build();

                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Approved);
                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Shipped);
                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Delivered);

                Assert.Throws <PurchaseOrderTrackerException>(() => purchaseOrder.ChangeSupplier(newSupplier));
            }
Exemple #23
0
        public void GivenPurchaseOrderBuilder_WhenBuild_ThenPostBuildRelationsMustExist()
        {
            var supplier             = new OrganisationBuilder(this.Session).WithName("supplier").Build();
            var internalOrganisation = this.InternalOrganisation;

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

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

            Assert.Equal(new PurchaseOrderStates(this.Session).Provisional, order.PurchaseOrderState);
            Assert.Equal(DateTime.UtcNow.Date, order.OrderDate.Date);
            Assert.Equal(DateTime.UtcNow.Date, order.EntryDate.Date);
            Assert.Equal(order.PreviousTakenViaSupplier, order.TakenViaSupplier);
        }
        public void GivenShipmentReceiptForPartWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility()
        {
            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

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

            var part = new NonUnifiedPartBuilder(this.Session)
                       .WithProductIdentification(new PartNumberBuilder(this.Session)
                                                  .WithIdentification("P1")
                                                  .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build())
                       .Build();

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

            var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(1).Build();

            order.AddPurchaseOrderItem(item1);

            this.Session.Derive();

            order.Confirm();

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

            var shipment     = new PurchaseShipmentBuilder(this.Session).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).WithShipFromParty(supplier).Build();
            var shipmentItem = new ShipmentItemBuilder(this.Session).WithPart(part).Build();

            shipment.AddShipmentItem(shipmentItem);

            var receipt = new ShipmentReceiptBuilder(this.Session)
                          .WithQuantityAccepted(1M)
                          .WithShipmentItem(shipmentItem)
                          .WithOrderItem(item1)
                          .Build();

            shipment.AppsComplete();

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

            Assert.Equal(new Facilities(this.Session).FindBy(M.Facility.FacilityType, new FacilityTypes(this.Session).Warehouse), receipt.InventoryItem.Facility);
            Assert.Equal(part.InventoryItemsWherePart[0], receipt.InventoryItem);

            this.Session.Rollback();
        }
Exemple #25
0
            public void StatusIsNotShippedOrDelivered_ReturnsTrue()
            {
                var purchaseOrder = new PurchaseOrderBuilder().Build();

                Assert.That(purchaseOrder.CanBeDeleted, Is.True);

                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.PendingApproval);
                Assert.That(purchaseOrder.CanBeDeleted, Is.True);

                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Approved);
                Assert.That(purchaseOrder.CanBeDeleted, Is.True);

                purchaseOrder.Status.Fire(PurchaseOrderStatus.Trigger.Cancelled);
                Assert.That(purchaseOrder.CanBeDeleted, Is.True);
            }
        /*
         * Create PurchaseOrder with Serialized PurchaseOrderItem
         */
        public static PurchaseOrder CreatePurchaseOrderWithSerializedItem(this Organisation @this)
        {
            var serializedPart = new UnifiedGoodBuilder(@this.Session()).WithSerialisedDefaults(@this).Build();
            var serializedItem = new SerialisedItemBuilder(@this.Session()).WithDefaults(@this).Build();

            serializedPart.AddSerialisedItem(serializedItem);

            var purchaseOrder = new PurchaseOrderBuilder(@this.Session()).WithDefaults(@this).Build();

            var item = new PurchaseOrderItemBuilder(@this.Session()).WithSerializedPartDefaults(serializedPart, serializedItem).Build();

            purchaseOrder.AddPurchaseOrderItem(item);

            return(purchaseOrder);
        }
Exemple #27
0
        public void GivenPurchaseOrder_WhenConfirming_ThenAllValidItemsAreInConfirmedState()
        {
            var supplier = new OrganisationBuilder(this.Session).WithName("customer2").Build();

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

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

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

            var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(1).Build();
            var item2 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(2).Build();
            var item3 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(3).Build();
            var item4 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(4).Build();

            order.AddPurchaseOrderItem(item1);
            order.AddPurchaseOrderItem(item2);
            order.AddPurchaseOrderItem(item3);
            order.AddPurchaseOrderItem(item4);

            this.Session.Derive();

            order.Confirm();

            this.Session.Derive();

            item4.Cancel();

            this.Session.Derive();

            Assert.Equal(3, order.ValidOrderItems.Count);
            Assert.Contains(item1, order.ValidOrderItems);
            Assert.Contains(item2, order.ValidOrderItems);
            Assert.Contains(item3, order.ValidOrderItems);
            Assert.Equal(new PurchaseOrderItemStates(this.Session).InProcess, item1.PurchaseOrderItemState);
            Assert.Equal(new PurchaseOrderItemStates(this.Session).InProcess, item2.PurchaseOrderItemState);
            Assert.Equal(new PurchaseOrderItemStates(this.Session).InProcess, item3.PurchaseOrderItemState);
            Assert.Equal(new PurchaseOrderItemStates(this.Session).Cancelled, item4.PurchaseOrderItemState);
        }
        public void GivenBilledToWithOrderNumberPrefix_WhenDeriving_ThenSortableOrderNumberIsSet()
        {
            this.InternalOrganisation.PurchaseOrderNumberPrefix = "prefix-";
            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

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

            this.Session.Derive();

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

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

            Assert.Equal(int.Parse(order.OrderNumber.Split('-')[1]), order.SortableOrderNumber);
        }
        public void GivenBilledToWithParametrizedOrderNumberPrefix_WhenDeriving_ThenSortableOrderNumberIsSet()
        {
            this.InternalOrganisation.PurchaseOrderNumberPrefix = "prefix-{year}-";
            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

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

            this.Session.Derive();

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

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

            Assert.Equal(int.Parse(string.Concat(this.Session.Now().Date.Year.ToString(), order.OrderNumber.Split('-').Last())), order.SortableOrderNumber);
        }
Exemple #30
0
        public void GivenShipmentReceiptForGoodWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).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 order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build();

            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(1).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);

            var receipt = new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(1M)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item1)
                .Build();

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

            shipment.AppsComplete();

            Assert.AreEqual(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"), receipt.InventoryItem.Facility);
            Assert.AreEqual(good.InventoryItemsWhereGood[0], receipt.InventoryItem);

            this.DatabaseSession.Rollback();
        }
Exemple #31
0
            public void PurchaseOrderIsOpen_SupplierChangedAndLineItemsCleared()
            {
                var product       = new ProductBuilder().SupplierId(111).Build();
                var purchaseOrder = new PurchaseOrderBuilder()
                                    .Supplier(new SupplierBuilder().Id(111).Build())
                                    .LineItems(
                    new List <PurchaseOrderLine>
                {
                    new PurchaseOrderLineBuilder().Product(product).Build(),
                    new PurchaseOrderLineBuilder().Product(product).Build(),
                    new PurchaseOrderLineBuilder().Product(product).Build()
                })
                                    .Build();
                var newSupplier = new SupplierBuilder().Id(222).Build();

                purchaseOrder.ChangeSupplier(newSupplier);

                Assert.That(purchaseOrder.LineItems.Any(), Is.False);
                Assert.That(purchaseOrder.Supplier, Is.SameAs(newSupplier));
            }
            public void UpdateToShipped_UpdatesAllPurchaseOrdersToShipped()
            {
                var purchaseOrder1 = new PurchaseOrderBuilder().Build();

                purchaseOrder1.UpdateStatus(PurchaseOrderStatus.Trigger.Approved);
                var purchaseOrder2 = new PurchaseOrderBuilder().Build();

                purchaseOrder2.UpdateStatus(PurchaseOrderStatus.Trigger.Approved);
                var shipment = new ShipmentBuilder()
                               .PurchaseOrders(new List <PurchaseOrder>(new[]
                {
                    purchaseOrder1,
                    purchaseOrder2
                }))
                               .Build();

                shipment.UpdateStatus(ShipmentStatus.Trigger.Shipped);

                Assert.That(
                    shipment.PurchaseOrders.All(p => p.Status.CurrentState == PurchaseOrderStatus.State.Shipped),
                    Is.True);
            }
Exemple #33
0
        public void GivenPurchaseOrder_WhenShipmentIsReceived_ThenCurrenShipmentStatusIsUpdated()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            var part = new RawMaterialBuilder(this.DatabaseSession).WithName("RawMaterial").Build();

            var order = new PurchaseOrderBuilder(this.DatabaseSession)
                .WithTakenViaSupplier(supplier)
                .WithBillToPurchaser(internalOrganisation)
                .WithVatRegime(new VatRegimes(this.DatabaseSession).Exempt)
                .Build();

            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(1).Build();
            var item2 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(2).Build();
            var item3 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(3).Build();
            order.AddPurchaseOrderItem(item1);
            order.AddPurchaseOrderItem(item2);
            order.AddPurchaseOrderItem(item3);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            var shipment1 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build();
            var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build();
            shipment1.AddShipmentItem(shipmentItem);

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

            shipment1.AppsComplete();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Received, item1.CurrentShipmentStatus.PurchaseOrderItemObjectState);
            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).PartiallyReceived, order.CurrentShipmentStatus.PurchaseOrderObjectState);
            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentOrderStatus.PurchaseOrderObjectState);

            var shipment2 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build();
            shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build();
            shipment2.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(2)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item2)
                .Build();

            shipment2.AppsComplete();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Received, item2.CurrentShipmentStatus.PurchaseOrderItemObjectState);
            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).PartiallyReceived, order.CurrentShipmentStatus.PurchaseOrderObjectState);
            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentOrderStatus.PurchaseOrderObjectState);

            var shipment3 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build();
            shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build();
            shipment3.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(3)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item3)
                .Build();

            shipment3.AppsComplete();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Received, item3.CurrentShipmentStatus.PurchaseOrderItemObjectState);
            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).Received, order.CurrentShipmentStatus.PurchaseOrderObjectState);
            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).Completed, order.CurrentOrderStatus.PurchaseOrderObjectState);
        }
Exemple #34
0
        public void GivenPurchaseOrder_WhenOrdering_ThenAllValidItemsAreInInProcessState()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            var part = new RawMaterialBuilder(this.DatabaseSession).WithName("RawMaterial").Build();

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

            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(1).Build();
            var item2 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(2).Build();
            var item3 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(3).Build();
            order.AddPurchaseOrderItem(item1);
            order.AddPurchaseOrderItem(item2);
            order.AddPurchaseOrderItem(item3);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(3, order.ValidOrderItems.Count);
            Assert.Contains(item1, order.ValidOrderItems);
            Assert.Contains(item2, order.ValidOrderItems);
            Assert.Contains(item3, order.ValidOrderItems);
            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).InProcess, item1.CurrentObjectState);
            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).InProcess, item2.CurrentObjectState);
            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).InProcess, item3.CurrentObjectState);
        }
Exemple #35
0
        public void GivenPurchaseOrder_WhenObjectStateIsOnHold_ThenCheckTransitions()
        {
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("orderProcessor", "Forms"), new string[0]);

            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

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

            order.Confirm();

            this.DatabaseSession.Derive(true);

            order.Hold();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).OnHold, order.CurrentObjectState);
            var acl = new AccessControlList(order, new Users(this.DatabaseSession).GetCurrentUser());
            Assert.IsTrue(acl.CanExecute(PurchaseOrders.Meta.Cancel));
            Assert.IsTrue(acl.CanExecute(PurchaseOrders.Meta.Continue));
            Assert.IsFalse(acl.CanExecute(PurchaseOrders.Meta.Confirm));
            Assert.IsFalse(acl.CanExecute(PurchaseOrders.Meta.Reject));
            Assert.IsFalse(acl.CanExecute(PurchaseOrders.Meta.Approve));
            Assert.IsFalse(acl.CanExecute(PurchaseOrders.Meta.Hold));
        }
Exemple #36
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 #37
0
        public void GivenPurchaseOrderCreatedByProcurementLevel1Role_WhenCurrentUserInAnotherProcurementLevel1RoleUserGroup_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 purchaser2 = new PersonBuilder(this.DatabaseSession).WithLastName("purchaser2").WithUserName("purchaser2").Build();

            var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession)
                .WithName("new internalOrganisation")
                .WithLocale(Singleton.Instance(this.DatabaseSession).DefaultLocale)
                .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator)
                .WithDefaultPaymentMethod(ownBankAccount)
                .WithPreferredCurrency(euro)
                .WithPartyContactMechanism(billToMechelen)
                .Build();

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

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

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

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("purchaser", "Forms"), new string[0]);
            var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).WithShipToBuyer(internalOrganisation).Build();

            this.DatabaseSession.Derive(true);

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

            Assert.IsTrue(acl.CanWrite(PurchaseOrders.Meta.Comment));
            Assert.IsTrue(acl.CanRead(PurchaseOrders.Meta.Comment));
            Assert.IsTrue(acl.CanExecute(PurchaseOrders.Meta.Confirm));

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

            Assert.IsFalse(acl.HasReadOperation);
        }
Exemple #38
0
        public void GivenPurchaseOrderCreatedByProcurementLevel1Role_WhenCurrentUserInAdministratorRole_ThenAccessIsGranted()
        {
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("purchaser", "Forms"), new string[0]);

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

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

            Assert.IsTrue(acl.CanWrite(PurchaseOrders.Meta.Comment));
            Assert.IsTrue(acl.CanRead(PurchaseOrders.Meta.Comment));
            Assert.IsTrue(acl.CanExecute(PurchaseOrders.Meta.Confirm));
        }
Exemple #39
0
        public void GivenPurchaseOrderBuilder_WhenBuild_ThenPostBuildRelationsMustExist()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

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

            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).Provisional, order.CurrentObjectState);
            Assert.AreEqual(DateTime.UtcNow.Date, order.OrderDate.Date);
            Assert.AreEqual(DateTime.UtcNow.Date, order.EntryDate.Date);
            Assert.AreEqual(order.PreviousTakenViaSupplier, order.TakenViaSupplier);
            Assert.AreEqual(internalOrganisation, order.ShipToBuyer);
            Assert.AreEqual(internalOrganisation, order.BillToPurchaser);
            Assert.AreEqual(order.ShipToBuyer.PreferredCurrency, order.CustomerCurrency);
            Assert.IsTrue(order.ExistUniqueId);
        }
Exemple #40
0
        public void GivenPurchaseOrder_WhenTakenViaSupplierChangesValue_ThenAccessPreviousSupplierIsDenied()
        {
            var supplierContact = new PersonBuilder(this.DatabaseSession).WithUserName("suppliercontact").WithLastName("suppliercontact").Build();
            var supplierContact2 = new PersonBuilder(this.DatabaseSession).WithUserName("suppliercontact2").WithLastName("suppliercontact2").Build();
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var supplier2 = new OrganisationBuilder(this.DatabaseSession).WithName("supplier2").Build();

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

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

            new OrganisationContactRelationshipBuilder(this.DatabaseSession).WithContact(supplierContact).WithOrganisation(supplier).WithFromDate(DateTime.UtcNow).Build();
            new OrganisationContactRelationshipBuilder(this.DatabaseSession).WithContact(supplierContact2).WithOrganisation(supplier2).WithFromDate(DateTime.UtcNow).Build();

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

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("purchaser", "Forms"), new string[0]);
            var order = new PurchaseOrderBuilder(this.DatabaseSession)
                .WithTakenViaSupplier(supplier)
                .Build();

            this.DatabaseSession.Derive(true);

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

            Assert.IsFalse(acl.CanWrite(PurchaseOrders.Meta.OrderDate));
            Assert.IsTrue(acl.CanRead(PurchaseOrders.Meta.OrderDate));
            Assert.IsTrue(acl.CanRead(PurchaseOrders.Meta.OrderNumber));
            Assert.IsTrue(acl.CanRead(PurchaseOrders.Meta.TotalExVat));
            Assert.IsFalse(acl.CanExecute(PurchaseOrders.Meta.Confirm));

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

            Assert.IsFalse(acl.HasReadOperation);

            order.TakenViaSupplier = supplier2;

            this.DatabaseSession.Derive(true);

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

            Assert.IsFalse(acl.HasReadOperation);

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

            Assert.IsFalse(acl.CanWrite(PurchaseOrders.Meta.OrderDate));
            Assert.IsTrue(acl.CanRead(PurchaseOrders.Meta.OrderDate));
            Assert.IsTrue(acl.CanRead(PurchaseOrders.Meta.OrderNumber));
            Assert.IsTrue(acl.CanRead(PurchaseOrders.Meta.TotalExVat));
            Assert.IsFalse(acl.CanExecute(PurchaseOrders.Meta.Confirm));
        }
Exemple #41
0
        public void GivenOrder_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            ContactMechanism takenViaContactMechanism = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var supplierContactMechanism = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(takenViaContactMechanism)
                .WithUseAsDefault(true)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).OrderAddress)
                .Build();
            supplier.AddPartyContactMechanism(supplierContactMechanism);

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

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

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

            this.DatabaseSession.Rollback();

            builder.WithTakenViaSupplier(supplier);
            builder.Build();

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

            builder.WithTakenViaContactMechanism(takenViaContactMechanism);
            builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Exemple #42
0
        public void GivenPurchaseOrderCreatedByProcurementLevel1Role_WhenCurrentUserInSameProcurementLevel1RoleUserGroup_ThenAccessIsGranted()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

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

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

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

            userGroup.AddMember(purchaser2);

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

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("purchaser", "Forms"), new string[0]);
            var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build();

            this.DatabaseSession.Derive(true);

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

            Assert.IsTrue(acl.CanWrite(SalesOrders.Meta.Comment));
            Assert.IsTrue(acl.CanRead(SalesOrders.Meta.Comment));
            Assert.IsTrue(acl.CanExecute(PurchaseOrders.Meta.Confirm));

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

            Assert.IsTrue(acl.CanWrite(PurchaseOrders.Meta.Comment));
            Assert.IsTrue(acl.CanRead(PurchaseOrders.Meta.Comment));
            Assert.IsTrue(acl.CanExecute(PurchaseOrders.Meta.Confirm));
        }
Exemple #43
0
        public void GivenShipmentReceiptWhenDerivingThenOrderItemQuantityReceivedIsUpdated()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).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 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();

            shipment.AppsComplete();

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

            Assert.AreEqual(10, item1.QuantityReceived);

            this.DatabaseSession.Rollback();
        }
Exemple #44
0
        public void GivenPurchaseOrderCreatedByProcurementLevel1Role_WhenCurrentUserIsCustomer_ThenAccessIsDenied()
        {
            new PersonBuilder(this.DatabaseSession).WithUserName("customer").WithLastName("customer").Build();
            var supplierContact = new PersonBuilder(this.DatabaseSession).WithUserName("suppliercontact").WithLastName("suppliercontact").Build();
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();

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

            new OrganisationContactRelationshipBuilder(this.DatabaseSession).WithContact(supplierContact).WithOrganisation(supplier).WithFromDate(DateTime.UtcNow).Build();

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

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

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

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

            Assert.IsFalse(acl.HasReadOperation);
        }
Exemple #45
0
        public void GivenShipmentReceiptForPartWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            var part = new RawMaterialBuilder(this.DatabaseSession)
                .WithName("RawMaterial")
                .Build();

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

            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(1).Build();
            order.AddPurchaseOrderItem(item1);

            this.DatabaseSession.Derive(true);

            order.Confirm();

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

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

            var receipt = new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(1M)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item1)
                .Build();

            shipment.AppsComplete();

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

            Assert.AreEqual(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"), receipt.InventoryItem.Facility);
            Assert.AreEqual(part.InventoryItemsWherePart[0], receipt.InventoryItem);

            this.DatabaseSession.Rollback();
        }
Exemple #46
0
        public void GivenPurchaseOrder_WhenGettingOrderNumberWithoutFormat_ThenOrderNumberShouldBeReturned()
        {
            var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession).Build();

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

            var order1 = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).WithBillToPurchaser(internalOrganisation).Build();
            Assert.AreEqual("1", order1.OrderNumber);

            var order2 = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).WithBillToPurchaser(internalOrganisation).Build();
            Assert.AreEqual("2", order2.OrderNumber);
        }