public void GivenSalesInvoice_WhenWrittenOff_ThenRevenueIsUpdated() { var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var contactMechanism = new PostalAddressBuilder(this.DatabaseSession) .WithAddress1("Haverwerf 15") .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession) .WithLocality("Mechelen") .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE")) .Build()) .Build(); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); internalOrganisation.PreferredCurrency = euro; var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build(); var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTimeFactory.CreateDate(2010, 01, 01)) .WithInvoiceNumber("1") .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithSalesChannel(new SalesChannels(this.DatabaseSession).WebChannel) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build(); var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build(); invoice1.AddSalesInvoiceItem(item1); this.DatabaseSession.Derive(true); invoice1.Send(); this.DatabaseSession.Derive(true); var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTimeFactory.CreateDate(2010, 01, 01)) .WithInvoiceNumber("2") .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithSalesChannel(new SalesChannels(this.DatabaseSession).WebChannel) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item2 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(1).WithActualUnitPrice(15).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build(); invoice2.AddSalesInvoiceItem(item2); this.DatabaseSession.Derive(true); var internalOrganisationRevenue = internalOrganisation.InternalOrganisationRevenuesWhereInternalOrganisation[0]; var storeRevenue = invoice1.Store.StoreRevenuesWhereStore[0]; var salesChannelRevenue = invoice1.SalesChannel.SalesChannelRevenuesWhereSalesChannel[0]; var productRevenue = good.ProductRevenuesWhereProduct[0]; var partyRevenue = customer.PartyRevenuesWhereParty[0]; var partypPrductRevenue = customer.PartyProductRevenuesWhereParty[0]; Assert.AreEqual(60, internalOrganisationRevenue.Revenue); Assert.AreEqual(2010, internalOrganisationRevenue.Year); Assert.AreEqual(60, storeRevenue.Revenue); Assert.AreEqual(2010, storeRevenue.Year); Assert.AreEqual(60, salesChannelRevenue.Revenue); Assert.AreEqual(2010, salesChannelRevenue.Year); Assert.AreEqual(60, productRevenue.Revenue); Assert.AreEqual(2010, productRevenue.Year); Assert.AreEqual(60, partyRevenue.Revenue); Assert.AreEqual(2010, partyRevenue.Year); Assert.AreEqual(60, partypPrductRevenue.Revenue); Assert.AreEqual(2010, partypPrductRevenue.Year); invoice2.WriteOff(); this.DatabaseSession.Derive(true); internalOrganisationRevenue = internalOrganisation.InternalOrganisationRevenuesWhereInternalOrganisation[0]; storeRevenue = invoice1.Store.StoreRevenuesWhereStore[0]; salesChannelRevenue = invoice1.SalesChannel.SalesChannelRevenuesWhereSalesChannel[0]; productRevenue = good.ProductRevenuesWhereProduct[0]; partyRevenue = customer.PartyRevenuesWhereParty[0]; partypPrductRevenue = customer.PartyProductRevenuesWhereParty[0]; Assert.AreEqual(45, internalOrganisationRevenue.Revenue); Assert.AreEqual(2010, internalOrganisationRevenue.Year); Assert.AreEqual(45, storeRevenue.Revenue); Assert.AreEqual(2010, storeRevenue.Year); Assert.AreEqual(45, salesChannelRevenue.Revenue); Assert.AreEqual(2010, salesChannelRevenue.Year); Assert.AreEqual(45, productRevenue.Revenue); Assert.AreEqual(2010, productRevenue.Year); Assert.AreEqual(45, partyRevenue.Revenue); Assert.AreEqual(2010, partyRevenue.Year); Assert.AreEqual(45, partypPrductRevenue.Revenue); Assert.AreEqual(2010, partypPrductRevenue.Year); }
public void GivenSalesInvoice_WhenObjectStateIsWrittenOff_ThenCheckTransitions() { var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build(); var contactMechanism = new PostalAddressBuilder(this.DatabaseSession) .WithAddress1("Haverwerf 15") .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession) .WithLocality("Mechelen") .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE")) .Build()) .Build(); var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("administrator").Build(); var administrators = new UserGroups(this.DatabaseSession).Administrators; administrators.AddMember(administrator); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("administrator", "Forms"), new string[0]); var invoice = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceNumber("1") .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .WithBilledFromInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation")) .Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build(); invoice.Send(); invoice.WriteOff(); this.DatabaseSession.Derive(true); var acl = new AccessControlList(invoice, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsFalse(acl.CanExecute(SalesInvoices.Meta.Send)); Assert.IsFalse(acl.CanExecute(SalesInvoices.Meta.WriteOff)); Assert.IsFalse(acl.CanExecute(SalesInvoices.Meta.CancelInvoice)); }