public void GivenBasePriceForVirtualProduct_WhenDeriving_ThenProductVirtualProductPriceComponentIsUpdated() { var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var virtualGood = new GoodBuilder(this.DatabaseSession) .WithName("virtual gizmo") .WithVatRate(vatRate21) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var physicalGood = new GoodBuilder(this.DatabaseSession) .WithName("real gizmo") .WithSku("10101") .WithVatRate(vatRate21) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); virtualGood.AddVariant(physicalGood); this.DatabaseSession.Derive(true); var basePrice = new BasePriceBuilder(this.DatabaseSession) .WithDescription("baseprice") .WithPrice(10) .WithProduct(virtualGood) .WithFromDate(DateTime.UtcNow) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(1, physicalGood.VirtualProductPriceComponents.Count); Assert.Contains(basePrice, physicalGood.VirtualProductPriceComponents); Assert.IsFalse(virtualGood.ExistVirtualProductPriceComponents); }
public void GivenInventoryItem_WhenDeriving_ThenProductCategoriesAreDerived() { var level1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("level1").Build(); var level2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("level2").WithParent(level1).Build(); var level3 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("level3").WithParent(level2).Build(); var category = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("category").Build(); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithVatRate(vatRate21) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithProductCategory(level3) .WithProductCategory(category) .Build(); var goodInventory = new NonSerializedInventoryItemBuilder(this.DatabaseSession) .WithGood(good) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(4, goodInventory.DerivedProductCategories.Count); Assert.Contains(level3, goodInventory.DerivedProductCategories); Assert.Contains(level2, goodInventory.DerivedProductCategories); Assert.Contains(level1, goodInventory.DerivedProductCategories); Assert.Contains(category, goodInventory.DerivedProductCategories); }
public void GivenConfirmedOrderItemForGood_WhenOrderItemIsRemoved_ThenItemIsRemovedFromValidOrderItems() { this.InstantiateObjects(this.DatabaseSession); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate, 21)) .Build(); var item = new PurchaseOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); this.order.AddPurchaseOrderItem(item); this.DatabaseSession.Derive(true); this.order.Confirm(); this.DatabaseSession.Derive(true); Assert.AreEqual(1, this.order.ValidOrderItems.Count); item.Cancel(); this.DatabaseSession.Derive(true); Assert.AreEqual(0, this.order.ValidOrderItems.Count); }
public void GivenOrderRequirementCommitment_WhenDeriving_ThenRequiredRelationsMustExist() { var shipToCustomer = new OrganisationBuilder(this.DatabaseSession).WithName("shipToCustomer").Build(); var billToCustomer = new OrganisationBuilder(this.DatabaseSession).WithName("billToCustomer").Build(); new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(billToCustomer) .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation) .Build(); new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(shipToCustomer) .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation) .Build(); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Gizmo") .WithSku("10101") .WithVatRate(vatRate21) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); this.DatabaseSession.Derive(true); var salesOrder = new SalesOrderBuilder(this.DatabaseSession) .WithShipToCustomer(shipToCustomer) .WithBillToCustomer(billToCustomer) .WithVatRegime(new VatRegimes(this.DatabaseSession).Export) .Build(); var goodOrderItem = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(1).Build(); salesOrder.AddSalesOrderItem(goodOrderItem); var customerRequirement = new CustomerRequirementBuilder(this.DatabaseSession).WithDescription("100 gizmo's").Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var builder = new OrderRequirementCommitmentBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithOrderItem(goodOrderItem); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithRequirement(customerRequirement); var tsts = builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenPartyWithOpenOrders_WhenDeriving_ThenOpenOrderAmountIsUpdated() { var organisation = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new CustomerRelationshipBuilder(this.DatabaseSession).WithCustomer(organisation).WithInternalOrganisation(internalOrganisation).Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var postalAddress = new PostalAddressBuilder(this.DatabaseSession) .WithAddress1("Kleine Nieuwedijkstraat 2") .WithGeographicBoundary(mechelen) .Build(); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithName("good") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); this.DatabaseSession.Derive(true); var salesOrder1 = new SalesOrderBuilder(this.DatabaseSession).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder1").Build(); var orderItem1 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(10) .WithActualUnitPrice(10) .Build(); salesOrder1.AddSalesOrderItem(orderItem1); var salesOrder2 = new SalesOrderBuilder(this.DatabaseSession).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder2").Build(); var orderItem2 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(10) .WithActualUnitPrice(10) .Build(); salesOrder2.AddSalesOrderItem(orderItem2); var salesOrder3 = new SalesOrderBuilder(this.DatabaseSession).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder3").Build(); var orderItem3 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(10) .WithActualUnitPrice(10) .Build(); salesOrder3.AddSalesOrderItem(orderItem3); salesOrder3.Cancel(); this.DatabaseSession.Derive(true); Assert.AreEqual(242M, organisation.OpenOrderAmount); }
public void GivenPaymentApplication_WhenDeriving_ThenAmountAppliedCannotBeLargerThenAmountReceived() { var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First; var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build()) .WithName("good") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build(); new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer) .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation) .Build(); var invoice = new SalesInvoiceBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(1).WithActualUnitPrice(1000M).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build()) .Build(); this.DatabaseSession.Derive(true); var receipt = new ReceiptBuilder(this.DatabaseSession) .WithAmount(100) .WithEffectiveDate(DateTime.UtcNow) .Build(); var paymentApplication = new PaymentApplicationBuilder(this.DatabaseSession) .WithAmountApplied(200) .WithInvoiceItem(invoice.InvoiceItems[0]) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); receipt.AddPaymentApplication(paymentApplication); var derivationLog = this.DatabaseSession.Derive(); Assert.IsTrue(derivationLog.HasErrors); Assert.Contains(PaymentApplications.Meta.AmountApplied, derivationLog.Errors[0].RoleTypes); }
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(); }
public void GivenNewGoodCoredOnFinishedGood_WhenDeriving_ThenNonSerializedInventryItemIsCreatedForEveryFinishedGoodAndFacility() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var secondFacility = new WarehouseBuilder(this.DatabaseSession).WithName("second facility").WithOwner(internalOrganisation).Build(); new SupplierRelationshipBuilder(this.DatabaseSession) .WithInternalOrganisation(internalOrganisation) .WithSupplier(supplier) .WithFromDate(DateTime.UtcNow) .Build(); var finishedGood = new FinishedGoodBuilder(this.DatabaseSession) .WithName("part") .Build(); var purchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow) .WithCurrency(new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR")) .WithPrice(1) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithFinishedGood(finishedGood) .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); new SupplierOfferingBuilder(this.DatabaseSession) .WithProduct(good) .WithSupplier(supplier) .WithProductPurchasePrice(purchasePrice) .WithFromDate(DateTime.UtcNow) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(2, good.FinishedGood.InventoryItemsWherePart.Count); Assert.AreEqual(1, internalOrganisation.DefaultFacility.InventoryItemsWhereFacility.Count); Assert.AreEqual(1, secondFacility.InventoryItemsWhereFacility.Count); }
public void GivenBasePriceForNonVirtualProduct_WhenDeriving_ThenProductVirtualProductPriceComponentIsNull() { var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var physicalGood = new GoodBuilder(this.DatabaseSession) .WithName("real gizmo") .WithSku("10101") .WithVatRate(vatRate21) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); new BasePriceBuilder(this.DatabaseSession) .WithDescription("baseprice") .WithPrice(10) .WithProduct(physicalGood) .WithFromDate(DateTime.UtcNow) .Build(); Assert.IsFalse(physicalGood.ExistVirtualProductPriceComponents); }
public void GivenInventoryItemForGood_WhenDerived_ThenSkuIsFromGood() { var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var category = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("category").Build(); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good1") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(category) .Build(); var item = new NonSerializedInventoryItemBuilder(this.DatabaseSession) .WithGood(good) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(good.Sku, item.Sku); }
public void DeriveHistory() { var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem; var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First; var customer1 = new OrganisationBuilder(this.DatabaseSession).WithName("customer1").Build(); var customer2 = new OrganisationBuilder(this.DatabaseSession).WithName("customer2").Build(); var salesRep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep1").Build(); var salesRep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep2").Build(); var package1 = new PackageBuilder(this.DatabaseSession).WithName("package1").Build(); var package2 = new PackageBuilder(this.DatabaseSession).WithName("package2").Build(); var salesChannel1 = new SalesChannels(this.DatabaseSession).WebChannel; var salesChannel2 = new SalesChannels(this.DatabaseSession).NoChannel; var catMain = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("main cat").Build(); var cat1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good1").WithParent(catMain).WithPackage(package1).Build(); var cat2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good2").WithParent(catMain).WithPackage(package2).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build(); this.DatabaseSession.Derive(true); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build(); this.DatabaseSession.Derive(true); var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good1") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(cat1) .Build(); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("10102") .WithVatRate(vatRate21) .WithName("good2") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(cat2) .Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); internalOrganisation.PreferredCurrency = euro; new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithInternalOrganisation(internalOrganisation).Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithInternalOrganisation(internalOrganisation).Build(); this.DatabaseSession.Derive(true); var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTime.UtcNow.AddMonths(-1)) .WithInvoiceNumber("1") .WithBillToCustomer(customer1) .WithBillToContactMechanism(contactMechanism) .WithSalesChannel(salesChannel1) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item1a = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item1a); var item1b = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item1b); var item1c = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(5).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item1c); this.DatabaseSession.Derive(true); var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTime.UtcNow) .WithInvoiceNumber("1") .WithBillToCustomer(customer1) .WithBillToContactMechanism(contactMechanism) .WithSalesChannel(salesChannel1) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item2a = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice2.AddSalesInvoiceItem(item2a); var item2b = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice2.AddSalesInvoiceItem(item2b); var item2c = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(5).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build(); invoice2.AddSalesInvoiceItem(item2c); this.DatabaseSession.Derive(true); Singleton.Instance(this.DatabaseSession).DeriveRevenues(); var salesRep1RevenueHistory = salesRep1.SalesRepRevenueHistoriesWhereSalesRep.First; Assert.AreEqual(90, salesRep1RevenueHistory.Revenue); var salesRep2RevenueHistory = salesRep2.SalesRepRevenueHistoriesWhereSalesRep.First; Assert.AreEqual(50, salesRep2RevenueHistory.Revenue); var invoice3 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTime.UtcNow) .WithInvoiceNumber("1") .WithBillToCustomer(customer2) .WithBillToContactMechanism(contactMechanism) .WithSalesChannel(salesChannel2) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item3a = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(1).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice3.AddSalesInvoiceItem(item3a); var item3b = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(1).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build(); invoice3.AddSalesInvoiceItem(item3b); this.DatabaseSession.Derive(true); Singleton.Instance(this.DatabaseSession).DeriveRevenues(); Assert.AreEqual(105, salesRep1RevenueHistory.Revenue); Assert.AreEqual(60, salesRep2RevenueHistory.Revenue); }
public void GivenConfirmedOrder_WhenOrderIsCancelled_ThenNonSerializedInventoryQuantitiesAreReleased() { var billToCustomer = new PersonBuilder(this.DatabaseSession).WithLastName("person1").Build(); var shipToCustomer = new PersonBuilder(this.DatabaseSession).WithLastName("person2").Build(); var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation; new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(billToCustomer).WithInternalOrganisation(internalOrganisation).Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(shipToCustomer).WithInternalOrganisation(internalOrganisation).Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var shipToContactMechanism = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var part1 = new FinishedGoodBuilder(this.DatabaseSession).WithName("part1").Build(); var part2 = new FinishedGoodBuilder(this.DatabaseSession).WithName("part2").Build(); var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good1") .WithFinishedGood(part1) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("10102") .WithVatRate(vatRate21) .WithName("good1") .WithFinishedGood(part2) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); this.DatabaseSession.Derive(true); var order = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(billToCustomer) .WithShipToCustomer(shipToCustomer) .WithShipToAddress(shipToContactMechanism) .Build(); var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build(); var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build(); var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(3).WithActualUnitPrice(15).Build(); var item4 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(4).WithActualUnitPrice(15).Build(); order.AddSalesOrderItem(item1); order.AddSalesOrderItem(item2); order.AddSalesOrderItem(item3); order.AddSalesOrderItem(item4); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); Assert.AreEqual(3, item1.ReservedFromInventoryItem.QuantityCommittedOut); Assert.AreEqual(0, item1.ReservedFromInventoryItem.AvailableToPromise); Assert.AreEqual(7, item3.ReservedFromInventoryItem.QuantityCommittedOut); Assert.AreEqual(0, item3.ReservedFromInventoryItem.AvailableToPromise); order.Cancel(); this.DatabaseSession.Derive(true); Assert.AreEqual(0, item1.ReservedFromInventoryItem.QuantityCommittedOut); Assert.AreEqual(0, item1.ReservedFromInventoryItem.AvailableToPromise); Assert.AreEqual(0, item3.ReservedFromInventoryItem.QuantityCommittedOut); Assert.AreEqual(0, item3.ReservedFromInventoryItem.AvailableToPromise); }
public void GivenShipmentReceiptWhenValidatingThenRequiredRelationsMustExist() { 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 inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Order).Build()); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var builder = new ShipmentReceiptBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithInventoryItem(inventoryItem); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build(); shipment.AddShipmentItem(shipmentItem); builder.WithShipmentItem(shipmentItem); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
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(); }
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); }
public void GivenSalesInvoice_WhenDerived_ThenTotalExVatIsAddedToPartyPackageRevenueHistory() { var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem; var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First; var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var package1 = new PackageBuilder(this.DatabaseSession).WithName("package1").Build(); var cat1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good1").WithPackage(package1).Build(); var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good1") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(cat1) .Build(); var customer = new Organisations(this.DatabaseSession).FindBy(Organisations.Meta.Name, "customer"); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); internalOrganisation.PreferredCurrency = euro; this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var date = DateTime.UtcNow.AddYears(-1).AddMonths(-1); decimal revenuePastTwelveMonths = 0; for (var i = 1; i <= 13; i++) { var invoice = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(date) .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithSalesChannel(new SalesChannels(this.DatabaseSession).WebChannel) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(1).WithActualUnitPrice(i * 10M).WithSalesInvoiceItemType(productItem).Build(); invoice.AddSalesInvoiceItem(item); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var history = customer.PartyPackageRevenueHistoriesWhereParty.First; //// first iteration is too old if (i > 1) { revenuePastTwelveMonths += i * 10M; } ////date in first iteration is too old, no history yet. if (history != null) { Assert.AreEqual(revenuePastTwelveMonths, history.Revenue); } date = date.AddMonths(1); } }
public void GivenSalesOrderForCustomerExceedingCreditLimit_WhenOrderIsConfirmed_ThenOrderRequestsApproval() { var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem; var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First; var assessable = new VatRegimes(this.DatabaseSession).Assessable; var vatRate0 = new VatRateBuilder(this.DatabaseSession).WithRate(0).Build(); assessable.VatRate = vatRate0; var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate0) .WithName("good1") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .Build(); var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer) .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation) .WithCreditLimit(100M) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var invoice = new SalesInvoiceBuilder(this.DatabaseSession) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithInvoiceDate(DateTime.UtcNow.AddYears(-1)) .Build(); var invoiceItem = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(10).WithActualUnitPrice(11).WithSalesInvoiceItemType(productItem).Build(); invoice.AddSalesInvoiceItem(invoiceItem); this.DatabaseSession.Derive(true); var order = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithVatRegime(assessable) .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .Build(); var item = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(10) .WithActualUnitPrice(5) .Build(); order.AddSalesOrderItem(item); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).RequestsApproval, order.CurrentObjectState); Assert.AreEqual(0, item.QuantityReserved); Assert.AreEqual(0, item.QuantityPendingShipment); Assert.AreEqual(0, item.QuantityRequestsShipping); Assert.AreEqual(0, item.QuantityShortFalled); order.Approve(); this.DatabaseSession.Derive(true); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentObjectState); Assert.AreEqual(10, item.QuantityReserved); Assert.AreEqual(10, item.QuantityPendingShipment); Assert.AreEqual(0, item.QuantityRequestsShipping); Assert.AreEqual(0, item.QuantityShortFalled); }
public void GivenSalesOrderForItemsThatAreAvailable_WhenShipped_ThenOrderIsCompleted() { var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress) .WithUseAsDefault(true) .Build(); var billToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).WithPartyContactMechanism(billToMechelen).Build(); var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation; new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good1") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .Build(); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("10102") .WithVatRate(vatRate21) .WithName("good2") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .Build(); var good1InventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good1).Build(); good1InventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var good2InventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good2).Build(); good2InventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var order = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithShipToAddress(mechelenAddress) .Build(); var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(15).Build(); var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(2).WithActualUnitPrice(15).Build(); var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantityOrdered(5).WithActualUnitPrice(15).Build(); order.AddSalesOrderItem(item1); order.AddSalesOrderItem(item2); order.AddSalesOrderItem(item3); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); var shipment = (CustomerShipment)mechelenAddress.ShipmentsWhereShipToAddress[0]; var pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem; pickList.Picker = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "orderProcessor"); pickList.SetPicked(); this.DatabaseSession.Derive(true); var package = new ShipmentPackageBuilder(this.DatabaseSession).Build(); shipment.AddShipmentPackage(package); foreach (ShipmentItem shipmentItem in shipment.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.DatabaseSession).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build()); } this.DatabaseSession.Derive(true); shipment.Ship(); this.DatabaseSession.Derive(true); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).Completed, order.CurrentObjectState); Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).Shipped, order.CurrentShipmentStatus.SalesOrderObjectState); Assert.IsFalse(order.ExistCurrentPaymentStatus); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Completed, item1.CurrentObjectState); Assert.IsFalse(item1.ExistCurrentPaymentStatus); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Shipped, item1.CurrentShipmentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Completed, item2.CurrentObjectState); Assert.IsFalse(item2.ExistCurrentPaymentStatus); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Shipped, item2.CurrentShipmentStatus.SalesOrderItemObjectState); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Completed, item3.CurrentObjectState); Assert.IsFalse(item3.ExistCurrentPaymentStatus); Assert.AreEqual(new SalesOrderItemObjectStates(this.DatabaseSession).Shipped, item3.CurrentShipmentStatus.SalesOrderItemObjectState); }
public void GivenInventoryItem_WhenDeriving_ThenRequiredRelationsMustExist() { 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(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var builder = new NonSerializedInventoryItemBuilder(this.DatabaseSession); var item = builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithPart(new FinishedGoodBuilder(this.DatabaseSession).WithName("part").WithManufacturerId("10101").Build()); item = builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); builder.WithGood(good); item = builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); item.RemovePart(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenOrderItemForProduct_WhenDerivingPrices_ThenUseProductCurrentPurchasePrice() { var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate,21)) .WithName("good") .Build(); var supplierOffering = new SupplierOfferingBuilder(this.DatabaseSession) .WithProduct(good) .WithSupplier(this.supplier) .WithFromDate(DateTime.UtcNow.AddYears(-1)) .Build(); var previousPurchasePriceGood = new ProductPurchasePriceBuilder(this.DatabaseSession) .WithCurrency(euro) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithFromDate(DateTime.UtcNow.AddYears(-1)) .WithThroughDate(DateTime.UtcNow.AddDays(-1)) .WithPrice(8) .Build(); var currentPurchasePriceGood = new ProductPurchasePriceBuilder(this.DatabaseSession) .WithCurrency(euro) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1)) .WithPrice(10) .Build(); var futurePurchasePriceGood = new ProductPurchasePriceBuilder(this.DatabaseSession) .WithCurrency(euro) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithFromDate(DateTime.UtcNow.AddYears(1)) .WithPrice(8) .Build(); supplierOffering.AddProductPurchasePrice(previousPurchasePriceGood); supplierOffering.AddProductPurchasePrice(currentPurchasePriceGood); supplierOffering.AddProductPurchasePrice(futurePurchasePriceGood); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); this.InstantiateObjects(this.DatabaseSession); const decimal QuantityOrdered = 3; var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(QuantityOrdered).Build(); this.order.AddPurchaseOrderItem(item1); this.DatabaseSession.Derive(true); Assert.AreEqual(currentPurchasePriceGood.Price, item1.UnitBasePrice); Assert.AreEqual(0, item1.UnitDiscount); Assert.AreEqual(0, item1.UnitSurcharge); Assert.AreEqual(currentPurchasePriceGood.Price, item1.CalculatedUnitPrice); Assert.AreEqual(currentPurchasePriceGood.Price * QuantityOrdered, item1.TotalBasePrice); Assert.AreEqual(0, item1.TotalDiscount); Assert.AreEqual(0, item1.TotalSurcharge); Assert.AreEqual(currentPurchasePriceGood.Price * QuantityOrdered, item1.TotalExVat); Assert.AreEqual(currentPurchasePriceGood.Price * QuantityOrdered, this.order.TotalBasePrice); Assert.AreEqual(0, this.order.TotalDiscount); Assert.AreEqual(0, this.order.TotalSurcharge); Assert.AreEqual(currentPurchasePriceGood.Price * QuantityOrdered, this.order.TotalExVat); }
public void DeriveRevenues() { var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem; var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First; var customer1 = new OrganisationBuilder(this.DatabaseSession).WithName("customer1").Build(); var customer2 = new OrganisationBuilder(this.DatabaseSession).WithName("customer2").Build(); var salesRep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep1").Build(); var salesRep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep2").Build(); var catMain = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("main cat").Build(); var cat1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good1").WithParent(catMain).Build(); var cat2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good2").WithParent(catMain).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build(); this.DatabaseSession.Derive(true); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build(); this.DatabaseSession.Derive(true); var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good1") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(cat1) .Build(); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("10102") .WithVatRate(vatRate21) .WithName("good2") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(cat2) .Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); internalOrganisation.PreferredCurrency = euro; new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithInternalOrganisation(internalOrganisation).Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithInternalOrganisation(internalOrganisation).Build(); this.DatabaseSession.Derive(true); var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTime.UtcNow) .WithInvoiceNumber("1") .WithBillToCustomer(customer1) .WithBillToContactMechanism(contactMechanism) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item1); var item2 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item2); var item3 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(5).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item3); this.DatabaseSession.Derive(true); Singleton.Instance(this.DatabaseSession).DeriveRevenues(); var customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty; Assert.AreEqual(2, customer1ProductRevenues.Count); customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty; customer1ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good1); var customer1Good1Revenue = customer1ProductRevenues.First; customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty; customer1ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good2); var customer1Good2Revenue = customer1ProductRevenues.First; Assert.AreEqual(90, customer1Good1Revenue.Revenue); Assert.AreEqual(6, customer1Good1Revenue.Quantity); Assert.AreEqual(50, customer1Good2Revenue.Revenue); Assert.AreEqual(5, customer1Good2Revenue.Quantity); var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTime.UtcNow) .WithInvoiceNumber("1") .WithBillToCustomer(customer2) .WithBillToContactMechanism(contactMechanism) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item4 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(1).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice2.AddSalesInvoiceItem(item4); this.DatabaseSession.Derive(true); var item5 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(1).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build(); invoice2.AddSalesInvoiceItem(item5); this.DatabaseSession.Derive(true); Singleton.Instance(this.DatabaseSession).DeriveRevenues(); var customer2ProductRevenues = customer2.PartyProductRevenuesWhereParty; Assert.AreEqual(2, customer2ProductRevenues.Count); customer2ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good1); var customer2Good1Revenue = customer2ProductRevenues.First; customer2ProductRevenues = customer2.PartyProductRevenuesWhereParty; customer2ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good2); var customer2Good2Revenue = customer2ProductRevenues.First; Assert.AreEqual(15, customer2Good1Revenue.Revenue); Assert.AreEqual(1, customer2Good1Revenue.Quantity); Assert.AreEqual(10, customer2Good2Revenue.Revenue); Assert.AreEqual(1, customer2Good2Revenue.Quantity); }
public void GivenInventoryItem_WhenQuantityOnHandIsRaised_ThenSalesOrderItemsWithQuantityShortFalledAreUpdated() { var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var category = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("category").Build(); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good1") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(category) .Build(); var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(5).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var order1 = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithDeliveryDate(DateTime.UtcNow) .Build(); var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item1").WithProduct(good).WithQuantityOrdered(10).WithActualUnitPrice(15).Build(); var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item2").WithProduct(good).WithQuantityOrdered(20).WithActualUnitPrice(15).Build(); order1.AddSalesOrderItem(item1); order1.AddSalesOrderItem(item2); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); order1.Confirm(); this.DatabaseSession.Derive(true); var order2 = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithDeliveryDate(DateTime.UtcNow.AddDays(1)) .Build(); var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item3").WithProduct(good).WithQuantityOrdered(10).WithActualUnitPrice(15).Build(); var item4 = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item4").WithProduct(good).WithQuantityOrdered(20).WithActualUnitPrice(15).Build(); order2.AddSalesOrderItem(item3); order2.AddSalesOrderItem(item4); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); order2.Confirm(); this.DatabaseSession.Derive(true); //Assert.AreEqual(0, item1.QuantityRequestsShipping); //Assert.AreEqual(5, item1.QuantityPendingShipment); //Assert.AreEqual(10, item1.QuantityReserved); //Assert.AreEqual(5, item1.QuantityShortFalled); //Assert.AreEqual(0, item2.QuantityRequestsShipping); //Assert.AreEqual(0, item2.QuantityPendingShipment); //Assert.AreEqual(20, item2.QuantityReserved); //Assert.AreEqual(20, item2.QuantityShortFalled); //Assert.AreEqual(0, item3.QuantityRequestsShipping); //Assert.AreEqual(0, item3.QuantityPendingShipment); //Assert.AreEqual(10, item3.QuantityReserved); //Assert.AreEqual(10, item3.QuantityShortFalled); //Assert.AreEqual(0, item4.QuantityRequestsShipping); //Assert.AreEqual(0, item4.QuantityPendingShipment); //Assert.AreEqual(20, item4.QuantityReserved); //Assert.AreEqual(20, item4.QuantityShortFalled); Assert.AreEqual(0, item1.ReservedFromInventoryItem.AvailableToPromise); Assert.AreEqual(5, item1.ReservedFromInventoryItem.QuantityOnHand); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(15).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); //// Orderitems are sorted as follows: item1, item2, item3, item4 //Assert.AreEqual(0, item1.QuantityRequestsShipping); //Assert.AreEqual(10, item1.QuantityPendingShipment); //Assert.AreEqual(10, item1.QuantityReserved); //Assert.AreEqual(0, item1.QuantityShortFalled); //Assert.AreEqual(0, item2.QuantityRequestsShipping); //Assert.AreEqual(10, item2.QuantityPendingShipment); //Assert.AreEqual(20, item2.QuantityReserved); //Assert.AreEqual(10, item2.QuantityShortFalled); //Assert.AreEqual(0, item3.QuantityRequestsShipping); //Assert.AreEqual(0, item3.QuantityPendingShipment); //Assert.AreEqual(10, item3.QuantityReserved); //Assert.AreEqual(10, item3.QuantityShortFalled); //Assert.AreEqual(0, item4.QuantityRequestsShipping); //Assert.AreEqual(0, item4.QuantityPendingShipment); //Assert.AreEqual(20, item4.QuantityReserved); //Assert.AreEqual(20, item4.QuantityShortFalled); Assert.AreEqual(0, item1.ReservedFromInventoryItem.AvailableToPromise); Assert.AreEqual(20, item1.ReservedFromInventoryItem.QuantityOnHand); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(85).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); //// Orderitems are sorted as follows: item2, item1, item4, item 3 Assert.AreEqual(0, item1.QuantityRequestsShipping); Assert.AreEqual(10, item1.QuantityPendingShipment); Assert.AreEqual(10, item1.QuantityReserved); Assert.AreEqual(0, item1.QuantityShortFalled); Assert.AreEqual(0, item2.QuantityRequestsShipping); Assert.AreEqual(20, item2.QuantityPendingShipment); Assert.AreEqual(20, item2.QuantityReserved); Assert.AreEqual(0, item2.QuantityShortFalled); Assert.AreEqual(0, item3.QuantityRequestsShipping); Assert.AreEqual(10, item3.QuantityPendingShipment); Assert.AreEqual(10, item3.QuantityReserved); Assert.AreEqual(0, item3.QuantityShortFalled); Assert.AreEqual(0, item4.QuantityRequestsShipping); Assert.AreEqual(20, item4.QuantityPendingShipment); Assert.AreEqual(20, item4.QuantityReserved); Assert.AreEqual(0, item4.QuantityShortFalled); Assert.AreEqual(45, item1.ReservedFromInventoryItem.AvailableToPromise); Assert.AreEqual(105, item1.ReservedFromInventoryItem.QuantityOnHand); }
public void GivenOrderItemWithoutDeliveryDate_WhenDeriving_ThenDerivedDeliveryDateIsOrderDeliveryDate() { this.InstantiateObjects(this.DatabaseSession); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate,21)) .Build(); var item = new PurchaseOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(1) .Build(); this.order.AddPurchaseOrderItem(item); this.DatabaseSession.Derive(true); Assert.AreEqual(item.DeliveryDate, this.order.DeliveryDate); }
public void GivenOrderItem_WhenObjectStateIsRejected_ThenItemMayNotBeCancelledOrRejectedOrDeleted() { var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build(); var administrators = new UserGroups(this.DatabaseSession).Administrators; administrators.AddMember(administrator); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); this.InstantiateObjects(this.DatabaseSession); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate,21)) .Build(); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]); var item = new PurchaseOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); this.order.AddPurchaseOrderItem(item); this.DatabaseSession.Derive(true); item.Reject(); this.DatabaseSession.Derive(true); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Rejected, item.CurrentObjectState); var acl = new AccessControlList(item, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsFalse(acl.CanExecute(PurchaseOrderItems.Meta.Cancel)); Assert.IsFalse(acl.CanExecute(PurchaseOrderItems.Meta.Reject)); Assert.IsFalse(acl.CanExecute(PurchaseOrderItems.Meta.Delete)); }
public void GivenOrderItem_WhenObjectStateIsPartiallyReceived_ThenProductChangeIsNotAllowed() { var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build(); var administrators = new UserGroups(this.DatabaseSession).Administrators; administrators.AddMember(administrator); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); this.InstantiateObjects(this.DatabaseSession); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate,21)) .Build(); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]); var item = new PurchaseOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); this.order.AddPurchaseOrderItem(item); this.order.Confirm(); this.DatabaseSession.Derive(true); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(this.supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build(); shipment.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(1) .WithShipmentItem(shipmentItem) .WithOrderItem(item) .Build(); shipment.AppsComplete(); this.DatabaseSession.Derive(true); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).PartiallyReceived, item.CurrentObjectState); var acl = new AccessControlList(item, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsFalse(acl.CanWrite(PurchaseOrderItems.Meta.Product)); }
public void GivenConfirmedOrderItemForGood_WhenQuantityOrderedIsDecreased_ThenQuantityMayNotBeLessThanQuantityShippped() { this.InstantiateObjects(this.DatabaseSession); var manual = new OrderKindBuilder(this.DatabaseSession).WithDescription("manual").WithScheduleManually(true).Build(); var testPart = new FinishedGoodBuilder(this.DatabaseSession).WithName("part1").Build(); var testgood = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(this.vatRate21) .WithName("good1") .WithFinishedGood(testPart) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var good1InventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithPart(testPart).Build(); good1InventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(110).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); var item = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(testgood) .WithQuantityOrdered(120) .WithActualUnitPrice(5) .Build(); this.order.AddSalesOrderItem(item); this.order.OrderKind = manual; this.DatabaseSession.Derive(true); this.order.Confirm(); this.DatabaseSession.Derive(true); item.QuantityShipNow = 100; this.DatabaseSession.Derive(true); var shipment = (CustomerShipment)this.order.ShipToAddress.ShipmentsWhereShipToAddress[0]; var pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem; pickList.Picker = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "orderProcessor"); pickList.SetPicked(); this.DatabaseSession.Derive(true); var package = new ShipmentPackageBuilder(this.DatabaseSession).Build(); shipment.AddShipmentPackage(package); foreach (ShipmentItem shipmentItem in shipment.ShipmentItems) { package.AddPackagingContent(new PackagingContentBuilder(this.DatabaseSession).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build()); } this.DatabaseSession.Derive(true); shipment.Ship(); this.DatabaseSession.Derive(true); Assert.AreEqual(100, item.QuantityShipped); item.QuantityOrdered = 90; var derivationLog = this.DatabaseSession.Derive(); Assert.IsTrue(derivationLog.HasErrors); }
public void GivenOrderItemWithPendingShipmentAndPendingPickList_WhenOrderItemIsCancelled_ThenPickListQuantityAndShipmentQuantityAreDecreased() { var inventoryItem = (NonSerializedInventoryItem)this.part.InventoryItemsWherePart.First; inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(10).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build()) .WithName("good1") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var good2inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good2).Build(); good2inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(10).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); this.InstantiateObjects(this.DatabaseSession); var item1 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(this.good) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); var item2 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(this.good) .WithQuantityOrdered(2) .WithActualUnitPrice(5) .Build(); var item3 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good2) .WithQuantityOrdered(7) .WithActualUnitPrice(5) .Build(); this.order.AddSalesOrderItem(item1); this.order.AddSalesOrderItem(item2); this.order.AddSalesOrderItem(item3); this.DatabaseSession.Derive(true); this.order.Confirm(); this.DatabaseSession.Derive(true); var shipment = (CustomerShipment)item1.OrderShipmentsWhereSalesOrderItem[0].ShipmentItem.ShipmentWhereShipmentItem; Assert.AreEqual(2, shipment.ShipmentItems.Count); Assert.AreEqual(5, shipment.ShipmentItems[0].Quantity); Assert.AreEqual(7, shipment.ShipmentItems[1].Quantity); var pickList = shipment.ShipmentItems[0].ItemIssuancesWhereShipmentItem[0].PickListItem.PickListWherePickListItem; Assert.AreEqual(5, pickList.PickListItems[0].RequestedQuantity); Assert.AreEqual(7, pickList.PickListItems[1].RequestedQuantity); item1.Cancel(); this.DatabaseSession.Derive(true); Assert.AreEqual(2, shipment.ShipmentItems.Count); Assert.AreEqual(2, shipment.ShipmentItems[0].Quantity); Assert.AreEqual(7, shipment.ShipmentItems[1].Quantity); Assert.AreEqual(2, pickList.PickListItems[0].RequestedQuantity); Assert.AreEqual(7, pickList.PickListItems[1].RequestedQuantity); item3.Cancel(); this.DatabaseSession.Derive(true); Assert.AreEqual(1, shipment.ShipmentItems.Count); Assert.AreEqual(2, shipment.ShipmentItems[0].Quantity); Assert.AreEqual(1, pickList.PickListItems.Count); Assert.AreEqual(2, pickList.PickListItems[0].RequestedQuantity); }
public void GivenBasePrice_WhenDeriving_ThenRequiredRelationsMustExist() { var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("gizmo") .WithSku("10101") .WithVatRate(vatRate21) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var colorFeature = new ColourBuilder(this.DatabaseSession) .WithName("golden") .WithVatRate(vatRate21) .WithLocalisedName(new LocalisedTextBuilder(this.DatabaseSession) .WithText("black") .WithLocale(Singleton.Instance(this.DatabaseSession).DefaultLocale) .Build()) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var builder = new BasePriceBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithPrice(1); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithProduct(good); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithProductFeature(colorFeature); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithFromDate(DateTime.UtcNow); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithDescription("description"); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenOrderItemForGoodWithoutSelectedInventoryItem_WhenConfirming_ThenReservedFromInventoryItemIsFromDefaultFacility() { this.InstantiateObjects(this.DatabaseSession); var good2PurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession) .WithCurrency(new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR")) .WithFromDate(DateTime.UtcNow) .WithPrice(7) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("10102") .WithVatRate(this.vatRate21) .WithName("good2") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); new SupplierRelationshipBuilder(this.DatabaseSession) .WithInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation")) .WithSupplier(this.supplier) .WithFromDate(DateTime.UtcNow) .Build(); new SupplierOfferingBuilder(this.DatabaseSession) .WithProduct(good2) .WithFromDate(DateTime.UtcNow) .WithSupplier(this.supplier) .WithProductPurchasePrice(good2PurchasePrice) .Build(); //// good with part as inventory item var item1 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(this.good) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); var item2 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good2) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); this.order.AddSalesOrderItem(item1); this.order.AddSalesOrderItem(item2); this.DatabaseSession.Derive(true); this.order.Confirm(); this.DatabaseSession.Derive(true); Assert.AreEqual(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"), item1.ReservedFromInventoryItem.Facility); Assert.AreEqual(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"), item2.ReservedFromInventoryItem.Facility); }
public void GivenCustomerWithUnpaidInvoices_WhenDeriving_ThenAmountOverDueIsUpdated() { var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build(); var customerRelationship = new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).Build(); var billToContactMechanism = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Mechelen").Build(); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build()) .WithName("good") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); this.DatabaseSession.Derive(true); var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .WithBillToCustomer(customer) .WithBillToContactMechanism(billToContactMechanism) .WithInvoiceDate(DateTime.UtcNow.AddDays(-30)) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(1).WithActualUnitPrice(100M).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build()) .Build(); this.DatabaseSession.Derive(true); var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .WithBillToCustomer(customer) .WithBillToContactMechanism(billToContactMechanism) .WithInvoiceDate(DateTime.UtcNow.AddDays(-5)) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(1).WithActualUnitPrice(200M).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build()) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(100M, customerRelationship.AmountOverDue); new ReceiptBuilder(this.DatabaseSession) .WithAmount(20) .WithPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(invoice1.SalesInvoiceItems[0]).WithAmountApplied(20).Build()) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(80, customerRelationship.AmountOverDue); invoice2.InvoiceDate = DateTime.UtcNow.AddDays(-10); this.DatabaseSession.Derive(true); Assert.AreEqual(280, customerRelationship.AmountOverDue); }